From 8302c9e1cab0c7671f159b62967c191e9c855f0d Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Sun, 5 Dec 2021 04:47:46 +0000 Subject: [PATCH] chore(style): wrap standalone scripts with a main function --- gpg-pubkey/gpg-pubkey-id.sh | 12 ++++++--- macos/install.sh | 44 +++++++++++++++++--------------- setcap-netbind/setcap-netbind.sh | 40 ++++++++++++++++------------- 3 files changed, 54 insertions(+), 42 deletions(-) diff --git a/gpg-pubkey/gpg-pubkey-id.sh b/gpg-pubkey/gpg-pubkey-id.sh index dd4062b..6277b43 100644 --- a/gpg-pubkey/gpg-pubkey-id.sh +++ b/gpg-pubkey/gpg-pubkey-id.sh @@ -2,7 +2,11 @@ set -e set -u -gpg --list-secret-keys --keyid-format LONG | - grep sec | - cut -d'/' -f2 | - cut -d' ' -f1 +function main() { + gpg --list-secret-keys --keyid-format LONG | + grep sec | + cut -d'/' -f2 | + cut -d' ' -f1 +} + +main diff --git a/macos/install.sh b/macos/install.sh index 0eb770c..feba281 100644 --- a/macos/install.sh +++ b/macos/install.sh @@ -2,29 +2,33 @@ set -e set -u -webi_download +function main() { + webi_download -pushd ~/Downloads/webi 2>&1 > /dev/null + pushd ~/Downloads/webi 2>&1 > /dev/null -if [ "Darwin" == "$(uname -s)" ]; then - curl -fsSL 'https://gist.githubusercontent.com/coolaj86/8c36d132250163011c83bad8284975ee/raw/5a291955813743c20c12ca2d35c7b1bb34f8aecc/create-bootable-installer-for-os-x-el-capitan.sh' -o create-bootable-installer-for-os-x-el-capitan.sh - bash create-bootable-installer-for-os-x-el-capitan.sh -else - curl -fsSL 'https://gist.githubusercontent.com/coolaj86/9834a45a6c21a41e8882698a00b55787/raw/c43061cd0c53ec675996f5cb66c7077e666aabd4/install-mac-tools.sh' -o install-mac-tools.sh - # TODO add xar to webinstall.dev - sudo apt install libz-dev # needed for xar - bash install-mac-tools.sh - echo "WARN: may need a restart for hfsplus to be recognized by the kernel" + if [ "Darwin" == "$(uname -s)" ]; then + curl -fsSL 'https://gist.githubusercontent.com/coolaj86/8c36d132250163011c83bad8284975ee/raw/5a291955813743c20c12ca2d35c7b1bb34f8aecc/create-bootable-installer-for-os-x-el-capitan.sh' -o create-bootable-installer-for-os-x-el-capitan.sh + bash create-bootable-installer-for-os-x-el-capitan.sh + else + curl -fsSL 'https://gist.githubusercontent.com/coolaj86/9834a45a6c21a41e8882698a00b55787/raw/c43061cd0c53ec675996f5cb66c7077e666aabd4/install-mac-tools.sh' -o install-mac-tools.sh + # TODO add xar to webinstall.dev + sudo apt install libz-dev # needed for xar + bash install-mac-tools.sh + echo "WARN: may need a restart for hfsplus to be recognized by the kernel" - curl -fsSL 'https://gist.github.com/coolaj86/04fd06560a8465a695337eb502f5b0e9/raw/0a06fb4dce91399d374d9a12958dabb48a9bd42a/empty.7400m.img.bz2' -o empty.7400m.img.bz2 + curl -fsSL 'https://gist.github.com/coolaj86/04fd06560a8465a695337eb502f5b0e9/raw/0a06fb4dce91399d374d9a12958dabb48a9bd42a/empty.7400m.img.bz2' -o empty.7400m.img.bz2 - curl -fsSL 'https://gist.githubusercontent.com/coolaj86/9834a45a6c21a41e8882698a00b55787/raw/c43061cd0c53ec675996f5cb66c7077e666aabd4/linux-create-bootable-macos-recovery-image.sh' -o linux-create-bootable-macos-recovery-image.sh - bash linux-create-bootable-macos-recovery-image.sh -fi + curl -fsSL 'https://gist.githubusercontent.com/coolaj86/9834a45a6c21a41e8882698a00b55787/raw/c43061cd0c53ec675996f5cb66c7077e666aabd4/linux-create-bootable-macos-recovery-image.sh' -o linux-create-bootable-macos-recovery-image.sh + bash linux-create-bootable-macos-recovery-image.sh + fi -mv ~/Downloads/webi/el-capitan.iso ~/Downloads/ -echo "" -echo "Created ~/Downloads/el-capitan.iso" -echo "" + mv ~/Downloads/webi/el-capitan.iso ~/Downloads/ + echo "" + echo "Created ~/Downloads/el-capitan.iso" + echo "" -popd 2>&1 > /dev/null + popd 2>&1 > /dev/null +} + +main diff --git a/setcap-netbind/setcap-netbind.sh b/setcap-netbind/setcap-netbind.sh index 97620b5..8241cc2 100644 --- a/setcap-netbind/setcap-netbind.sh +++ b/setcap-netbind/setcap-netbind.sh @@ -2,25 +2,29 @@ set -e set -u -my_bin="${1}" -# ex: node -if [ -z "$(command -v "${my_bin}")" ]; then - echo "setcap-netbind: '${my_bin}' not found" - exit 1 -fi +function main() { + my_bin="${1}" + # ex: node + if [ -z "$(command -v "${my_bin}")" ]; then + echo "setcap-netbind: '${my_bin}' not found" + exit 1 + fi -my_sudo="" -if [ -n "$(command -v sudo)" ]; then - my_sudo=sudo -fi + my_sudo="" + if [ -n "$(command -v sudo)" ]; then + my_sudo=sudo + fi -# get full path -# ex: ~/.local/opt/node/bin/node -my_bin="$(command -v "${my_bin}")" + # get full path + # ex: ~/.local/opt/node/bin/node + my_bin="$(command -v "${my_bin}")" -# get canonical full path -# ex: ~/.local/opt/node-v16.13.0/bin/node -my_bin="$(readlink -f "${my_bin}")" + # get canonical full path + # ex: ~/.local/opt/node-v16.13.0/bin/node + my_bin="$(readlink -f "${my_bin}")" -# ex: sudo setcap 'cap_net_bind_service=+ep' ~/.local/opt/node-v16.13.0/bin/node" -"${my_sudo}" setcap 'cap_net_bind_service=+ep' "${my_bin}" + # ex: sudo setcap 'cap_net_bind_service=+ep' ~/.local/opt/node-v16.13.0/bin/node" + "${my_sudo}" setcap 'cap_net_bind_service=+ep' "${my_bin}" +} + +main "${1:-}"