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

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

fixing LANG

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