Ignore:
Timestamp:
Sep 19, 2016, 1:16:38 PM (3 years ago)
Author:
daduve
Message:

invoque new home-linker

File:
1 edited

Legend:

Unmodified
Added
Removed
  • xdg-lliurex-dirs/trunk/fuentes/install/etc/lightdm/Session.d/home-linker

    r323 r2467  
    22set -x
    33
    4 trim() {
    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 if [ -n "$1" ]; then
    12         USER="$1"
    13 fi
    14 
    15 USER=$(trim "$USER")
    16 
    17 NHOME=$(python -c "
    18 
    19 tmp='$HOME'.split('/')
    20 last=tmp[-1]
    21 print '/'.join(tmp[:-1])+'/'+last.strip()
    22 
    23 ")
    24 
    25 HOME="$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
    32 GRP_USER="$(id -ng $USER)"
    33 
    34 # Source for user-dirs if it exists
    35 USER_DIRS="$HOME/.config/user-dirs.dirs"
    36 [ ! -r $USER_DIRS ] || . $USER_DIRS
    37 
    38 # Source the token file if it exists
    39 LAST_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" ;}
    45 TEMP_NEW_USER_DIRS="$HOME/.config/aux-user-dirs.create"
    46 :> $TEMP_NEW_USER_DIRS
    47 
    48 #set Acl on Home to be more restricted
    49 get_acl_from_server "$HOME" "$GRP_USER" $USER
    50 
    51 # Download directory actions
    52 DOWNLOADS_LOCALE="$(/usr/bin/xdg_translator "$LANG" "Downloads")"
    53 DESKTOP_LOCALE="$(/usr/bin/xdg_translator "$LANG"  "Desktop")"
    54 DOCUMENTS_LOCALE="$(/usr/bin/xdg_translator "$LANG"  "Documents")"
    55 SHARE_LOCALE="$(/usr/bin/xdg_translator "$LANG"  "Share")"
    56 SHARETEACHERS_LOCALE="$(/usr/bin/xdg_translator "$LANG"  "Teachers_Share")"
    57 GROUPSSHARE_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
    67 LIST_BIND_MOUNTED="$(mount | grep -E '[,(]bind[,)]' | cut -d ' ' -f3 | tr '\n' ' ')"
    68 for 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
    74 done
    75 
    76 
    77 if [ "$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
    83 fi
    84 
    85 if [ -L "$HOME/${DESKTOP_LOCALE}" ]; then
    86     rm -rf "$HOME/${DESKTOP_LOCALE}"
    87     mkdir $HOME/${DESKTOP_LOCALE}
    88 fi
    89 
    90 chown $USER:$GRP_USER $HOME/${DESKTOP_LOCALE}
    91 echo "TOKEN_DESKTOP=\"$DESKTOP_LOCALE\"" >> $TEMP_NEW_USER_DIRS
    92 
    93 
    94 if [ "$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
    100 fi
    101 
    102 if [ -L "$HOME/${DOCUMENTS_LOCALE}" ]; then
    103     rm -rf "$HOME/${DOCUMENTS_LOCALE}"
    104     mkdir $HOME/${DOCUMENTS_LOCALE}
    105 fi
    106 
    107 
    108 chown $USER:$GRP_USER $HOME/${DOCUMENTS_LOCALE}
    109 echo "TOKEN_DOCUMENTS=\"$DOCUMENTS_LOCALE\"" >> $TEMP_NEW_USER_DIRS
    110 
    111 if [ "$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
    117 fi
    118 
    119 if [ -L "$HOME/${DOWNLOADS_LOCALE}" ]; then
    120     rm -rf "$HOME/${DOWNLOADS_LOCALE}"
    121     mkdir $HOME/${DOWNLOADS_LOCALE}
    122 fi
    123 
    124 chown $USER:$GRP_USER $HOME/${DOWNLOADS_LOCALE}
    125 echo "TOKEN_DOWNLOADS=\"$DOWNLOADS_LOCALE\"" >> $TEMP_NEW_USER_DIRS
    126 
    127 if [ -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
    159 fi
    160 
    161 if [ "$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
    167 fi
    168 
    169 if [ -L "$HOME/${GROUPSSHARE_LOCALE}" ]; then
    170     rm -rf "$HOME/${GROUPSSHARE_LOCALE}"
    171     mkdir "$HOME/${GROUPSSHARE_LOCALE}"
    172 fi
    173 
    174 chown $USER:$GRP_USER $HOME/${GROUPSSHARE_LOCALE}
    175 echo "TOKEN_GROUPSSHARE=\"$GROUPSSHARE_LOCALE\"" >> $TEMP_NEW_USER_DIRS
    176 
    177 fix_owner_home "$HOME" "$GRP_USER" "$USER"
    178 
    179 if [ -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    
    191 elif [ -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
    202 fi
    203 mv ${TEMP_NEW_USER_DIRS} ${LAST_LOGIN_DIRECTORIES}
    204 
    205 
    206 cat > $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 #
    214 XDG_DESKTOP_DIR="\$HOME/$DESKTOP_LOCALE"
    215 XDG_DOWNLOAD_DIR="\$HOME/$DOWNLOADS_LOCALE"
    216 XDG_DOCUMENTS_DIR="\$HOME/$DOCUMENTS_LOCALE"
    217 
    218 EOF
    219 chmod 600 "$USER_DIRS"
    220 chown $USER:$GRP_USER "$USER_DIRS"
     4/usr/bin/home-linker $USER
    2215
    2226exit 0
Note: See TracChangeset for help on using the changeset viewer.