Magellan Linux

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

Parent Directory Parent Directory | Revision Log Revision Log


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