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

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

wip

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