1. #!/bin/bash
  2.  
  3. mkdir "$HOME/bak"
  4. #function to backup to a local git repo
  5. box="ENTER BACKUP HERE"
  6. backup_files () {
  7. echo "Do you want to back up a file/folder? (type 1 or 2)"
  8. select yn in "Yes" "No"; do
  9. case $yn in
  10. Yes )
  11. while true; do
  12. read -p "Enter the file/folder path: " file_path
  13.  
  14. if [[ -z "$file_path" ]]; then
  15. echo "File path cannot be empty. Please try again."
  16. elif [[ ! -e "$file_path" ]]; then
  17. echo "File or directory was not found, point the backup to an existing location"
  18. else
  19. break
  20. fi
  21. done
  22. sudo cp -r "$file_path" "$HOME/bak"
  23. scp $HOME/bak/$file_basename [email protected]:~/$box
  24. file_basename=$(basename "$file_path")
  25. NewPath="$HOME/bak/$file_basename"
  26. echo "backup complete for $NewPath"
  27. run_it_back
  28. break
  29. ;;
  30. No ) exit ;;
  31. esac
  32. done
  33. }
  34. run_it_back() {
  35. echo "Would you like to backup another file"
  36. select yn in "Yes" "No"; do
  37. case $yn in
  38. Yes ) backup_files; break;;
  39. No ) exit;;
  40. esac
  41. done
  42. }
  43.  
  44. #run it baby
  45.  
  46. git_install
  47.  
  48.  
  49.  
  50. echo "--------------------------------------------------------------------------------"
  51. echo "moving you to the correct location /home and creating a git repo locally for you"
  52. echo "--------------------------------------------------------------------------------"
  53.  
  54. # Move to the correct location and create a local Git repo if it doesn't exist
  55. BACKUP_DIR="$HOME/bak"
  56.  
  57. echo "--------------------------------------------------------------------------------"
  58. echo "Making a backup of some key files for you now, select more to add yourself below"
  59. echo "--------------------------------------------------------------------------------"
  60. #add file paths here before comp that you want backed up
  61. files_to_backup=(
  62. "/etc/ssh/sshd_config"
  63. "/usr/bin/ls"
  64. "/etc/passwd"
  65. "/etc/shadow"
  66. "/etc/group"
  67. "/etc/pam.d"
  68. #"/etc/iptables/rules.v4"
  69. "/$HOME/.bash_history"
  70. )
  71.  
  72. for file in "${files_to_backup[@]}"; do
  73. if [ -e "$file" ]; then
  74. name=$(basename "$file")
  75. sudo cp -r "$file" "$BACKUP_DIR/"
  76. scp $HOME/bak/name [email protected]:~/$box
  77. sudo git add "$BACKUP_DIR/$name"
  78. else
  79. echo "Skipping $file (not found)"
  80. fi
  81. done
  82.  
  83. echo "--------------------------------------------------------------------------------"
  84. echo "Completed backup of key files"
  85. echo "--------------------------------------------------------------------------------"
  86.  
  87. backup_files