From 48a16a315eb98a6e09a8f44ad8e658bda56ebfc1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcin=20Wo=C5=BAniak?= Date: Sun, 14 Aug 2022 02:17:56 +0200 Subject: [PATCH] refactor!(posix): replace simple [[ with [ (partial fix for #465) --- _webi/bootstrap.sh | 6 +++--- _webi/template.sh | 36 ++++++++++++++++++------------------ brew/install.sh | 4 ++-- git/install.sh | 2 +- gpg-pubkey/gpg-pubkey.sh | 6 +++--- gpg/install.sh | 10 +++++----- iterm2/install.sh | 6 +++--- myip/myip.sh | 6 +++--- python/install.sh | 2 +- python2/install.sh | 2 +- ssh-adduser/ssh-adduser.sh | 12 ++++++------ test/install.sh | 2 +- yq/install.sh | 2 +- 13 files changed, 48 insertions(+), 48 deletions(-) diff --git a/_webi/bootstrap.sh b/_webi/bootstrap.sh index 98685f2..e26b5dc 100644 --- a/_webi/bootstrap.sh +++ b/_webi/bootstrap.sh @@ -182,12 +182,12 @@ __webi_main() { echo "" } - if [[ \$# -eq 0 ]] || [[ "\$1" =~ ^(-V|--version|version)$ ]]; then + if [ \$# -eq 0 ] || [ "\$1" =~ ^(-V|--version|version)$ ]; then version exit 0 fi - if [[ "\$1" =~ ^(-h|--help|help)$ ]]; then + if [ "\$1" =~ ^(-h|--help|help)$ ]; then usage "\$@" exit 0 fi @@ -207,7 +207,7 @@ EOF chmod a+x "$HOME/.local/bin/webi" - if [[ -n ${WEBI_PKG:-} ]]; then + if [ -n ${WEBI_PKG:-} ]; then "$HOME/.local/bin/webi" "${WEBI_PKG}" else echo "" diff --git a/_webi/template.sh b/_webi/template.sh index 3ac5274..be37981 100644 --- a/_webi/template.sh +++ b/_webi/template.sh @@ -119,7 +119,7 @@ __bootstrap_webi() { if cmp -s "${pkg_src_cmd}" "${my_current_cmd}"; then echo "${my_canonical_name} already installed:" echo -n " ${pkg_dst}" - if [[ ${pkg_src_cmd} != "${my_current_cmd}" ]]; then + if [ ${pkg_src_cmd} != "${my_current_cmd}" ]; then echo -n " => ${pkg_src}" fi echo "" @@ -181,7 +181,7 @@ __bootstrap_webi() { # TODO wget -c --content-disposition "$my_url" set +e my_show_progress="" - if [[ $- == *i* ]]; then + if [ $- == *i* ]; then my_show_progress="--show-progress" fi if ! wget -q $my_show_progress --user-agent="wget $WEBI_UA" -c "$my_url" -O "$my_dl.part"; then @@ -193,7 +193,7 @@ __bootstrap_webi() { # Neither GNU nor BSD curl have sane resume download options, hence we don't bother # TODO curl -fsSL --remote-name --remote-header-name --write-out "$my_url" my_show_progress="-#" - if [[ $- == *i* ]]; then + if [ $- == *i* ]; then my_show_progress="" fi # shellcheck disable=SC2086 @@ -317,7 +317,7 @@ __bootstrap_webi() { WEBI_SINGLE= - if [[ -z ${WEBI_WELCOME:-} ]]; then + if [ -z ${WEBI_WELCOME:-} ]; then echo "" printf "Thanks for using webi to install '\e[32m${WEBI_PKG:-}\e[0m' on '\e[31m$(uname -s)/$(uname -m)\e[0m'.\n" echo "Have a problem? Experience a bug? Please let us know:" @@ -351,14 +351,14 @@ __bootstrap_webi() { command -v pkg_post_install > /dev/null || command -v pkg_done_message > /dev/null || command -v pkg_format_cmd_version > /dev/null || - [[ -n ${WEBI_SINGLE:-} ]] || - [[ -n ${pkg_cmd_name:-} ]] || - [[ -n ${pkg_dst_cmd:-} ]] || - [[ -n ${pkg_dst_dir:-} ]] || - [[ -n ${pkg_dst:-} ]] || - [[ -n ${pkg_src_cmd:-} ]] || - [[ -n ${pkg_src_dir:-} ]] || - [[ -n ${pkg_src:-} ]]; then + [ -n ${WEBI_SINGLE:-} ] || + [ -n ${pkg_cmd_name:-} ] || + [ -n ${pkg_dst_cmd:-} ] || + [ -n ${pkg_dst_dir:-} ] || + [ -n ${pkg_dst:-} ] || + [ -n ${pkg_src_cmd:-} ] || + [ -n ${pkg_src_dir:-} ] || + [ -n ${pkg_src:-} ]; then pkg_cmd_name="${pkg_cmd_name:-$PKG_NAME}" @@ -382,11 +382,11 @@ __bootstrap_webi() { # shellcheck disable=SC2034 pkg_dst_bin="$(dirname "$pkg_dst_cmd")" - if [[ -n "$(command -v pkg_pre_install)" ]]; then pkg_pre_install; else webi_pre_install; fi + if [ -n "$(command -v pkg_pre_install)" ]; then pkg_pre_install; else webi_pre_install; fi pushd "$WEBI_TMP" > /dev/null 2>&1 echo "Installing to $pkg_src_cmd" - if [[ -n "$(command -v pkg_install)" ]]; then pkg_install; else webi_install; fi + if [ -n "$(command -v pkg_install)" ]; then pkg_install; else webi_install; fi chmod a+x "$pkg_src" chmod a+x "$pkg_src_cmd" popd > /dev/null 2>&1 @@ -395,19 +395,19 @@ __bootstrap_webi() { _webi_enable_exec pushd "$WEBI_TMP" > /dev/null 2>&1 - if [[ -n "$(command -v pkg_post_install)" ]]; then pkg_post_install; else webi_post_install; fi + if [ -n "$(command -v pkg_post_install)" ]; then pkg_post_install; else webi_post_install; fi popd > /dev/null 2>&1 pushd "$WEBI_TMP" > /dev/null 2>&1 - if [[ -n "$(command -v pkg_done_message)" ]]; then pkg_done_message; else _webi_done_message; fi + if [ -n "$(command -v pkg_done_message)" ]; then pkg_done_message; else _webi_done_message; fi popd > /dev/null 2>&1 echo "" fi webi_path_add "$HOME/.local/bin" - if [[ -z ${_WEBI_CHILD:-} ]] && [[ -f "$_webi_tmp/.PATH.env" ]]; then - if [[ -n $(cat "$_webi_tmp/.PATH.env") ]]; then + if [ -z ${_WEBI_CHILD:-} ] && [ -f "$_webi_tmp/.PATH.env" ]; then + if [ -n $(cat "$_webi_tmp/.PATH.env") ]; then printf 'PATH.env updated with:\n' sort -u "$_webi_tmp/.PATH.env" printf "\n" diff --git a/brew/install.sh b/brew/install.sh index 8c27937..136104f 100644 --- a/brew/install.sh +++ b/brew/install.sh @@ -7,9 +7,9 @@ _install_brew() { # Straight from https://brew.sh #/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)" - if [[ -n "$(uname -a | grep -i darwin)" ]]; then + if [ -n "$(uname -a | grep -i darwin)" ]; then needs_xcode="$(/usr/bin/xcode-select -p > /dev/null 2> /dev/null || echo "true")" - if [[ -n ${needs_xcode} ]]; then + if [ -n ${needs_xcode} ]; then echo "" echo "" echo "ERROR: Run this command to install XCode Command Line Tools first:" diff --git a/git/install.sh b/git/install.sh index 77fac54..4cc28b5 100644 --- a/git/install.sh +++ b/git/install.sh @@ -5,7 +5,7 @@ set -u __init_git() { if [ -z "$(command -v git)" ]; then - if [[ -n "$(uname -a | grep -i darwin)" ]]; then + if [ -n "$(uname -a | grep -i darwin)" ]; then echo >&2 "Error: 'git' not found. You may have to re-install 'git' on Mac after every major update." echo >&2 " for example, try: xcode-select --install" # sudo xcodebuild -license accept diff --git a/gpg-pubkey/gpg-pubkey.sh b/gpg-pubkey/gpg-pubkey.sh index f0d42db..49387fd 100755 --- a/gpg-pubkey/gpg-pubkey.sh +++ b/gpg-pubkey/gpg-pubkey.sh @@ -15,20 +15,20 @@ __get_pubkey_id() { } _create_gpg_key() { - if [[ ! -e ~/.gitconfig ]]; then + if [ ! -e ~/.gitconfig ]; then return 1 fi #grep 'name\s*=' ~/.gitconfig | head -n 1 | cut -d'=' -f2 | sed -e 's/^[\t ]*//' MY_NAME="$(git config --global user.name)" - if [[ -z ${MY_NAME} ]]; then + if [ -z ${MY_NAME} ]; then return 1 fi MY_EMAIL="$( __get_git_email )" - if [[ -z ${MY_EMAIL} ]]; then + if [ -z ${MY_EMAIL} ]; then return 1 fi diff --git a/gpg/install.sh b/gpg/install.sh index 22932fe..7f37094 100644 --- a/gpg/install.sh +++ b/gpg/install.sh @@ -26,7 +26,7 @@ _install_gpg() { hdiutil detach -quiet /Volumes/GnuPG* # Move to ~/.local/opt/gnugp (where it belongs!) - if [[ ! -e ~/.local/opt/gnupg-"${WEBI_VERSION}" ]]; then + if [ ! -e ~/.local/opt/gnupg-"${WEBI_VERSION}" ]; then mv ~/Downloads/webi/GnuPG-"${WEBI_VERSION}".d/GnuPG.pkg/Payload/ ~/.local/opt/gnupg-"${WEBI_VERSION}" fi @@ -41,7 +41,7 @@ _install_gpg() { # Prep for first use mkdir -p ~/.gnupg/ chmod 0700 ~/.gnupg/ - if [[ ! -e ~/.gnupg/gpg-agent.conf ]] || ! grep 'pinentry-program' ~/.gnupg/gpg-agent.conf; then + if [ ! -e ~/.gnupg/gpg-agent.conf ] || ! grep 'pinentry-program' ~/.gnupg/gpg-agent.conf; then echo "pinentry-program $HOME/.local/opt/gnupg/bin/pinentry-mac.app/Contents/MacOS/pinentry-mac" >> ~/.gnupg/gpg-agent.conf fi @@ -91,19 +91,19 @@ _install_gpg() { } _create_gpg_key() { - if [[ ! -e ~/.gitconfig ]]; then + if [ ! -e ~/.gitconfig ]; then return 0 fi #grep 'name\s*=' ~/.gitconfig | head -n 1 | cut -d'=' -f2 | sed -e 's/^[\t ]*//' MY_NAME="$(git config --global user.name)" - if [[ -z ${MY_NAME} ]]; then + if [ -z ${MY_NAME} ]; then return 0 fi # grep 'email\s*=.*@' ~/.gitconfig | tr -d '\t ' | head -n 1 | cut -d'=' -f2 MY_EMAIL="$(git config --global user.email)" - if [[ -z ${MY_EMAIL} ]]; then + if [ -z ${MY_EMAIL} ]; then return 0 fi diff --git a/iterm2/install.sh b/iterm2/install.sh index 0f1a1ed..94ee40a 100644 --- a/iterm2/install.sh +++ b/iterm2/install.sh @@ -5,7 +5,7 @@ set -u _install_iterm2() { # only for macOS - if [[ "Darwin" != "$(uname -s)" ]]; then + if [ "Darwin" != "$(uname -s)" ]; then echo "" echo "iTerm2 is only for macOS" echo "" @@ -19,13 +19,13 @@ _install_iterm2() { webi_download webi_extract - if [[ ! -d "${WEBI_TMP}/iTerm.app" ]]; then + if [ ! -d "${WEBI_TMP}/iTerm.app" ]; then echo "error unpacking iTerm2:" ls -lAF "${WEBI_TMP}" exit 1 fi - if [[ -d ~/Applications/iTerm.app ]]; then + if [ -d ~/Applications/iTerm.app ]; then mv ~/Applications/iTerm.app "${WEBI_TMP}/iTerm.app-webi.bak" fi mkdir -p ~/Applications/ diff --git a/myip/myip.sh b/myip/myip.sh index a83d201..78e9578 100644 --- a/myip/myip.sh +++ b/myip/myip.sh @@ -7,15 +7,15 @@ __show_my_ip() { ipv4=$(curl -s https://api.ipify.org || true) ipv6=$(curl -s https://api6.ipify.org || true) - if [[ -n ${ipv4} ]]; then + if [ -n ${ipv4} ]; then echo "IPv4 (A) : $ipv4" fi - if [[ -n ${ipv6} ]] && [[ ${ipv6} != "${ipv4}" ]]; then + if [ -n ${ipv6} ] && [ ${ipv6} != "${ipv4}" ]; then echo "IPv6 (AAAA): ${ipv6}" fi - if [[ -z ${ipv4} ]] && [[ -z ${ipv6} ]]; then + if [ -z ${ipv4} ] && [ -z ${ipv6} ]; then echo >&2 "error: no public IP address" fi } diff --git a/python/install.sh b/python/install.sh index ce41a31..1839afe 100644 --- a/python/install.sh +++ b/python/install.sh @@ -4,7 +4,7 @@ set -e set -u __init_python() { - if [[ ! -x "${HOME}/.pyenv/bin/pyenv" ]]; then + if [ ! -x "${HOME}/.pyenv/bin/pyenv" ]; then "${HOME}/.local/bin/webi" "pyenv" fi export PATH="${HOME}/.pyenv/bin:${PATH}" diff --git a/python2/install.sh b/python2/install.sh index 5cea9ba..20e65d8 100644 --- a/python2/install.sh +++ b/python2/install.sh @@ -4,7 +4,7 @@ set -e set -u __init_python2() { - if [[ ! -x "${HOME}/.pyenv/bin/pyenv" ]]; then + if [ ! -x "${HOME}/.pyenv/bin/pyenv" ]; then "${HOME}/.local/bin/webi" "pyenv" fi export PATH="${HOME}/.pyenv/bin:${PATH}" diff --git a/ssh-adduser/ssh-adduser.sh b/ssh-adduser/ssh-adduser.sh index ef3b229..89ecc8f 100644 --- a/ssh-adduser/ssh-adduser.sh +++ b/ssh-adduser/ssh-adduser.sh @@ -10,12 +10,12 @@ main() { #my_existing_user="${2:-"root"}" # TODO would $EUID be better? - if [[ "root" != "$(whoami)" ]]; then + if [ "root" != "$(whoami)" ]; then echo "webi adduser: running user is already a non-root user" exit 0 fi - if [[ ! -e ~/.ssh/authorized_keys ]] || ! grep -v '#' ~/.ssh/authorized_keys; then + if [ ! -e ~/.ssh/authorized_keys ] || ! grep -v '#' ~/.ssh/authorized_keys; then echo "" echo "Error:" echo " You must add a key to ~/.ssh/authorized_keys before adding a new ssh user." @@ -56,20 +56,20 @@ main() { # TODO ensure that ssh-password login is off my_pass="$(grep 'PasswordAuthentication yes' /etc/ssh/sshd_config)" my_pam="" - if [[ "Darwin" = "$(uname -s)" ]]; then + if [ "Darwin" = "$(uname -s)" ]; then # Turn off PAM for macOS or it will allow password login my_pam="$(grep 'UsePAM yes' /etc/ssh/sshd_config)" fi - if [[ -n ${my_pass} ]] || [[ -n ${my_pam} ]]; then + if [ -n ${my_pass} ] || [ -n ${my_pam} ]; then echo "######################################################################" echo "# #" echo "# WARNING #" echo "# #" echo "# Found /etc/ssh/sshd_config: #" - if [[ -n ${my_pass} ]]; then + if [ -n ${my_pass} ]; then echo "# PasswordAuthentication yes #" fi - if [[ -n ${my_pam} ]]; then + if [ -n ${my_pam} ]; then echo "# UsePAM yes #" fi echo "# #" diff --git a/test/install.sh b/test/install.sh index 347dcd7..31483d0 100644 --- a/test/install.sh +++ b/test/install.sh @@ -3,7 +3,7 @@ set -e set -u __rmrf_local() { - if [[ -d "${HOME}/.local/opt" ]]; then + if [ -d "${HOME}/.local/opt" ]; then pushd "${HOME}/.local/opt" 2>&1 > /dev/null rm -rf \ arc \ diff --git a/yq/install.sh b/yq/install.sh index 7f0ff98..b1a89a7 100644 --- a/yq/install.sh +++ b/yq/install.sh @@ -19,7 +19,7 @@ __init_yq() { # - yq_linux_amd64 # - yq.1 # - install-man-page.sh - if [[ -e ./yq.1 ]]; then + if [ -e ./yq.1 ]; then mkdir -p ~/.local/share/man/man1 mv ./yq.1 ~/.local/share/man/man1/ fi