79 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			Bash
		
	
	
	
	
	
			
		
		
	
	
			79 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			Bash
		
	
	
	
	
	
#! /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
 | 
						|
#
 | 
						|
 | 
						|
addtologs() {
 | 
						|
	echo "$(date +'%Y.%m.%d-%H:%M:%S') $1" | tee -a $logs
 | 
						|
}
 | 
						|
 | 
						|
execpause() {
 | 
						|
	read -p "Press [ENTER] to continue... "
 | 
						|
}
 | 
						|
execquite() {
 | 
						|
	addtologs "execution time is $(($(date +%s)-$time)) seconds, exit"
 | 
						|
	if [ "${show}" != "qn" ];then
 | 
						|
		execpause
 | 
						|
	fi
 | 
						|
	exit
 | 
						|
}
 | 
						|
execerror() {
 | 
						|
	addtologs "error: $1"
 | 
						|
	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)
 | 
						|
cd "$(dirname "$(realpath "$0")")"
 | 
						|
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!"
 |