Scripts required to make AME
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

213 lines
14 KiB

  1. #!/bin/bash
  2. clear
  3. echo " ╔═══════════════╗"
  4. echo " ║ !!!WARNING!!! ║"
  5. echo "╔════════════════╩═══════════════╩══════════════════╗"
  6. echo "║ This script comes without any warranty. ║"
  7. echo "║ If your computer no longer boots, explodes, or ║"
  8. echo "║ divides by zero, you are the only one responsible ║"
  9. echo "╟╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╢"
  10. echo "║ This script only works on Debian based distros. ║"
  11. echo "║ An Ubuntu 16.04/18.04 Live ISO is recommended. ║"
  12. echo "╚═══════════════════════════════════════════════════╝"
  13. echo ""
  14. read -p "To continue press [ENTER], or Ctrl-C to exit"
  15. title_bar() {
  16. clear
  17. echo "╔═══════════════════════════════════════════════════╗"
  18. echo "║ AMEliorate Windows 10 1903 2020.03.27 ║"
  19. echo "╚═══════════════════════════════════════════════════╝"
  20. }
  21. # prompts to install git and 7zip if not already installed
  22. title_bar
  23. sudo apt update
  24. PKG_OK=$(dpkg-query -W --showformat='${Status}\n' git|grep "install ok installed")
  25. echo "Checking for git: $PKG_OK"
  26. if [ "" == "$PKG_OK" ]; then
  27. echo "curl not found, prompting to install git..."
  28. sudo apt-get -y install git
  29. fi
  30. PKG_OK=$(dpkg-query -W --showformat='${Status}\n' p7zip-full|grep "install ok installed")
  31. echo "Checking for 7zip: $PKG_OK"
  32. if [ "" == "$PKG_OK" ]; then
  33. echo "curl not found, prompting to install 7zip..."
  34. sudo apt-get -y install p7zip-full
  35. fi
  36. # prompts to install fzf if not already installed
  37. title_bar
  38. echo "fzf is required for this script to function"
  39. echo "Please allow for fzf to install following this message"
  40. echo "Enter "y" (yes) for all prompts"
  41. read -p "To continue press [ENTER], or Ctrl-C to exit"
  42. echo "\n"
  43. title_bar
  44. git clone --depth 1 https://github.com/junegunn/fzf.git ~/.fzf
  45. ~/.fzf/install
  46. # start AME process
  47. title_bar
  48. echo "Starting AME process, searching for files..."
  49. Term=(applocker autologger clipsvc clipup cortana DeliveryOptimization diagtrack dmclient dosvc EnhancedStorage homegroup hotspot invagent microsoftedge.exe msra sihclient slui startupscan storsvc usoclient usocore windowsmaps windowsupdate wsqmcons wua wus)
  50. touch fzf_list.txt
  51. for i in "${Term[@]}"
  52. do
  53. echo "Looking for $i"
  54. $HOME/.fzf/bin/fzf -e -f $i >> fzf_list.txt
  55. done
  56. # check if fzf found anything
  57. title_bar
  58. FZFCHECK = wc -l fzf_list.txt
  59. if FZFCHECK = 0; then
  60. echo "ERROR! no files found, exiting..."
  61. exit 1
  62. elif FZFCHECK > 0; then
  63. echo "Directory file not empty, continuing..."
  64. fi
  65. # directory processing starts here!
  66. rm dirs*
  67. touch dirs.txt
  68. # removes the FileMaps directories/files
  69. awk '!/FileMaps/' fzf_list.txt > fzf_list_cleaned.txt
  70. # removes everything after the last slash in the file list
  71. sed 's%/[^/]*$%/%' fzf_list_cleaned.txt >> dirs.txt
  72. # removes a trailing slash, repeats several times to get all the directories
  73. for a in {0..12..2}
  74. do
  75. if [ $a -eq 0 ]
  76. then
  77. cat dirs.txt > dirs$a.txt
  78. fi
  79. b=$((a+1))
  80. c=$((b+1))
  81. sed 's,/$,,' dirs$a.txt >> dirs$b.txt
  82. sed 's%/[^/]*$%/%' dirs$b.txt >> dirs$c.txt
  83. cat dirs$c.txt >> dirs.txt
  84. done
  85. # removes duplicates and sorts by length
  86. awk '!a[$0]++' dirs.txt > dirs_deduped.txt
  87. awk '{ print length($0) " " $0; }' dirs_deduped.txt | sort -n | cut -d ' ' -f 2- > dirs_sorted.txt
  88. # appends root backup directory
  89. awk -v quote='"' '{print "mkdir " quote "AME_Backup/" $0 quote}' dirs_sorted.txt > mkdirs.sh
  90. # adds some needed things
  91. echo 'mkdir "AME_Backup/Program Files (x86)"' | cat - mkdirs.sh > temp && mv temp mkdirs.sh
  92. echo 'mkdir AME_Backup/Windows/SoftwareDistribution' | cat - mkdirs.sh > temp && mv temp mkdirs.sh
  93. echo 'mkdir AME_Backup/Windows/InfusedApps' | cat - mkdirs.sh > temp && mv temp mkdirs.sh
  94. echo 'mkdir AME_Backup/Windows' | cat - mkdirs.sh > temp && mv temp mkdirs.sh
  95. echo 'mkdir AME_Backup' | cat - mkdirs.sh > temp && mv temp mkdirs.sh
  96. echo '#!/bin/bash' | cat - mkdirs.sh > temp && mv temp mkdirs.sh
  97. chmod +x mkdirs.sh
  98. rm dirs*
  99. # creates backup script
  100. awk -v quote='"' '{print "cp -fa --preserve=all " quote $0 quote " " quote "AME_Backup/" $0 quote}' fzf_list_cleaned.txt > backup.txt
  101. # adds individual directories to top of script
  102. echo 'cp -fa --preserve=all "Program Files/Internet Explorer" "AME_Backup/Program Files/Internet Explorer"' | cat - backup.txt > temp && mv temp backup.txt
  103. echo 'cp -fa --preserve=all "Program Files/WindowsApps" "AME_Backup/Program Files/WindowsApps"' | cat - backup.txt > temp && mv temp backup.txt
  104. echo 'cp -fa --preserve=all "Program Files/Windows Defender" "AME_Backup/Program Files/Windows Defender"' | cat - backup.txt > temp && mv temp backup.txt
  105. echo 'cp -fa --preserve=all "Program Files/Windows Mail" "AME_Backup/Program Files/Windows Mail"' | cat - backup.txt > temp && mv temp backup.txt
  106. echo 'cp -fa --preserve=all "Program Files/Windows Media Player" "AME_Backup/Program Files/Windows Media Player"' | cat - backup.txt > temp && mv temp backup.txt
  107. echo 'cp -fa --preserve=all "Program Files (x86)/Internet Explorer" "AME_Backup/Program Files (x86)/Internet Explorer"' | cat - backup.txt > temp && mv temp backup.txt
  108. echo 'cp -fa --preserve=all "Program Files (x86)/Windows Defender" "AME_Backup/Program Files (x86)/Windows Defender"' | cat - backup.txt > temp && mv temp backup.txt
  109. echo 'cp -fa --preserve=all "Program Files (x86)/Windows Mail" "AME_Backup/Program Files (x86)/Windows Mail"' | cat - backup.txt > temp && mv temp backup.txt
  110. echo 'cp -fa --preserve=all "Program Files (x86)/Windows Media Player" "AME_Backup/Program Files (x86)/Windows Media Player"' | cat - backup.txt > temp && mv temp backup.txt
  111. echo 'cp -fa --preserve=all Windows/System32/wua* AME_Backup/Windows/System32' | cat - backup.txt > temp && mv temp backup.txt
  112. echo 'cp -fa --preserve=all Windows/System32/wups* AME_Backup/Windows/System32' | cat - backup.txt > temp && mv temp backup.txt
  113. echo 'cp -fa --preserve=all Windows/SystemApps/*CloudExperienceHost* AME_Backup/Windows/SystemApps' | cat - backup.txt > temp && mv temp backup.txt
  114. echo 'cp -fa --preserve=all Windows/SystemApps/*ContentDeliveryManager* AME_Backup/Windows/SystemApps' | cat - backup.txt > temp && mv temp backup.txt
  115. echo 'cp -fa --preserve=all Windows/SystemApps/Microsoft.MicrosoftEdge* AME_Backup/Windows/SystemApps' | cat - backup.txt > temp && mv temp backup.txt
  116. echo 'cp -fa --preserve=all Windows/SystemApps/Microsoft.Windows.Cortana* AME_Backup/Windows/SystemApps' | cat - backup.txt > temp && mv temp backup.txt
  117. echo 'cp -fa --preserve=all Windows/SystemApps/Microsoft.XboxGameCallableUI* AME_Backup/Windows/SystemApps' | cat - backup.txt > temp && mv temp backup.txt
  118. echo 'cp -fa --preserve=all Windows/diagnostics/system/Apps AME_Backup/Windows/diagnostics/system' | cat - backup.txt > temp && mv temp backup.txt
  119. echo 'cp -fa --preserve=all Windows/diagnostics/system/WindowsUpdate AME_Backup/Windows/diagnostics/system' | cat - backup.txt > temp && mv temp backup.txt
  120. echo '#!/bin/bash' | cat - backup.txt > temp && mv temp backup.txt
  121. awk '{ print length($0) " " $0; }' backup.txt | sort -n | cut -d ' ' -f 2- > backup.sh
  122. rm backup.txt
  123. chmod +x backup.sh
  124. # creates recovery script
  125. awk -v quote='"' '{print "cp -fa --preserve=all " quote "AME_Backup/" $0 quote " " quote $0 quote}' fzf_list_cleaned.txt > restore.txt
  126. echo 'cp -fa --preserve=all "AME_Backup/Program Files/Internet Explorer" "Program Files/Internet Explorer"' | cat - restore.txt > temp && mv temp restore.txt
  127. echo 'cp -fa --preserve=all "AME_Backup/Program Files/WindowsApps" "Program Files/WindowsApps"' | cat - restore.txt > temp && mv temp restore.txt
  128. echo 'cp -fa --preserve=all "AME_Backup/Program Files/Windows Defender" "Program Files/Windows Defender"' | cat - restore.txt > temp && mv temp restore.txt
  129. echo 'cp -fa --preserve=all "AME_Backup/Program Files/Windows Mail" "Program Files/Windows Mail"' | cat - restore.txt > temp && mv temp restore.txt
  130. echo 'cp -fa --preserve=all "AME_Backup/Program Files/Windows Media Player" "Program Files/Windows Media Player"' | cat - restore.txt > temp && mv temp restore.txt
  131. echo 'cp -fa --preserve=all "AME_Backup/Program Files (x86)/Internet Explorer" "Program Files (x86)/Internet Explorer"' | cat - restore.txt > temp && mv temp restore.txt
  132. echo 'cp -fa --preserve=all "Program Files (x86)/Windows Defender" "Program Files (x86)/Windows Defender"' | cat - restore.txt > temp && mv temp restore.txt
  133. echo 'cp -fa --preserve=all "AME_Backup/Program Files (x86)/Windows Mail" "Program Files (x86)/Windows Mail"' | cat - restore.txt > temp && mv temp restore.txt
  134. echo 'cp -fa --preserve=all "AME_Backup/Program Files (x86)/Windows Media Player" "Program Files (x86)/Windows Media Player"' | cat - restore.txt > temp && mv temp restore.txt
  135. echo 'cp -fa --preserve=all AME_Backup/Windows/System32/wua* Windows/System32' | cat - restore.txt > temp && mv temp restore.txt
  136. echo 'cp -fa --preserve=all AME_Backup/Windows/System32/wups* Windows/System32' | cat - restore.txt > temp && mv temp restore.txt
  137. echo 'cp -fa --preserve=all AME_Backup/Windows/SystemApps/*CloudExperienceHost* Windows/SystemApps' | cat - restore.txt > temp && mv temp restore.txt
  138. echo 'cp -fa --preserve=all AME_Backup/Windows/SystemApps/*ContentDeliveryManager* Windows/SystemApps' | cat - restore.txt > temp && mv temp restore.txt
  139. echo 'cp -fa --preserve=all AME_Backup/Windows/SystemApps/Microsoft.MicrosoftEdge* Windows/SystemApps' | cat - restore.txt > temp && mv temp restore.txt
  140. echo 'cp -fa --preserve=all AME_Backup/Windows/SystemApps/Microsoft.Windows.Cortana* Windows/SystemApps' | cat - restore.txt > temp && mv temp restore.txt
  141. echo 'cp -fa --preserve=all AME_Backup/Windows/SystemApps/Microsoft.XboxGameCallableUI* Windows/SystemApps' | cat - restore.txt > temp && mv temp restore.txt
  142. echo 'cp -fa --preserve=all AME_Backup/Windows/diagnostics/system/Apps Windows/diagnostics/system' | cat - restore.txt > temp && mv temp restore.txt
  143. echo 'cp -fa --preserve=all AME_Backup/Windows/diagnostics/system/WindowsUpdate Windows/diagnostics/system' | cat - restore.txt > temp && mv temp restore.txt
  144. awk '{ print length($0) " " $0; }' restore.txt | sort -n | cut -d ' ' -f 2- > restore.sh
  145. echo 'read -p "To continue press [ENTER], or Ctrl-C to exit"' | cat - restore.sh > temp && mv temp restore.sh
  146. echo 'echo "This script will restore all the necessary files for Windows Updates to be installed manually"' | cat - restore.sh > temp && mv temp restore.sh
  147. echo '#!/bin/bash' | cat - restore.sh > temp && mv temp restore.sh
  148. rm restore.txt
  149. chmod +x restore.sh
  150. # creates removal script
  151. awk -v quote='"' '{print "rm -rf " quote $0 quote}' fzf_list_cleaned.txt > remove.sh
  152. echo 'rm -rf "Program Files/Internet Explorer"' | cat - remove.sh > temp && mv temp remove.sh
  153. echo 'rm -rf "Program Files/WindowsApps"' | cat - remove.sh > temp && mv temp remove.sh
  154. echo 'rm -rf "Program Files/Windows Defender"' | cat - remove.sh > temp && mv temp remove.sh
  155. echo 'rm -rf "Program Files/Windows Mail"' | cat - remove.sh > temp && mv temp remove.sh
  156. echo 'rm -rf "Program Files/Windows Media Player"' | cat - remove.sh > temp && mv temp remove.sh
  157. echo 'rm -rf "Program Files (x86)/Internet Explorer"' | cat - remove.sh > temp && mv temp remove.sh
  158. echo 'rm -rf "Program Files (x86)/Windows Defender"' | cat - remove.sh > temp && mv temp remove.sh
  159. echo 'rm -rf "Program Files (x86)/Windows Mail"' | cat - remove.sh > temp && mv temp remove.sh
  160. echo 'rm -rf "Program Files (x86)/Windows Media Player"' | cat - remove.sh > temp && mv temp remove.sh
  161. echo 'rm -rf Windows/System32/wua*' | cat - remove.sh > temp && mv temp remove.sh
  162. echo 'rm -rf Windows/System32/wups*' | cat - remove.sh > temp && mv temp remove.sh
  163. echo 'rm -rf Windows/SystemApps/*CloudExperienceHost*' | cat - remove.sh > temp && mv temp remove.sh
  164. echo 'rm -rf Windows/SystemApps/*ContentDeliveryManager*' | cat - remove.sh > temp && mv temp remove.sh
  165. echo 'rm -rf Windows/SystemApps/Microsoft.MicrosoftEdge*' | cat - remove.sh > temp && mv temp remove.sh
  166. echo 'rm -rf Windows/SystemApps/Microsoft.Windows.Cortana*' | cat - remove.sh > temp && mv temp remove.sh
  167. echo 'rm -rf Windows/SystemApps/Microsoft.XboxGameCallableUI*' | cat - remove.sh > temp && mv temp remove.sh
  168. echo 'rm -rf Windows/SystemApps/Microsoft.XboxIdentityProvider*' | cat - remove.sh > temp && mv temp remove.sh
  169. echo 'rm -rf Windows/diagnostics/system/Apps' | cat - remove.sh > temp && mv temp remove.sh
  170. echo 'rm -rf Windows/diagnostics/system/WindowsUpdate' | cat - remove.sh > temp && mv temp remove.sh
  171. echo 'rm -rf "Windows/System32/smartscreen.exe"' | cat - remove.sh > temp && mv temp remove.sh
  172. echo 'rm -rf "Windows/System32/smartscreenps.dll"' | cat - remove.sh > temp && mv temp remove.sh
  173. echo 'rm -rf "Windows/System32/SecurityHealthAgent.dll"' | cat - remove.sh > temp && mv temp remove.sh
  174. echo 'rm -rf "Windows/System32/SecurityHealthService.exe"' | cat - remove.sh > temp && mv temp remove.sh
  175. echo 'rm -rf "Windows/System32/SecurityHealthSystray.exe"' | cat - remove.sh > temp && mv temp remove.sh
  176. echo '#!/bin/bash' | cat - remove.sh > temp && mv temp remove.sh
  177. chmod +x remove.sh
  178. # runs the scripts
  179. title_bar
  180. FILE=./AME_Backup/
  181. if [ -d $FILE ]; then
  182. now=$(date +"%Y.%m.%d.%H.%M")
  183. 7z a AME_Backup_$now.zip AME_Backup/
  184. rm -rf AME_Backup/
  185. else
  186. echo "$FILE' not found, continuing"
  187. fi
  188. echo "Creating Directories"
  189. ./mkdirs.sh
  190. echo "Done."
  191. echo "Backing up files"
  192. ./backup.sh
  193. echo "Done."
  194. echo "Removing files"
  195. ./remove.sh
  196. echo "Done."
  197. sync
  198. title_bar
  199. echo "You may now reboot into Windows"