Contents of /mcore-src/trunk/mcore-tools/daemon/client/include/system.client.class
Parent Directory | Revision Log
Revision 2061 -
(show annotations)
(download)
Wed May 8 12:57:23 2013 UTC (11 years, 4 months ago) by niro
File size: 5092 byte(s)
Wed May 8 12:57:23 2013 UTC (11 years, 4 months ago) by niro
File size: 5092 byte(s)
-support systemd units
1 | # $Id$ |
2 | |
3 | provide basic-system |
4 | |
5 | help_system_reboot() |
6 | { |
7 | mecho "set system.reboot" |
8 | mecho " Reboots the system." |
9 | } |
10 | |
11 | # set_system_reboot |
12 | set_system_reboot() |
13 | { |
14 | reboot |
15 | } |
16 | |
17 | help_system_shutdown() |
18 | { |
19 | mecho "set system.shutdown" |
20 | mecho " Shuts the system down." |
21 | } |
22 | |
23 | # set_system_shutdown |
24 | set_system_shutdown() |
25 | { |
26 | poweroff |
27 | } |
28 | |
29 | help_system_console() |
30 | { |
31 | mecho "set system.console [user]" |
32 | mecho " Opens a console with user or root privileges." |
33 | mecho " Known users:" |
34 | mecho " ${MCORE_UNPRIV_USER} - mcore standard user only with user privileges" |
35 | mecho " root - mcore root user with full system privileges" |
36 | } |
37 | |
38 | help_system_passwd() |
39 | { |
40 | mecho "set system.passwd [user] [password]" |
41 | mecho " Sets a system password for given user." |
42 | mecho " Allowed users: ${MCORE_UNPRIV_USER}, root" |
43 | mecho " If password is empty, the current password will be deleted." |
44 | } |
45 | |
46 | help_system_autologon() |
47 | { |
48 | mecho "get system.autologon" |
49 | mecho " Shows the state of autlogon" |
50 | mecho |
51 | mecho "set system.autologon [action]" |
52 | mecho " Enables or disables X11 autologins of the mcore user." |
53 | mecho " Available actions:" |
54 | mecho " enable - enables autologon" |
55 | mecho " disable - disables autologon" |
56 | } |
57 | |
58 | set_system_console() |
59 | { |
60 | local user="$1" |
61 | [[ -z ${user} ]] && help_system_console && return 1 |
62 | |
63 | case "${user}" in |
64 | ${MCORE_UNPRIV_USER}) x11runas "rxvt &" ;; |
65 | root) x11runas "rxvt -T 'Login as root' -e /bin/bash -c 'echo \"Login as root\";exec /bin/login root' &" ;; |
66 | *) help_system_console && return 1 ;; |
67 | esac |
68 | } |
69 | |
70 | help_system_service() |
71 | { |
72 | mecho "set system.service [command] [service] [opts]" |
73 | mecho " Controls system services." |
74 | mecho " Commands:" |
75 | mecho " status - prints status of given service" |
76 | mecho " start - starts given service" |
77 | mecho " stop - stops given service" |
78 | mecho " restart - restart given service" |
79 | mecho " reload - reloads given service if possible" |
80 | mecho " add - adds a service to default runlevels" |
81 | mecho " del - deletes a service from all runlevels" |
82 | } |
83 | |
84 | helper_system_service_sysvinit() |
85 | { |
86 | local command="$1" |
87 | local service="$2" |
88 | local opts="$3" |
89 | |
90 | [[ -z ${command} ]] && help_system_service && return 1 |
91 | [[ -z ${service} ]] && help_system_service && return 1 |
92 | |
93 | if [[ ! -x ${MROOT}/etc/rc.d/init.d/${service} ]] |
94 | then |
95 | eecho "Service '${service}' unkown!" |
96 | return 1 |
97 | fi |
98 | |
99 | case "${command}" in |
100 | start) /etc/rc.d/init.d/"${service}" start ;; |
101 | stop) /etc/rc.d/init.d/"${service}" stop ;; |
102 | restart) /etc/rc.d/init.d/"${service}" restart ;; |
103 | reload) /etc/rc.d/init.d/"${service}" reload ;; |
104 | status) /etc/rc.d/init.d/"${service}" status ;; |
105 | add) rc-config add "${service}" ;; |
106 | del) rc-config del "${service}" ;; |
107 | *) help_system_service && return ;; |
108 | esac |
109 | } |
110 | |
111 | helper_system_service_systemd() |
112 | { |
113 | local command="$1" |
114 | local service="$2" |
115 | local opts="$3" |
116 | |
117 | [[ -z ${command} ]] && help_system_service && return 1 |
118 | [[ -z ${service} ]] && help_system_service && return 1 |
119 | |
120 | if [[ -n $(systemctl status ${service} | grep 'Reason: No such file or directory') ]] |
121 | then |
122 | eecho "Service '${service}' unkown!" |
123 | return 1 |
124 | fi |
125 | |
126 | case "${command}" in |
127 | start) systemctl start "${service}" ;; |
128 | stop) systemctl stop "${service}" ;; |
129 | restart) systemctl try-restart "${service}" ;; |
130 | reload) systemctl reload-or-try-restart "${service}" ;; |
131 | status) systemctl status "${service}" ;; |
132 | add) systemctl enable "${service}" ;; |
133 | del) systemctl disable "${service}" ;; |
134 | *) help_system_service && return ;; |
135 | esac |
136 | } |
137 | |
138 | set_system_service() |
139 | { |
140 | if [[ -x $(type -P systemctl) ]] |
141 | then |
142 | helper_system_service_systemd $* |
143 | else |
144 | helper_system_service_sysvinit $* |
145 | fi |
146 | } |
147 | |
148 | set_system_passwd() |
149 | { |
150 | local user="$1" |
151 | local pass="$2" |
152 | |
153 | [[ -z ${user} ]] && help_system_passwd && return 1 |
154 | [[ -z ${pass} ]] && mecho "deleting password!" |
155 | |
156 | case "${user}" in |
157 | root|${MCORE_UNPRIV_USER}) (echo "${pass}"; sleep 0.1; echo "${pass}") | passwd "${user}" ;; |
158 | *) help_system_passwd && return 1 ;; |
159 | esac |
160 | } |
161 | |
162 | help_system_vt() |
163 | { |
164 | mecho "get system.vt" |
165 | mecho " Prints tty number of the current vt terminal." |
166 | mecho |
167 | mecho "set system.vt [tty]" |
168 | mecho " Change current vt terminal to given tty." |
169 | mecho " Valid tty numbers are 1-9." |
170 | } |
171 | |
172 | set_system_vt() |
173 | { |
174 | local tty="$1" |
175 | [[ -z ${tty} ]] && help_system_vt && return 1 |
176 | case "${tty}" in |
177 | [1-9]) |
178 | chvt "${tty}" |
179 | mecho "current vt changed to ${tty}." |
180 | ;; |
181 | *) help_system_vt && return 1 ;; |
182 | esac |
183 | } |
184 | |
185 | get_system_vt() |
186 | { |
187 | local tty |
188 | tty="$(fgconsole)" |
189 | rvecho "${tty}" |
190 | } |
191 | |
192 | get_system_autologon() |
193 | { |
194 | local var |
195 | var=$(grep auto_login /etc/slim.conf | sed 's:auto_login.*\([yn].*\):\1:') |
196 | case "${var}" in |
197 | yes) mecho "autologon currently enabled"; rvecho "1" ;; |
198 | no) mecho "autologon currently disabled"; rvecho "0" ;; |
199 | *) eecho "unkown state" ;; |
200 | esac |
201 | } |
202 | |
203 | set_system_autologon() |
204 | { |
205 | local action="$1" |
206 | [[ -z ${action} ]] && help_system_autologon && return 1 |
207 | |
208 | ## splash X11 tty too? |
209 | |
210 | case "${action}" in |
211 | enable) |
212 | sed -i 's:^\(auto_login\).*:\1\tyes:' /etc/slim.conf |
213 | mecho "autologon enabled" |
214 | ;; |
215 | disable) |
216 | sed -i 's:^\(auto_login\).*:\1\tno:' /etc/slim.conf |
217 | mecho "autologon disabled" |
218 | ;; |
219 | *) help_system_autologon && return 1 ;; |
220 | esac |
221 | } |