moved journal.sh to archive and joined all former bashlib files in on file(just for future reference)
This commit is contained in:
parent
24a0c36f6f
commit
121e84fc36
|
@ -1,9 +1,119 @@
|
|||
# bashlib
|
||||
# frequently used shell/bash functions
|
||||
|
||||
# socialnerds log engine for bash/shell scripts
|
||||
#
|
||||
# version: 0.1a
|
||||
# author: david@socialnerds.org
|
||||
|
||||
# **** 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
|
||||
}
|
||||
|
||||
|
||||
# this gives your bash scripts the ability to get updated
|
||||
# basically it does a simple git pull
|
||||
|
||||
# **** help ****
|
||||
# global vars needed: $repopath, $bashlibpath
|
||||
# it depends on bashlib
|
||||
|
||||
|
||||
# **** update (git pull) ****
|
||||
update()
|
||||
{
|
||||
|
||||
# checking for root privileges
|
||||
amiroot
|
||||
|
||||
# update start message
|
||||
log info "update - starting update of $logwhat and bashlib"
|
||||
|
||||
# bashlib update
|
||||
cd $bashlibpath
|
||||
git pull origin master | grep "files changed"
|
||||
local returncode=$?
|
||||
if [ $returncode = "0" ]; then
|
||||
log info "update - bashlib has been updated"
|
||||
else
|
||||
log info "update - bashlib is already up-to-date"
|
||||
fi
|
||||
|
||||
# update
|
||||
cd $repopath
|
||||
git pull origin master | grep "files changed"
|
||||
local returncode=$?
|
||||
if [ $returncode = "0" ]; then
|
||||
log info "update - $logwhat has been updated"
|
||||
else
|
||||
log info "update - $logwhat is already up-to-date"
|
||||
fi
|
||||
|
||||
}
|
||||
|
||||
|
||||
# **** dialog helper ****
|
||||
graph()
|
||||
{
|
||||
local bgtitle="kvm-tools $version | $1"
|
||||
|
||||
if [ $2 = "--inputbox" ]; then
|
||||
local size="7 80"
|
||||
elif [ $2 = "--yesno" ]; then
|
||||
local size="20 80"
|
||||
elif [ $2 = "--fselect" ]; then
|
||||
local size="12 80"
|
||||
else
|
||||
local size="20 80 14"
|
||||
fi
|
||||
|
||||
dialog --backtitle "$bgtitle" --no-cancel "$2" "$3" $size $4 2> /tmp/dialog
|
||||
local returncode=$?
|
||||
clear
|
||||
dialogresult=$(cat /tmp/dialog)
|
||||
rm /tmp/dialog
|
||||
return $returncode
|
||||
|
||||
}
|
||||
|
||||
|
||||
# log engine
|
||||
|
||||
# **** help ****
|
||||
# this is basically a collection of bash functions
|
||||
|
@ -152,4 +262,3 @@ log()
|
|||
|
||||
}
|
||||
|
||||
# end of file
|
53
dialog
53
dialog
|
@ -1,53 +0,0 @@
|
|||
#!/bin/bash
|
||||
|
||||
#
|
||||
# dialog helper
|
||||
#
|
||||
|
||||
dh()
|
||||
{
|
||||
local bgtitle="kvm-tools $version | $1"
|
||||
|
||||
if [ $2 = "--inputbox" ]; then
|
||||
local size="7 80"
|
||||
elif [ $2 = "--yesno" ]; then
|
||||
local size="20 80"
|
||||
elif [ $2 = "--fselect" ]; then
|
||||
local size="12 80"
|
||||
else
|
||||
local size="20 80 14"
|
||||
fi
|
||||
|
||||
dialog --backtitle "$bgtitle" --no-cancel "$2" "$3" $size $4 2> /tmp/dialog
|
||||
local returncode=$?
|
||||
clear
|
||||
dialogresult=$(cat /tmp/dialog)
|
||||
rm /tmp/dialog
|
||||
return $returncode
|
||||
|
||||
}
|
||||
|
||||
|
||||
# this is still needed by kvm-tools
|
||||
graph()
|
||||
{
|
||||
local bgtitle="kvm-tools $version | $1"
|
||||
|
||||
if [ $2 = "--inputbox" ]; then
|
||||
local size="7 80"
|
||||
elif [ $2 = "--yesno" ]; then
|
||||
local size="20 80"
|
||||
elif [ $2 = "--fselect" ]; then
|
||||
local size="12 80"
|
||||
else
|
||||
local size="20 80 14"
|
||||
fi
|
||||
|
||||
dialog --backtitle "$bgtitle" --no-cancel "$2" "$3" $size $4 2> /tmp/dialog
|
||||
local returncode=$?
|
||||
clear
|
||||
dialogresult=$(cat /tmp/dialog)
|
||||
rm /tmp/dialog
|
||||
return $returncode
|
||||
|
||||
}
|
74
main
74
main
|
@ -1,74 +0,0 @@
|
|||
|
||||
# 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
|
||||
}
|
||||
|
||||
|
39
update
39
update
|
@ -1,39 +0,0 @@
|
|||
# this gives your bash scripts the ability to get updated
|
||||
# basically it does a simple git pull
|
||||
|
||||
# **** help ****
|
||||
# global vars needed: $repopath, $bashlibpath
|
||||
# it depends on bashlib
|
||||
|
||||
|
||||
# **** update (git pull) ****
|
||||
update()
|
||||
{
|
||||
|
||||
# checking for root privileges
|
||||
amiroot
|
||||
|
||||
# update start message
|
||||
log info "update - starting update of $logwhat and bashlib"
|
||||
|
||||
# bashlib update
|
||||
cd $bashlibpath
|
||||
git pull origin master | grep "files changed"
|
||||
local returncode=$?
|
||||
if [ $returncode = "0" ]; then
|
||||
log info "update - bashlib has been updated"
|
||||
else
|
||||
log info "update - bashlib is already up-to-date"
|
||||
fi
|
||||
|
||||
# update
|
||||
cd $repopath
|
||||
git pull origin master | grep "files changed"
|
||||
local returncode=$?
|
||||
if [ $returncode = "0" ]; then
|
||||
log info "update - $logwhat has been updated"
|
||||
else
|
||||
log info "update - $logwhat is already up-to-date"
|
||||
fi
|
||||
|
||||
}
|
Loading…
Reference in New Issue