Magellan Linux

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 272 - (hide annotations) (download) (as text)
Thu Apr 28 22:45:05 2005 UTC (19 years ago) by niro
File MIME type: application/x-sh
File size: 6686 byte(s)
cleaned the code; and added auto colors :)

1 niro 272 # $Header: /home/cvsd/alx-cvs/alx-src/alxconfig-ng/functions/config_sessions.sh,v 1.7 2005-04-28 22:45:05 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     #all arrays:
9     # -> session1 session2 ... sessionN
10    
11     #get settings from database
12     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     #split'em up and put in an array (only if $all not zero)
16     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     #get settings from database
35     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     #get settings from database
56     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     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 236 config_sessions()
125     {
126 niro 246 # generate ica session files
127     generate_ica_session_files
128    
129 niro 236 #first of all get the vars
130     get_sessions_settings
131 niro 246 get_autostart_settings
132 niro 236
133     local count=${#ALX_SESSIONS[*]}
134     local icon
135 niro 272 local i
136 niro 236
137     # DEBUG
138 niro 241 # declare -i i=0
139     # echo count=${count}
140     # echo "Number of new sessions: ${count}"
141     # for ((i=0; i < count; i++))
142     # do
143     # echo "${i} - ${ALX_SESSIONS[${i}]}"
144     # done
145 niro 236
146     # now setup fluxbox for user station
147    
148     # create a fresh fluxbox directory
149     [ -d ${ALX_UNPRIV_HOME}/.fluxbox ] && rm -rf ${ALX_UNPRIV_HOME}/.fluxbox
150     install -d ${ALX_UNPRIV_HOME}/.fluxbox
151    
152     # now generate fluxbox config files
153    
154     # fluxbox main config
155     cat ${ALX_SKELETONS}/fluxbox/init \
156     > ${ALX_UNPRIV_HOME}/.fluxbox/init
157    
158     # fluxbox autostart
159     cat ${ALX_SKELETONS}/fluxbox/apps \
160     > ${ALX_UNPRIV_HOME}/.fluxbox/apps
161    
162 niro 246 # add autostart session
163     if [[ ${ALX_AUTOSTART} != "" ]]
164     then
165     echo "[startup] {wfica ${ALX_ICA_SESSIONS}/${ALX_AUTOSTART}}" \
166     >> ${ALX_UNPRIV_HOME}/.fluxbox/apps
167     fi
168    
169 niro 236 # fluxbox hotkeys
170     cat ${ALX_SKELETONS}/fluxbox/apps \
171     > ${ALX_UNPRIV_HOME}/.fluxbox/keys
172    
173     # fluxbox menu header
174     cat ${ALX_SKELETONS}/fluxbox/menu.header \
175     > ${ALX_UNPRIV_HOME}/.fluxbox/menu
176    
177 niro 239 # add a newline (maybe there is no crlf in the header)
178     echo >> ${ALX_UNPRIV_HOME}/.fluxbox/menu
179    
180 niro 236 # fluxbox menu sessions
181     for (( i=0; i < count; i++ ))
182     do
183 niro 239 echo "[exec] ($(basename ${ALX_SESSIONS[${i}]} .ica)) {wfica ${ALX_ICA_SESSIONS}/${ALX_SESSIONS[${i}]}}" \
184 niro 236 >> ${ALX_UNPRIV_HOME}/.fluxbox/menu
185     done
186    
187     # fluxbox menu footer
188     cat ${ALX_SKELETONS}/fluxbox/menu.footer \
189     >> ${ALX_UNPRIV_HOME}/.fluxbox/menu
190    
191 niro 239 # add a newline (maybe there is no crlf in the footer)
192     echo >> ${ALX_UNPRIV_HOME}/.fluxbox/menu
193 niro 236
194     # now we generate the desktop icons
195     cat ${ALX_SKELETONS}/idesk/ideskrc \
196 niro 237 > ${ALX_UNPRIV_HOME}/.ideskrc
197 niro 236
198     # whipe out old stuff and install a fresh directory
199     [ -d ${ALX_UNPRIV_HOME}/.idesktop ] && rm -rf ${ALX_UNPRIV_HOME}/.idesktop
200     install -d ${ALX_UNPRIV_HOME}/.idesktop
201    
202     local name
203     for (( i=0; i < count; i++ ))
204     do
205     name="$(basename ${ALX_SESSIONS[${i}]} .ica)"
206    
207     if [ -f ${ALX_SESSIONS_ICONS}/${name}.png ]
208     then
209     icon="${ALX_SESSIONS_ICONS}/${name}.png"
210     else
211     icon="${ALX_SESSIONS_ICONS}/default.png"
212     fi
213    
214     echo "table Icon
215     Caption: ${name}
216 niro 239 Command: wfica ${ALX_ICA_SESSIONS}/${name}.ica
217 niro 236 Icon: ${icon}
218     end" > ${ALX_UNPRIV_HOME}/.idesktop/${name}.lnk
219     done
220    
221     # set correct permissions
222     chown ${ALX_UNPRIV_USER}:${ALX_UNPRIV_GROUP} ${ALX_UNPRIV_HOME}
223     chown ${ALX_UNPRIV_USER}:${ALX_UNPRIV_GROUP} ${ALX_UNPRIV_HOME}/.fluxbox
224     chmod 0755 ${ALX_UNPRIV_HOME}/.fluxbox
225     chmod 0755 ${ALX_UNPRIV_HOME}/.idesktop
226     chmod 0644 ${ALX_UNPRIV_HOME}/.ideskrc
227    
228    
229     # unset vars
230     unset ALX_SESSIONS
231     }