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

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

translation for data alumn

  • Property svn:executable set to *
File size: 9.1 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 -E '[,(]bind[,)]' | cut -d ' ' -f3 | tr '\n' ' ')"
93for MOUNT_POINT in $LIST_BIND_MOUNTED; do
94    rc=0
95    $(echo $MOUNT_POINT | grep -q $HL_HOME) || rc=1
96    if [ $rc -eq 0 ]; then
97        umount $MOUNT_POINT || true
98    fi
99done
100
101
102if [ "$TOKEN_DESKTOP" != "$DESKTOP_LOCALE" ]; then
103    if [ ! -z "$TOKEN_DESKTOP" -a -e $HL_HOME/${TOKEN_DESKTOP} ]; then 
104        mv $HL_HOME/${TOKEN_DESKTOP} $HL_HOME/${DESKTOP_LOCALE}
105    else
106        mkdir $HL_HOME/${DESKTOP_LOCALE} || true
107    fi
108fi
109
110if [ -L "$HL_HOME/${DESKTOP_LOCALE}" ]; then
111    rm -rf "$HL_HOME/${DESKTOP_LOCALE}"
112    mkdir $HL_HOME/${DESKTOP_LOCALE}
113fi
114
115chown $HL_USER:$GRP_USER $HL_HOME/${DESKTOP_LOCALE}
116echo "TOKEN_DESKTOP=\"$DESKTOP_LOCALE\"" >> $TEMP_NEW_USER_DIRS
117
118
119if [ "$TOKEN_DOCUMENTS" != "$DOCUMENTS_LOCALE" ]; then
120    if [ ! -z "$TOKEN_DOCUMENTS" -a -e $HL_HOME/${TOKEN_DOCUMENTS} ]; then 
121        mv $HL_HOME/${TOKEN_DOCUMENTS} $HL_HOME/${DOCUMENTS_LOCALE}
122    else
123        mkdir $HL_HOME/${DOCUMENTS_LOCALE} || true
124    fi
125fi
126
127if [ -L "$HL_HOME/${DOCUMENTS_LOCALE}" ]; then
128    rm -rf "$HL_HOME/${DOCUMENTS_LOCALE}"
129    mkdir $HL_HOME/${DOCUMENTS_LOCALE}
130fi
131
132
133chown $HL_USER:$GRP_USER $HL_HOME/${DOCUMENTS_LOCALE}
134echo "TOKEN_DOCUMENTS=\"$DOCUMENTS_LOCALE\"" >> $TEMP_NEW_USER_DIRS
135
136if [ "$TOKEN_DOWNLOADS" != "$DOWNLOADS_LOCALE" ]; then
137    if [ ! -z "$TOKEN_DOWNLOADS" -a -e $HL_HOME/${TOKEN_DOWNLOADS} ]; then 
138        mv $HL_HOME/${TOKEN_DOWNLOADS} $HL_HOME/${DOWNLOADS_LOCALE}
139    else
140        mkdir $HL_HOME/${DOWNLOADS_LOCALE} || true
141    fi
142fi
143
144if [ -L "$HL_HOME/${DOWNLOADS_LOCALE}" ]; then
145    rm -rf "$HL_HOME/${DOWNLOADS_LOCALE}"
146    mkdir $HL_HOME/${DOWNLOADS_LOCALE}
147fi
148
149chown $HL_USER:$GRP_USER $HL_HOME/${DOWNLOADS_LOCALE}
150echo "TOKEN_DOWNLOADS=\"$DOWNLOADS_LOCALE\"" >> $TEMP_NEW_USER_DIRS
151
152if [ -d "/run/$HL_USER/home" -o -d "/net/server-sync/home/" ]; then 
153    if [ "$TOKEN_SHARE" != "$SHARE_LOCALE" ]; then
154            if [ ! -z "$TOKEN_SHARE" -a -e $HL_HOME/${TOKEN_SHARE} ]; then
155                mv $HL_HOME/${TOKEN_SHARE} $HL_HOME/${SHARE_LOCALE}
156            else
157                mkdir $HL_HOME/${SHARE_LOCALE} || true
158            fi
159    fi
160
161    if [ -L "$HL_HOME/${SHARE_LOCALE}" ]; then
162            rm -rf "$HL_HOME/${SHARE_LOCALE}"
163            mkdir "$HL_HOME/${SHARE_LOCALE}"
164    fi
165    chown $HL_USER:$GRP_USER $HL_HOME/${SHARE_LOCALE}
166    echo "TOKEN_SHARE=\"$SHARE_LOCALE\"" >> $TEMP_NEW_USER_DIRS
167    if [ "$GRP_USER" = "teachers" ]; then
168        if [ "$TOKEN_SHARETEACHERS" != "$SHARETEACHERS_LOCALE" ]; then
169                if [ ! -z "$SHARETEACHERS_TOKEN" -a -e $HL_HOME/${SHARETEACHERS_TOKEN} ]; then
170                        mv $HL_HOME/${SHARETEACHERS_TOKEN} $HL_HOME/${SHARETEACHERS_LOCALE}
171                else
172                        mkdir $HL_HOME/${SHARETEACHERS_LOCALE} || true
173                fi
174        fi
175
176        if [ -L "$HL_HOME/${SHARETEACHERS_LOCALE}" ]; then
177            rm -rf "$HL_HOME/${SHARETEACHERS_LOCALE}"
178            mkdir "$HL_HOME/${SHARETEACHERS_LOCALE}"
179        fi
180
181        chown $HL_USER:$GRP_USER $HL_HOME/${SHARETEACHERS_LOCALE}
182        echo "TOKEN_SHARETEACHERS=\"$SHARETEACHERS_LOCALE\"" >> $TEMP_NEW_USER_DIRS
183    fi
184fi
185
186if [ "$TOKEN_GROUPSSHARE" != "$GROUPSSHARE_LOCALE" ]; then
187    if [ ! -z "$TOKEN_GROUPSSHARE" -a -e $HL_HOME/${TOKEN_GROUPSSHARE} ]; then 
188        mv $HL_HOME/${TOKEN_GROUPSSHARE} $HL_HOME/${GROUPSSHARE_LOCALE}
189    else
190        mkdir $HL_HOME/${GROUPSSHARE_LOCALE} || true
191    fi
192fi
193
194if [ -L "$HL_HOME/${GROUPSSHARE_LOCALE}" ]; then
195    rm -rf "$HL_HOME/${GROUPSSHARE_LOCALE}"
196    mkdir "$HL_HOME/${GROUPSSHARE_LOCALE}"
197fi
198
199chown $HL_USER:$GRP_USER $HL_HOME/${GROUPSSHARE_LOCALE}
200echo "TOKEN_GROUPSSHARE=\"$GROUPSSHARE_LOCALE\"" >> $TEMP_NEW_USER_DIRS
201
202fix_owner_home "$HL_HOME" "$GRP_USER" "$HL_USER"
203
204if [ -d "/net/server-sync/home/$GRP_USER/$HL_USER/" ]; then
205    # other machines in aula
206    echo "OTHER MACHINES IN AULA" >> "$LOG"
207    [ "${DESKTOP_LOCALE}" = "" ] || mount --bind /net/server-sync/home/$GRP_USER/$HL_USER/Desktop $HL_HOME/${DESKTOP_LOCALE} || true
208    [ "${DOCUMENTS_LOCALE}" = "" ] || mount --bind /net/server-sync/home/$GRP_USER/$HL_USER/Documents $HL_HOME/${DOCUMENTS_LOCALE} || true
209    [ "${SHARE_LOCALE}" = "" ] || mount --bind /net/server-sync/share $HL_HOME/${SHARE_LOCALE} || true
210    if [ "$GRP_USER" = "teachers" ]; then
211        [ "${DESKTOP_LOCALE}" = "" ] || mount --bind /net/server-sync/teachers_share $HL_HOME/${SHARETEACHERS_LOCALE} || true
212        [ -d $HL_HOME/$DATA_ALUM ] || mkdir $HL_HOME/$DATA_ALUM
213        mount --bind /net/server-sync/home/students/ $HL_HOME/$DATA_ALUM || true
214    fi
215    [ "${GROUPSSHARE_LOCALE}" = "" ] || mount --bind /net/server-sync/groups_share $HL_HOME/${GROUPSSHARE_LOCALE} || true
216   
217elif [ -d "/var/run/$HL_USER/home" ]; then
218    #Fat clients
219    echo "FATCLIENTS IN AULA" >> "$LOG"
220    [ "${DESKTOP_LOCALE}" = "" ] || mount --bind /run/$HL_USER/home/$GRP_USER/$HL_USER/Desktop $HL_HOME/${DESKTOP_LOCALE} || true
221    [ "${DOCUMENTS_LOCALE}" = "" ] || mount --bind /run/$HL_USER/home/$GRP_USER/$HL_USER/Documents $HLHOME/${DOCUMENTS_LOCALE} || true
222    [ "${SHARE_LOCALE}" = "" ] || mount --bind /run/$HL_USER/share $HL_HOME/${SHARE_LOCALE} || true
223    if [ "$GRP_USER" = "teachers" ]; then
224        [ "${SHARETEACHERS_LOCALE}" = "" ] || mount --bind /run/$HL_USER/teachers_share $HL_HOME/${SHARETEACHERS_LOCALE} || true
225        [ -d $HL_HOME/$DATA_ALUM ] || mkdir $HL_HOME/$DATA_ALUM
226        mount --bind /run/$HL_USER/home/students $HL_HOME/$DATA_ALUM || true
227    fi
228    [ "${GROUPSSHARE_LOCALE}" = "" ] || mount --bind /run/$HL_USER/groups_share $HL_HOME/${GROUPSSHARE_LOCALE} || true
229fi
230mv ${TEMP_NEW_USER_DIRS} ${LAST_LOGIN_DIRECTORIES}
231
232
233cat > $USER_DIRS << EOF
234# This file is written by xdg-user-dirs-update
235# If you want to change or add directories, just edit the line you're
236# interested in. All local changes will be retained on the next run
237# Format is XDG_xxx_DIR="$HL_HOME/yyy", where yyy is a shell-escaped
238# homedir-relative path, or XDG_xxx_DIR="/yyy", where /yyy is an
239# absolute path. No other format is supported.
240#
241XDG_DESKTOP_DIR="\$HOME/$DESKTOP_LOCALE"
242XDG_DOWNLOAD_DIR="\$HOME/$DOWNLOADS_LOCALE"
243XDG_DOCUMENTS_DIR="\$HOME/$DOCUMENTS_LOCALE"
244
245EOF
246chmod 600 "$USER_DIRS"
247chown $HL_USER:$GRP_USER "$USER_DIRS"
248
249date >> "$LOG"
250echo "" >> "$LOG"
251echo "Las variables a tener en cuenta son:" >> "$LOG"
252echo "         \$HL_USER -> $HL_USER" >> "$LOG"
253echo "         \$HL_HOME -> $HL_HOME" >> "$LOG"
254echo "         \$HOME -> $HOME" >> "$LOG"
255echo "         \$DESKTOP_LOCALE -> $DESKTOP_LOCALE" >> "$LOG"
256echo "" >> "$LOG"
257echo "El idioma es $AUX_LANG" >> "$LOG"
258echo "" >> "$LOG"
259echo "AFTER HOME LINKER" >> "$LOG"
260tree $HL_HOME >> "$LOG"
261echo "" >> "$LOG"
262cat $HL_HOME/.config/user-dirs.created >> "$LOG"
263echo "" >> "$LOG"
264cat $HL_HOME/.config/user-dirs.dirs >> "$LOG"
265echo "" >> "$LOG"
266echo "END /usr/sbin/home-linker" >> "$LOG"
267
268
269
270exit 0
Note: See TracBrowser for help on using the repository browser.