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

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

Eliminate dependence sudoers in ldm-client

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