5 |
help_system_reboot() |
help_system_reboot() |
6 |
{ |
{ |
7 |
mecho "set system.reboot" |
mecho "set system.reboot" |
8 |
mecho " reboots the system." |
mecho " Reboots the system." |
9 |
} |
} |
10 |
|
|
11 |
# set_system_reboot |
# set_system_reboot |
17 |
help_system_shutdown() |
help_system_shutdown() |
18 |
{ |
{ |
19 |
mecho "set system.shutdown" |
mecho "set system.shutdown" |
20 |
mecho " shuts the system down." |
mecho " Shuts the system down." |
21 |
} |
} |
22 |
|
|
23 |
# set_system_shutdown |
# set_system_shutdown |
24 |
set_system_shutdown() |
set_system_shutdown() |
25 |
{ |
{ |
26 |
halt |
poweroff |
27 |
} |
} |
28 |
|
|
29 |
help_system_console() |
help_system_console() |
30 |
{ |
{ |
31 |
mecho "set system.console" |
mecho "set system.console [user]" |
32 |
mecho " opens a console with user privileges." |
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() |
set_system_console() |
59 |
{ |
{ |
60 |
x11runas "DISPLAY=:0 rxvt" |
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 "get system.service [command] [service]" |
73 |
|
mecho " Status information of system services." |
74 |
|
mecho " Commands:" |
75 |
|
mecho " status - prints status of given service" |
76 |
|
mecho " enabled - check whether a service was enabled" |
77 |
|
mecho " runlevel - print current system runlevel" |
78 |
|
mecho |
79 |
|
mecho "set system.service [command] [service] [opts]" |
80 |
|
mecho " Controls system services." |
81 |
|
mecho " Commands:" |
82 |
|
mecho " start - starts given service" |
83 |
|
mecho " stop - stops given service" |
84 |
|
mecho " restart - restart given service" |
85 |
|
mecho " reload - reloads given service if possible" |
86 |
|
mecho " add - adds a service to default runlevels" |
87 |
|
mecho " del - deletes a service from all runlevels" |
88 |
|
} |
89 |
|
|
90 |
|
helper_set_system_service_sysvinit() |
91 |
|
{ |
92 |
|
local command="$1" |
93 |
|
local service="$2" |
94 |
|
local opts="$3" |
95 |
|
|
96 |
|
[[ -z ${command} ]] && help_system_service && return 1 |
97 |
|
[[ -z ${service} ]] && help_system_service && return 1 |
98 |
|
|
99 |
|
if [[ ! -x ${MROOT}/etc/rc.d/init.d/${service} ]] |
100 |
|
then |
101 |
|
eecho "Service '${service}' unkown!" |
102 |
|
return 1 |
103 |
|
fi |
104 |
|
|
105 |
|
case "${command}" in |
106 |
|
start) /etc/rc.d/init.d/"${service}" start ;; |
107 |
|
stop) /etc/rc.d/init.d/"${service}" stop ;; |
108 |
|
restart) /etc/rc.d/init.d/"${service}" restart ;; |
109 |
|
reload) /etc/rc.d/init.d/"${service}" reload ;; |
110 |
|
add) rc-config add "${service}" ;; |
111 |
|
del) rc-config del "${service}" ;; |
112 |
|
*) help_system_service && return ;; |
113 |
|
esac |
114 |
|
} |
115 |
|
|
116 |
|
helper_set_system_service_systemd() |
117 |
|
{ |
118 |
|
local command="$1" |
119 |
|
local service="$2" |
120 |
|
local opts="$3" |
121 |
|
|
122 |
|
[[ -z ${command} ]] && help_system_service && return 1 |
123 |
|
[[ -z ${service} ]] && help_system_service && return 1 |
124 |
|
|
125 |
|
if [[ -n $(systemctl status ${service} | grep 'Reason: No such file or directory') ]] |
126 |
|
then |
127 |
|
eecho "Service '${service}' unkown!" |
128 |
|
return 1 |
129 |
|
fi |
130 |
|
|
131 |
|
case "${command}" in |
132 |
|
start) systemctl start "${service}" ;; |
133 |
|
stop) systemctl stop "${service}" ;; |
134 |
|
restart) systemctl try-restart "${service}" ;; |
135 |
|
reload) systemctl reload-or-try-restart "${service}" ;; |
136 |
|
add) systemctl enable "${service}" ;; |
137 |
|
del) systemctl disable "${service}" ;; |
138 |
|
*) help_system_service && return ;; |
139 |
|
esac |
140 |
|
} |
141 |
|
|
142 |
|
set_system_service() |
143 |
|
{ |
144 |
|
if [[ -x $(type -P systemctl) ]] |
145 |
|
then |
146 |
|
helper_set_system_service_systemd $* |
147 |
|
else |
148 |
|
helper_set_system_service_sysvinit $* |
149 |
|
fi |
150 |
|
} |
151 |
|
|
152 |
|
helper_get_system_service_sysvinit() |
153 |
|
{ |
154 |
|
local command="$1" |
155 |
|
local service="$2" |
156 |
|
|
157 |
|
[[ -z ${command} ]] && help_system_service && return 1 |
158 |
|
[[ -z ${service} ]] && help_system_service && return 1 |
159 |
|
|
160 |
|
if [[ ! -x ${MROOT}/etc/rc.d/init.d/${service} ]] |
161 |
|
then |
162 |
|
eecho "Service '${service}' unkown!" |
163 |
|
return 1 |
164 |
|
fi |
165 |
|
|
166 |
|
case "${command}" in |
167 |
|
status) /etc/rc.d/init.d/"${service}" status ;; |
168 |
|
enabled) rc-config show "${service}" ;; |
169 |
|
runlevel) eecho "function on todo" ;; |
170 |
|
*) help_system_service && return ;; |
171 |
|
esac |
172 |
|
} |
173 |
|
|
174 |
|
helper_get_system_service_systemd() |
175 |
|
{ |
176 |
|
local command="$1" |
177 |
|
local service="$2" |
178 |
|
|
179 |
|
[[ -z ${command} ]] && help_system_service && return 1 |
180 |
|
[[ -z ${service} ]] && help_system_service && return 1 |
181 |
|
|
182 |
|
if [[ -n $(systemctl status ${service} | grep 'Reason: No such file or directory') ]] |
183 |
|
then |
184 |
|
eecho "Service '${service}' unkown!" |
185 |
|
return 1 |
186 |
|
fi |
187 |
|
|
188 |
|
case "${command}" in |
189 |
|
status) systemctl status "${service}" ;; |
190 |
|
enabled) systemctl is-enabled "${service}"; rvecho "$?" ;; |
191 |
|
runlevel) rvecho "$(readline ${MROOT}/etc/systemd/system/default.target)" ;; |
192 |
|
*) help_system_service && return ;; |
193 |
|
esac |
194 |
|
} |
195 |
|
|
196 |
|
get_system_service() |
197 |
|
{ |
198 |
|
if [[ -x $(type -P systemctl) ]] |
199 |
|
then |
200 |
|
helper_get_system_service_systemd $* |
201 |
|
else |
202 |
|
helper_get_system_service_sysvinit $* |
203 |
|
fi |
204 |
|
} |
205 |
|
|
206 |
|
set_system_passwd() |
207 |
|
{ |
208 |
|
local user="$1" |
209 |
|
local pass="$2" |
210 |
|
|
211 |
|
[[ -z ${user} ]] && help_system_passwd && return 1 |
212 |
|
[[ -z ${pass} ]] && mecho "deleting password!" |
213 |
|
|
214 |
|
case "${user}" in |
215 |
|
root|${MCORE_UNPRIV_USER}) (echo "${pass}"; sleep 0.1; echo "${pass}") | passwd "${user}" ;; |
216 |
|
*) help_system_passwd && return 1 ;; |
217 |
|
esac |
218 |
|
} |
219 |
|
|
220 |
|
help_system_vt() |
221 |
|
{ |
222 |
|
mecho "get system.vt" |
223 |
|
mecho " Prints tty number of the current vt terminal." |
224 |
|
mecho |
225 |
|
mecho "set system.vt [tty]" |
226 |
|
mecho " Change current vt terminal to given tty." |
227 |
|
mecho " Valid tty numbers are 1-9." |
228 |
|
} |
229 |
|
|
230 |
|
set_system_vt() |
231 |
|
{ |
232 |
|
local tty="$1" |
233 |
|
[[ -z ${tty} ]] && help_system_vt && return 1 |
234 |
|
case "${tty}" in |
235 |
|
[1-9]) |
236 |
|
chvt "${tty}" |
237 |
|
mecho "current vt changed to ${tty}." |
238 |
|
;; |
239 |
|
*) help_system_vt && return 1 ;; |
240 |
|
esac |
241 |
} |
} |
242 |
|
|
243 |
help_system_rootconsole() |
get_system_vt() |
244 |
{ |
{ |
245 |
mecho "set system.rootconsole" |
local tty |
246 |
mecho " opens a console with system privileges." |
tty="$(fgconsole)" |
247 |
|
rvecho "${tty}" |
248 |
} |
} |
249 |
|
|
250 |
# opens a root console |
get_system_autologon() |
|
set_system_rootconsole() |
|
251 |
{ |
{ |
252 |
x11runas "DISPLAY=:0 rxvt -e '/bin/login -f root" |
local var |
253 |
|
var=$(grep auto_login /etc/slim.conf | sed 's:auto_login.*\([yn].*\):\1:') |
254 |
|
case "${var}" in |
255 |
|
yes) mecho "autologon currently enabled"; rvecho "1" ;; |
256 |
|
no) mecho "autologon currently disabled"; rvecho "0" ;; |
257 |
|
*) eecho "unkown state" ;; |
258 |
|
esac |
259 |
|
} |
260 |
|
|
261 |
|
set_system_autologon() |
262 |
|
{ |
263 |
|
local action="$1" |
264 |
|
[[ -z ${action} ]] && help_system_autologon && return 1 |
265 |
|
|
266 |
|
## splash X11 tty too? |
267 |
|
|
268 |
|
case "${action}" in |
269 |
|
enable) |
270 |
|
sed -i 's:^\(auto_login\).*:\1\tyes:' /etc/slim.conf |
271 |
|
mecho "autologon enabled" |
272 |
|
;; |
273 |
|
disable) |
274 |
|
sed -i 's:^\(auto_login\).*:\1\tno:' /etc/slim.conf |
275 |
|
mecho "autologon disabled" |
276 |
|
;; |
277 |
|
*) help_system_autologon && return 1 ;; |
278 |
|
esac |
279 |
} |
} |