Advertisement
13minutes-yt

ame.sh

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