#!/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" export TEXTDOMAIN USER_FILES="$HOME/UserFiles" netUserFiles() { GRP_USER="$(id -ng $USER_NAME)" NET_HOME="/net/home/$GRP_USER/$USERNAME" if [ ! -w "$NET_HOME" ] ; then return 0 fi if [ ! -d "$NET_HOME/UserFiles" ]; then mkdir $NET_HOME/UserFiles fi if [ ! -d "$NET_HOME/Desktop" ]; then mkdir $NET_HOME/Desktop fi if [ -d "$HOME/UserFiles" ]; then rsync -rlptD --backup --suffix=".$(date +%F_%R)" $HOME/UserFiles $NET_HOME/ rm -rf $HOME/UserFiles fi if [ -d "$HOME/Desktop" ]; then rsync -rlptD --backup --suffix=".$(date +%F_%R)" $HOME/Desktop/ $NET_HOME/Desktop/ rm -rf $HOME/Desktop fi [ -L "$USER_FILES" ] || ln -s $NET_HOME/UserFiles $HOME/UserFiles [ -L "$HOME/Desktop" ] || ln -s $NET_HOME/Desktop $HOME/Desktop } create_user_dirs() { if [ $DEBUG_MODE = "YES" ]; then echo "Method : Create_user_dirs " >> $HOME/.logxdguserdirs 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 [ -h "$i" ] && rm -f "$i" done } create_link() { if [ -d "$USER_FILES/$1" ]; then #log "creating link" "$UserFiles/$1" 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" [ -d $1 ] || mkdir $1 } create_nonuserfiles_link() { local NAMDIR check_and_make_dir $1 NAMDIR=$(basename $1) TRNAMDIR=$(LANGUAGE="$LNG" gettext "$NAMDIR") if [ ! -e "$TRNAMDIR" ]; then #log "creating link" "$UserFiles/$1" 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 } 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\n" 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" #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 exit 0