Magellan Linux

Annotation of /alx-src/trunk/alxconfig-ng/functions/config_sessions.sh

Parent Directory Parent Directory | Revision Log Revision Log


Revision 291 - (hide annotations) (download) (as text)
Thu Aug 18 02:51:16 2005 UTC (18 years, 8 months ago) by niro
File MIME type: application/x-sh
File size: 8430 byte(s)
fixed whitespaces and added variable menu header support

1 niro 291 # $Header: /home/cvsd/alx-cvs/alx-src/alxconfig-ng/functions/config_sessions.sh,v 1.10 2005-08-18 02:51:16 niro Exp $
2 niro 236 # configures ica-sessions on the host via mysql db settings
3    
4     get_sessions_settings()
5     {
6     local x i all count
7    
8 niro 291 # all arrays:
9 niro 236 # -> session1 session2 ... sessionN
10    
11 niro 291 # get settings from database
12 niro 236 all=$(mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \
13 niro 246 "select filename from cfg_sessions where serial='${ALX_SERIAL}'")
14 niro 236
15 niro 291 # split'em up and put in an array (only if $all not zero)
16 niro 236 declare -i i=0
17     if [ -n "${all}" ]
18     then
19     for x in ${all}
20     do
21     ALX_SESSIONS[${i}]=${x}
22     ((i++))
23     done
24     count=${i}
25     else
26     count=0
27     fi
28    
29     export ALX_SESSIONS
30     }
31    
32 niro 246 get_autostart_settings()
33     {
34 niro 291 # get settings from database
35 niro 246 ALX_AUTOSTART=$(mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \
36     "select session from cfg_autostart where serial='${ALX_SERIAL}'")
37    
38 niro 272 export ALX_AUTOSTART
39 niro 246 }
40    
41     generate_ica_session_files()
42     {
43     local all_ids
44     local i
45     local x
46     local server
47     local ses_session
48     local ses_filename
49     local ses_username
50     local ses_domain
51     local ses_password
52     local ses_browseradrs
53 niro 272 local ses_colors
54 niro 246
55 niro 291 # get settings from database
56 niro 246 all_ids=$(mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \
57     "select id from cfg_sessions where serial='${ALX_SERIAL}'")
58    
59     for i in ${all_ids}
60     do
61     # get settings
62 niro 272 ses_session=$(mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \
63 niro 246 "select session from cfg_sessions where serial='${ALX_SERIAL}' and id='${i}'")
64    
65 niro 272 ses_filename=$(mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \
66 niro 246 "select filename from cfg_sessions where serial='${ALX_SERIAL}' and id='${i}'")
67    
68 niro 272 ses_username=$(mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \
69 niro 246 "select username from cfg_sessions where serial='${ALX_SERIAL}' and id='${i}'")
70    
71 niro 272 ses_domain=$(mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \
72 niro 246 "select domain from cfg_sessions where serial='${ALX_SERIAL}' and id='${i}'")
73    
74 niro 272 ses_password=$(mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \
75 niro 246 "select password from cfg_sessions where serial='${ALX_SERIAL}' and id='${i}'")
76    
77 niro 272 ses_browseradrs=$(mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \
78 niro 246 "select browseradrs from cfg_sessions where serial='${ALX_SERIAL}' and id='${i}'")
79    
80 niro 272 # get the right colors
81     ses_colors=$(mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \
82     "select depth from cfg_graphic where serial='${ALX_SERIAL}'")
83     case ${ses_colors} in
84     24) ses_colors="8";;
85     16) ses_colors="4";;
86     8) ses_colors="2";;
87     *) ses_colors="2";;
88     esac
89    
90 niro 246 # write session files
91     echo '[WFClient]' > ${ALX_ICA_SESSIONS}/${ses_filename}
92     echo 'Version=2' >> ${ALX_ICA_SESSIONS}/${ses_filename}
93     OLD_IFS="$IFS"
94     IFS=";"
95 niro 272 declare -i x=0
96     for server in ${ses_browseradrs}
97 niro 246 do
98 niro 272 (( x++ ))
99     echo "TcpBrowserAddress${x}=${server}" >> ${ALX_ICA_SESSIONS}/${ses_filename}
100 niro 246 done
101     IFS="${OLD_IFS}"
102 niro 272 unset x
103 niro 246 unset OLD_IFS
104    
105     echo 'ScreenPercent=0' >> ${ALX_ICA_SESSIONS}/${ses_filename}
106    
107     echo '[ApplicationServers]' >> ${ALX_ICA_SESSIONS}/${ses_filename}
108 niro 272 echo "${ses_session}=" >> ${ALX_ICA_SESSIONS}/${ses_filename}
109 niro 246
110 niro 272 echo "[${ses_session}]" >> ${ALX_ICA_SESSIONS}/${ses_filename}
111     echo "Address=${ses_session}" >> ${ALX_ICA_SESSIONS}/${ses_filename}
112     echo "InitialProgram=#${ses_session}" >> ${ALX_ICA_SESSIONS}/${ses_filename}
113 niro 273 echo "DesiredColor=${ses_colors}" >> ${ALX_ICA_SESSIONS}/${ses_filename}
114 niro 246 echo 'TransportDriver=TCP/IP' >> ${ALX_ICA_SESSIONS}/${ses_filename}
115     echo 'WinStationDriver=ICA 3.0' >> ${ALX_ICA_SESSIONS}/${ses_filename}
116 niro 272 echo "ClearPassword=${ses_password}" >> ${ALX_ICA_SESSIONS}/${ses_filename}
117     echo "Username=${ses_username}" >> ${ALX_ICA_SESSIONS}/${ses_filename}
118     echo "Domain=${ses_domain}" >> ${ALX_ICA_SESSIONS}/${ses_filename}
119 niro 246 echo 'UseFullScreen=Yes' >> ${ALX_ICA_SESSIONS}/${ses_filename}
120     echo 'NoWindowManager=True' >> ${ALX_ICA_SESSIONS}/${ses_filename}
121     done
122     }
123    
124 niro 277 get_other_menuitems()
125     {
126     local x i count name exec icon workdir
127    
128 niro 291 # all arrays:
129 niro 277 # -> session1 session2 ... sessionN
130    
131 niro 291 # get settings from database
132 niro 277 count=$(mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \
133     "select name from cfg_other_menuitems where serial='${ALX_SERIAL}'")
134    
135     # get all instances and put them into an array
136     if [ -n "${count}" ]
137     then
138     for x in ${count}
139     do
140     # to be sure
141     unset name
142     unset exec
143     unset workdir
144     unset icon
145    
146     name=$(mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \
147     "select name from cfg_other_menuitems where serial='${ALX_SERIAL}' and name='${x}'")
148    
149     exec=$(mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \
150     "select exec from cfg_other_menuitems where serial='${ALX_SERIAL}' and name='${x}'")
151    
152     workdir=$(mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \
153     "select workdir from cfg_other_menuitems where serial='${ALX_SERIAL}' and name='${x}'")
154    
155     icon=$(mysql_command ${SQL_USER} ${SQL_PASS} ${SQL_HOST} ${SQL_DB} \
156     "select icon from cfg_other_menuitems where serial='${ALX_SERIAL}' and name='${x}'")
157    
158     # debug only
159     #echo "DEBUG: ${x}: name:'${name}' exec:'${exec}' workdir:'${workdir}' ic$
160    
161     # now echo config line for fluxbox-menu
162     # make it "configureable" :P
163     [ -n "${workdir}" ] && workdir="cd ${workdir};"
164     [ -n "${icon}" ] && icon="[${icon}]"
165     echo "[exec] (${name}) {${workdir}${exec}} ${icon}"
166     done
167     fi
168     }
169    
170 niro 236 config_sessions()
171     {
172 niro 246 # generate ica session files
173     generate_ica_session_files
174    
175 niro 291 # first of all get the vars
176 niro 236 get_sessions_settings
177 niro 246 get_autostart_settings
178 niro 236
179     local count=${#ALX_SESSIONS[*]}
180     local icon
181 niro 272 local i
182 niro 236
183     # DEBUG
184 niro 241 # declare -i i=0
185     # echo count=${count}
186     # echo "Number of new sessions: ${count}"
187     # for ((i=0; i < count; i++))
188     # do
189     # echo "${i} - ${ALX_SESSIONS[${i}]}"
190     # done
191 niro 236
192     # now setup fluxbox for user station
193    
194     # create a fresh fluxbox directory
195     [ -d ${ALX_UNPRIV_HOME}/.fluxbox ] && rm -rf ${ALX_UNPRIV_HOME}/.fluxbox
196     install -d ${ALX_UNPRIV_HOME}/.fluxbox
197    
198     # now generate fluxbox config files
199    
200     # fluxbox main config
201     cat ${ALX_SKELETONS}/fluxbox/init \
202     > ${ALX_UNPRIV_HOME}/.fluxbox/init
203    
204     # fluxbox autostart
205     cat ${ALX_SKELETONS}/fluxbox/apps \
206     > ${ALX_UNPRIV_HOME}/.fluxbox/apps
207    
208 niro 246 # add autostart session
209     if [[ ${ALX_AUTOSTART} != "" ]]
210     then
211     echo "[startup] {wfica ${ALX_ICA_SESSIONS}/${ALX_AUTOSTART}}" \
212     >> ${ALX_UNPRIV_HOME}/.fluxbox/apps
213     fi
214    
215 niro 236 # fluxbox hotkeys
216     cat ${ALX_SKELETONS}/fluxbox/apps \
217     > ${ALX_UNPRIV_HOME}/.fluxbox/keys
218    
219     # fluxbox menu header
220     cat ${ALX_SKELETONS}/fluxbox/menu.header \
221     > ${ALX_UNPRIV_HOME}/.fluxbox/menu
222    
223 niro 291 # now fix it with proper messages :P
224     local ver="$(< /etc/mageversion)"
225     sed -i "s:@CHANGEME@:alx-${ver} #${ALX_SERIAL}:g" \
226     ${ALX_UNPRIV_HOME}/.fluxbox/menu
227    
228 niro 239 # add a newline (maybe there is no crlf in the header)
229     echo >> ${ALX_UNPRIV_HOME}/.fluxbox/menu
230    
231 niro 236 # fluxbox menu sessions
232     for (( i=0; i < count; i++ ))
233     do
234 niro 277 [ -n "${ALX_SESSIONS[${i}]}" ] && \
235     echo "[exec] ($(basename ${ALX_SESSIONS[${i}]} .ica)) {wfica ${ALX_ICA_SESSIONS}/${ALX_SESSIONS[${i}]}}" \
236     >> ${ALX_UNPRIV_HOME}/.fluxbox/menu
237 niro 236 done
238    
239 niro 277 # add other menuitems
240     get_other_menuitems >> ${ALX_UNPRIV_HOME}/.fluxbox/menu
241    
242 niro 236 # fluxbox menu footer
243     cat ${ALX_SKELETONS}/fluxbox/menu.footer \
244     >> ${ALX_UNPRIV_HOME}/.fluxbox/menu
245    
246 niro 239 # add a newline (maybe there is no crlf in the footer)
247     echo >> ${ALX_UNPRIV_HOME}/.fluxbox/menu
248 niro 236
249     # now we generate the desktop icons
250     cat ${ALX_SKELETONS}/idesk/ideskrc \
251 niro 237 > ${ALX_UNPRIV_HOME}/.ideskrc
252 niro 236
253     # whipe out old stuff and install a fresh directory
254     [ -d ${ALX_UNPRIV_HOME}/.idesktop ] && rm -rf ${ALX_UNPRIV_HOME}/.idesktop
255     install -d ${ALX_UNPRIV_HOME}/.idesktop
256    
257     local name
258     for (( i=0; i < count; i++ ))
259     do
260     name="$(basename ${ALX_SESSIONS[${i}]} .ica)"
261    
262     if [ -f ${ALX_SESSIONS_ICONS}/${name}.png ]
263     then
264     icon="${ALX_SESSIONS_ICONS}/${name}.png"
265     else
266     icon="${ALX_SESSIONS_ICONS}/default.png"
267     fi
268    
269     echo "table Icon
270     Caption: ${name}
271 niro 239 Command: wfica ${ALX_ICA_SESSIONS}/${name}.ica
272 niro 236 Icon: ${icon}
273     end" > ${ALX_UNPRIV_HOME}/.idesktop/${name}.lnk
274     done
275    
276     # set correct permissions
277     chown ${ALX_UNPRIV_USER}:${ALX_UNPRIV_GROUP} ${ALX_UNPRIV_HOME}
278     chown ${ALX_UNPRIV_USER}:${ALX_UNPRIV_GROUP} ${ALX_UNPRIV_HOME}/.fluxbox
279     chmod 0755 ${ALX_UNPRIV_HOME}/.fluxbox
280     chmod 0755 ${ALX_UNPRIV_HOME}/.idesktop
281     chmod 0644 ${ALX_UNPRIV_HOME}/.ideskrc
282    
283    
284     # unset vars
285     unset ALX_SESSIONS
286     }