--- mcore-src/trunk/mcore-tools/daemon/client/include/system.client.class 2011/02/02 20:20:24 1248 +++ mcore-src/trunk/mcore-tools/daemon/client/include/system.client.class 2011/02/04 20:05:37 1262 @@ -5,7 +5,7 @@ help_system_reboot() { mecho "set system.reboot" - mecho " reboots the system." + mecho " Reboots the system." } # set_system_reboot @@ -17,7 +17,7 @@ help_system_shutdown() { mecho "set system.shutdown" - mecho " shuts the system down." + mecho " Shuts the system down." } # set_system_shutdown @@ -28,23 +28,111 @@ help_system_console() { - mecho "set system.console" - mecho " opens a console with user privileges." + mecho "set system.console [user]" + mecho " Opens a console with user or root privileges." + mecho " Known users:" + mecho " mcore - mcore standard user only with user privileges" + mecho " root - mcore root user with full system privileges" +} + +help_system_passwd() +{ + mecho "set system.passwd [user] [password]" + mecho " Sets a system password for given user." + mecho " Allowed users: mcore, root" + mecho " If password is empty, the current password will be deleted." } set_system_console() { - x11runas "DISPLAY=:0 rxvt" + local user="$1" + [[ -z ${user} ]] && help_system_console && return 1 + + case "${user}" in + mcore) x11runas "rxvt &" ;; + root) x11runas "rxvt -T 'Login as root' -e /bin/bash -c 'echo \"Login as root\";exec /bin/login root' &" ;; + *) help_system_console && return 1 ;; + esac +} + +help_system_service() +{ + mecho "set system.service [command] [service] [opts]" + mecho " Controls system services." + mecho " Commands:" + mecho " start - starts given service" + mecho " stop - stops given service" + mecho " restart - restart given service" + mecho " reload - reloads given service if possible" + mecho " add - adds a service to default runlevels" + mecho " del - deletes a service from all runlevels" +} + +set_system_service() +{ + local command="$1" + local service="$2" + local opts="$3" + + [[ -z ${command} ]] && help_system_service && return 1 + [[ -z ${service} ]] && help_system_service && return 1 + + if [[ ! -x /etc/rc.d/init.d/${service} ]] + then + mecho "Service '${service}' unkown!" + fi + + case "${command}" in + start) /etc/rc.d/init.d/"${service}" start ;; + stop) /etc/rc.d/init.d/"${service}" stop ;; + restart) /etc/rc.d/init.d/"${service}" restart ;; + reload) /etc/rc.d/init.d/"${service}" reload ;; + add) rc-config add "${service}" ;; + del) rc-config del "${service}" ;; + *) help_system_service && return ;; + esac +} + +set_system_passwd() +{ + local user="$1" + local pass="$2" + + [[ -z ${user} ]] && help_system_passwd && return 1 + [[ -z ${pass} ]] && mecho "deleting password!" + + case "${user}" in + root|mcore) (echo "${pass}"; sleep 0.1; echo "${pass}") | passwd "${user}" ;; + *) help_system_passwd && return 1 ;; + esac +} + +help_system_vt() +{ + mecho "get system.vt" + mecho " Prints tty number of the current vt terminal." + mecho + mecho "set system.vt [tty]" + mecho " Change current vt terminal to given tty." + mecho " Valid tty numbers are 1-9." } -help_system_rootconsole() +set_system_vt() { - mecho "set system.rootconsole" - mecho " opens a console with system privileges." + local tty="$1" + [[ -z ${tty} ]] && help_system_vt && return 1 + case "${tty}" in + [1-9]) + chvt "${tty}" + mecho "current vt changed to ${tty}." + ;; + *) help_system_vt && return 1 ;; + esac } -# opens a root console -set_system_rootconsole() +get_system_vt() { - x11runas "DISPLAY=:0 rxvt -e '/bin/login -f root" + local tty + tty="$(fgconsole)" + mecho "${tty}" }