source: home-linker/trunk/fuentes/home-linker.install/usr/bin/home-linker @ 2451

Last change on this file since 2451 was 2451, checked in by daduve, 4 years ago

wip

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