From 1bb6c591c9e33e39a295ca425d7b577031696c8b Mon Sep 17 00:00:00 2001 From: JAMES RYAN Date: Thu, 5 Sep 2024 21:25:37 -0400 Subject: [PATCH 1/2] Use XDG standard binary location for setup script Following XDG standard, I changed the default install location to '$HOME/.local/bin'. It can retain the old location if ran as root --- setup.sh | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/setup.sh b/setup.sh index 282e6aa..97aad8a 100755 --- a/setup.sh +++ b/setup.sh @@ -13,7 +13,7 @@ get_latest_release_url() { download_url=$(echo "$release_data" | grep "browser_download_url" | grep "$os" | grep "$arch" | cut -d '"' -f 4) echo "$download_url" -} +} # Detect the OS case "$(uname)" in @@ -78,10 +78,16 @@ if ! chmod +x "$tmp_file"; then fi printf "OK!\n" -# Move the binary to /usr/local/bin and handle permission errors -if ! mv "$tmp_file" /usr/local/bin/wd-41; then - echo "Failed to move the binary to /usr/local/bin/wd-41, see error above. Try running the script with sudo, or run 'mv $tmp_file '." +# Move the binary to standard XDG location and handle permission errors +INSTALL_DIR=$HOME/.local/bin +# If run as 'sudo', install to /usr/local/bin for systemwide use +if [ $EUID -eq 0 ]; then + INSTALL_DIR=/usr/local/bin +fi + +if ! mv "$tmp_file" $INSTALL_DIR/wd-41; then + echo "Failed to move the binary to $INSTALL_DIR/wd-41, see error above. Try making sure you have write permission there, or run 'mv $tmp_file '." exit 1 fi -echo "wd-41 installed successfully in /usr/local/bin, try it out with 'wd-41 h'" +echo "wd-41 installed successfully in $INSTALL_DIR, try it out with 'wd-41 h'" From 477defd0f097ea0d03d1175ecc0bb14a08bda0ba Mon Sep 17 00:00:00 2001 From: JAMES RYAN Date: Sun, 8 Sep 2024 17:49:26 -0400 Subject: [PATCH 2/2] add a check to ensure 'id' coreutil is present. used to check if user is running as root --- setup.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/setup.sh b/setup.sh index 97aad8a..35f8388 100755 --- a/setup.sh +++ b/setup.sh @@ -81,8 +81,10 @@ printf "OK!\n" # Move the binary to standard XDG location and handle permission errors INSTALL_DIR=$HOME/.local/bin # If run as 'sudo', install to /usr/local/bin for systemwide use -if [ $EUID -eq 0 ]; then - INSTALL_DIR=/usr/local/bin +if [ -x /usr/bin/id ]; then + if [ `/usr/bin/id -u` -eq 0 ]; then + INSTALL_DIR=/usr/local/bin + fi fi if ! mv "$tmp_file" $INSTALL_DIR/wd-41; then