Standardized script syntax

This commit is contained in:
Sun Knudsen 2021-03-16 14:23:21 -04:00
parent 8b4def74ec
commit 78ee1e0e3b
No known key found for this signature in database
GPG Key ID: 1FA767862BBD1305
7 changed files with 34 additions and 34 deletions

View File

@ -265,8 +265,8 @@ cat << EOF > /usr/local/bin/check.sh
set -e set -e
red=$'\e[1;31m' red=\$(tput setaf 1)
nc=$'\e[0m' normal=\$(tput sgr0)
printf "Backup hash: " printf "Backup hash: "
@ -275,7 +275,7 @@ read -r previous
current=\$(openssl dgst -sha512 "$BACKUP_VOLUME_PATH") current=\$(openssl dgst -sha512 "$BACKUP_VOLUME_PATH")
if [ "\$current" != "\$previous" ]; then if [ "\$current" != "\$previous" ]; then
printf "\${red}%s\${nc}\n" "Integrity check failed" printf "\$red%s\$normal\n" "Integrity check failed"
exit 1 exit 1
fi fi

View File

@ -18,7 +18,7 @@ Listed: true
```shell ```shell
sudo mkdir -p /usr/local/bin sudo mkdir -p /usr/local/bin
sudo chown ${USER}:admin /usr/local/bin sudo chown ${USER}:staff /usr/local/bin
``` ```
### Step 2: download [app-cleaner.sh](./app-cleaner.sh) ([PGP signature](./app-cleaner.sh.sig), [PGP public key](https://sunknudsen.com/sunknudsen.asc)) ### Step 2: download [app-cleaner.sh](./app-cleaner.sh) ([PGP signature](./app-cleaner.sh.sig), [PGP public key](https://sunknudsen.com/sunknudsen.asc))
@ -36,13 +36,13 @@ chmod +x /usr/local/bin/app-cleaner.sh
```console ```console
$ app-cleaner.sh /Applications/AppCleaner.app $ app-cleaner.sh /Applications/AppCleaner.app
Checking for running processes... Checking for running processes
Finding application data... Finding application data
/Applications/AppCleaner.app /Applications/AppCleaner.app
/Users/sunknudsen/Library/Preferences/net.freemacsoft.AppCleaner.plist /Users/sunknudsen/Library/Preferences/net.freemacsoft.AppCleaner.plist
/Users/sunknudsen/Library/Saved Application State/net.freemacsoft.AppCleaner.savedState /Users/sunknudsen/Library/Saved Application State/net.freemacsoft.AppCleaner.savedState
Move application data to trash (y or n)? y Move application data to trash (y or n)? y
Moving application data to trash... Moving application data to trash
Done Done
``` ```

View File

@ -7,8 +7,8 @@ fi
IFS=$'\n' IFS=$'\n'
red=$'\e[1;31m' red=$(tput setaf 1)
nc=$'\e[0m' normal=$(tput sgr0)
if [ ! -e "$1/Contents/Info.plist" ]; then if [ ! -e "$1/Contents/Info.plist" ]; then
printf "%s\n" "Cannot find app plist" printf "%s\n" "Cannot find app plist"
@ -31,7 +31,7 @@ processes=($(pgrep -afil "$app_name" | grep -v "app-cleaner.sh"))
if [ ${#processes[@]} -gt 0 ]; then if [ ${#processes[@]} -gt 0 ]; then
printf "%s\n" "${processes[@]}" printf "%s\n" "${processes[@]}"
printf "${red}%s${nc}" "Kill running processes (y or n)? " printf "$red%s$normal" "Kill running processes (y or n)? "
read -r answer read -r answer
if [ "$answer" = "y" ]; then if [ "$answer" = "y" ]; then
printf "%s\n" "Killing running processes…" printf "%s\n" "Killing running processes…"
@ -113,7 +113,7 @@ paths=($(printf "%s\n" "${paths[@]}" | sort -u));
printf "%s\n" "${paths[@]}" printf "%s\n" "${paths[@]}"
printf "${red}%s${nc}" "Move app data to trash (y or n)? " printf "$red%s$normal" "Move app data to trash (y or n)? "
read -r answer read -r answer
if [ "$answer" = "y" ]; then if [ "$answer" = "y" ]; then
printf "%s\n" "Moving app data to trash…" printf "%s\n" "Moving app data to trash…"

View File

@ -256,7 +256,7 @@ sudo pfctl -F all -f /etc/pf.conf
```shell ```shell
sudo mkdir -p /usr/local/sbin sudo mkdir -p /usr/local/sbin
sudo chown $USER:admin /usr/local/sbin sudo chown ${USER}:admin /usr/local/sbin
``` ```
### Step 11: source `/usr/local/sbin` folder ### Step 11: source `/usr/local/sbin` folder
@ -294,8 +294,8 @@ if [ "$(id -u)" != "0" ]; then
exit 1 exit 1
fi fi
green=$'\e[1;32m' green=$(tput setaf 2)
nc=$'\e[0m' normal=$(tput sgr0)
# /usr/libexec/ApplicationFirewall/socketfilterfw --blockapp /Applications/1Password\ 7.app # /usr/libexec/ApplicationFirewall/socketfilterfw --blockapp /Applications/1Password\ 7.app
# /usr/libexec/ApplicationFirewall/socketfilterfw --blockapp /usr/local/Cellar/squid/4.8/sbin/squid # /usr/libexec/ApplicationFirewall/socketfilterfw --blockapp /usr/local/Cellar/squid/4.8/sbin/squid
@ -309,7 +309,7 @@ printf "\n"
pfctl -F all -f /etc/pf.conf pfctl -F all -f /etc/pf.conf
printf "\n${green}%s${nc}\n" "Strict mode enabled" printf "\n$green%s$normal\n" "Strict mode enabled"
EOF EOF
chmod +x /usr/local/sbin/strict.sh chmod +x /usr/local/sbin/strict.sh
``` ```
@ -335,8 +335,8 @@ function disable()
trap disable INT trap disable INT
red=$'\e[1;31m' red=$(tput setaf 1)
nc=$'\e[0m' normal=$(tput sgr0)
# /usr/libexec/ApplicationFirewall/socketfilterfw --unblockapp /Applications/1Password\ 7.app # /usr/libexec/ApplicationFirewall/socketfilterfw --unblockapp /Applications/1Password\ 7.app
# /usr/libexec/ApplicationFirewall/socketfilterfw --unblockapp /usr/local/Cellar/squid/4.8/sbin/squid # /usr/libexec/ApplicationFirewall/socketfilterfw --unblockapp /usr/local/Cellar/squid/4.8/sbin/squid
@ -350,7 +350,7 @@ printf "\n"
pfctl -F all -f /etc/pf.conf pfctl -F all -f /etc/pf.conf
printf "\n${red}%s${nc}\n\n" "Trusted mode enabled (press ctrl+c to disable)" printf "\n$red%s$normal\n\n" "Trusted mode enabled (press ctrl+c to disable)"
while : while :
do do
@ -379,12 +379,12 @@ function disable()
trap disable INT trap disable INT
red=$'\e[1;31m' red=$(tput setaf 1)
nc=$'\e[0m' normal=$(tput sgr0)
pfctl -d pfctl -d
printf "\n${red}%s${nc}\n\n" "Firewall disabled (press ctrl+c to enable)" printf "\n$red%s$normal\n\n" "Firewall disabled (press ctrl+c to enable)"
while : while :
do do

View File

@ -246,7 +246,7 @@ Insert micro SD card into macOS computer, run following and eject card.
```shell ```shell
volume_path="/Volumes/boot" volume_path="/Volumes/boot"
volume_uuid=`diskutil info "$volume_path" | awk '/Volume UUID:/ { print $3 }'` volume_uuid=$(diskutil info "$volume_path" | awk '/Volume UUID:/ { print $3 }')
echo "UUID=$volume_uuid none msdos rw,noauto" | sudo tee -a /etc/fstab echo "UUID=$volume_uuid none msdos rw,noauto" | sudo tee -a /etc/fstab
``` ```

View File

@ -83,13 +83,13 @@ cat << "EOF" >> ~/.zshrc
# Kill apps that match string # Kill apps that match string
function kill-apps() { function kill-apps() {
IFS=$'\n' IFS=$'\n'
red=$'\e[1;31m' red=$(tput setaf 1)
nc=$'\e[0m' normal=$(tput sgr0)
if [ -z "$1" ]; then if [ -z "$1" ]; then
printf "%s\n" "Usage: kill-apps string" printf "%s\n" "Usage: kill-apps string"
return 1 return 1
fi fi
printf "%s\n" "Finding apps that match \"$1\"..." printf "%s\n" "Finding apps that match \"$1\""
sleep 1 sleep 1
processes=($(pgrep -afil "$1")) processes=($(pgrep -afil "$1"))
if [ ${#processes[@]} -eq 0 ]; then if [ ${#processes[@]} -eq 0 ]; then
@ -97,10 +97,10 @@ function kill-apps() {
return 0 return 0
else else
printf "%s\n" "${processes[@]}" printf "%s\n" "${processes[@]}"
printf "${red}%s${nc}" "Kill found apps (y or n)? " printf "$red%s$normal" "Kill found apps (y or n)? "
read -r answer read -r answer
if [ "$answer" = "y" ]; then if [ "$answer" = "y" ]; then
printf "%s\n" "Killing found apps..." printf "%s\n" "Killing found apps"
sleep 1 sleep 1
for process in "${processes[@]}"; do for process in "${processes[@]}"; do
echo $process | awk '{print $1}' | xargs sudo kill 2>&1 | grep -v "No such process" echo $process | awk '{print $1}' | xargs sudo kill 2>&1 | grep -v "No such process"
@ -122,7 +122,7 @@ source ~/.zshrc
```console ```console
$ kill-apps adobe $ kill-apps adobe
Finding apps that match "adobe"... Finding apps that match "adobe"
46639 /Library/Application Support/Adobe/Adobe Desktop Common/IPCBox/AdobeIPCBroker.app/Contents/MacOS/AdobeIPCBroker -launchedbyvulcan /Applications/Adobe Premiere Pro 2020/Adobe Premiere Pro 2020.app/Contents/MacOS/Adobe Premiere Pro 2020 46639 /Library/Application Support/Adobe/Adobe Desktop Common/IPCBox/AdobeIPCBroker.app/Contents/MacOS/AdobeIPCBroker -launchedbyvulcan /Applications/Adobe Premiere Pro 2020/Adobe Premiere Pro 2020.app/Contents/MacOS/Adobe Premiere Pro 2020
46645 /Library/Application Support/Adobe/Creative Cloud Libraries/CCLibrary.app/Contents/MacOS/../libs/node /Library/Application Support/Adobe/Creative Cloud Libraries/CCLibrary.app/Contents/MacOS/../js/server.js 46645 /Library/Application Support/Adobe/Creative Cloud Libraries/CCLibrary.app/Contents/MacOS/../libs/node /Library/Application Support/Adobe/Creative Cloud Libraries/CCLibrary.app/Contents/MacOS/../js/server.js
46653 /Applications/Utilities/Adobe Creative Cloud Experience/CCXProcess/CCXProcess.app/Contents/MacOS/../libs/Adobe_CCXProcess.node /Applications/Utilities/Adobe Creative Cloud Experience/CCXProcess/CCXProcess.app/Contents/MacOS/../js/main.js 46653 /Applications/Utilities/Adobe Creative Cloud Experience/CCXProcess/CCXProcess.app/Contents/MacOS/../libs/Adobe_CCXProcess.node /Applications/Utilities/Adobe Creative Cloud Experience/CCXProcess/CCXProcess.app/Contents/MacOS/../js/main.js

View File

@ -65,19 +65,19 @@ export LC_CTYPE=C
basedir=$(dirname "$0") basedir=$(dirname "$0")
# Spoof computer name # Spoof computer name
first_name=`sed "$(jot -r 1 1 2048)q;d" $basedir/first-names.txt | sed -e 's/[^a-zA-Z]//g'` first_name=$(sed "$(jot -r 1 1 2048)q;d" $basedir/first-names.txt | sed -e 's/[^a-zA-Z]//g')
model_name=`system_profiler SPHardwareDataType | awk '/Model Name/ {$1=$2=""; print $0}' | sed -e 's/^[ ]*//'` model_name=$(system_profiler SPHardwareDataType | awk '/Model Name/ {$1=$2=""; print $0}' | sed -e 's/^[ ]*//')
computer_name="$first_names $model_name" computer_name="$first_names $model_name"
host_name=`echo $computer_name | sed -e 's///g' | sed -e 's/ /-/g'` host_name=$(echo $computer_name | sed -e 's///g' | sed -e 's/ /-/g')
sudo scutil --set ComputerName "$computer_name" sudo scutil --set ComputerName "$computer_name"
sudo scutil --set LocalHostName "$host_name" sudo scutil --set LocalHostName "$host_name"
sudo scutil --set HostName "$host_name" sudo scutil --set HostName "$host_name"
printf "%s\n" "Spoofed hostname to $host_name" printf "%s\n" "Spoofed hostname to $host_name"
# Spoof MAC address of en0 interface # Spoof MAC address of en0 interface
mac_address_prefix=`sed "$(jot -r 1 1 768)q;d" $basedir/mac-address-prefixes.txt | sed -e 's/[^A-F0-9:]//g'` mac_address_prefix=$(sed "$(jot -r 1 1 768)q;d" $basedir/mac-address-prefixes.txt | sed -e 's/[^A-F0-9:]//g')
mac_address_suffix=`openssl rand -hex 3 | sed 's/\(..\)/\1:/g; s/.$//'` mac_address_suffix=$(openssl rand -hex 3 | sed 's/\(..\)/\1:/g; s/.$//')
mac_address=`echo "$mac_address_prefix:$mac_address_suffix" | awk '{print toupper($0)}'` mac_address=$(echo "$mac_address_prefix:$mac_address_suffix" | awk '{print toupper($0)}')
sudo ifconfig en0 ether "$mac_address" sudo ifconfig en0 ether "$mac_address"
printf "%s\n" "Spoofed MAC address of en0 interface to $mac_address" printf "%s\n" "Spoofed MAC address of en0 interface to $mac_address"
EOF EOF