#!/bin/bash log(){ echo -n "$1:" >>/tmp/log shift echo "$@" >>/tmp/log } LNG="$(set | grep GDM_LANG |sed -e "s#GDM_LANG=\(.*\)#\1#g;s#\(.*\)\.\(.*\)#\1#")" #log LNG $LNG TEXTDOMAIN="xdg-user-dirs" LOGFILE="$HOME/.logxdguserdirs" export TEXTDOMAIN USER_FILES="$HOME/UserFiles" GRP_USER="$(id -ng $USER_NAME)" NET_HOME="/net/home/$GRP_USER/$USERNAME" netUserFiles() { if [ $DEBUG_MODE = "YES" ]; then echo -e "FUNCTION NETUSERFILES\n" >> $LOGFILE echo -e "GROUP USER:$GRP_USER" >> $LOGFILE echo -e "NET HOME:$NET_HOME" >> $LOGFILE fi if [ ! -w "$NET_HOME" ] ; then if [ $DEBUG_MODE = "YES" ]; then echo -e "DIR : $NET_HOME isn't readable and writable" >> $LOGFILE fi return 0 fi if [ ! -d "$NET_HOME/UserFiles" ]; then if [ $DEBUG_MODE = "YES" ]; then echo -e "Creating net home : $NET_HOME/UserFiles" >> $LOGFILE fi mkdir $NET_HOME/UserFiles fi if [ ! -d "$NET_HOME/Desktop" ]; then if [ $DEBUG_MODE = "YES" ]; then echo -e "Creating net desktop dir : $NET_HOME/Desktop" >> $LOGFILE fi mkdir $NET_HOME/Desktop fi if [ -d "$HOME/UserFiles" -a ! -L "$HOME/UserFiles" ]; then if [ $DEBUG_MODE = "YES" ]; then echo -e "Exist on HOME UserFiles directory" >> $LOGFILE echo -e "Rsync command : rsync -rlptD --backup --suffix='.$(date +%F_%R)' $HOME/UserFiles $NET_HOME/" >> $LOGFILE echo -e "rm command : rm -rf $HOME/UserFiles" >> $LOGFILE fi rsync -rlptD --backup --suffix=".$(date +%F_%R)" $HOME/UserFiles $NET_HOME/ rm -rf $HOME/UserFiles fi if [ -d "$HOME/Desktop" -a ! -L "$HOME/Desktop" ]; then if [ $DEBUG_MODE = "YES" ]; then echo -e "Exist on HOME Desktop directory" >> $LOGFILE echo -e "Rsync command : rsync -rlptD --backup --suffix='.$(date +%F_%R)' $HOME/Desktop/ $NET_HOME/Desktop/" >> $LOGFILE echo -e "rm command : rm -rf $HOME/Desktop" >> $LOGFILE fi rsync -rlptD --backup --suffix=".$(date +%F_%R)" $HOME/Desktop/ $NET_HOME/Desktop/ rm -rf $HOME/Desktop fi if [ ! -L "$USER_FILES" ]; then if [ $DEBUG_MODE = "YES" ]; then echo -e "UserFiles isn't Link .... Creating Link" >> $LOGFILE echo -e "ln command : ln -s $NET_HOME/UserFiles $HOME/UserFiles" >> $LOGFILE fi ln -s $NET_HOME/UserFiles $HOME/UserFiles fi if [ ! -L "$HOME/Desktop" ]; then if [ $DEBUG_MODE = "YES" ]; then echo -e "Desktop isn't Link .... Creating Link" >> $LOGFILE echo -e "ln command : ln -s $NET_HOME/Desktop $HOME/Desktop" >> $LOGFILE fi ln -s $NET_HOME/Desktop $HOME/Desktop fi } create_user_dirs() { if [ $DEBUG_MODE = "YES" ]; then echo "Method : Create_user_dirs " >> $LOGFILE fi [ -d $HOME/.config ] || mkdir -p $HOME/.config cat < $HOME/.config/user-dirs.dirs XDG_DESKTOP_DIR="$HOME/Desktop" XDG_DOWNLOAD_DIR="$HOME/$(LANGUAGE="$LNG" gettext "Downloads")" XDG_TEMPLATES_DIR="$HOME/$(LANGUAGE="$LNG" gettext "Templates")" XDG_PUBLICSHARE_DIR="$HOME/$(LANGUAGE="$LNG" gettext "Public")" XDG_DOCUMENTS_DIR="$HOME/$(LANGUAGE="$LNG" gettext "Documents")" XDG_MUSIC_DIR="$HOME/$(LANGUAGE="$LNG" gettext "Music")" XDG_PICTURES_DIR="$HOME/$(LANGUAGE="$LNG" gettext "Pictures")" XDG_PHOTOS_DIR="$HOME/$(LANGUAGE="$LNG" gettext "Photos")" XDG_VIDEOS_DIR="$HOME/$(LANGUAGE="$LNG" gettext "Videos")" XDG_SHARE_DIR="$HOME/$(LANGUAGE="$LNG" gettext "Share")" XDG_GROUPS_DIR="$HOME/$(LANGUAGE="$LNG" gettext "Groups")" EOF } remove_old_links() { ARRAY_LINKS=$1 for i in $ARRAY_LINKS; do #log 'i' $i if [ -h "$i" ]; then if [ $DEBUG_MODE = "YES" ]; then echo -e "Directory $i is a Link" >> $LOGFILE fi rm -f "$i" else if [ $DEBUG_MODE = "YES" ]; then echo -e "Directory $i isn't a Link" >> $LOGFILE fi fi done } create_link() { if [ -d "$USER_FILES/$1" ]; then #log "creating link" "$UserFiles/$1" if [ $DEBUG_MODE = "YES" ]; then echo -e "Creating link : ln -s $USER_FILES/$1 LANGUAGE=$LNG gettext $1" >> $LOGFILE fi ln -s "$USER_FILES/$1" "$(LANGUAGE="$LNG" gettext "$1")" modify_bookmark "$1" "$2" fi } # Name :check_and_make_dir # Function : This function check directory exist by other way create directory # Arguments : directory_path check_and_make_dir() { NAMDIR="$1" if [ ! -d $1 ]; then if [ $DEBUG_MODE = "YES" ]; then echo -e "Creating dir $1" >> $LOGFILE fi mkdir $1 fi } create_nonuserfiles_link() { local NAMDIR check_and_make_dir $1 NAMDIR=$(basename $1) TRNAMDIR=$(LANGUAGE="$LNG" gettext "$NAMDIR") if [ $DEBUG_MODE = "YES" ]; then echo -e "VAR NAMDIR = $NAMDIR" >> $LOGFILE echo -e "VAR TRNAMDIR = $TRNAMDIR" >> $LOGFILE fi if [ ! -e "$TRNAMDIR" ]; then #log "creating link" "$UserFiles/$1" if [ $DEBUG_MODE = "YES" ]; then echo -e "Not TRNAMDIR : $TRNAMDIR" >> $LOGFILE echo -e "creating link command : ln -s $NAMDIR $TRNAMDIR" fi ln -s "$NAMDIR" "$TRNAMDIR" modify_bookmark "$NAMDIR" "$TRNAMDIR" fi } set_lang(){ echo $LNG > $HOME/.config/user-dirs.locale } escape(){ echo -n "$1" | perl -pe's/([^-_.~A-Za-z0-9])/sprintf("%%%02X", ord($1))/seg' } modify_bookmark(){ LOCALIZED="file://$HOME/$(escape "$(LANGUAGE="$LNG" gettext "$1")")" #log LOCALIZED "$LOCALIZED" echo $LOCALIZED >> "$HOME"/.gtk-bookmarks OLD="file://$(escape "$2"|sed 's#%2F#/#g')" #log OLD "$OLD" sed -i "$HOME"/.gtk-bookmarks -e "s#$OLD#$LOCALIZED#g" cat "$HOME"/.gtk-bookmarks |sort -u >"$HOME"/.gtk-bookmarks.bak mv -f "$HOME"/.gtk-bookmarks.bak "$HOME"/.gtk-bookmarks if [ $DEBUG_MODE = "YES" ]; then echo -e "Modify bookmark" >> $LOGFILE echo -e "Localized var : $LOCALIZED" >> $LOGFILE echo -e "sed -i '$HOME'/.gtk-bookmarks -e 's#$OLD#$LOCALIZED#g'" >> $LOGFILE echo -e "cat '$HOME'/.gtk-bookmarks | sort -u >'$HOME'/.gtk-bookmarks.bak" >> $LOGFILE echo -e "mv -f '$HOME'/.gtk-bookmarks.bak '$HOME'/.gtk-bookmarks" >> $LOGFILE fi } create_trash(){ ALTERN=$(readlink /etc/alternatives/x-session-manager) if [ "$GDMSESSION" = "LXDE" -o "$DESKTOP_SESSION" = "LXDE" -o "$ALTERN" = "/usr/bin/startlxde" ]; then if [ ! -d "$HOME/Desktop" ]; then mkdir "$HOME/Desktop" fi if [ ! -e "$HOME/Desktop/pcmanfm-trash.desktop" ]; then cp /usr/share/pcmanfm/pcmanfm-trash.desktop "$HOME/Desktop/" fi fi if [ "$GDMSESSION" = "gnome" -o "$DESKTOP_SESSION" = "gnome" ]; then rm -f "$HOME/Desktop/pcmanfm-trash.desktop" fi } #create_profile(){ #FILE_PROFILE="$HOME/.mozilla/firefox/profiles.ini" #PATH_WEB="/usr/share/doc/lliurex-profile/" # if [ ! -f $FILE_PROFILE ] ; then # $(firefox $PATH_WEB/index.html) # fi #} # ################ Main ################### DEBUG_MODE="YES" if [ $DEBUG_MODE = "YES" ]; then echo -e "************************************************************************************************\n" echo -e "************************************************************************************************\n" echo -e "************************************************************************************************\n" echo -e "************************************************************************************************\n" echo -e "************************************************************************************************\n" date >> $LOGFILE echo -e "************************************************************************************************\n" echo -e "************************************************************************************************\n" echo -e "************************************************************************************************\n" echo -e "************************************************************************************************\n" echo -e "************************************************************************************************\n" echo -e "status HOME before xdg" >> $LOGFILE ls -l $HOME >> $LOGFILE ls -l -R $NET_HOME >> $LOGFILE echo -e "\n\n\n" >> $LOGFILE fi [ -f "$HOME/.config/user-dirs.dirs" ] || create_user_dirs . $HOME/.config/user-dirs.dirs LLX_XDG_LINKS="$XDG_TEMPLATES_DIR $XDG_PUBLICSHARE_DIR $XDG_DOCUMENTS_DIR $XDG_MUSIC_DIR $XDG_PICTURES_DIR $XDG_PHOTOS_DIR $XDG_VIDEOS_DIR $XDG_SHARE_DIR $XDG_GROUPS_DIR" if [ $DEBUG_MODE = "YES" ]; then echo -e "User dirs file\n" >> $LOGFILE cat $HOME/.config/user-dirs.dirs >> $LOGFILE echo -e "\n" >> $LOGFILE echo -e "Vars of system\n" >> $LOGFILE echo $LLX_XDG_LINKS >> $LOGFILE echo -e "\n" >> $LOGFILE fi #Create net UserFiles for users with local home but they are net users netUserFiles #log "LLX_XDG_LINKS" $LLX_XDG_LINKS remove_old_links "${LLX_XDG_LINKS}" #create_link Desktop $XDG_DESKTOP_DIR create_link Templates $XDG_TEMPLATES_DIR create_link Public $XDG_PUBLICSHARE_DIR create_link Documents $XDG_DOCUMENTS_DIR create_link Music $XDG_MUSIC_DIR create_link Pictures $XDG_PICTURES_DIR create_link Photos $XDG_PHOTOS_DIR create_link Videos $XDG_VIDEOS_DIR create_link Share $XDG_SHARE_DIR create_link Groups $XDG_GROUPS_DIR LLX_XDG_LINKS_NONUSERFILES="$XDG_DOWNLOAD_DIR" remove_old_links "${LLX_XDG_LINKS_NONUSERFILES}" create_nonuserfiles_link Download create_user_dirs create_trash set_lang if [ $DEBUG_MODE = "YES" ]; then echo -e "status HOME after xdg" >> $LOGFILE ls -l $HOME >> $LOGFILE ls -l -R $NET_HOME >> $LOGFILE echo -e "\n\n\n" >> $LOGFILE fi exit 0