#!/bin/sh set -x trim() { local var="$*" var="${var#"${var%%[![:space:]]*}"}" # remove leading whitespace characters var="${var%"${var##*[![:space:]]}"}" # remove trailing whitespace characters echo -n "$var" } if [ -n "$1" ]; then USER="$1" fi USER=$(trim "$USER") NHOME=$(python -c " tmp='$HOME'.split('/') last=tmp[-1] print '/'.join(tmp[:-1])+'/'+last.strip() ") HOME="$NHOME" # From this file get $LANG { [ -r "$HOME/.pam_environment" ] && . "$HOME/.pam_environment" ;} || { [ -r "/etc/default/locale" ] && . "/etc/default/locale" ;} || LANG="en" # Get Usernames GRP_USER="$(id -ng $USER)" # Source for user-dirs if it exists USER_DIRS="$HOME/.config/user-dirs.dirs" [ ! -r $USER_DIRS ] || . $USER_DIRS # Source the token file if it exists LAST_LOGIN_DIRECTORIES="$HOME/.config/user-dirs.created" [ ! -r "$LAST_LOGIN_DIRECTORIES" ] || . "$LAST_LOGIN_DIRECTORIES" #Temp file with new user-dirs [ -d "$HOME" ] || { mkdir -p "$HOME" ; chown $USER:$GRP_USER "$HOME" ;} [ -d "$HOME/.config" ] || { mkdir -p "$HOME/.config" ; chown $USER:$GRP_USER "$HOME/.config" ;} TEMP_NEW_USER_DIRS="$HOME/.config/aux-user-dirs.create" :> $TEMP_NEW_USER_DIRS #set Acl on Home to be more restricted get_acl_from_server "$HOME" "$GRP_USER" $USER # Download directory actions DOWNLOADS_LOCALE="$(/usr/bin/xdg_translator "$LANG" "Downloads")" DESKTOP_LOCALE="$(/usr/bin/xdg_translator "$LANG" "Desktop")" DOCUMENTS_LOCALE="$(/usr/bin/xdg_translator "$LANG" "Documents")" SHARE_LOCALE="$(/usr/bin/xdg_translator "$LANG" "Share")" SHARETEACHERS_LOCALE="$(/usr/bin/xdg_translator "$LANG" "Teachers_Share")" GROUPSSHARE_LOCALE="$(/usr/bin/xdg_translator "$LANG" "Groups_Share")" [ ! -z $DESKTOP_LOCALE ] || DESKTOP_LOCALE="Desktop" [ ! -z $DOWNLOADS_LOCALE ] || DOWNLOADS_LOCALE="Downloads" [ ! -z $DOCUMENTS_LOCALE ] || DOCUMENTS_LOCALE="Documents" [ ! -z $SHARE_LOCALE ] || SHARE_LOCALE="Share" [ ! -z $SHARETEACHERS_LOCALE ] || SHARETEACHERS_LOCALE="Teachers_Share" [ ! -z $GROUPSSHARE_LOCALE ] || GROUPSSHARE_LOCALE="Groups_Share" # Umount directories mounted previously LIST_BIND_MOUNTED="$(mount | grep -E '[,(]bind[,)]' | cut -d ' ' -f3 | tr '\n' ' ')" for MOUNT_POINT in $LIST_BIND_MOUNTED; do rc=0 $(echo $MOUNT_POINT | grep -q $HOME) || rc=1 if [ $rc -eq 0 ]; then umount $MOUNT_POINT || true fi done if [ "$TOKEN_DESKTOP" != "$DESKTOP_LOCALE" ]; then if [ ! -z "$TOKEN_DESKTOP" -a -e $HOME/${TOKEN_DESKTOP} ]; then mv $HOME/${TOKEN_DESKTOP} $HOME/${DESKTOP_LOCALE} else mkdir $HOME/${DESKTOP_LOCALE} || true fi fi if [ -L "$HOME/${DESKTOP_LOCALE}" ]; then rm -rf "$HOME/${DESKTOP_LOCALE}" mkdir $HOME/${DESKTOP_LOCALE} fi chown $USER:$GRP_USER $HOME/${DESKTOP_LOCALE} echo "TOKEN_DESKTOP=\"$DESKTOP_LOCALE\"" >> $TEMP_NEW_USER_DIRS if [ "$TOKEN_DOCUMENTS" != "$DOCUMENTS_LOCALE" ]; then if [ ! -z "$TOKEN_DOCUMENTS" -a -e $HOME/${TOKEN_DOCUMENTS} ]; then mv $HOME/${TOKEN_DOCUMENTS} $HOME/${DOCUMENTS_LOCALE} else mkdir $HOME/${DOCUMENTS_LOCALE} || true fi fi if [ -L "$HOME/${DOCUMENTS_LOCALE}" ]; then rm -rf "$HOME/${DOCUMENTS_LOCALE}" mkdir $HOME/${DOCUMENTS_LOCALE} fi chown $USER:$GRP_USER $HOME/${DOCUMENTS_LOCALE} echo "TOKEN_DOCUMENTS=\"$DOCUMENTS_LOCALE\"" >> $TEMP_NEW_USER_DIRS if [ "$TOKEN_DOWNLOADS" != "$DOWNLOADS_LOCALE" ]; then if [ ! -z "$TOKEN_DOWNLOADS" -a -e $HOME/${TOKEN_DOWNLOADS} ]; then mv $HOME/${TOKEN_DOWNLOADS} $HOME/${DOWNLOADS_LOCALE} else mkdir $HOME/${DOWNLOADS_LOCALE} || true fi fi if [ -L "$HOME/${DOWNLOADS_LOCALE}" ]; then rm -rf "$HOME/${DOWNLOADS_LOCALE}" mkdir $HOME/${DOWNLOADS_LOCALE} fi chown $USER:$GRP_USER $HOME/${DOWNLOADS_LOCALE} echo "TOKEN_DOWNLOADS=\"$DOWNLOADS_LOCALE\"" >> $TEMP_NEW_USER_DIRS if [ -d "/run/$USER/home" -o -d "/net/server-sync/home/" ]; then if [ "$TOKEN_SHARE" != "$SHARE_LOCALE" ]; then if [ ! -z "$TOKEN_SHARE" -a -e $HOME/${TOKEN_SHARE} ]; then mv $HOME/${TOKEN_SHARE} $HOME/${SHARE_LOCALE} else mkdir $HOME/${SHARE_LOCALE} || true fi fi if [ -L "$HOME/${SHARE_LOCALE}" ]; then rm -rf "$HOME/${SHARE_LOCALE}" mkdir "$HOME/${SHARE_LOCALE}" fi chown $USER:$GRP_USER $HOME/${SHARE_LOCALE} echo "TOKEN_SHARE=\"$SHARE_LOCALE\"" >> $TEMP_NEW_USER_DIRS if [ "$GRP_USER" = "teachers" ]; then if [ "$TOKEN_SHARETEACHERS" != "$SHARETEACHERS_LOCALE" ]; then if [ ! -z "$SHARETEACHERS_TOKEN" -a -e $HOME/${SHARETEACHERS_TOKEN} ]; then mv $HOME/${SHARETEACHERS_TOKEN} $HOME/${SHARETEACHERS_LOCALE} else mkdir $HOME/${SHARETEACHERS_LOCALE} || true fi fi if [ -L "$HOME/${SHARETEACHERS_LOCALE}" ]; then rm -rf "$HOME/${SHARETEACHERS_LOCALE}" mkdir "$HOME/${SHARETEACHERS_LOCALE}" fi chown $USER:$GRP_USER $HOME/${SHARETEACHERS_LOCALE} echo "TOKEN_SHARETEACHERS=\"$SHARETEACHERS_LOCALE\"" >> $TEMP_NEW_USER_DIRS fi fi if [ "$TOKEN_GROUPSSHARE" != "$GROUPSSHARE_LOCALE" ]; then if [ ! -z "$TOKEN_GROUPSSHARE" -a -e $HOME/${TOKEN_GROUPSSHARE} ]; then mv $HOME/${TOKEN_GROUPSSHARE} $HOME/${GROUPSSHARE_LOCALE} else mkdir $HOME/${GROUPSSHARE_LOCALE} || true fi fi if [ -L "$HOME/${GROUPSSHARE_LOCALE}" ]; then rm -rf "$HOME/${GROUPSSHARE_LOCALE}" mkdir "$HOME/${GROUPSSHARE_LOCALE}" fi chown $USER:$GRP_USER $HOME/${GROUPSSHARE_LOCALE} echo "TOKEN_GROUPSSHARE=\"$GROUPSSHARE_LOCALE\"" >> $TEMP_NEW_USER_DIRS fix_owner_home "$HOME" "$GRP_USER" "$USER" if [ -d "/net/server-sync/home/$GRP_USER/$USER/" ]; then # other machines in aula [ "${DESKTOP_LOCALE}" = "" ] || mount --bind /net/server-sync/home/$GRP_USER/$USER/Desktop $HOME/${DESKTOP_LOCALE} || true [ "${DOCUMENTS_LOCALE}" = "" ] || mount --bind /net/server-sync/home/$GRP_USER/$USER/Documents $HOME/${DOCUMENTS_LOCALE} || true [ "${SHARE_LOCALE}" = "" ] || mount --bind /net/server-sync/share $HOME/${SHARE_LOCALE} || true if [ "$GRP_USER" = "teachers" ]; then [ "${DESKTOP_LOCALE}" = "" ] || mount --bind /net/server-sync/teachers_share $HOME/${SHARETEACHERS_LOCALE} || true [ -d $HOME/alum ] || mkdir $HOME/alum mount --bind /net/server-sync/home/students/ $HOME/alum || true fi [ "${GROUPSSHARE_LOCALE}" = "" ] || mount --bind /net/server-sync/groups_share $HOME/${GROUPSSHARE_LOCALE} || true elif [ -d "/var/run/$USER/home" ]; then #Fat clients [ "${DESKTOP_LOCALE}" = "" ] || mount --bind /run/$USER/home/$GRP_USER/$USER/Desktop $HOME/${DESKTOP_LOCALE} || true [ "${DOCUMENTS_LOCALE}" = "" ] || mount --bind /run/$USER/home/$GRP_USER/$USER/Documents $HOME/${DOCUMENTS_LOCALE} || true [ "${SHARE_LOCALE}" = "" ] || mount --bind /run/$USER/share $HOME/${SHARE_LOCALE} || true if [ "$GRP_USER" = "teachers" ]; then [ "${SHARETEACHERS_LOCALE}" = "" ] || mount --bind /run/$USER/teachers_share $HOME/${SHARETEACHERS_LOCALE} || true [ -d $HOME/alum ] || mkdir $HOME/alum mount --bind /run/$USER/home/students $HOME/alum || true fi [ "${GROUPSSHARE_LOCALE}" = "" ] || mount --bind /run/$USER/groups_share $HOME/${GROUPSSHARE_LOCALE} || true fi mv ${TEMP_NEW_USER_DIRS} ${LAST_LOGIN_DIRECTORIES} cat > $USER_DIRS << EOF # This file is written by xdg-user-dirs-update # If you want to change or add directories, just edit the line you're # interested in. All local changes will be retained on the next run # Format is XDG_xxx_DIR="$HOME/yyy", where yyy is a shell-escaped # homedir-relative path, or XDG_xxx_DIR="/yyy", where /yyy is an # absolute path. No other format is supported. # XDG_DESKTOP_DIR="\$HOME/$DESKTOP_LOCALE" XDG_DOWNLOAD_DIR="\$HOME/$DOWNLOADS_LOCALE" XDG_DOCUMENTS_DIR="\$HOME/$DOCUMENTS_LOCALE" EOF chmod 600 "$USER_DIRS" chown $USER:$GRP_USER "$USER_DIRS" exit 0