This week only. Pastebin PRO Accounts Christmas Special! Don't miss out!Want more features on Pastebin? Sign Up, it's FREE!
Guest

sync.sh

By: a guest on Feb 20th, 2011  |  syntax: Bash  |  size: 1.63 KB  |  views: 232  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #!/bin/bash    
  2. echo "Running sync script"
  3. date=`date '+%m.%d.%y.%H'`
  4. homedir="/home/skraps" # Duh
  5. dropbox="/Dropbox" #
  6. netbookdir="/skraps-netbook"
  7.  
  8. rootdir="${homedir}/Dropbox${netbookdir}"
  9. androiddir="/media/BLACKBERRY${netbookdir}"
  10. thumbdir="/media/ext4-usb${netbookdir}"
  11.  
  12. syncdirs=( $rootdir $androiddir $thumbdir )
  13.  
  14. keepass="/tools/KeePass/skraps.kdbx" #Password DB
  15. phone="/Android/backup" #Directory
  16. notes="/Documents/notes.txt" #Personal tech notes
  17. taxes="/Documents/Taxes" #Directory
  18. scripts="/scripts" #Directory
  19. androiddev="/workspace/vmArchiver" #Dir
  20. resume="/resume" #Dir
  21.  
  22. #       rootdir androiddir
  23. dirs=( $phone $taxes $scripts $androiddev $resume )
  24. files=( $keepass $notes )
  25. #check for thumb drive
  26. df | grep ext4-usb > /dev/null
  27. if [ $? = "0" ]; then
  28.         thumbdrive_mounted="1"
  29.         echo "Thumbdrive mounted"
  30. else
  31.         thumbdrive_mounted="0"
  32. fi
  33.  
  34. #check for phone drive
  35. df | grep BLACKBERRY > /dev/null
  36. if [ $? = "0" ];then
  37.         android_mounted="1"
  38.         echo "Phone mounted"
  39. else
  40.         android_mounted="0"
  41. fi
  42.  
  43. function copyfiles {
  44.         for b in ${dirs[@]}; do
  45.                 cp -R ${homedir}${b} ${1}
  46.         done
  47.         for c in ${files[@]}; do
  48.                 cp ${homedir}${c} ${1}
  49.         done
  50.  
  51. }
  52.  
  53. function mkdirectory {
  54.         mkdir -p "$1"
  55. }
  56.  
  57. function exists {
  58.         if [ -e "$1" ];then
  59.                 return 0
  60.         else
  61.                 mkdirectory "$1"
  62.         fi
  63. }
  64.  
  65. for a in ${syncdirs[@]}; do
  66.                        
  67.  
  68. case $a in
  69.  
  70. "$rootdir")
  71.         exists "$a"
  72.         copyfiles "$a"
  73.         ;;
  74. "$androiddir")
  75.         if [ $android_mounted = "1" ];then
  76.                 exists "$a"
  77.                 copyfiles "$a"
  78.         fi
  79.         ;;     
  80. "$thumbdir")
  81.         if [ $thumbdrive_mounted = "1" ];then
  82.                 exists "$a"
  83.                 copyfiles "$a"
  84.         fi
  85.         ;;
  86. esac
  87.  
  88. done
clone this paste RAW Paste Data