root/openPolicies/openPolicies

Revision 2, 4.7 KB (checked in by svngov, 11 years ago)

v1.0

Line 
1PROJECTNAME=linuxint
2
3# functions and definitions used by several scripts
4
5function debug {
6
7TAG=$PROJECTNAME-scripts
8logger -p local1.notice -t $TAG "$0 $@"
9
10}
11
12function runScript
13{
14
15# filenames may have spaces, protect them
16MYFILE="$1"
17
18debug "searching for $MYFILE"
19if [ -f "$MYFILE" ]; then
20   debug "executing $MYFILE"
21   /bin/bash "$@"
22fi
23
24}
25
26CHARSET=utf8
27
28# replaces a command called mountpoint that doesn't work with spaces on filenames
29function check_mount {
30
31for 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
37done
38
39return 1
40
41}
42
43function mountshare
44{
45
46SERVER=$1
47SHARE=$2
48SERVERNAME=$3
49GID=`id -g`
50TDIR="$HOME/mnt/$SHARE"
51
52# check if target dir exists
53if [ ! -d "$TDIR" ]; then
54  mkdir -p "$TDIR"
55fi
56
57# check if it is already mounted
58
59check_mount "$TDIR"
60rc=$?
61
62# do nothing if it is already mounted
63
64if [ $rc -eq 0 ]; then
65  return
66fi
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
78DISPLAYNAME=`echo $SHARE | awk -F/ '{ print $NF }'`
79
80# create a symlink on the Desktop
81
82ln -s "$TDIR" $HOME/Desktop/"$DISPLAYNAME em $SERVER"
83
84}
85
86function firefox_init_profile
87{
88
89PROFILENAME=$PROJECTNAME
90
91if [ ! -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
95fi
96
97}
98
99function 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
105PREFS=`find $HOME/.mozilla/firefox -name prefs.js| head`
106NAME=$1
107VALUE=$2
108TYPE=$3 # equals 1 if pref value is a string
109
110if [ ! -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
118fi
119
120
121}
122
123function firefox_set_proxy
124{
125
126PROXYTYPE=$1
127URL=$2
128PORT=$3
129NOPROXY="$4"
130firefox_set_pref network.proxy.type $PROXYTYPE 0
131
132# http://kb.mozillazine.org/Network.proxy.type
133
134case $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) 
152esac
153
154}
155
156function 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
164function firefox_set_ntlm_auth_link
165{
166
167if [ ! -e $HOME/ntlm_auth ]; then
168  ln -s /usr/bin/ntlm_auth $HOME/ntlm_auth
169fi
170
171}
172
173function firefox_set_homepage
174{
175
176  firefox_set_pref browser.startup.homepage $1 1
177
178}
179
180function firefox_install_CA
181{
182CERTURL=$1
183CERTNICK=$2
184PROFILENAME=$PROJECTNAME
185TMPFILE=$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
204function system_set_proxy
205{
206
207AUTOCONFIG_URL="http://wpad/wpad.dat"
208gconftool-2 --type string --set /system/proxy/mode "auto"
209gconftool-2 --type string --set /system/proxy/autoconfig_url $AUTOCONFIG_URL
210
211}
212
213function gnome_set_pref
214{
215NAME=$1
216VALUE=$2
217TYPE=$3 # equals 1 if pref value is a string
218
219  gconftool-2  --type $TYPE  --set $NAME "$VALUE"
220
221}
222
223function gnome_set_wallpaper
224{
225
226WALLPAPER=$1
227gnome_set_pref /desktop/gnome/background/picture_filename $WALLPAPER string
228
229}
230
231function linux_init_profile
232{
233
234PTDIR="$HOME/Área de Trabalho"
235# we MUST have a Desktop
236
237if [[ $LANG =~ "pt_PT" ]] && [ ! -e $HOME/Desktop ]; then
238  if [ ! -e "$PTDIR" ]; then mkdir "$PTDIR"; fi
239  ln -s "$PTDIR" $HOME/Desktop
240else
241  if [ ! -e $HOME/Desktop ]; then mkdir  $HOME/Desktop; fi
242fi
243
244}
245
Note: See TracBrowser for help on using the browser.