Magellan Linux

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1648 - (show annotations) (download)
Thu Mar 10 18:15:47 2011 UTC (13 years, 1 month ago) by niro
File size: 4074 byte(s)
-make use of error echo function eecho()
-use rvecho() for function retvals
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_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 " start - starts given service"
76 mecho " stop - stops given service"
77 mecho " restart - restart given service"
78 mecho " reload - reloads given service if possible"
79 mecho " add - adds a service to default runlevels"
80 mecho " del - deletes a service from all runlevels"
81 }
82
83 set_system_service()
84 {
85 local command="$1"
86 local service="$2"
87 local opts="$3"
88
89 [[ -z ${command} ]] && help_system_service && return 1
90 [[ -z ${service} ]] && help_system_service && return 1
91
92 if [[ ! -x /etc/rc.d/init.d/${service} ]]
93 then
94 eecho "Service '${service}' unkown!"
95 fi
96
97 case "${command}" in
98 start) /etc/rc.d/init.d/"${service}" start ;;
99 stop) /etc/rc.d/init.d/"${service}" stop ;;
100 restart) /etc/rc.d/init.d/"${service}" restart ;;
101 reload) /etc/rc.d/init.d/"${service}" reload ;;
102 add) rc-config add "${service}" ;;
103 del) rc-config del "${service}" ;;
104 *) help_system_service && return ;;
105 esac
106 }
107
108 set_system_passwd()
109 {
110 local user="$1"
111 local pass="$2"
112
113 [[ -z ${user} ]] && help_system_passwd && return 1
114 [[ -z ${pass} ]] && mecho "deleting password!"
115
116 case "${user}" in
117 root|${MCORE_UNPRIV_USER}) (echo "${pass}"; sleep 0.1; echo "${pass}") | passwd "${user}" ;;
118 *) help_system_passwd && return 1 ;;
119 esac
120 }
121
122 help_system_vt()
123 {
124 mecho "get system.vt"
125 mecho " Prints tty number of the current vt terminal."
126 mecho
127 mecho "set system.vt [tty]"
128 mecho " Change current vt terminal to given tty."
129 mecho " Valid tty numbers are 1-9."
130 }
131
132 set_system_vt()
133 {
134 local tty="$1"
135 [[ -z ${tty} ]] && help_system_vt && return 1
136 case "${tty}" in
137 [1-9])
138 chvt "${tty}"
139 mecho "current vt changed to ${tty}."
140 ;;
141 *) help_system_vt && return 1 ;;
142 esac
143 }
144
145 get_system_vt()
146 {
147 local tty
148 tty="$(fgconsole)"
149 rvecho "${tty}"
150 }
151
152 get_system_autologon()
153 {
154 local var
155 var=$(grep auto_login /etc/slim.conf | sed 's:auto_login.*\([yn].*\):\1:')
156 case "${var}" in
157 yes) mecho "autologon currently enabled"; rvecho "1" ;;
158 no) mecho "autologon currently disabled"; rvecho "0" ;;
159 *) eecho "unkown state" ;;
160 esac
161 }
162
163 set_system_autologon()
164 {
165 local action="$1"
166 [[ -z ${action} ]] && help_system_autologon && return 1
167
168 ## splash X11 tty too?
169
170 case "${action}" in
171 enable)
172 sed -i 's:^\(auto_login\).*:\1\tyes:' /etc/slim.conf
173 mecho "autologon enabled"
174 ;;
175 disable)
176 sed -i 's:^\(auto_login\).*:\1\tno:' /etc/slim.conf
177 mecho "autologon disabled"
178 ;;
179 *) help_system_autologon && return 1 ;;
180 esac
181 }