# $Id$ # import_resource $table $serial $resource $value import_resource() { local table="$1" local serial="$2" local resource="$3" local value="$4" if [[ ${DEBUG} = 1 ]] then echo "${table}->${resource}=${value}" >> /root/lala.log echo "mysqldo \"update ${table} set ${resource}='${value}' where serial=${serial};\"" >> /root/lala.log fi mysql_insert "${table}",serial="${serial}","${resource}"="${value}" } # run_class $method $caller $argv1 $argv2 ... $argvN run_class() { local method="$1" local caller="$2" local class local cmd local argv if validate_session then class="${caller%.*}" cmd="${caller#*.}" argv="${@/${caller}/}" # remove caller argv="${argv/${method}/}" # remove method # echo "method=${method}" # echo "caller=${caller}" # echo "class=${class}" # echo "cmd=${cmd}" # echo "argv=${argv}" # check if class.cmd exist if [[ ! -z $(typeset -f "${method}"_"${class}"_"${cmd}") ]] then "${method}"_"${class}"_"${cmd}" ${argv} else echo "unkown method '${method}' . class '${class}' . cmd '${cmd}'" fi else invalid_session fi } help_topics() { local i local topics topics=$(typeset -f | grep '^help_' | sed 's:help_\(.*\)\ .*():\1:' | sed 's:_:\.:' | sort) mecho "Global commands:" mecho "\timport - import settings to database" mecho "\tget - shows current value for a settings" mecho "\tset - sets value for a setting" mecho "\tauth - authenticate to the daemon" mecho "\tprovide - shows provides of a system" mecho "\thelp - shows help" mecho mecho "Help topics:" for i in ${topics} do # excludes case ${i} in help_topics|topics) continue ;; esac mecho "\t${i}" done } # on newer xorg-servers root is not allowed to run progs in a user session x11runas() { su - "${MCORE_UNPRIV_USER}" -c "$@" } addconfig() { if [[ -z ${CONFIG} ]] then echo "You must define \$CONFIG varibale first!" return 1 fi if [[ ! -d $(dirname ${CONFIG}) ]] then install -d $(dirname ${CONFIG}) fi echo "$@" >> ${CONFIG} } clearconfig() { if [[ -z ${CONFIG} ]] then echo "You must define \$CONFIG varibale first!" return 1 fi : > ${CONFIG} } require() { local requires="$@" local i for i in ${requires} do export REQUIRE="${REQUIRE} ${i}" done } not_provided() { local i local item="$1" for i in ${PROVIDE} do [[ ${i} = ${item} ]] && return 1 done return 0 } provide() { local provides="$@" local i for i in ${provides} do # check for duplicate provides if not_provided "${i}" then export PROVIDE="${PROVIDE} ${i}" else [[ ${DEBUG} = 1 ]] && echo "duplicate provide '${i}' detected!" fi done } print_provide() { local sorted # sort them alpabetically sorted=$(for i in ${PROVIDE}; do echo "${i}"; done | sort) # do not escape, or CRLFS get printed to screen too mecho ${sorted} } mecho() { local COLCYAN="\033[1;36m" local COLDEFAULT="\033[0m" if [[ ${NOCOLORS} = true ]] then COLCYAN="" COLDEFAULT="" fi echo -e "${COLCYAN}$@${COLDEFAULT}" }