refactor!(posix): replace simple [[ with [ (partial fix for #465)

This commit is contained in:
Marcin Woźniak
2022-08-21 03:06:08 +00:00
committed by AJ ONeal
parent 6051f6ab72
commit 48a16a315e
13 changed files with 48 additions and 48 deletions
+3 -3
View File
@@ -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 ""
+18 -18
View File
@@ -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"
+2 -2
View File
@@ -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:"
+1 -1
View File
@@ -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
+3 -3
View File
@@ -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
+5 -5
View File
@@ -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
+3 -3
View File
@@ -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/
+3 -3
View File
@@ -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
}
+1 -1
View File
@@ -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}"
+1 -1
View File
@@ -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}"
+6 -6
View File
@@ -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 "# #"
+1 -1
View File
@@ -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 \
+1 -1
View File
@@ -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