1
1
Fork 0
scripts/main

75 lines
1.5 KiB
Plaintext

# bashlib, main file
#
# frequently used functions for
# pretty much every bash scripts
# **** help ****
#
# amiroot
# usage: amiroot <options>
# examples:
# amiroot (will end script if you are not root)
# amiroot not (will end script if you are root)
#
# gettimestamp
# generates different kinds of timestamps
# usage: gettimestamp <options>
# examples:
# gettimestamp
# gettimestamp nice
# gettimestamp short
#
# bashtrap
# usage: trap bashtrap INT
#
# **** check for root privileges ****
amiroot()
{
local user=$(whoami)
case $1 in
not) #not needed
log debug "amiroot - checking for unnecessary root privileges" #debug log
if [ "$(whoami)" = "root" ]; then
log error "amiroot - you probably should not run this as root. it could mess up your karma."
exit 1
fi
;;
*) #required
log debug "amiroot - checking for necessary root privileges" #debug log
if [ "$(whoami)" != "root" ]; then
log error "amiroot - $USER, you need to gain root privileges to do this."
exit 1;
fi
;;
esac
}
# **** generate timestamp ****
gettimestamp()
{
if [ -z $1 ]; then
date '+%Y%m%d%H%M'
elif [ $1 = "nice" ]; then
date '+%d.%m.%Y %H:%M'
elif [ $1 = "short" ]; then
date '+%Y%m%d'
fi
}
# **** bashtrap ****
bashtrap()
{
log debug "bashtrap - triggered"
clear
echo "CTRL+C detected.. exiting!"
exit 1
}