This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# convert a string to lower characters | |
# @param string input | |
function strtolower() | |
{ | |
[ -z "$1" ] && return 1 | |
printf "%s\\n" "$@" | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' # tr '[:upper:]' '[:lower:]' | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# remove lines with certain strings from crontab | |
# @param string search | |
rmcron() | |
{ #remove cron job, returns 1 on error | |
[ -z "$1" ] && return 1 | |
crontab -l | grep -v "$1" | crontab | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# check if port is a num and if it's privated (<1025), returns 0 on success, 1 otherwise | |
# @param int portnumber | |
function isprivport() | |
{ | |
[ -z "$1" ] && return 1 | |
printf "%s\\n" "$1" | grep -v "[^0-9]" >/dev/null | |
if [ $? -eq 0 ]; then | |
[ $1 -gt 0 ] && [ $1 -lt 1025 ] && return 0 || return 1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# returns 0 if string is a number | |
# @param string input | |
function isnumber() | |
{ #look for a number, returns 0 on success, 1 otherwise | |
[ -z "$1" ] && return 1 | |
printf "%s\\n" "$@" | grep -v "[^0-9]" >/dev/null | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# compare the dates of two files, return true (0) if file1 has | |
# been modified more recently otherwise 1 | |
# @param string file1 | |
# @param string file2 | |
function is_newer() | |
{ | |
[ $# -ne 2 ] && return 1 | |
if [ ! -f $1 ] || [ ! -f $2 ]; then | |
return 1 # No |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# returns 0 if monitor is attached | |
function ismonitorattached() | |
{ | |
xrandr | grep "^VGA" | grep " connected" >/dev/null && return 0 | |
xrandr | grep "^HDMI" | grep " connected" >/dev/null && return 0 | |
return 1 | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# detect a livecd system, return 0 on success, 1 otherwise | |
function islivecd() | |
grep boot=live /proc/cmdline >/dev/null && return 0 | |
grep boot=casper /proc/cmdline >/dev/null && return 0 | |
return 1 | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# detect if arg is an empty file, returns 0 on sucess, 1 otherwise | |
# @param string file | |
function isemptyfile() | |
{ [ -z "$1" ] && return 1 | |
if [ -f "$1" ] && [ X"$(wc -c "$1" | cut -d" " -f1)" = X"0" ]; then | |
return 0 | |
else | |
return 1 | |
fi |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# return distro name in a lower string | |
function getdistro() | |
{ | |
_distro_var_DIST_INFO="/etc/lsb-release" | |
if [ -r "$_distro_var_DIST_INFO" ]; then | |
. "$_distro_var_DIST_INFO" | |
fi | |
if [ -z "$DISTRIB_ID" ]; then |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# print a stacktrace with a msg, exits with 1 | |
function stacktrace() | |
{ | |
if [ -n "$BASH" ]; then | |
_die_var_frame=0 | |
while caller $_die_var_frame; do | |
_die_var_frame=$(expr $_die_var_frame + 1); | |
done | |
fi |