Annotation of /alx-src/tags/alxconf-0_6_0-rc13/functions/config_sessions.sh
Parent Directory | Revision Log
Revision 2161 -
(hide annotations)
(download)
(as text)
Wed May 18 14:35:13 2011 UTC (13 years, 4 months ago) by niro
Original Path: alx-src/branches/alxconf-060/functions/config_sessions.sh
File MIME type: application/x-sh
File size: 11705 byte(s)
Wed May 18 14:35:13 2011 UTC (13 years, 4 months ago) by niro
Original Path: alx-src/branches/alxconf-060/functions/config_sessions.sh
File MIME type: application/x-sh
File size: 11705 byte(s)
-fixed handling to support whitespaces in names and added params for execs
1 | niro | 2001 | # $Id$ |
2 | niro | 236 | # configures ica-sessions on the host via mysql db settings |
3 | |||
4 | niro | 2161 | fix_whitespaces() |
5 | { | ||
6 | local var="$@" | ||
7 | echo "${var//\ /_}" | ||
8 | } | ||
9 | |||
10 | niro | 2149 | # helper function to create citrix session files |
11 | generate_ica_session_file() | ||
12 | niro | 236 | { |
13 | niro | 246 | local i |
14 | niro | 2149 | local num |
15 | niro | 246 | local server |
16 | local ses_session | ||
17 | local ses_filename | ||
18 | local ses_username | ||
19 | local ses_domain | ||
20 | local ses_password | ||
21 | local ses_browseradrs | ||
22 | niro | 2035 | local CONFIG |
23 | niro | 246 | |
24 | niro | 2149 | # very basic getops |
25 | for i in $* | ||
26 | niro | 246 | do |
27 | niro | 2149 | case $1 in |
28 | --session) shift; ses_session="$1" ;; | ||
29 | --filename) shift; ses_filename="$1" ;; | ||
30 | --username) shift; ses_username="$1" ;; | ||
31 | --password) shift; ses_password="$1" ;; | ||
32 | --domain) shift; ses_domain="$1" ;; | ||
33 | niro | 2161 | --server) shift; ses_browseradrs="$1" ;; |
34 | niro | 2149 | esac |
35 | shift | ||
36 | done | ||
37 | niro | 246 | |
38 | niro | 2149 | # abort if session, filename or server not given |
39 | niro | 2161 | [[ -z ${ses_session} ]] && return 1 |
40 | [[ -z ${ses_filename} ]] && return 1 | ||
41 | [[ -z ${ses_browseradrs} ]] && return 1 | ||
42 | niro | 272 | |
43 | niro | 2149 | # write session files |
44 | CONFIG="${ALX_ICA_SESSIONS}/${ses_filename}" | ||
45 | clearconfig | ||
46 | niro | 2035 | |
47 | niro | 2149 | addconfig '[WFClient]' |
48 | addconfig 'Version=2' | ||
49 | niro | 1654 | |
50 | niro | 2149 | # use ';' as ifs |
51 | declare -i i=0 | ||
52 | for server in ${ses_browseradrs//;/ } | ||
53 | do | ||
54 | (( i++ )) | ||
55 | num="${i}" | ||
56 | # support newer ica-clients: | ||
57 | # the first address must be named TcpBrowserAddress, but not TcpBrowserAddress1 !! | ||
58 | [[ ${i} -eq 1 ]] && num="" | ||
59 | addconfig "TcpBrowserAddress${num}=${server}" | ||
60 | niro | 246 | done |
61 | niro | 2149 | |
62 | addconfig 'ScreenPercent=0' | ||
63 | addconfig '[ApplicationServers]' | ||
64 | addconfig "${ses_session}=" | ||
65 | addconfig "[${ses_session}]" | ||
66 | addconfig "Address=${ses_session}" | ||
67 | addconfig "InitialProgram=#${ses_session}" | ||
68 | addconfig 'TransportDriver=TCP/IP' | ||
69 | addconfig 'WinStationDriver=ICA 3.0' | ||
70 | addconfig "ClearPassword=${ses__password}" | ||
71 | addconfig "Username=${ses_username}" | ||
72 | addconfig "Domain=${ses_domain}" | ||
73 | addconfig 'UseFullScreen=Yes' | ||
74 | addconfig 'NoWindowManager=True' | ||
75 | niro | 246 | } |
76 | |||
77 | niro | 317 | # generates a sh file to start programs |
78 | generate_program_sh() | ||
79 | { | ||
80 | local dest | ||
81 | local name | ||
82 | local exec | ||
83 | niro | 2161 | local param |
84 | niro | 317 | local workdir |
85 | niro | 2035 | local CONFIG |
86 | niro | 317 | |
87 | # very basic getops | ||
88 | for i in $* | ||
89 | do | ||
90 | case $1 in | ||
91 | --name|-n) shift; name="$1" ;; | ||
92 | --exec|-x) shift; exec="$1" ;; | ||
93 | niro | 2161 | --param|-p) shift; param="$1" ;; |
94 | niro | 317 | --dest|-d) shift; dest="$1" ;; |
95 | --workdir|-w) shift; workdir="$1" ;; | ||
96 | esac | ||
97 | shift | ||
98 | done | ||
99 | |||
100 | # abort if name, dest or exec not given | ||
101 | niro | 2149 | [[ -z ${name} ]] && return 1 |
102 | [[ -z ${exec} ]] && return 1 | ||
103 | [[ -z ${dest} ]] && return 1 | ||
104 | niro | 317 | |
105 | niro | 2149 | CONFIG="${dest}" |
106 | niro | 2035 | addconfig "#!/bin/sh" |
107 | [ -n "${workdir}" ] && addconfig "cd ${workdir}" | ||
108 | niro | 2161 | addconfig "exec ${exec} ${param}" |
109 | niro | 317 | |
110 | niro | 2149 | chmod 0755 "${dest}" |
111 | niro | 317 | } |
112 | |||
113 | niro | 304 | # helper functions for generate all desktop icons |
114 | generate_icon() | ||
115 | { | ||
116 | local name | ||
117 | local icon | ||
118 | local command | ||
119 | local dest | ||
120 | local yres | ||
121 | local xres | ||
122 | local iwidth | ||
123 | local iheight | ||
124 | niro | 317 | local deficon |
125 | niro | 2035 | local CONFIG |
126 | niro | 304 | |
127 | # very basic getops | ||
128 | for i in $* | ||
129 | do | ||
130 | case $1 in | ||
131 | --name|-n) shift; name="$1" ;; | ||
132 | --command|-c) shift; command="$1" ;; | ||
133 | --icon|-i) shift; icon="$1" ;; | ||
134 | --dest|-d) shift; dest="$1" ;; | ||
135 | --xres|-x) shift; xres="$1" ;; | ||
136 | --yres|-y) shift; yres="$1" ;; | ||
137 | --icon-width|-w) shift; iwidth="$1" ;; | ||
138 | --icon-height|-h) shift; iheight="$1" ;; | ||
139 | niro | 317 | --default-icon) shift; deficon="$1" ;; |
140 | niro | 304 | esac |
141 | shift | ||
142 | done | ||
143 | |||
144 | niro | 2149 | # some sanity checks: |
145 | niro | 304 | |
146 | # abort if name or command not given | ||
147 | niro | 2035 | [[ -z ${name} ]] && return 1 |
148 | [[ -z ${command} ]] && return 1 | ||
149 | niro | 304 | |
150 | # use some defaults for icon, dest, {x,y}res | ||
151 | niro | 2035 | [[ -z ${xres} ]] && xres=30 |
152 | [[ -z ${yres} ]] && xres=30 | ||
153 | [[ -z ${dest} ]] && dest="${ALX_UNPRIV_HOME}/.xtdesktop/${name}.lnk" | ||
154 | if [[ -z ${icon} ]] || [ ! -f ${icon} ] | ||
155 | niro | 304 | then |
156 | niro | 317 | # if no default icon is given use default.png |
157 | niro | 2035 | [[ -z ${deficon} ]] && deficon="default.png" |
158 | niro | 317 | icon="${ALX_SESSIONS_ICONS}/${deficon}" |
159 | niro | 304 | fi |
160 | |||
161 | niro | 2161 | CONFIG="${dest}" |
162 | niro | 2035 | clearconfig |
163 | niro | 304 | |
164 | niro | 2035 | addconfig 'table Icon' |
165 | addconfig ' Type: Program' | ||
166 | addconfig " Caption: ${name}" | ||
167 | addconfig " Command: ${command}" | ||
168 | addconfig " Icon: ${icon}" | ||
169 | addconfig " X: ${xres}" | ||
170 | addconfig " Y: ${yres}" | ||
171 | |||
172 | niro | 304 | # add these only if not zero |
173 | niro | 2035 | if [[ ! -z ${iwidth} ]] && [[ ! -z ${iheight} ]] |
174 | niro | 304 | then |
175 | niro | 2035 | addconfig " IconWidth: ${iwidth}" |
176 | addconfig " IconHeight: ${iheight}" | ||
177 | niro | 304 | fi |
178 | |||
179 | niro | 2035 | addconfig 'end' |
180 | niro | 304 | } |
181 | |||
182 | generate_all_desktop_icons() | ||
183 | { | ||
184 | niro | 2149 | local session_list="$1" |
185 | local other_menuitem_list="$2" | ||
186 | niro | 304 | local res |
187 | local xres | ||
188 | local yres | ||
189 | local x | ||
190 | local y | ||
191 | niro | 2161 | local i |
192 | niro | 2149 | local name |
193 | niro | 317 | local progsh_path |
194 | niro | 304 | |
195 | niro | 2149 | # progsh path |
196 | niro | 2161 | progsh_path="${ALX_UNPRIV_HOME}/.alxprogs" |
197 | niro | 2149 | |
198 | niro | 304 | # get the resolution |
199 | niro | 342 | res=$(mysqldo "select resolution from cfg_graphic where serial='${ALX_SERIAL}'") |
200 | niro | 304 | |
201 | # split res to x & y | ||
202 | niro | 2149 | xres="${res%x*}" |
203 | xres="${res#*x}" | ||
204 | niro | 304 | |
205 | # top left edge of the icon is given in config file | ||
206 | # remove a little bit to simulate the bottom-right edge | ||
207 | xres="$(( ${xres} - 120 ))" | ||
208 | yres="$(( ${yres} - 80 ))" | ||
209 | |||
210 | # basic config | ||
211 | cat ${ALX_SKELETONS}/xtdesktop/xtdeskrc > ${ALX_UNPRIV_HOME}/.xtdeskrc | ||
212 | |||
213 | # clean desktop icon location | ||
214 | [ -d ${ALX_UNPRIV_HOME}/.xtdesktop ] && rm -rf ${ALX_UNPRIV_HOME}/.xtdesktop | ||
215 | install -d ${ALX_UNPRIV_HOME}/.xtdesktop | ||
216 | |||
217 | # default settings | ||
218 | niro | 1594 | declare -i x=30 |
219 | declare -i y=30 | ||
220 | niro | 304 | |
221 | niro | 2149 | # ica icons |
222 | niro | 2161 | for i in ${session_list} |
223 | niro | 304 | do |
224 | # abort if empty | ||
225 | niro | 2161 | [[ -z ${i} ]] && continue |
226 | niro | 304 | |
227 | niro | 2161 | # get database information |
228 | evaluate_table cfg_sessions "where serial='${ALX_SERIAL}' and id='${i}'" | ||
229 | |||
230 | niro | 304 | # new line if x > xres |
231 | niro | 2035 | if [ ${x} -ge ${xres} ] |
232 | then | ||
233 | niro | 1594 | x=30 |
234 | niro | 304 | y=$((${y} + 80)) |
235 | fi | ||
236 | |||
237 | # new row if y > yres | ||
238 | niro | 2035 | if [ ${y} -ge ${yres} ] |
239 | then | ||
240 | niro | 304 | x=$((${x} + 120)) |
241 | niro | 1594 | y=30 |
242 | niro | 304 | |
243 | # re-check x | ||
244 | niro | 1594 | [ ${x} -ge ${xres} ] && x=30 |
245 | niro | 304 | fi |
246 | |||
247 | generate_icon \ | ||
248 | niro | 2161 | --name "${cfg_session_session}" \ |
249 | --command "nice -n 19 wfica ${ALX_ICA_SESSIONS}/$(fix_whitespaces ${cfg_session_filename})" \ | ||
250 | --icon "${ALX_SESSIONS_ICONS}/$(fix_whitespaces ${cfg_session_session}).png" \ | ||
251 | --dest "${ALX_UNPRIV_HOME}/.xtdesktop/$(fix_whitespaces ${cfg_session_session}).lnk" \ | ||
252 | niro | 304 | --xres "${x}" \ |
253 | --yres "${y}" | ||
254 | |||
255 | y=$((${y} + 80)) | ||
256 | done | ||
257 | |||
258 | niro | 2161 | for i in ${other_menuitem_list} |
259 | niro | 317 | do |
260 | # abort if empty | ||
261 | niro | 2161 | [[ -z ${i} ]] && continue |
262 | niro | 317 | |
263 | niro | 2161 | # get database information |
264 | evaluate_table cfg_other_menuitems "where serial='${ALX_SERIAL}' and id='${i}'" | ||
265 | |||
266 | niro | 317 | # new line if x > xres |
267 | niro | 2035 | if [ ${x} -ge ${xres} ] |
268 | then | ||
269 | niro | 1594 | x=30 |
270 | niro | 317 | y=$((${y} + 80)) |
271 | fi | ||
272 | |||
273 | # new row if y > yres | ||
274 | niro | 2035 | if [ ${y} -ge ${yres} ] |
275 | then | ||
276 | niro | 317 | x=$((${x} + 120)) |
277 | niro | 1594 | y=30 |
278 | niro | 317 | |
279 | # re-check x | ||
280 | niro | 1594 | [ ${x} -ge ${xres} ] && x=30 |
281 | niro | 317 | fi |
282 | |||
283 | generate_icon \ | ||
284 | niro | 2161 | --name "${cfg_other_menuitems_name}" \ |
285 | --command "${progsh_path}/$(fix_whitespaces ${cfg_other_menuitems_exec})" \ | ||
286 | --icon "${ALX_SESSIONS_ICONS}/$(fix_whitespaces ${cfg_other_menuitems_name}).png" \ | ||
287 | --dest "${ALX_UNPRIV_HOME}/.xtdesktop/$(fix_whitespaces ${cfg_other_menuitems_name}).lnk" \ | ||
288 | niro | 317 | --xres "${x}" \ |
289 | --yres "${y}" \ | ||
290 | --default-icon "default_item.png" | ||
291 | |||
292 | y=$((${y} + 80)) | ||
293 | done | ||
294 | |||
295 | niro | 304 | # last but not least gen a icon with some sys informations |
296 | local sysinfo | ||
297 | local hostname | ||
298 | local osversion | ||
299 | |||
300 | osversion="$(< /etc/mageversion)" | ||
301 | niro | 342 | hostname=$(mysqldo "select hostname from cfg_network where serial='${ALX_SERIAL}'") |
302 | niro | 304 | sysinfo="Hostname: ${hostname} Serial: #${ALX_SERIAL} OS: alx-${osversion} Kernel: $(uname -r)" |
303 | |||
304 | # now get the right position: | ||
305 | # restore orig values of xres | ||
306 | xres="$(( ${xres} + 120 ))" | ||
307 | # default y pos (full yres -22 = cur yres + 58 !) | ||
308 | yres="$(( ${yres} + 58 ))" | ||
309 | # middle of the screen | ||
310 | # (no txt - length required, xtdesk manage that itself) | ||
311 | xres="$(( ${xres} / 2))" | ||
312 | |||
313 | generate_icon \ | ||
314 | --name "${sysinfo}" \ | ||
315 | --command "exit 0" \ | ||
316 | --icon "${ALX_SESSIONS_ICONS}/sysinfo.png" \ | ||
317 | --dest "${ALX_UNPRIV_HOME}/.xtdesktop/sysinfo.lnk" \ | ||
318 | --xres "${xres}" \ | ||
319 | --yres "${yres}" \ | ||
320 | --icon-width "1" \ | ||
321 | --icon-height "1" | ||
322 | } | ||
323 | |||
324 | niro | 236 | config_sessions() |
325 | { | ||
326 | niro | 272 | local i |
327 | niro | 2149 | local all_ses_ids |
328 | local all_other_ids | ||
329 | niro | 2035 | local CONFIG |
330 | niro | 2149 | local screensaver_passwd_cmd |
331 | niro | 236 | |
332 | niro | 2149 | # get all session ids from database |
333 | all_ses_ids=$(mysqldo "select id from cfg_sessions where serial='${ALX_SERIAL}'") | ||
334 | # get all other_menutiem ids from database | ||
335 | all_other_ids=$(mysqldo "select id from cfg_other_menuitems where serial='${ALX_SERIAL}'") | ||
336 | |||
337 | # get screensaver settings | ||
338 | evaluate_table cfg_screensaver | ||
339 | # get autostart settings | ||
340 | evaluate_table cfg_autostart | ||
341 | |||
342 | niro | 236 | # now setup fluxbox for user station |
343 | |||
344 | # create a fresh fluxbox directory | ||
345 | [ -d ${ALX_UNPRIV_HOME}/.fluxbox ] && rm -rf ${ALX_UNPRIV_HOME}/.fluxbox | ||
346 | install -d ${ALX_UNPRIV_HOME}/.fluxbox | ||
347 | |||
348 | # now generate fluxbox config files | ||
349 | |||
350 | # fluxbox main config | ||
351 | niro | 2149 | cat ${ALX_SKELETONS}/fluxbox/init > ${ALX_UNPRIV_HOME}/.fluxbox/init |
352 | niro | 236 | |
353 | # fluxbox autostart | ||
354 | niro | 2149 | cat ${ALX_SKELETONS}/fluxbox/apps > ${ALX_UNPRIV_HOME}/.fluxbox/apps |
355 | niro | 236 | |
356 | niro | 2149 | CONFIG="${ALX_UNPRIV_HOME}/.fluxbox/apps" |
357 | niro | 338 | # add screensaver |
358 | niro | 2149 | if [[ ! -z ${cfg_screensaver_screensaver} ]] && [[ ! -z ${cfg_screensaver_screensaver_timeout} ]] |
359 | niro | 338 | then |
360 | niro | 2149 | if [[ -z ${cfg_screensaver_password} ]] || [[ ${cfg_screensaver_password} = NULL ]] |
361 | niro | 338 | then |
362 | niro | 2149 | screensaver_passwd_cmd="-nolock" |
363 | niro | 338 | else |
364 | niro | 2149 | screensaver_passwd_cmd="-cpasswd $(cryptpw -m des ${cfg_screensaver_password})" |
365 | niro | 338 | fi |
366 | |||
367 | niro | 2149 | addconfig "[startup] {nohup xautolock -time ${cfg_screensaver_timeout} -locker 'xlock -mode ${cfg_screensaver_screensaver} ${screensaver_passwd_cmd}' > /dev/null &}" |
368 | niro | 338 | fi |
369 | |||
370 | niro | 246 | # add autostart session |
371 | niro | 2149 | if [[ ! -z ${cfg_autostart_session} ]] |
372 | niro | 246 | then |
373 | niro | 2161 | addconfig "[startup] {nohup nice -n 19 wfica ${ALX_ICA_SESSIONS}/$(fix_whitespaces ${cfg_autostart_session}) &}" |
374 | niro | 246 | fi |
375 | |||
376 | niro | 236 | # fluxbox hotkeys |
377 | niro | 2035 | cat ${ALX_SKELETONS}/fluxbox/keys > ${ALX_UNPRIV_HOME}/.fluxbox/keys |
378 | niro | 236 | |
379 | niro | 2035 | # generate a fluxbox menu |
380 | niro | 2161 | CONFIG="${ALX_UNPRIV_HOME}/.fluxbox/menu" |
381 | niro | 2035 | clearconfig |
382 | |||
383 | niro | 236 | # fluxbox menu header |
384 | niro | 2035 | cat ${ALX_SKELETONS}/fluxbox/menu.header >> ${ALX_UNPRIV_HOME}/.fluxbox/menu |
385 | niro | 291 | # now fix it with proper messages :P |
386 | local ver="$(< /etc/mageversion)" | ||
387 | niro | 2035 | sed -i "s:@CHANGEME@:alx-${ver} #${ALX_SERIAL}:g" ${ALX_UNPRIV_HOME}/.fluxbox/menu |
388 | niro | 239 | # add a newline (maybe there is no crlf in the header) |
389 | niro | 2035 | addconfig |
390 | niro | 239 | |
391 | niro | 2149 | # first generate session files |
392 | for i in ${all_ses_ids} | ||
393 | niro | 236 | do |
394 | niro | 2149 | evaluate_table cfg_sessions "where serial='${ALX_SERIAL}' and id='${i}'" |
395 | generate_ica_session_file \ | ||
396 | --session "${cfg_sessions_session}" \ | ||
397 | niro | 2161 | --filename "$(fix_whitespaces ${cfg_sessions_filename})" \ |
398 | niro | 2149 | --username "${cfg_sessions_username}" \ |
399 | --password "${cfg_sessions_password}" \ | ||
400 | --domain "${cfg_sessions_domain}" \ | ||
401 | --server "${cfg_sessions_browseradrs}" | ||
402 | |||
403 | # fluxbox menusession | ||
404 | niro | 2161 | addconfig "[exec] (${cfg_sessions_session}) {nice -n 19 wfica ${ALX_ICA_SESSIONS}/$(fix_whitespaces ${cfg_sessions_filename})}" |
405 | niro | 2149 | done |
406 | |||
407 | # delete all progs | ||
408 | progsh_path="${ALX_UNPRIV_HOME}/.alxprogs" | ||
409 | [ -d ${progsh_path} ] && rm -rf ${progsh_path} | ||
410 | install -d ${progsh_path} | ||
411 | |||
412 | # add other menuitems | ||
413 | for i in ${all_other_ids} | ||
414 | do | ||
415 | evaluate_table cfg_other_menuitems "where serial='${ALX_SERIAL}' and id='${i}'" | ||
416 | |||
417 | # now echo config line for fluxbox-menu | ||
418 | # make it "configureable" :p | ||
419 | if [[ -n ${cfg_other_menuitems_workdir} ]] | ||
420 | niro | 2035 | then |
421 | niro | 2149 | workdir="--workdir ${cfg_other_menuitems_workdir}" |
422 | niro | 2035 | fi |
423 | niro | 2149 | if [[ -n ${cfg_other_menuitems_icon} ]] |
424 | then | ||
425 | cfg_other_menuitems_icon="<${cfg_other_menuitems_icon}>" | ||
426 | fi | ||
427 | |||
428 | # gen prog startup wrapper | ||
429 | generate_program_sh \ | ||
430 | --name "${cfg_other_menuitems_name}" \ | ||
431 | --exec "${cfg_other_menuitems_exec}" \ | ||
432 | niro | 2161 | --param "${cfg_other_menuitems_param}" \ |
433 | --dest "${progsh_path}/$(fix_whitespaces ${cfg_other_menuitems_name})" \ | ||
434 | "${workdir}" | ||
435 | niro | 2149 | |
436 | niro | 2161 | addconfig "[exec] (${cfg_other_menuitems_name}) {${progsh_path}/$(fix_whitespaces ${cfg_other_menuitems_name})} ${cfg_other_menuitems_icon}" |
437 | niro | 236 | done |
438 | |||
439 | # fluxbox menu footer | ||
440 | niro | 2035 | cat ${ALX_SKELETONS}/fluxbox/menu.footer >> ${ALX_UNPRIV_HOME}/.fluxbox/menu |
441 | niro | 239 | # add a newline (maybe there is no crlf in the footer) |
442 | niro | 2035 | addconfig |
443 | niro | 236 | |
444 | niro | 304 | # now it's a good time to generate *all* icons :) |
445 | niro | 2161 | generate_all_desktop_icons "${all_ses_ids}" "${all_other_ids}" |
446 | niro | 236 | |
447 | niro | 2149 | # fix permissions |
448 | niro | 236 | chown ${ALX_UNPRIV_USER}:${ALX_UNPRIV_GROUP} ${ALX_UNPRIV_HOME} |
449 | chown ${ALX_UNPRIV_USER}:${ALX_UNPRIV_GROUP} ${ALX_UNPRIV_HOME}/.fluxbox | ||
450 | chmod 0755 ${ALX_UNPRIV_HOME}/.fluxbox | ||
451 | niro | 338 | chmod 0755 ${ALX_UNPRIV_HOME}/.xtdesktop |
452 | chmod 0644 ${ALX_UNPRIV_HOME}/.xtdeskrc | ||
453 | niro | 236 | } |