source: home-linker/trunk/fuentes/home-linker.install/usr/sbin/home-linker @ 4096

Last change on this file since 4096 was 4096, checked in by daduve, 3 years ago

Fix bug in wellcome echo

  • Property svn:executable set to *
File size: 12.5 KB
Line 
1#!/bin/sh
2set -x
3
4
5echo 
6
7LOG="/var/log/home_linker.log"
8echo "" > "$LOG"
9echo "******************************" >> "$LOG"
10echo "WELLCOME TO HOME-LINKER LOG" >> "$LOG"
11echo "" >> "$LOG"
12date >> "$LOG"
13echo "******************************" >> "$LOG"
14echo "" >> "$LOG"
15echo "Username -> $1" >> "$LOG"
16
17trim() {
18    local var="$*"
19    var="${var#"${var%%[![:space:]]*}"}"   # remove leading whitespace characters
20    var="${var%"${var##*[![:space:]]}"}"   # remove trailing whitespace characters
21    echo -n "$var"
22}
23
24#SET VARIABLES FOR THE ENVIRONMENT
25
26#GET VARIABLES
27USER=$1
28HL_USER=$(trim "$USER")
29
30if [ ! -z "$2" ]; then
31                HL_HOME="$2"   
32        else
33                NHOME=$(python -c "
34tmp='$HOME'.split('/')
35last=tmp[-1]
36print '/'.join(tmp[:-1])+'/'+last.strip()
37")
38
39                HL_HOME="$NHOME"
40fi
41
42# From this file get $LANG
43{ [ -r "$HL_HOME/.pam_environment" ] && . "$HL_HOME/.pam_environment" ;} || { [ -r "/etc/default/locale" ] && . "/etc/default/locale" ;} || LANG="en"
44
45if [ ! -z "$LDM_LANGUAGE" ]; then
46                AUX_LANG="$LDM_LANGUAGE"       
47        else
48                AUX_LANG="$LANG"
49fi
50
51
52
53
54
55
56# Get Usernames
57GRP_USER="$(id -ng $HL_USER)"
58
59# Source for user-dirs if it exists
60USER_DIRS="$HL_HOME/.config/user-dirs.dirs"
61[ ! -r $USER_DIRS ] || . $USER_DIRS
62
63# Source the token file if it exists
64LAST_LOGIN_DIRECTORIES="$HL_HOME/.config/user-dirs.created"
65[ ! -r "$LAST_LOGIN_DIRECTORIES" ] || . "$LAST_LOGIN_DIRECTORIES"
66
67#Temp file with new user-dirs
68[ -d "$HL_HOME" ] || { mkdir -p "$HL_HOME" ; chown $HL_USER:$GRP_USER "$HL_HOME" ;}
69[ -d "$HL_HOME/.config" ] || { mkdir -p "$HL_HOME/.config" ; chown $HL_USER:$GRP_USER "$HL_HOME/.config" ;}
70TEMP_NEW_USER_DIRS="$HL_HOME/.config/aux-user-dirs.create"
71:> $TEMP_NEW_USER_DIRS
72
73#set Acl on Home to be more restricted
74get_acl_from_server "$HL_HOME" "$GRP_USER" $HL_USER
75
76# Download directory actions
77DOWNLOADS_LOCALE="$(/usr/bin/xdg_translator "$AUX_LANG" "Downloads")"
78DESKTOP_LOCALE="$(/usr/bin/xdg_translator "$AUX_LANG"  "Desktop")"
79DOCUMENTS_LOCALE="$(/usr/bin/xdg_translator "$AUX_LANG"  "Documents")"
80SHARE_LOCALE="$(/usr/bin/xdg_translator "$AUX_LANG"  "Share")"
81SHARETEACHERS_LOCALE="$(/usr/bin/xdg_translator "$AUX_LANG"  "Teachers_Share")"
82GROUPSSHARE_LOCALE="$(/usr/bin/xdg_translator "$AUX_LANG"  "Groups_Share")"
83DATA_ALUM="$(/usr/bin/xdg_translator "$AUX_LANG"  "Data_Alum")"
84
85
86[ ! -z $DESKTOP_LOCALE ] || DESKTOP_LOCALE="Desktop"
87[ ! -z $DOWNLOADS_LOCALE ] || DOWNLOADS_LOCALE="Downloads"
88[ ! -z $DOCUMENTS_LOCALE ] || DOCUMENTS_LOCALE="Documents"
89[ ! -z $SHARE_LOCALE ] || SHARE_LOCALE="Share"
90[ ! -z $SHARETEACHERS_LOCALE ] || SHARETEACHERS_LOCALE="Teachers_Share"
91[ ! -z $GROUPSSHARE_LOCALE ] || GROUPSSHARE_LOCALE="Groups_Share"
92[ ! -z $DATA_ALUM ] || DATA_ALUM="Data_Alumn"
93
94
95
96
97# Umount directories mounted previously
98NEEDLE="${DESKTOP_LOCALE}|${DOCUMENTS_LOCALE}|${SHARE_LOCALE}|${SHARETEACHERS_LOCALE}|${GROUPSSHARE_LOCALE}|${DATA_ALUM}"
99LIST_BIND_MOUNTED="$(mount | grep -E '/net|/server' | grep '/'$USER'/' | grep -E $NEEDLE | cut -d ' ' -f3 | tr '\n' ' ')"
100echo "" >> "$LOG"
101echo "     LIST MOUNTED POINTS AT LOGIN" >> "$LOG"
102echo "---------------------------------------" >> "$LOG"
103echo "$LIST_BIND_MOUNTED" >> "$LOG"
104echo "_______________________________________________________" >> "$LOG"
105echo "" >> "$LOG"
106for MOUNT_POINT in $LIST_BIND_MOUNTED; do
107    rc=0
108    $(echo $MOUNT_POINT | grep -q $HL_HOME) || rc=1
109    echo "" >> "$LOG"
110    echo "TESTING THIS MOUNT_POINT: $MOUNT_POINT" >> "$LOG"
111    echo "UMOUNT POINT IF RC!=0, VALOR ACTUALLY FOR RC IS $rc" >> "$LOG"
112    if [ $rc -eq 0 ]; then
113        echo "umount point: $MOUNT_POINT" >> "$LOG"
114        umount $MOUNT_POINT || true
115    fi
116    echo "_______________________________________________________" >> "$LOG"
117done
118
119
120if [ "$TOKEN_DESKTOP" != "$DESKTOP_LOCALE" ]; then
121    if [ ! -z "$TOKEN_DESKTOP" -a -e $HL_HOME/${TOKEN_DESKTOP} ]; then 
122        mv $HL_HOME/${TOKEN_DESKTOP} $HL_HOME/${DESKTOP_LOCALE}
123    else
124        mkdir $HL_HOME/${DESKTOP_LOCALE} || true
125    fi
126fi
127
128if [ -L "$HL_HOME/${DESKTOP_LOCALE}" ]; then
129    rm -rf "$HL_HOME/${DESKTOP_LOCALE}"
130    mkdir $HL_HOME/${DESKTOP_LOCALE}
131fi
132
133chown $HL_USER:$GRP_USER $HL_HOME/${DESKTOP_LOCALE}
134echo "TOKEN_DESKTOP=\"$DESKTOP_LOCALE\"" >> $TEMP_NEW_USER_DIRS
135
136
137if [ "$TOKEN_DOCUMENTS" != "$DOCUMENTS_LOCALE" ]; then
138    if [ ! -z "$TOKEN_DOCUMENTS" -a -e $HL_HOME/${TOKEN_DOCUMENTS} ]; then 
139        mv $HL_HOME/${TOKEN_DOCUMENTS} $HL_HOME/${DOCUMENTS_LOCALE}
140    else
141        mkdir $HL_HOME/${DOCUMENTS_LOCALE} || true
142    fi
143fi
144
145if [ -L "$HL_HOME/${DOCUMENTS_LOCALE}" ]; then
146    rm -rf "$HL_HOME/${DOCUMENTS_LOCALE}"
147    mkdir $HL_HOME/${DOCUMENTS_LOCALE}
148fi
149
150
151chown $HL_USER:$GRP_USER $HL_HOME/${DOCUMENTS_LOCALE}
152echo "TOKEN_DOCUMENTS=\"$DOCUMENTS_LOCALE\"" >> $TEMP_NEW_USER_DIRS
153
154if [ "$TOKEN_DOWNLOADS" != "$DOWNLOADS_LOCALE" ]; then
155    if [ ! -z "$TOKEN_DOWNLOADS" -a -e $HL_HOME/${TOKEN_DOWNLOADS} ]; then 
156        mv $HL_HOME/${TOKEN_DOWNLOADS} $HL_HOME/${DOWNLOADS_LOCALE}
157    else
158        mkdir $HL_HOME/${DOWNLOADS_LOCALE} || true
159    fi
160fi
161
162if [ -L "$HL_HOME/${DOWNLOADS_LOCALE}" ]; then
163    rm -rf "$HL_HOME/${DOWNLOADS_LOCALE}"
164    mkdir $HL_HOME/${DOWNLOADS_LOCALE}
165fi
166
167chown $HL_USER:$GRP_USER $HL_HOME/${DOWNLOADS_LOCALE}
168echo "TOKEN_DOWNLOADS=\"$DOWNLOADS_LOCALE\"" >> $TEMP_NEW_USER_DIRS
169
170if [ -d "/run/$HL_USER/home" -o -d "/net/server-sync/home/" ]; then 
171    if [ "$TOKEN_SHARE" != "$SHARE_LOCALE" ]; then
172            if [ ! -z "$TOKEN_SHARE" -a -e $HL_HOME/${TOKEN_SHARE} ]; then
173                mv $HL_HOME/${TOKEN_SHARE} $HL_HOME/${SHARE_LOCALE}
174            else
175                mkdir $HL_HOME/${SHARE_LOCALE} || true
176            fi
177    fi
178
179    if [ -L "$HL_HOME/${SHARE_LOCALE}" ]; then
180            rm -rf "$HL_HOME/${SHARE_LOCALE}"
181            mkdir "$HL_HOME/${SHARE_LOCALE}"
182    fi
183    chown $HL_USER:$GRP_USER $HL_HOME/${SHARE_LOCALE}
184    echo "TOKEN_SHARE=\"$SHARE_LOCALE\"" >> $TEMP_NEW_USER_DIRS
185    if [ "$GRP_USER" = "teachers" ]; then
186        if [ "$TOKEN_SHARETEACHERS" != "$SHARETEACHERS_LOCALE" ]; then
187                if [ ! -z "$SHARETEACHERS_TOKEN" -a -e $HL_HOME/${SHARETEACHERS_TOKEN} ]; then
188                        mv $HL_HOME/${SHARETEACHERS_TOKEN} $HL_HOME/${SHARETEACHERS_LOCALE}
189                else
190                        mkdir $HL_HOME/${SHARETEACHERS_LOCALE} || true
191                fi
192        fi
193
194        if [ -L "$HL_HOME/${SHARETEACHERS_LOCALE}" ]; then
195            rm -rf "$HL_HOME/${SHARETEACHERS_LOCALE}"
196            mkdir "$HL_HOME/${SHARETEACHERS_LOCALE}"
197        fi
198
199        chown $HL_USER:$GRP_USER $HL_HOME/${SHARETEACHERS_LOCALE}
200        echo "TOKEN_SHARETEACHERS=\"$SHARETEACHERS_LOCALE\"" >> $TEMP_NEW_USER_DIRS
201    fi
202fi
203
204if [ "$TOKEN_GROUPSSHARE" != "$GROUPSSHARE_LOCALE" ]; then
205    if [ ! -z "$TOKEN_GROUPSSHARE" -a -e $HL_HOME/${TOKEN_GROUPSSHARE} ]; then 
206        mv $HL_HOME/${TOKEN_GROUPSSHARE} $HL_HOME/${GROUPSSHARE_LOCALE}
207    else
208        mkdir $HL_HOME/${GROUPSSHARE_LOCALE} || true
209    fi
210fi
211
212if [ -L "$HL_HOME/${GROUPSSHARE_LOCALE}" ]; then
213    rm -rf "$HL_HOME/${GROUPSSHARE_LOCALE}"
214    mkdir "$HL_HOME/${GROUPSSHARE_LOCALE}"
215fi
216
217chown $HL_USER:$GRP_USER $HL_HOME/${GROUPSSHARE_LOCALE}
218echo "TOKEN_GROUPSSHARE=\"$GROUPSSHARE_LOCALE\"" >> $TEMP_NEW_USER_DIRS
219
220fix_owner_home "$HL_HOME" "$GRP_USER" "$HL_USER"
221
222if [ -d "/net/server-sync/home/$GRP_USER/$HL_USER/" ]; then
223    # other machines in aula
224    echo " THIN CLIENT TO MOUNT" >> "$LOG"
225    echo "----------------------" >> "$LOG"
226    echo "MOUNTING ${DESKTOP_LOCALE}" >> "$LOG"
227    [ "${DESKTOP_LOCALE}" = "" ] || mount --bind /net/server-sync/home/$GRP_USER/$HL_USER/Desktop $HL_HOME/${DESKTOP_LOCALE} 1>> $LOG 2>>$LOG || true
228    echo "MOUNTING ${DOCUMENTS_LOCALE}" >> "$LOG"
229    [ "${DOCUMENTS_LOCALE}" = "" ] || mount --bind /net/server-sync/home/$GRP_USER/$HL_USER/Documents $HL_HOME/${DOCUMENTS_LOCALE} 1>> $LOG 2>>$LOG  || true
230    echo "MOUNTING ${SHARE_LOCALE}" >> "$LOG"
231    [ "${SHARE_LOCALE}" = "" ] || mount --bind /net/server-sync/share $HL_HOME/${SHARE_LOCALE} 1>> $LOG 2>>$LOG  || true
232    if [ "$GRP_USER" = "teachers" ]; then
233        # DELETE OLD DIRECTORIES FOR OTHER LANGUAGES
234        for i in es_ES.UTF-8 ca_ES.UTF-8@Valencia ca_ES.UTF-8@valencia en; do
235                SHARETEACHERS_LOCALE_ERASE="$(/usr/bin/xdg_translator "$i"  "Teachers_Share")"
236                if [ -d "$HL_HOME/$SHARETEACHERS_LOCALE_ERASE" ]; then 
237                        echo "Borrando $HL_HOME/$SHARETEACHERS_LOCALE_ERASE" >> "$LOG"
238                        rm -d "$HL_HOME/$SHARETEACHERS_LOCALE_ERASE" >> "$LOG"
239                fi
240        done
241        for i in es_ES.UTF-8 ca_ES.UTF-8@Valencia ca_ES.UTF-8@valencia en; do
242                DATA_ALUM_ERASE="$(/usr/bin/xdg_translator "$i"  "Data_Alum")"
243                if [ -d "$HL_HOME/$DATA_ALUM_ERASE" ]; then 
244                        echo "Borrando $HL_HOME/$DATA_ALUM_ERASE" >> "$LOG"
245                        rm -d "$HL_HOME/$DATA_ALUM_ERASE" >> "$LOG"
246                fi
247        done
248       
249       
250        echo "MOUNTING ${SHARETEACHERS_LOCALE}" >> "$LOG"
251        [ -d ${HL_HOME}/${SHARETEACHERS_LOCALE} ] || mkdir ${HL_HOME}/${SHARETEACHERS_LOCALE}
252        [ "${SHARETEACHERS_LOCALE}" = "" ] || mount --bind /net/server-sync/teachers_share $HL_HOME/${SHARETEACHERS_LOCALE} 1>>$LOG 2>>$LOG || true
253       
254        echo "MOUNTING ${DATA_ALUM}" >> "$LOG"
255        [ -d $HL_HOME/$DATA_ALUM ] || mkdir $HL_HOME/$DATA_ALUM
256        [ "${DATA_ALUM}" = "" ]  || mount --bind /net/server-sync/home/students/ $HL_HOME/$DATA_ALUM 1>>$LOG 2>>$LOG || true
257       
258    fi
259    echo "MOUNTING ${GROUPSSHARE_LOCALE}" >> "$LOG"
260    [ "${GROUPSSHARE_LOCALE}" = "" ] || mount --bind /net/server-sync/groups_share $HL_HOME/${GROUPSSHARE_LOCALE} 1>>$LOG 2>>$LOG  || true
261   
262elif [ -d "/var/run/$HL_USER/home" ]; then
263    #Fat clients
264    echo " FATCLIENTS TO MOUNT" >> "$LOG"
265    echo "----------------------" >> "$LOG"
266    echo "MOUNTING ${DESKTOP_LOCALE}" >> "$LOG"
267    [ "${DESKTOP_LOCALE}" = "" ] || mount --bind /run/$HL_USER/home/$GRP_USER/$HL_USER/Desktop $HL_HOME/${DESKTOP_LOCALE} 1>>$LOG 2>>$LOG || true
268    echo "MOUNTING ${DOCUMENTS_LOCALE}" >> "$LOG"
269    [ "${DOCUMENTS_LOCALE}" = "" ] || mount --bind /run/$HL_USER/home/$GRP_USER/$HL_USER/Documents $HL_HOME/${DOCUMENTS_LOCALE} 1>>$LOG 2>>$LOG || true
270    echo "MOUNTING ${SHARE_LOCALE}" >> "$LOG"
271    [ "${SHARE_LOCALE}" = "" ] || mount --bind /run/$HL_USER/share $HL_HOME/${SHARE_LOCALE} 1>>$LOG 2>>$LOG || true
272    if [ "$GRP_USER" = "teachers" ]; then
273        # DELETE OLD DIRECTORIES FOR OTHER LANGUAGES
274        for i in es_ES.UTF-8 ca_ES.UTF-8@Valencia ca_ES.UTF-8@valencia en; do
275                SHARETEACHERS_LOCALE_ERASE="$(/usr/bin/xdg_translator "$i"  "Teachers_Share")"
276                if [ -d $HL_HOME/$SHARETEACHERS_LOCALE_ERASE ]; then 
277                        echo "Borrando $HL_HOME/$SHARETEACHERS_LOCALE_ERASE" >> "$LOG"
278                        rm -d $HL_HOME/$SHARETEACHERS_LOCALE_ERASE >> "$LOG"
279                fi
280        done
281        for i in es_ES.UTF-8 ca_ES.UTF-8@Valencia ca_ES.UTF-8@valencia en; do
282                DATA_ALUM_ERASE="$(/usr/bin/xdg_translator "$i"  "Data_Alum")"
283                if [ -d $HL_HOME/$DATA_ALUM_ERASE ]; then 
284                        echo "Borrando $HL_HOME/$DATA_ALUM_ERASE" >> "$LOG"
285                        rm -d $HL_HOME/$DATA_ALUM_ERASE >> "$LOG"
286                fi
287        done
288       
289        echo "MOUNTING ${SHARETEACHERS_LOCALE}" >> "$LOG"
290        [ -d ${HL_HOME}/${SHARETEACHERS_LOCALE} ] || mkdir ${HL_HOME}/${SHARETEACHERS_LOCALE}
291        [ "${SHARETEACHERS_LOCALE}" = "" ] || mount --bind /run/$HL_USER/teachers_share $HL_HOME/${SHARETEACHERS_LOCALE} 1>>$LOG 2>>$LOG || true
292       
293        [ -d $HL_HOME/$DATA_ALUM ] || mkdir $HL_HOME/$DATA_ALUM
294        [ "${DATA_ALUM}" = "" ]  || mount --bind /run/$HL_USER/home/students $HL_HOME/$DATA_ALUM || true
295    fi
296   
297   
298    echo "MOUNTING ${GROUPSSHARE_LOCALE}" >> "$LOG"
299    [ "${GROUPSSHARE_LOCALE}" = "" ] || mount --bind /run/$HL_USER/groups_share $HL_HOME/${GROUPSSHARE_LOCALE} 1>>$LOG 2>>$LOG || true
300   
301fi
302mv ${TEMP_NEW_USER_DIRS} ${LAST_LOGIN_DIRECTORIES}
303
304
305cat > $USER_DIRS << EOF
306# This file is written by xdg-user-dirs-update
307# If you want to change or add directories, just edit the line you're
308# interested in. All local changes will be retained on the next run
309# Format is XDG_xxx_DIR="$HL_HOME/yyy", where yyy is a shell-escaped
310# homedir-relative path, or XDG_xxx_DIR="/yyy", where /yyy is an
311# absolute path. No other format is supported.
312#
313XDG_DESKTOP_DIR="\$HOME/$DESKTOP_LOCALE"
314XDG_DOWNLOAD_DIR="\$HOME/$DOWNLOADS_LOCALE"
315XDG_DOCUMENTS_DIR="\$HOME/$DOCUMENTS_LOCALE"
316
317EOF
318chmod 600 "$USER_DIRS"
319chown $HL_USER:$GRP_USER "$USER_DIRS"
320echo "" >> "$LOG"
321echo "******* MOUNT SCRIPT FINISHED - RESUME *****" >> "$LOG"
322echo "--------------------------------------------" >> "$LOG"
323echo "" >> "$LOG"
324echo "lANGUAGE IS $AUX_LANG" >> "$LOG"
325echo "" >> "$LOG"
326echo "Las variables a tener en cuenta son:" >> "$LOG"
327echo "         \$HL_USER -> $HL_USER" >> "$LOG"
328echo "         \$HL_HOME -> $HL_HOME" >> "$LOG"
329echo "         \$HOME -> $HOME" >> "$LOG"
330echo "         \$DESKTOP_LOCALE -> $DESKTOP_LOCALE" >> "$LOG"
331echo "" >> "$LOG"
332echo "----- HOME FROM USER AFTER HOME-LINKER ----" >> "$LOG"
333tree $HL_HOME >> "$LOG"
334echo "" >> "$LOG"
335cat $HL_HOME/.config/user-dirs.created >> "$LOG"
336echo "" >> "$LOG"
337cat $HL_HOME/.config/user-dirs.dirs >> "$LOG"
338echo "" >> "$LOG"
339echo "END /usr/sbin/home-linker" >> "$LOG"
340
341
342
343exit 0
Note: See TracBrowser for help on using the repository browser.