Magellan Linux

Contents of /mcore-src/trunk/mcore-tools/daemon/client/include/system.client.class

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2090 - (show annotations) (download)
Fri May 10 13:37:51 2013 UTC (10 years, 11 months ago) by niro
File size: 4023 byte(s)
-use enable|disable commands to add|remove services from runlevels
1 # $Id$
2
3 provide basic-system
4 require basic-init
5
6 help_system_reboot()
7 {
8 mecho "set system.reboot"
9 mecho " Reboots the system."
10 }
11
12 # set_system_reboot
13 set_system_reboot()
14 {
15 reboot
16 }
17
18 help_system_shutdown()
19 {
20 mecho "set system.shutdown"
21 mecho " Shuts the system down."
22 }
23
24 # set_system_shutdown
25 set_system_shutdown()
26 {
27 poweroff
28 }
29
30 help_system_console()
31 {
32 mecho "set system.console [user]"
33 mecho " Opens a console with user or root privileges."
34 mecho " Known users:"
35 mecho " ${MCORE_UNPRIV_USER} - mcore standard user only with user privileges"
36 mecho " root - mcore root user with full system privileges"
37 }
38
39 help_system_autologon()
40 {
41 mecho "get system.autologon"
42 mecho " Shows the state of autlogon"
43 mecho
44 mecho "set system.autologon [action]"
45 mecho " Enables or disables X11 autologins of the mcore user."
46 mecho " Available actions:"
47 mecho " enable - enables autologon"
48 mecho " disable - disables autologon"
49 }
50
51 set_system_console()
52 {
53 local user="$1"
54 [[ -z ${user} ]] && help_system_console && return 1
55
56 if [[ -n ${MROOT} ]] && [[ ${MROOT} != / ]]
57 then
58 eecho "command not available while \$MROOT is set."
59 return 1
60 fi
61
62 case "${user}" in
63 ${MCORE_UNPRIV_USER}) x11runas "rxvt &" ;;
64 root) x11runas "rxvt -T 'Login as root' -e /bin/bash -c 'echo \"Login as root\";exec /bin/login root' &" ;;
65 *) help_system_console && return 1 ;;
66 esac
67 }
68
69 help_system_service()
70 {
71 mecho "get system.service [command] [service]"
72 mecho " Status information of system services."
73 mecho " Commands:"
74 mecho " status - prints status of given service"
75 mecho " enabled - check whether a service was enabled"
76 mecho " runlevel - print current system runlevel"
77 mecho
78 mecho "set system.service [command] [service] [opts]"
79 mecho " Controls system services."
80 mecho " Commands:"
81 mecho " start - starts given service"
82 mecho " stop - stops given service"
83 mecho " restart - restart given service"
84 mecho " reload - reloads given service if possible"
85 mecho " enable - adds a service to default runlevels"
86 mecho " disable - deletes a service from all runlevels"
87 }
88
89 help_system_passwd()
90 {
91 mecho "set system.passwd [user] [password]"
92 mecho " Sets a system password for given user."
93 mecho " Allowed users: ${MCORE_UNPRIV_USER}, root"
94 mecho " If password is empty, the current password will be deleted."
95 }
96
97 set_system_passwd()
98 {
99 local user="$1"
100 local pass="$2"
101
102 [[ -z ${user} ]] && help_system_passwd && return 1
103 [[ -z ${pass} ]] && mecho "deleting password!"
104
105 local chrooted
106 if [[ -n ${MROOT} ]] && [[ ${MROOT} != / ]]
107 then
108 chrooted="system_chroot"
109 fi
110
111 case "${user}" in
112 root|${MCORE_UNPRIV_USER}) (echo "${pass}"; sleep 0.1; echo "${pass}") | ${chrooted} passwd "${user}" ;;
113 *) help_system_passwd && return 1 ;;
114 esac
115 }
116
117 help_system_vt()
118 {
119 mecho "get system.vt"
120 mecho " Prints tty number of the current vt terminal."
121 mecho
122 mecho "set system.vt [tty]"
123 mecho " Change current vt terminal to given tty."
124 mecho " Valid tty numbers are 1-9."
125 }
126
127 set_system_vt()
128 {
129 local tty="$1"
130 [[ -z ${tty} ]] && help_system_vt && return 1
131 case "${tty}" in
132 [1-9])
133 chvt "${tty}"
134 mecho "current vt changed to ${tty}."
135 ;;
136 *) help_system_vt && return 1 ;;
137 esac
138 }
139
140 get_system_vt()
141 {
142 local tty
143 tty="$(fgconsole)"
144 rvecho "${tty}"
145 }
146
147 get_system_autologon()
148 {
149 local var
150 var=$(grep auto_login ${MROOT}/etc/slim.conf | sed 's:auto_login.*\([yn].*\):\1:')
151 case "${var}" in
152 yes) mecho "autologon currently enabled"; rvecho "1" ;;
153 no) mecho "autologon currently disabled"; rvecho "0" ;;
154 *) eecho "unkown state" ;;
155 esac
156 }
157
158 set_system_autologon()
159 {
160 local action="$1"
161 [[ -z ${action} ]] && help_system_autologon && return 1
162
163 ## splash X11 tty too?
164
165 case "${action}" in
166 enable)
167 sed -i 's:^\(auto_login\).*:\1\tyes:' ${MROOT}/etc/slim.conf
168 mecho "autologon enabled"
169 ;;
170 disable)
171 sed -i 's:^\(auto_login\).*:\1\tno:' ${MROOT}/etc/slim.conf
172 mecho "autologon disabled"
173 ;;
174 *) help_system_autologon && return 1 ;;
175 esac
176 }