Magellan Linux

Annotation of /alx-src/branches/alxconf-060/functions/config_sessions.sh

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2408 - (hide annotations) (download) (as text)
Wed Jun 15 12:54:42 2011 UTC (12 years, 10 months ago) by niro
File MIME type: application/x-sh
File size: 12471 byte(s)
-typo
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 2401 local utility
127 niro 304
128     # very basic getops
129     for i in $*
130     do
131     case $1 in
132     --name|-n) shift; name="$1" ;;
133     --command|-c) shift; command="$1" ;;
134     --icon|-i) shift; icon="$1" ;;
135     --dest|-d) shift; dest="$1" ;;
136     --xres|-x) shift; xres="$1" ;;
137     --yres|-y) shift; yres="$1" ;;
138     --icon-width|-w) shift; iwidth="$1" ;;
139     --icon-height|-h) shift; iheight="$1" ;;
140 niro 317 --default-icon) shift; deficon="$1" ;;
141 niro 304 esac
142     shift
143     done
144    
145 niro 2149 # some sanity checks:
146 niro 2401
147 niro 304 # abort if name or command not given
148 niro 2035 [[ -z ${name} ]] && return 1
149     [[ -z ${command} ]] && return 1
150 niro 304
151 niro 2401 # which utility are we using idesk|xtdesk ?
152     if [ -x /usr/bin/idesk ]
153     then
154     utility="idesk"
155     [[ -z ${dest} ]] && dest="${ALX_UNPRIV_HOME}/.idesktop/${name}.lnk"
156     else
157     utility="xtdesk"
158     [[ -z ${dest} ]] && dest="${ALX_UNPRIV_HOME}/.xtdesktop/${name}.lnk"
159     fi
160    
161 niro 304 # use some defaults for icon, dest, {x,y}res
162 niro 2035 [[ -z ${xres} ]] && xres=30
163     [[ -z ${yres} ]] && xres=30
164     if [[ -z ${icon} ]] || [ ! -f ${icon} ]
165 niro 304 then
166 niro 317 # if no default icon is given use default.png
167 niro 2035 [[ -z ${deficon} ]] && deficon="default.png"
168 niro 317 icon="${ALX_SESSIONS_ICONS}/${deficon}"
169 niro 304 fi
170    
171 niro 2161 CONFIG="${dest}"
172 niro 2035 clearconfig
173 niro 304
174 niro 2035 addconfig 'table Icon'
175 niro 2401 [[ ${utility} = xtdesk ]] && addconfig ' Type: Program'
176 niro 2035 addconfig " Caption: ${name}"
177     addconfig " Command: ${command}"
178     addconfig " Icon: ${icon}"
179     addconfig " X: ${xres}"
180     addconfig " Y: ${yres}"
181    
182 niro 304 # add these only if not zero
183 niro 2035 if [[ ! -z ${iwidth} ]] && [[ ! -z ${iheight} ]]
184 niro 304 then
185 niro 2401 if [[ ${utility} = xtdesk ]]
186     then
187     addconfig " IconWidth: ${iwidth}"
188     addconfig " IconHeight: ${iheight}"
189     fi
190     if [[ ${utility} = idesk ]]
191     then
192     addconfig " Width: ${iwidth}"
193     addconfig " Height: ${iheight}"
194     fi
195 niro 304 fi
196    
197 niro 2035 addconfig 'end'
198 niro 304 }
199    
200     generate_all_desktop_icons()
201     {
202 niro 2149 local session_list="$1"
203     local other_menuitem_list="$2"
204 niro 304 local res
205     local xres
206     local yres
207     local x
208     local y
209 niro 2161 local i
210 niro 2149 local name
211 niro 317 local progsh_path
212 niro 2401 local utility
213     local dest
214     local rc
215 niro 304
216 niro 2401 # which utility are we using idesk|xtdesk ?
217     if [ -x /usr/bin/idesk ]
218     then
219     utility="idesk"
220     dest="${ALX_UNPRIV_HOME}/.idesktop"
221     rc="${ALX_UNPRIV_HOME}/.ideskrc"
222     else
223     utility="xtdesk"
224     dest="${ALX_UNPRIV_HOME}/.xtdesktop"
225     rc="${ALX_UNPRIV_HOME}/.xtdeskrc"
226     fi
227    
228    
229 niro 2149 # progsh path
230 niro 2161 progsh_path="${ALX_UNPRIV_HOME}/.alxprogs"
231 niro 2149
232 niro 304 # get the resolution
233 niro 342 res=$(mysqldo "select resolution from cfg_graphic where serial='${ALX_SERIAL}'")
234 niro 304
235     # split res to x & y
236 niro 2149 xres="${res%x*}"
237 niro 2166 yres="${res#*x}"
238 niro 304
239     # top left edge of the icon is given in config file
240     # remove a little bit to simulate the bottom-right edge
241     xres="$(( ${xres} - 120 ))"
242     yres="$(( ${yres} - 80 ))"
243    
244     # clean desktop icon location
245 niro 2401 [ -d ${dest} ] && rm -rf ${dest}
246     [ -f ${rc} ] && rm -f ${rc}
247     install -d ${dest}
248 niro 304
249 niro 2401 if [[ ${utility} = xtdesk ]]
250     then
251 niro 2381 # basic config
252     cat ${ALX_SKELETONS}/xtdesktop/xtdeskrc > ${ALX_UNPRIV_HOME}/.xtdesktop/xtdeskrc
253 niro 2401 fi
254 niro 2381
255 niro 304 # default settings
256 niro 1594 declare -i x=30
257     declare -i y=30
258 niro 304
259 niro 2149 # ica icons
260 niro 2161 for i in ${session_list}
261 niro 304 do
262     # abort if empty
263 niro 2161 [[ -z ${i} ]] && continue
264 niro 304
265 niro 2161 # get database information
266     evaluate_table cfg_sessions "where serial='${ALX_SERIAL}' and id='${i}'"
267    
268 niro 304 # new line if x > xres
269 niro 2035 if [ ${x} -ge ${xres} ]
270     then
271 niro 1594 x=30
272 niro 304 y=$((${y} + 80))
273     fi
274    
275     # new row if y > yres
276 niro 2035 if [ ${y} -ge ${yres} ]
277     then
278 niro 304 x=$((${x} + 120))
279 niro 1594 y=30
280 niro 304
281     # re-check x
282 niro 1594 [ ${x} -ge ${xres} ] && x=30
283 niro 304 fi
284    
285     generate_icon \
286 niro 2166 --name "${cfg_sessions_session}" \
287     --command "nice -n 19 wfica ${ALX_ICA_SESSIONS}/$(fix_whitespaces ${cfg_sessions_filename})" \
288     --icon "${ALX_SESSIONS_ICONS}/$(fix_whitespaces ${cfg_sessions_session}).png" \
289 niro 2401 --dest "${dest}/$(fix_whitespaces ${cfg_sessions_session}).lnk" \
290 niro 304 --xres "${x}" \
291     --yres "${y}"
292    
293     y=$((${y} + 80))
294     done
295    
296 niro 2161 for i in ${other_menuitem_list}
297 niro 317 do
298     # abort if empty
299 niro 2161 [[ -z ${i} ]] && continue
300 niro 317
301 niro 2161 # get database information
302     evaluate_table cfg_other_menuitems "where serial='${ALX_SERIAL}' and id='${i}'"
303    
304 niro 317 # new line if x > xres
305 niro 2035 if [ ${x} -ge ${xres} ]
306     then
307 niro 1594 x=30
308 niro 317 y=$((${y} + 80))
309     fi
310    
311     # new row if y > yres
312 niro 2035 if [ ${y} -ge ${yres} ]
313     then
314 niro 317 x=$((${x} + 120))
315 niro 1594 y=30
316 niro 317
317     # re-check x
318 niro 1594 [ ${x} -ge ${xres} ] && x=30
319 niro 317 fi
320    
321     generate_icon \
322 niro 2161 --name "${cfg_other_menuitems_name}" \
323 niro 2381 --command "${progsh_path}/$(fix_whitespaces ${cfg_other_menuitems_name})" \
324 niro 2161 --icon "${ALX_SESSIONS_ICONS}/$(fix_whitespaces ${cfg_other_menuitems_name}).png" \
325 niro 2401 --dest "${dest}/$(fix_whitespaces ${cfg_other_menuitems_name}).lnk" \
326 niro 317 --xres "${x}" \
327     --yres "${y}" \
328     --default-icon "default_item.png"
329    
330     y=$((${y} + 80))
331     done
332    
333 niro 304 # last but not least gen a icon with some sys informations
334     local sysinfo
335     local hostname
336     local osversion
337    
338     osversion="$(< /etc/mageversion)"
339 niro 342 hostname=$(mysqldo "select hostname from cfg_network where serial='${ALX_SERIAL}'")
340 niro 304 sysinfo="Hostname: ${hostname} Serial: #${ALX_SERIAL} OS: alx-${osversion} Kernel: $(uname -r)"
341    
342     # now get the right position:
343     # restore orig values of xres
344     xres="$(( ${xres} + 120 ))"
345     # default y pos (full yres -22 = cur yres + 58 !)
346     yres="$(( ${yres} + 58 ))"
347     # middle of the screen
348     # (no txt - length required, xtdesk manage that itself)
349     xres="$(( ${xres} / 2))"
350    
351     generate_icon \
352     --name "${sysinfo}" \
353     --command "exit 0" \
354     --icon "${ALX_SESSIONS_ICONS}/sysinfo.png" \
355 niro 2401 --dest "${dest}/sysinfo.lnk" \
356 niro 304 --xres "${xres}" \
357     --yres "${yres}" \
358     --icon-width "1" \
359     --icon-height "1"
360     }
361    
362 niro 236 config_sessions()
363     {
364 niro 272 local i
365 niro 2149 local all_ses_ids
366     local all_other_ids
367 niro 2035 local CONFIG
368 niro 2149 local screensaver_passwd_cmd
369 niro 236
370 niro 2149 # get all session ids from database
371     all_ses_ids=$(mysqldo "select id from cfg_sessions where serial='${ALX_SERIAL}'")
372     # get all other_menutiem ids from database
373     all_other_ids=$(mysqldo "select id from cfg_other_menuitems where serial='${ALX_SERIAL}'")
374    
375     # get screensaver settings
376     evaluate_table cfg_screensaver
377     # get autostart settings
378     evaluate_table cfg_autostart
379    
380 niro 236 # now setup fluxbox for user station
381    
382     # create a fresh fluxbox directory
383     [ -d ${ALX_UNPRIV_HOME}/.fluxbox ] && rm -rf ${ALX_UNPRIV_HOME}/.fluxbox
384     install -d ${ALX_UNPRIV_HOME}/.fluxbox
385    
386     # now generate fluxbox config files
387    
388     # fluxbox main config
389 niro 2149 cat ${ALX_SKELETONS}/fluxbox/init > ${ALX_UNPRIV_HOME}/.fluxbox/init
390 niro 236
391     # fluxbox autostart
392 niro 2149 cat ${ALX_SKELETONS}/fluxbox/apps > ${ALX_UNPRIV_HOME}/.fluxbox/apps
393 niro 236
394 niro 2149 CONFIG="${ALX_UNPRIV_HOME}/.fluxbox/apps"
395 niro 338 # add screensaver
396 niro 2149 if [[ ! -z ${cfg_screensaver_screensaver} ]] && [[ ! -z ${cfg_screensaver_screensaver_timeout} ]]
397 niro 338 then
398 niro 2149 if [[ -z ${cfg_screensaver_password} ]] || [[ ${cfg_screensaver_password} = NULL ]]
399 niro 338 then
400 niro 2149 screensaver_passwd_cmd="-nolock"
401 niro 338 else
402 niro 2149 screensaver_passwd_cmd="-cpasswd $(cryptpw -m des ${cfg_screensaver_password})"
403 niro 338 fi
404    
405 niro 2149 addconfig "[startup] {nohup xautolock -time ${cfg_screensaver_timeout} -locker 'xlock -mode ${cfg_screensaver_screensaver} ${screensaver_passwd_cmd}' > /dev/null &}"
406 niro 338 fi
407    
408 niro 246 # add autostart session
409 niro 2149 if [[ ! -z ${cfg_autostart_session} ]]
410 niro 246 then
411 niro 2371 # sleep one second to wait until busybox is fully initialized and the screen is really centered
412     addconfig "[startup] {sleep 1 && nohup nice -n 19 wfica ${ALX_ICA_SESSIONS}/$(fix_whitespaces ${cfg_autostart_session}) &}"
413 niro 246 fi
414    
415 niro 236 # fluxbox hotkeys
416 niro 2035 cat ${ALX_SKELETONS}/fluxbox/keys > ${ALX_UNPRIV_HOME}/.fluxbox/keys
417 niro 236
418 niro 2035 # generate a fluxbox menu
419 niro 2161 CONFIG="${ALX_UNPRIV_HOME}/.fluxbox/menu"
420 niro 2035 clearconfig
421    
422 niro 236 # fluxbox menu header
423 niro 2035 cat ${ALX_SKELETONS}/fluxbox/menu.header >> ${ALX_UNPRIV_HOME}/.fluxbox/menu
424 niro 291 # now fix it with proper messages :P
425     local ver="$(< /etc/mageversion)"
426 niro 2035 sed -i "s:@CHANGEME@:alx-${ver} #${ALX_SERIAL}:g" ${ALX_UNPRIV_HOME}/.fluxbox/menu
427 niro 239 # add a newline (maybe there is no crlf in the header)
428 niro 2035 addconfig
429 niro 239
430 niro 2149 # first generate session files
431     for i in ${all_ses_ids}
432 niro 236 do
433 niro 2149 evaluate_table cfg_sessions "where serial='${ALX_SERIAL}' and id='${i}'"
434     generate_ica_session_file \
435     --session "${cfg_sessions_session}" \
436 niro 2161 --filename "$(fix_whitespaces ${cfg_sessions_filename})" \
437 niro 2149 --username "${cfg_sessions_username}" \
438     --password "${cfg_sessions_password}" \
439     --domain "${cfg_sessions_domain}" \
440     --server "${cfg_sessions_browseradrs}"
441    
442     # fluxbox menusession
443 niro 2161 addconfig "[exec] (${cfg_sessions_session}) {nice -n 19 wfica ${ALX_ICA_SESSIONS}/$(fix_whitespaces ${cfg_sessions_filename})}"
444 niro 2149 done
445    
446     # delete all progs
447     progsh_path="${ALX_UNPRIV_HOME}/.alxprogs"
448     [ -d ${progsh_path} ] && rm -rf ${progsh_path}
449     install -d ${progsh_path}
450    
451     # add other menuitems
452     for i in ${all_other_ids}
453     do
454     evaluate_table cfg_other_menuitems "where serial='${ALX_SERIAL}' and id='${i}'"
455    
456     # now echo config line for fluxbox-menu
457     # make it "configureable" :p
458     if [[ -n ${cfg_other_menuitems_workdir} ]]
459 niro 2035 then
460 niro 2149 workdir="--workdir ${cfg_other_menuitems_workdir}"
461 niro 2035 fi
462 niro 2149 if [[ -n ${cfg_other_menuitems_icon} ]]
463     then
464     cfg_other_menuitems_icon="<${cfg_other_menuitems_icon}>"
465     fi
466    
467     # gen prog startup wrapper
468     generate_program_sh \
469     --name "${cfg_other_menuitems_name}" \
470     --exec "${cfg_other_menuitems_exec}" \
471 niro 2161 --param "${cfg_other_menuitems_param}" \
472     --dest "${progsh_path}/$(fix_whitespaces ${cfg_other_menuitems_name})" \
473     "${workdir}"
474 niro 2149
475 niro 2161 addconfig "[exec] (${cfg_other_menuitems_name}) {${progsh_path}/$(fix_whitespaces ${cfg_other_menuitems_name})} ${cfg_other_menuitems_icon}"
476 niro 236 done
477    
478     # fluxbox menu footer
479 niro 2035 cat ${ALX_SKELETONS}/fluxbox/menu.footer >> ${ALX_UNPRIV_HOME}/.fluxbox/menu
480 niro 239 # add a newline (maybe there is no crlf in the footer)
481 niro 2035 addconfig
482 niro 236
483 niro 304 # now it's a good time to generate *all* icons :)
484 niro 2161 generate_all_desktop_icons "${all_ses_ids}" "${all_other_ids}"
485 niro 236
486 niro 2149 # fix permissions
487 niro 236 chown ${ALX_UNPRIV_USER}:${ALX_UNPRIV_GROUP} ${ALX_UNPRIV_HOME}
488     chown ${ALX_UNPRIV_USER}:${ALX_UNPRIV_GROUP} ${ALX_UNPRIV_HOME}/.fluxbox
489     chmod 0755 ${ALX_UNPRIV_HOME}/.fluxbox
490 niro 338 chmod 0755 ${ALX_UNPRIV_HOME}/.xtdesktop
491     chmod 0644 ${ALX_UNPRIV_HOME}/.xtdeskrc
492 niro 236 }