2013-03-22 10:15:50 -07:00
|
|
|
|
|
|
|
# Check to see if a command exists
|
|
|
|
function command_exists {
|
|
|
|
command -v "$1" &> /dev/null
|
|
|
|
}
|
|
|
|
|
2013-03-22 18:13:45 -07:00
|
|
|
# log to a central logfile (specified by its caller globally)
|
2013-03-22 10:15:50 -07:00
|
|
|
function do_log {
|
|
|
|
printf "[%s] %s: %s" "$(`basename $BASH_SOURCE`)" "`date`" "$1" >> $logfile
|
|
|
|
}
|
|
|
|
|
2013-03-22 18:13:45 -07:00
|
|
|
# Check if a symlink exists before trying to create it
|
2013-03-22 10:15:50 -07:00
|
|
|
function do_link {
|
2013-03-23 00:44:56 -07:00
|
|
|
if [ -e "$2" ]; then
|
|
|
|
rm -rf "$2"
|
2013-03-22 10:15:50 -07:00
|
|
|
fi
|
2013-03-22 18:13:45 -07:00
|
|
|
if [ ! -e "$2" ]; then
|
|
|
|
ln -sf "$1" "$2"
|
|
|
|
fi
|
2013-03-22 10:15:50 -07:00
|
|
|
}
|
2013-03-22 18:10:59 -07:00
|
|
|
|
2013-10-21 01:17:36 -07:00
|
|
|
# Ask for admin password up front and keep sudo alive until the end of the script
|
|
|
|
function keep_alive {
|
|
|
|
sudo -v
|
|
|
|
while true; do sudo -n true; sleep 60; kill -0 "$$" || exit; done 2>/dev/null &
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-03-22 18:10:59 -07:00
|
|
|
# vim:set ft=zsh:
|