Untitled
raw download clone
TEXT
views 38
,
size 7296 b
#!/bin/bash
trap 'exit 0' INT
PATH=/bin:/usr/bin:




NONE='\033[00m'
RED='\033[01;31m'
GREEN='\033[01;32m'
YELLOW='\033[01;33m'
PURPLE='\033[01;35m'
CYAN='\033[01;36m'
WHITE='\033[01;37m'
BOLD='\033[1m'
UNDERLINE='\033[4m'
# ${NONE}
# ${RED}
# ${GREEN}
# ${YELLOW}
# ${PURPLE}
# ${CYAN}
# ${WHITE}
# ${BOLD}




macuser="$(logname)"
volume_list=""
comp_list=""








copy_to_usb(){
	caffeinate -t 18000 &
	echo ""
	i=1
	# user="$( cd /Users/ ; ls 2>&1 )"
	user="$( dscl . list /Users | grep -v "_" | grep -v "3" | grep -v "casperadmin" | grep -v "daemon" | grep -v "mfe" | grep -v "nobody" | grep -v "root" )"
	for r in ${user[@]}
		do
		 a=$(( i++))
		 echo ""$a".) "$r" "
		done
	echo	""
	sleep 1
	echo -e "${RED}"
	read -p "USER NAME FOR BACKUP: " usr
	echo -e "${NONE}"
	echo ""
	b=1
	usb="$( cd /Volumes/ ; ls 2>&1 )"
	for h in ${usb[@]}
		do
		 g=$(( b++))
		 echo ""$g".) "$h" "
		done
	echo ""
	sleep 1
	echo -e "${RED}"
	read -p "ENTER THE DESTINATION DISK NAME:  " dir
	echo -e "${NONE}"
	echo""
	mkdir -p /Volumes/"$dir"/"$usr"_$(date +%Y.%m.%d)
	# mkdir -p /Volumes/"$dir"/"$usr"_$(date +%Y.%m.%d)_outlook
	target=$( echo "/Volumes/"$dir"/"$usr"_$(date +%Y.%m.%d)" )
	# target_outlook=$( echo /Volumes/"$dir"/"$usr"_$(date +%Y.%m.%d)_outlook )
	# source_outlook=$( echo "/Users/"$usr"/Library/Group Containers/UBF8T346G9.Office/Outlook/" )
	home_data="$( du -h -s -IApplication -ILibrary /Users/"$usr"/ | awk '{print  $1}'  )"
	usb_size="$( df -h /Volumes/"$dir"/ | awk 'NR==2{print $4}'  )"
	echo ""
	echo -n "YOUR HOME DIRECTORY FOR BACKUP IS ---> "$home_data" <--- BIG  . THERE IS  ---> "$usb_size" <--- FREE SPACE ON THE DESTINATION EXTERNAL DISK. DO YOU WISH TO CONTINUE ? Y/N "
	read answer
	answer="$(echo $answer | tr '[:upper:]' '[:lower:] ' | cut -c1)"
	if [ "$answer" != "y" ] ; then # Nothink important ;)
	 echo ""
	 echo                                                           " MAYBY OTHER USB OR SOMETHING ELSE ?"
	 sleep 2
	 printMenu
	else
	# rsync -azhe --exclude '.Trash/'  --progress  "$source_outlook"  "$target_outlook"/
	rsync -azhe --exclude '.Trash/' --exclude '.DS_Store/' --exclude 'Application/' --exclude 'Library/'  --exclude 'Box Documents/' --exclude 'Box Sync/' --progress  "/Users/"$usr"" ""$target"/"
	fi
}




copy_from_usb(){
	caffeinate -t 18000 &
	echo ""
	usb="$( cd /Volumes/ ; ls 2>&1 )"
	b=1
	for h in ${usb[@]}
		do
		 g=$(( b++))
		 echo ""$g".) "$h" "
		done
	echo	""
	sleep 1
	echo -e "${RED}"
	read -p "EXTERNAL USB NAME: " dir
	echo -e "${NONE}"
	echo 	""
	i=1
	# user="$(last | awk  '{ if (a[$1]++ == 0) print  $1}' "$@" )"
	user="$( dscl . list /Users | grep -v "_" | grep -v "3" | grep -v "casperadmin" | grep -v "daemon" | grep -v "mfe" | grep -v "nobody" | grep -v "root" )"
	for r in ${user[@]}
		do
		 a=$(( i++))
		 echo ""$a".) "$r" "
		done
	echo	""
	echo -e "${RED}"
	read -p "USER NAME FROM BACKUP: " usr
	echo -e "${NONE}"
	sleep 1
	echo ""
	src_main="$( cd /Volumes/"$dir"/ ; ls 2>&1 )"
	s=1
	for r in ${src_main[@]}
                do
                 a=$(( s++))
                 echo ""$a".) "$r" "
                done
	echo ""
        sleep 1
	echo -e "${RED}"
	read -p "FULL NAME OF THE DIRECTORY WHERE IS BACKUP: " src_main_1
	echo -e "${NONE}"
	src=$(echo "/Volumes/"$dir"/"$src_main_1"/"$usr"")
        echo""
        # mkdir -p /Volumes/"$dir"/"$usr"_$(date +%Y.%m.%d)
        # target=$( echo "/Volumes/"$dir"/"$usr"_$(date +%Y.%m.%d)" )
        home_data_2="$( du -h -s  "$src" | awk '{print  $1}'  )"
        dest_size_2="$( df -h /Users/ | awk 'NR==2{print $4}'  )"
        echo ""
        echo -n "YOUR HOME DIRECTORY FOR BACKUP IS ---> "$home_data_2" <--- BIG  . THERE IS  ---> "$dest_size_2" <--- FREE SPACE ON THE DESTINATION EXTERNAL DISK. DO YOU WISH TO CONTINUE ? Y/N "
        read answer
        answer="$(echo $answer | tr '[:upper:]' '[:lower:] ' | cut -c1)"
        if [ "$answer" != "y" ] ; then # Nothink important ;)
         echo ""
         echo                                                           " BACK TO MENUE ?"
         sleep 2
         printMenu
        else
	rsync -azhe --exclude '.Trash/' --exclude 'Library/'  --progress --stats  ""$src"" /Users/
	fi
}




restor_outlook(){
echo ""
usb="$( cd /Volumes/ ; ls 2>&1 )"
	b=1
	for h in ${usb[@]}
		do
		 g=$(( b++))
		 echo ""$g".) "$h" "
		done
	echo	""
	sleep 1
	echo -e "${RED}"
	read -p "EXTERNAL USB NAME: " dir
	echo -e "${NONE}"
	echo 	""
	i=1
	# user="$(last | awk  '{ if (a[$1]++ == 0) print  $1}' "$@" ) "
	user="$( dscl . list /Users | grep -v "_" | grep -v "3" | grep -v "casperadmin" | grep -v "daemon" | grep -v "mfe" | grep -v "nobody" | grep -v "root" )"
	for r in ${user[@]}
		do
		 a=$(( i++))
		 echo ""$a".) "$r" "
		done
	echo	""
	sleep 1
	echo -e "${RED}"
	read -p "USER NAME FROM BACKUP: " usr
	echo -e "${NONE}"
	echo ""
	src_main="$( cd /Volumes/"$dir"/ ; ls 2>&1 )"
	s=1
	for r in ${src_main[@]}
                do
                 a=$(( s++))
                 echo ""$a".) "$r" "
                done
	echo ""
	sleep 1
	echo -e "${RED}"
        read -p "FULL NAME OF THE DIRECTORY WHERE IS BACKUP: " src_main_1
	echo -e "${NONE}"
	src_o=$( echo "/Volumes/"$dir"/"$src_main_1"/" )
        dest_outlook=$( echo "/Users/"$usr"/Library/Group\ Containers/UBF8T346G9.Office" )




	rsync  -azhe --exclude '.Trash/'   --progress --stats  "$src_o" /Users/"$usr"/Library/Group\ Containers/UBF8T346G9.Office/Outlook/




}
exit(){
osascript -e 'tell application "Terminal" to close first windows'
}
printMenu(){ 
    clear 
    echo "" 
    # caffeinate -t 7200
    echo  " "$macuser" "
    echo -e "${GREEN}" 
    echo "" 
    echo "                                 Select the option by entering the number and confirming with the enter button " 
    echo "" 
    echo -e "                                                          \t1)  Backup on ext usb"
    echo -e "                                                          \t2)  Backup from ext usb"
    # echo -e "							       \t3)  Restore Outlook"
    echo -e "                                                          \t3)  EXIT TO DESKTOP"
    echo -e "${NONE}"
    echo ""  
    read option; 
    while [[ $option -gt 4 || ! $(echo $option | grep '^[1-9]$') ]] 
    do
        printMenu
    done 
    runOption 
}
############################# 
#8.    RUN OPTION        # 
############################# 
runOption(){ 
    case $option in 
        1) copy_to_usb;; 
        2) copy_from_usb;;
	# 3) restor_outlook;;
	3) exit;;
    esac 
    echo "Press any Key to continue" 
    read x 
    printMenu 
} 
while true ; 
do     
    printMenu 
done
close fullscreen
Login or Register to edit or fork this paste. It's free.