1 | PROJECTNAME=linuxint |
---|
2 | |
---|
3 | # functions and definitions used by several scripts |
---|
4 | |
---|
5 | function debug { |
---|
6 | |
---|
7 | TAG=$PROJECTNAME-scripts |
---|
8 | logger -p local1.notice -t $TAG "$0 $@" |
---|
9 | |
---|
10 | } |
---|
11 | |
---|
12 | function runScript |
---|
13 | { |
---|
14 | |
---|
15 | # filenames may have spaces, protect them |
---|
16 | MYFILE="$1" |
---|
17 | |
---|
18 | debug "searching for $MYFILE" |
---|
19 | if [ -f "$MYFILE" ]; then |
---|
20 | debug "executing $MYFILE" |
---|
21 | /bin/bash "$@" |
---|
22 | fi |
---|
23 | |
---|
24 | } |
---|
25 | |
---|
26 | CHARSET=utf8 |
---|
27 | |
---|
28 | # replaces a command called mountpoint that doesn't work with spaces on filenames |
---|
29 | function check_mount { |
---|
30 | |
---|
31 | for i in `cat /proc/mounts | cut -d' ' -f2`; do |
---|
32 | NAMEWITH040=`echo $1 | sed 's/ /\\\040/g'`; |
---|
33 | MYNAME=${NAMEWITH040%/} |
---|
34 | if [ "x$MYNAME" = "x$i" ]; then |
---|
35 | return 0 |
---|
36 | fi |
---|
37 | done |
---|
38 | |
---|
39 | return 1 |
---|
40 | |
---|
41 | } |
---|
42 | |
---|
43 | function mountshare |
---|
44 | { |
---|
45 | |
---|
46 | SERVER=$1 |
---|
47 | SHARE=$2 |
---|
48 | SERVERNAME=$3 |
---|
49 | GID=`id -g` |
---|
50 | TDIR="$HOME/mnt/$SHARE" |
---|
51 | |
---|
52 | # check if target dir exists |
---|
53 | if [ ! -d "$TDIR" ]; then |
---|
54 | mkdir -p "$TDIR" |
---|
55 | fi |
---|
56 | |
---|
57 | # check if it is already mounted |
---|
58 | |
---|
59 | check_mount "$TDIR" |
---|
60 | rc=$? |
---|
61 | |
---|
62 | # do nothing if it is already mounted |
---|
63 | |
---|
64 | if [ $rc -eq 0 ]; then |
---|
65 | return |
---|
66 | fi |
---|
67 | |
---|
68 | |
---|
69 | # a opcao nodsf e' necessaria para certas versoes do samba server como WA de um bug |
---|
70 | # https://bugs.launchpad.net/ubuntu/+source/samba/+bug/286828 |
---|
71 | # idem para a opcao nobrl |
---|
72 | # https://bugs.launchpad.net/ubuntu/+source/openoffice.org/+bug/578402 |
---|
73 | |
---|
74 | /sbin/mount.cifs "//$SERVER/$SHARE" "$TDIR" -o nobrl,nodfs,suid,username=$4,password=$5,uid=$UID,gid=$GID,file_mode=0600,dir_mode=0700,iocharset=$CHARSET |
---|
75 | |
---|
76 | # clear $SHARE from "/"s, if we are mounting a subdir let's keep only the last component |
---|
77 | |
---|
78 | DISPLAYNAME=`echo $SHARE | awk -F/ '{ print $NF }'` |
---|
79 | |
---|
80 | # create a symlink on the Desktop |
---|
81 | |
---|
82 | ln -s "$TDIR" $HOME/Desktop/"$DISPLAYNAME em $SERVER" |
---|
83 | |
---|
84 | } |
---|
85 | |
---|
86 | function firefox_init_profile |
---|
87 | { |
---|
88 | |
---|
89 | PROFILENAME=$PROJECTNAME |
---|
90 | |
---|
91 | if [ ! -d $HOME/.mozilla/firefox/$PROFILENAME.default ]; then |
---|
92 | mkdir -p $HOME/.mozilla/firefox/$PROFILENAME.default |
---|
93 | touch $HOME/.mozilla/firefox/$PROFILENAME.default/prefs.js |
---|
94 | echo -e "[Profile0]\\nName=default\\nIsRelative=1\\nPath=$PROFILENAME.default" > $HOME/.mozilla/firefox/profiles.ini |
---|
95 | fi |
---|
96 | |
---|
97 | } |
---|
98 | |
---|
99 | function firefox_set_pref |
---|
100 | { |
---|
101 | |
---|
102 | # the prefs.js file must exist in order for this to work |
---|
103 | # that is ensure by the init_firefox_profile function |
---|
104 | |
---|
105 | PREFS=`find $HOME/.mozilla/firefox -name prefs.js| head` |
---|
106 | NAME=$1 |
---|
107 | VALUE=$2 |
---|
108 | TYPE=$3 # equals 1 if pref value is a string |
---|
109 | |
---|
110 | if [ ! -z $PREFS ] && [ -f $PREFS ]; then |
---|
111 | cp -f $PREFS $PREFS.bak |
---|
112 | cat $PREFS.bak |grep -v \"$NAME\" > $PREFS |
---|
113 | if [ $TYPE = 1 ]; then |
---|
114 | echo "user_pref(\"$NAME\", \"$VALUE\");" >> $PREFS |
---|
115 | else |
---|
116 | echo "user_pref(\"$NAME\", $VALUE);" >> $PREFS |
---|
117 | fi |
---|
118 | fi |
---|
119 | |
---|
120 | |
---|
121 | } |
---|
122 | |
---|
123 | function firefox_set_proxy |
---|
124 | { |
---|
125 | |
---|
126 | PROXYTYPE=$1 |
---|
127 | URL=$2 |
---|
128 | PORT=$3 |
---|
129 | NOPROXY="$4" |
---|
130 | firefox_set_pref network.proxy.type $PROXYTYPE 0 |
---|
131 | |
---|
132 | # http://kb.mozillazine.org/Network.proxy.type |
---|
133 | |
---|
134 | case $PROXYTYPE in |
---|
135 | 0) |
---|
136 | ;; |
---|
137 | 1) |
---|
138 | firefox_set_pref network.proxy.http $URL 1 |
---|
139 | firefox_set_pref network.proxy.http_port $PORT 0 |
---|
140 | firefox_set_pref network.proxy.ssl $URL 1 0 |
---|
141 | firefox_set_pref network.proxy.ssl $PORT 0 |
---|
142 | firefox_set_pref network.proxy.no_proxies_on "$NOPROXY" 1 |
---|
143 | ;; |
---|
144 | 2) |
---|
145 | firefox_set_pref network.proxy.autoconfig_url $URL 1 |
---|
146 | ;; |
---|
147 | 3) |
---|
148 | ;; |
---|
149 | 4) |
---|
150 | ;; |
---|
151 | 5) |
---|
152 | esac |
---|
153 | |
---|
154 | } |
---|
155 | |
---|
156 | function firefox_set_sso |
---|
157 | { |
---|
158 | |
---|
159 | firefox_set_pref network.automatic-ntlm-auth.trusted-uris $1 1 |
---|
160 | firefox_set_pref network.negotiate-auth.trusted-uris $1 1 |
---|
161 | |
---|
162 | } |
---|
163 | |
---|
164 | function firefox_set_ntlm_auth_link |
---|
165 | { |
---|
166 | |
---|
167 | if [ ! -e $HOME/ntlm_auth ]; then |
---|
168 | ln -s /usr/bin/ntlm_auth $HOME/ntlm_auth |
---|
169 | fi |
---|
170 | |
---|
171 | } |
---|
172 | |
---|
173 | function firefox_set_homepage |
---|
174 | { |
---|
175 | |
---|
176 | firefox_set_pref browser.startup.homepage $1 1 |
---|
177 | |
---|
178 | } |
---|
179 | |
---|
180 | function firefox_install_CA |
---|
181 | { |
---|
182 | CERTURL=$1 |
---|
183 | CERTNICK=$2 |
---|
184 | PROFILENAME=$PROJECTNAME |
---|
185 | TMPFILE=$HOME/tmp/tmpcert.crt |
---|
186 | |
---|
187 | certutil -d $HOME/.mozilla/firefox/$PROFILENAME.default/ -L -n $CERTNICK >& /dev/null |
---|
188 | RC=$? |
---|
189 | |
---|
190 | if [ ! $RC -eq 0 ]; then |
---|
191 | debug "Installing certificate $CERTURL with name $CERTNICK" |
---|
192 | if [[ "$CERTURL" =~ "http://" ]]; then |
---|
193 | wget -O $TMPFILE $CERTURL |
---|
194 | CERTFILE=$TMPFILE |
---|
195 | else |
---|
196 | CERTFILE=$CERTURL |
---|
197 | fi |
---|
198 | certutil -d $HOME/.mozilla/firefox/$PROFILENAME.default/ -A -t "TC,c,c" -i $CERTFILE -n $CERTNICK |
---|
199 | rm -f $TMPFILE |
---|
200 | fi |
---|
201 | |
---|
202 | } |
---|
203 | |
---|
204 | function system_set_proxy |
---|
205 | { |
---|
206 | |
---|
207 | AUTOCONFIG_URL="http://wpad/wpad.dat" |
---|
208 | gconftool-2 --type string --set /system/proxy/mode "auto" |
---|
209 | gconftool-2 --type string --set /system/proxy/autoconfig_url $AUTOCONFIG_URL |
---|
210 | |
---|
211 | } |
---|
212 | |
---|
213 | function gnome_set_pref |
---|
214 | { |
---|
215 | NAME=$1 |
---|
216 | VALUE=$2 |
---|
217 | TYPE=$3 # equals 1 if pref value is a string |
---|
218 | |
---|
219 | gconftool-2 --type $TYPE --set $NAME "$VALUE" |
---|
220 | |
---|
221 | } |
---|
222 | |
---|
223 | function gnome_set_wallpaper |
---|
224 | { |
---|
225 | |
---|
226 | WALLPAPER=$1 |
---|
227 | gnome_set_pref /desktop/gnome/background/picture_filename $WALLPAPER string |
---|
228 | |
---|
229 | } |
---|
230 | |
---|
231 | function linux_init_profile |
---|
232 | { |
---|
233 | |
---|
234 | PTDIR="$HOME/Ãrea de Trabalho" |
---|
235 | # we MUST have a Desktop |
---|
236 | |
---|
237 | if [[ $LANG =~ "pt_PT" ]] && [ ! -e $HOME/Desktop ]; then |
---|
238 | if [ ! -e "$PTDIR" ]; then mkdir "$PTDIR"; fi |
---|
239 | ln -s "$PTDIR" $HOME/Desktop |
---|
240 | else |
---|
241 | if [ ! -e $HOME/Desktop ]; then mkdir $HOME/Desktop; fi |
---|
242 | fi |
---|
243 | |
---|
244 | } |
---|
245 | |
---|