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

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

Adding new package

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