Contents of /mcore-src/trunk/mcore-tools/daemon/client/include/system.client.class
Parent Directory | Revision Log
Revision 1262 -
(show annotations)
(download)
Fri Feb 4 20:05:37 2011 UTC (13 years, 7 months ago) by niro
File size: 3002 byte(s)
Fri Feb 4 20:05:37 2011 UTC (13 years, 7 months ago) by niro
File size: 3002 byte(s)
- fixed spelling - merged system.console and system.rootconsole to one function - fixed the root console that it really opens up a root console with asking for roots password before changing the privileges - added system.service functionality - added system.passwd functionality - added system.vt functionality
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 | halt |
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 - 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, root" |
43 | mecho " If password is empty, the current password will be deleted." |
44 | } |
45 | |
46 | set_system_console() |
47 | { |
48 | local user="$1" |
49 | [[ -z ${user} ]] && help_system_console && return 1 |
50 | |
51 | case "${user}" in |
52 | mcore) x11runas "rxvt &" ;; |
53 | root) x11runas "rxvt -T 'Login as root' -e /bin/bash -c 'echo \"Login as root\";exec /bin/login root' &" ;; |
54 | *) help_system_console && return 1 ;; |
55 | esac |
56 | } |
57 | |
58 | help_system_service() |
59 | { |
60 | mecho "set system.service [command] [service] [opts]" |
61 | mecho " Controls system services." |
62 | mecho " Commands:" |
63 | mecho " start - starts given service" |
64 | mecho " stop - stops given service" |
65 | mecho " restart - restart given service" |
66 | mecho " reload - reloads given service if possible" |
67 | mecho " add - adds a service to default runlevels" |
68 | mecho " del - deletes a service from all runlevels" |
69 | } |
70 | |
71 | set_system_service() |
72 | { |
73 | local command="$1" |
74 | local service="$2" |
75 | local opts="$3" |
76 | |
77 | [[ -z ${command} ]] && help_system_service && return 1 |
78 | [[ -z ${service} ]] && help_system_service && return 1 |
79 | |
80 | if [[ ! -x /etc/rc.d/init.d/${service} ]] |
81 | then |
82 | mecho "Service '${service}' unkown!" |
83 | fi |
84 | |
85 | case "${command}" in |
86 | start) /etc/rc.d/init.d/"${service}" start ;; |
87 | stop) /etc/rc.d/init.d/"${service}" stop ;; |
88 | restart) /etc/rc.d/init.d/"${service}" restart ;; |
89 | reload) /etc/rc.d/init.d/"${service}" reload ;; |
90 | add) rc-config add "${service}" ;; |
91 | del) rc-config del "${service}" ;; |
92 | *) help_system_service && return ;; |
93 | esac |
94 | } |
95 | |
96 | set_system_passwd() |
97 | { |
98 | local user="$1" |
99 | local pass="$2" |
100 | |
101 | [[ -z ${user} ]] && help_system_passwd && return 1 |
102 | [[ -z ${pass} ]] && mecho "deleting password!" |
103 | |
104 | case "${user}" in |
105 | root|mcore) (echo "${pass}"; sleep 0.1; echo "${pass}") | passwd "${user}" ;; |
106 | *) help_system_passwd && return 1 ;; |
107 | esac |
108 | } |
109 | |
110 | help_system_vt() |
111 | { |
112 | mecho "get system.vt" |
113 | mecho " Prints tty number of the current vt terminal." |
114 | mecho |
115 | mecho "set system.vt [tty]" |
116 | mecho " Change current vt terminal to given tty." |
117 | mecho " Valid tty numbers are 1-9." |
118 | } |
119 | |
120 | set_system_vt() |
121 | { |
122 | local tty="$1" |
123 | [[ -z ${tty} ]] && help_system_vt && return 1 |
124 | case "${tty}" in |
125 | [1-9]) |
126 | chvt "${tty}" |
127 | mecho "current vt changed to ${tty}." |
128 | ;; |
129 | *) help_system_vt && return 1 ;; |
130 | esac |
131 | } |
132 | |
133 | get_system_vt() |
134 | { |
135 | local tty |
136 | tty="$(fgconsole)" |
137 | mecho "${tty}" |
138 | } |