├── .gitattributes ├── LICENSE ├── README.md └── maid.sh /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Jerry Gamblin 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # MacOS Maid 2 | A simple shell script I run to keep my MacBook clean and patched. 3 | 4 | ## What It Does: 5 | - Prompt For Password If Not Root 6 | - Deletes Saved Wireless Networks 7 | - Installs Needed System Updates 8 | - Empties The Trash 9 | - Deletes All System Logs 10 | - Deletes The QuickLook files 11 | - Updates And Cleans Homebrew 12 | - Cleans Ruby 13 | - Removes All Docker Containers 14 | - Purges Memory 15 | - Removes known_hosts file. 16 | - Securely Wipes Free-space 17 | 18 | ## Usage: 19 | - Review for your preferences and comment out options **You** dont want. 20 | - Set `homessid` and `workssid` variable to stop from deleting those! 21 | 22 | **To Run:** 23 | 24 | ``` 25 | chmod +x maid.sh 26 | ./maid.sh 27 | ``` 28 | 29 | ## Important Notice 30 | I likely dont know what I am doing and this could be done faster, better and simpler some other way. These scripts could also break your MacBook and make you cry. 31 | -------------------------------------------------------------------------------- /maid.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | SECONDS=0 3 | 4 | #Check if running as root and if not elevate 5 | amiroot=$(sudo -n uptime 2>&1| grep -c "load") 6 | if [ "$amiroot" -eq 0 ] 7 | then 8 | printf "Maid Service Require Root Access. Please Enter Your Password.\n" 9 | sudo -v 10 | printf "\n" 11 | fi 12 | 13 | #Delete Saved SSIDs For Security 14 | #Be Sure To Set Home And Work SSID for ease of use. 15 | printf "Deleting saved wireless networks.\n" 16 | homessid="AddMe" 17 | workssid="AddMe" 18 | IFS=$'\n' 19 | for ssid in $(networksetup -listpreferredwirelessnetworks en0 | grep -v "Preferred networks on en0:" | grep -v $homessid | grep -v $workssid | sed "s/[\ ]//g") 20 | do 21 | networksetup -removepreferredwirelessnetwork en0 "$ssid" > /dev/null 2>&1 22 | done 23 | 24 | #Install Updates. 25 | printf "Installing needed updates.\n" 26 | softwareupdate -i -a > /dev/null 2>&1 27 | 28 | #Taking out the trash. 29 | printf "Emptying the trash.\n" 30 | sudo rm -rfv /Volumes/*/.Trashes > /dev/null 2>&1 31 | sudo rm -rfv ~/.Trash > /dev/null 2>&1 32 | 33 | #Clean the logs. 34 | printf "Emptying the system log files.\n" 35 | sudo rm -rfv /private/var/log/* > /dev/null 2>&1 36 | sudo rm -rfv /Library/Logs/DiagnosticReports/* > /dev/null 2>&1 37 | 38 | printf "Deleting the quicklook files.\n" 39 | sudo rm -rf /private/var/folders/ > /dev/null 2>&1 40 | 41 | #Cleaning Up Homebrew. 42 | printf "Cleaning up Homebrew.\n" 43 | brew cleanup --force -s > /dev/null 2>&1 44 | brew cask cleanup > /dev/null 2>&1 45 | rm -rfv /Library/Caches/Homebrew/* > /dev/null 2>&1 46 | brew tap --repair > /dev/null 2>&1 47 | brew update > /dev/null 2>&1 48 | brew upgrade > /dev/null 2>&1 49 | 50 | #Cleaning Up Ruby. 51 | printf "Cleanup up Ruby.\n" 52 | gem cleanup > /dev/null 2>&1 53 | 54 | #Cleaning Up Docker. 55 | #You May Not Want To Do This. 56 | printf "Removing all Docker containers.\n" 57 | docker rmi -f "$(docker images -q --filter 'dangling=true')" > /dev/null 2>&1 58 | 59 | #Purging Memory. 60 | printf "Purging memory.\n" 61 | sudo purge > /dev/null 2>&1 62 | 63 | #Removing Known SSH Hosts 64 | printf "Removing known ssh hosts.\n" 65 | sudo rm -f /Users/"$(whoami)"/.ssh/known_hosts > /dev/null 2>&1 66 | 67 | #Securly Erasing Data. 68 | printf "Securely erasing free space (This will take a while). \n" 69 | diskutil secureErase freespace 0 "$( df -h / | tail -n 1 | awk '{print $1}')" > /dev/null 2>&1 70 | 71 | #Finishing Up. 72 | timed="$((SECONDS / 3600)) Hours $(((SECONDS / 60) % 60)) Minutes $((SECONDS % 60)) seconds" 73 | 74 | printf "Maid Service Took %s this time. Dont Forget To Tip!\n" "$timed" 75 | --------------------------------------------------------------------------------