--- mcore-src/trunk/mcore-tools/daemon/client/include/system.client.class 2013/05/10 10:45:18 2075 +++ mcore-src/trunk/mcore-tools/daemon/client/include/system.client.class 2013/05/10 13:17:18 2087 @@ -1,6 +1,7 @@ # $Id$ provide basic-system +require basic-init help_system_reboot() { @@ -35,14 +36,6 @@ 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_UNPRIV_USER}, root" - mecho " If password is empty, the current password will be deleted." -} - help_system_autologon() { mecho "get system.autologon" @@ -60,6 +53,12 @@ local user="$1" [[ -z ${user} ]] && help_system_console && return 1 + if [[ -n ${MROOT} ]] && [[ ${MROOT} != / ]] + then + eecho "command not available while \$MROOT is set." + return 1 + fi + case "${user}" in ${MCORE_UNPRIV_USER}) x11runas "rxvt &" ;; root) x11runas "rxvt -T 'Login as root' -e /bin/bash -c 'echo \"Login as root\";exec /bin/login root' &" ;; @@ -87,120 +86,12 @@ mecho " del - deletes a service from all runlevels" } -helper_set_system_service_sysvinit() -{ - 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 ${MROOT}/etc/rc.d/init.d/${service} ]] - then - eecho "Service '${service}' unkown!" - return 1 - 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 -} - -helper_set_system_service_systemd() -{ - local command="$1" - local service="$2" - local opts="$3" - - [[ -z ${command} ]] && help_system_service && return 1 - [[ -z ${service} ]] && help_system_service && return 1 - - if [[ -n $(systemctl status ${service} | grep 'Reason: No such file or directory') ]] - then - eecho "Service '${service}' unkown!" - return 1 - fi - - case "${command}" in - start) systemctl start "${service}" ;; - stop) systemctl stop "${service}" ;; - restart) systemctl try-restart "${service}" ;; - reload) systemctl reload-or-try-restart "${service}" ;; - add) systemctl enable "${service}" ;; - del) systemctl disable "${service}" ;; - *) help_system_service && return ;; - esac -} - -set_system_service() -{ - if [[ -x $(type -P systemctl) ]] - then - helper_set_system_service_systemd $* - else - helper_set_system_service_sysvinit $* - fi -} - -helper_get_system_service_sysvinit() -{ - local command="$1" - local service="$2" - - [[ -z ${command} ]] && help_system_service && return 1 - [[ -z ${service} ]] && help_system_service && return 1 - - if [[ ! -x ${MROOT}/etc/rc.d/init.d/${service} ]] - then - eecho "Service '${service}' unkown!" - return 1 - fi - - case "${command}" in - status) /etc/rc.d/init.d/"${service}" status ;; - enabled) rc-config show "${service}" ;; - runlevel) eecho "function on todo" ;; - *) help_system_service && return ;; - esac -} - -helper_get_system_service_systemd() -{ - local command="$1" - local service="$2" - - [[ -z ${command} ]] && help_system_service && return 1 - [[ -z ${service} ]] && help_system_service && return 1 - - if [[ -n $(systemctl status ${service} | grep 'Reason: No such file or directory') ]] - then - eecho "Service '${service}' unkown!" - return 1 - fi - - case "${command}" in - status) systemctl status "${service}" ;; - enabled) systemctl is-enabled "${service}"; rvecho "$?" ;; - runlevel) rvecho "$(readline ${MROOT}/etc/systemd/system/default.target)" ;; - *) help_system_service && return ;; - esac -} - -get_system_service() +help_system_passwd() { - if [[ -x $(type -P systemctl) ]] - then - helper_get_system_service_systemd $* - else - helper_get_system_service_sysvinit $* - fi + mecho "set system.passwd [user] [password]" + mecho " Sets a system password for given user." + mecho " Allowed users: ${MCORE_UNPRIV_USER}, root" + mecho " If password is empty, the current password will be deleted." } set_system_passwd() @@ -211,8 +102,14 @@ [[ -z ${user} ]] && help_system_passwd && return 1 [[ -z ${pass} ]] && mecho "deleting password!" + local chrooted + if [[ -n ${MROOT} ]] && [[ ${MROOT} != / ]] + then + chrooted="system_chroot" + fi + case "${user}" in - root|${MCORE_UNPRIV_USER}) (echo "${pass}"; sleep 0.1; echo "${pass}") | passwd "${user}" ;; + root|${MCORE_UNPRIV_USER}) (echo "${pass}"; sleep 0.1; echo "${pass}") | ${chrooted} passwd "${user}" ;; *) help_system_passwd && return 1 ;; esac } @@ -250,7 +147,7 @@ get_system_autologon() { local var - var=$(grep auto_login /etc/slim.conf | sed 's:auto_login.*\([yn].*\):\1:') + var=$(grep auto_login ${MROOT}/etc/slim.conf | sed 's:auto_login.*\([yn].*\):\1:') case "${var}" in yes) mecho "autologon currently enabled"; rvecho "1" ;; no) mecho "autologon currently disabled"; rvecho "0" ;; @@ -267,11 +164,11 @@ case "${action}" in enable) - sed -i 's:^\(auto_login\).*:\1\tyes:' /etc/slim.conf + sed -i 's:^\(auto_login\).*:\1\tyes:' ${MROOT}/etc/slim.conf mecho "autologon enabled" ;; disable) - sed -i 's:^\(auto_login\).*:\1\tno:' /etc/slim.conf + sed -i 's:^\(auto_login\).*:\1\tno:' ${MROOT}/etc/slim.conf mecho "autologon disabled" ;; *) help_system_autologon && return 1 ;;