Ignore:
Timestamp:
Sep 15, 2016, 2:03:24 PM (3 years ago)
Author:
daduve
Message:

wip

File:
1 edited

Legend:

Unmodified
Added
Removed
  • home-linker/trunk/fuentes/home-linker.install/usr/bin/home-linker

    r2431 r2442  
    99}
    1010
    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"
     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
    2639
    2740# From this file get $LANG
    28 { [ -r "$HOME/.pam_environment" ] && . "$HOME/.pam_environment" ;} || { [ -r "/etc/default/locale" ] && . "/etc/default/locale" ;} || LANG="en"
     41{ [ -r "$HL_HOME/.pam_environment" ] && . "$HL_HOME/.pam_environment" ;} || { [ -r "/etc/default/locale" ] && . "/etc/default/locale" ;} || LANG="en"
    2942
    3043
    3144# Get Usernames
    32 GRP_USER="$(id -ng $USER)"
     45GRP_USER="$(id -ng $HL_USER)"
    3346
    3447# Source for user-dirs if it exists
    35 USER_DIRS="$HOME/.config/user-dirs.dirs"
     48USER_DIRS="$HL_HOME/.config/user-dirs.dirs"
    3649[ ! -r $USER_DIRS ] || . $USER_DIRS
    3750
    3851# Source the token file if it exists
    39 LAST_LOGIN_DIRECTORIES="$HOME/.config/user-dirs.created"
     52LAST_LOGIN_DIRECTORIES="$HL_HOME/.config/user-dirs.created"
    4053[ ! -r "$LAST_LOGIN_DIRECTORIES" ] || . "$LAST_LOGIN_DIRECTORIES"
    4154
    4255#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"
     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"
    4659:> $TEMP_NEW_USER_DIRS
    4760
    4861#set Acl on Home to be more restricted
    49 get_acl_from_server "$HOME" "$GRP_USER" $USER
     62get_acl_from_server "$HL_HOME" "$GRP_USER" $HL_USER
    5063
    5164# 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")"
     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
    5872
    5973[ ! -z $DESKTOP_LOCALE ] || DESKTOP_LOCALE="Desktop"
     
    6478[ ! -z $GROUPSSHARE_LOCALE ] || GROUPSSHARE_LOCALE="Groups_Share"
    6579
     80
     81
     82
    6683# Umount directories mounted previously
    6784LIST_BIND_MOUNTED="$(mount | grep -E '[,(]bind[,)]' | cut -d ' ' -f3 | tr '\n' ' ')"
    6885for MOUNT_POINT in $LIST_BIND_MOUNTED; do
    6986    rc=0
    70     $(echo $MOUNT_POINT | grep -q $HOME) || rc=1
     87    $(echo $MOUNT_POINT | grep -q $HL_HOME) || rc=1
    7188    if [ $rc -eq 0 ]; then
    7289        umount $MOUNT_POINT || true
     
    7693
    7794if [ "$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}
     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}
    91108echo "TOKEN_DESKTOP=\"$DESKTOP_LOCALE\"" >> $TEMP_NEW_USER_DIRS
    92109
    93110
    94111if [ "$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}
     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}
    109126echo "TOKEN_DOCUMENTS=\"$DOCUMENTS_LOCALE\"" >> $TEMP_NEW_USER_DIRS
    110127
    111128if [ "$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}
     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}
    125142echo "TOKEN_DOWNLOADS=\"$DOWNLOADS_LOCALE\"" >> $TEMP_NEW_USER_DIRS
    126143
    127 if [ -d "/run/$USER/home" -o -d "/net/server-sync/home/" ]; then
     144if [ -d "/run/$HL_USER/home" -o -d "/net/server-sync/home/" ]; then
    128145    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}
     146            if [ ! -z "$TOKEN_SHARE" -a -e $HL_HOME/${TOKEN_SHARE} ]; then
     147                mv $HL_HOME/${TOKEN_SHARE} $HL_HOME/${SHARE_LOCALE}
    131148            else
    132                 mkdir $HOME/${SHARE_LOCALE} || true
     149                mkdir $HL_HOME/${SHARE_LOCALE} || true
    133150            fi
    134151    fi
    135152
    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}
     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}
    141158    echo "TOKEN_SHARE=\"$SHARE_LOCALE\"" >> $TEMP_NEW_USER_DIRS
    142159    if [ "$GRP_USER" = "teachers" ]; then
    143160        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}
     161                if [ ! -z "$SHARETEACHERS_TOKEN" -a -e $HL_HOME/${SHARETEACHERS_TOKEN} ]; then
     162                        mv $HL_HOME/${SHARETEACHERS_TOKEN} $HL_HOME/${SHARETEACHERS_LOCALE}
    146163                else
    147                         mkdir $HOME/${SHARETEACHERS_LOCALE} || true
     164                        mkdir $HL_HOME/${SHARETEACHERS_LOCALE} || true
    148165                fi
    149166        fi
    150167
    151         if [ -L "$HOME/${SHARETEACHERS_LOCALE}" ]; then
    152             rm -rf "$HOME/${SHARETEACHERS_LOCALE}"
    153             mkdir "$HOME/${SHARETEACHERS_LOCALE}"
     168        if [ -L "$HL_HOME/${SHARETEACHERS_LOCALE}" ]; then
     169            rm -rf "$HL_HOME/${SHARETEACHERS_LOCALE}"
     170            mkdir "$HL_HOME/${SHARETEACHERS_LOCALE}"
    154171        fi
    155172
    156         chown $USER:$GRP_USER $HOME/${SHARETEACHERS_LOCALE}
     173        chown $HL_USER:$GRP_USER $HL_HOME/${SHARETEACHERS_LOCALE}
    157174        echo "TOKEN_SHARETEACHERS=\"$SHARETEACHERS_LOCALE\"" >> $TEMP_NEW_USER_DIRS
    158175    fi
     
    160177
    161178if [ "$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}
     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}
    175192echo "TOKEN_GROUPSSHARE=\"$GROUPSSHARE_LOCALE\"" >> $TEMP_NEW_USER_DIRS
    176193
    177 fix_owner_home "$HOME" "$GRP_USER" "$USER"
    178 
    179 if [ -d "/net/server-sync/home/$GRP_USER/$USER/" ]; then
     194fix_owner_home "$HL_HOME" "$GRP_USER" "$HL_USER"
     195
     196if [ -d "/net/server-sync/home/$GRP_USER/$HL_USER/" ]; then
    180197    # 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
     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
    184201    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
     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
    190207   
    191 elif [ -d "/var/run/$USER/home" ]; then
     208elif [ -d "/var/run/$HL_USER/home" ]; then
    192209    #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
     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
    196213    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
     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
    202219fi
    203220mv ${TEMP_NEW_USER_DIRS} ${LAST_LOGIN_DIRECTORIES}
     
    208225# If you want to change or add directories, just edit the line you're
    209226# 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
     227# Format is XDG_xxx_DIR="$HL_HOME/yyy", where yyy is a shell-escaped
    211228# homedir-relative path, or XDG_xxx_DIR="/yyy", where /yyy is an
    212229# absolute path. No other format is supported.
    213230#
    214 XDG_DESKTOP_DIR="\$HOME/$DESKTOP_LOCALE"
    215 XDG_DOWNLOAD_DIR="\$HOME/$DOWNLOADS_LOCALE"
    216 XDG_DOCUMENTS_DIR="\$HOME/$DOCUMENTS_LOCALE"
     231XDG_DESKTOP_DIR="\$HL_HOME/$DESKTOP_LOCALE"
     232XDG_DOWNLOAD_DIR="\$HL_HOME/$DOWNLOADS_LOCALE"
     233XDG_DOCUMENTS_DIR="\$HL_HOME/$DOCUMENTS_LOCALE"
    217234
    218235EOF
    219236chmod 600 "$USER_DIRS"
    220 chown $USER:$GRP_USER "$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
    221252
    222253exit 0
Note: See TracChangeset for help on using the changeset viewer.