update template
This commit is contained in:
parent
a6a755042d
commit
6ed92abe63
73
script.sh
Normal file
73
script.sh
Normal file
|
@ -0,0 +1,73 @@
|
|||
#! /bin/bash
|
||||
|
||||
#
|
||||
## DESCRIPTION:
|
||||
# returning current username if privileged rights are exist
|
||||
# or
|
||||
# returning error, if privileged rights are not exist
|
||||
#
|
||||
|
||||
#
|
||||
## DEPENDENCIES: sudo apt|yum install -y whoami
|
||||
#
|
||||
|
||||
#
|
||||
## FUNCTIONS
|
||||
#
|
||||
|
||||
execpause() {
|
||||
read -p "Press [ENTER] to continue... "
|
||||
}
|
||||
execquite() {
|
||||
echo "$(date +'%Y.%m.%d-%H:%M:%S') execution time is $(($(date +%s)-$time)) seconds, exit" | tee -a $logs
|
||||
if [ "${show}" != "qn" ];then
|
||||
execpause
|
||||
fi
|
||||
exit
|
||||
}
|
||||
execerror() {
|
||||
echo "$(date +'%Y.%m.%d-%H:%M:%S') error: $1" | tee -a $logs
|
||||
execquite
|
||||
}
|
||||
getconfig() {
|
||||
logs=$(cat $conf | grep "logs=" | cut -d= -f2)
|
||||
}
|
||||
checkroot() {
|
||||
if [ "${EUID}" -ne 0 ];then
|
||||
return 1 # false
|
||||
else
|
||||
return 0 # true
|
||||
fi
|
||||
}
|
||||
|
||||
#
|
||||
## PARAMETERS
|
||||
#
|
||||
|
||||
show=${1}
|
||||
conf=${2}
|
||||
if [ -z "${conf}" ] || [ "${conf}" == "-" ];then
|
||||
conf=$(dirname $(realpath $0))/$(basename -s .sh $0).conf
|
||||
fi
|
||||
|
||||
#
|
||||
## VARIABLES
|
||||
#
|
||||
|
||||
time=$(date +%s)
|
||||
if [ ! -e ${conf} ];then
|
||||
:
|
||||
else
|
||||
getconfig
|
||||
fi
|
||||
if [ -z "${logs}" ];then
|
||||
logs=/dev/null
|
||||
elif [ ! -e ${logs} ];then
|
||||
touch ${logs}
|
||||
fi
|
||||
|
||||
#
|
||||
## RUN
|
||||
#
|
||||
|
||||
checkroot && echo "Running as $(whoami)" && execquite || execerror "Restart this as root!"
|
Loading…
Reference in New Issue
Block a user