# ****************************************************************************
# * functions.sh *
# * -------------------- *
# * Copyright (C) 2001-2011 Markus Kohlmeyer <rootservice@gmail.com> *
# * *
# ****************************************************************************
# * *
# * License GPLv2: GNU GPL version 2 <http://gnu.org/licenses/gpl.html> *
# * This is free software: You are free to change and redistribute *
# * it under the terms of the GNU General Public License version 2 *
# * There is NO WARRANTY, to the extent permitted by law *
# * *
# ****************************************************************************
#
function getopt_simple() {
until [ -z "${1}" ]
do
case "${1}" in
--*=*)
local tmpopt="${1:2}"
local cmdopt="${tmpopt%%=*}"
local cmdval="${tmpopt##*=}"
for allowed in "${ALLOWEDOPTS[@]}"
do
if [ "${allowed}" = "${cmdopt}" ]
then
eval ${cmdopt}="${cmdval}"
fi
done
;;
--version|-V) show_version;;
--help|-h|*) show_usage;;
esac
shift
done
return
}
function getopt_arrays() {
until [ -z "${1}" ]
do
case "${1}" in
--*=*)
local tmpopt="${1:2}"
local cmdopt="${tmpopt%%=*}"
local cmdval="${tmpopt##*=}"
for allowed in "${ALLOWEDOPTS[@]}"
do
if [ "${allowed}" = "${cmdopt}" ]
then
cmdopts_arr=( "${cmdopts_arr[@]}" "${tmpopt}" )
cmdopt_arr=( "${cmdopt_arr[@]}" "${cmdopt}" )
cmdval_arr=( "${cmdval_arr[@]}" "${cmdval}" )
fi
done
;;
--version|-V) show_version;;
--help|-h|*) show_usage;;
esac
shift
done
return
}
function read_prompt() {
read -p "$(echo -en "\E[1;37m${1}\E[0m " >&2)" "${2:-REPLY}"
# until [ -z $(echo "${2:-REPLY}" | tr -d [:print:]) ]
# do
# show_warn "non-printable char(s) detected! Please retry...\n"
# read_prompt "${1}" "${2}"
# done
return
}
function read_passwd() {
read -s -p "$(echo -en "\E[1;37m${1}\E[0m " >&2)" "${2:-REPLY}"
# until [ -z $(echo "${2:-REPLY}" | tr -d [:print:]) ]
# do
# show_warn "non-printable char(s) detected! Please retry...\n"
# read_prompt "${1}" "${2}"
# done
return
}
function show_text() {
echo -en "\E[1;37m${1}\E[0m" >&2
return
}
function show_info() {
echo -en "\E[1;32m${1}\E[0m" >&2
return
}
function show_warn() {
echo -en "\E[1;33m${1}\E[0m" >&2
return
}
function show_error() {
echo -en "\E[1;31m${1}\E[0m" >&2
return
}
function show_usage() {
echo "Usage: $(basename ${0}) [OPTIONS]
OPTIONS:
${USAGEOPTIONS}
--help display this help and exit
--version output version information and exit
Report any bugs to: ${CONTACT}
" >&2
exit 1
}
function show_version() {
echo "$(basename ${0}) ${VERSION}
${COPYRIGHT}
License GPLv2: GNU GPL version 2 <http://gnu.org/licenses/gpl.html>
This is free software: You are free to change and redistribute
it under the terms of the GNU General Public License version 2.
There is NO WARRANTY, to the extent permitted by law.
Written by ${AUTHORS}
" >&2
exit 1
}
function rootonly() {
if [ "${UID}" != "0" ] || [ "${EUID}" != "0" ]
then
show_error "You must be root to run this script!"
fi
return
}