From 819fe8fe356a610d54338c9d15afacb1667f4ce3 Mon Sep 17 00:00:00 2001 From: Jose Meira Date: Wed, 3 Sep 2025 11:08:22 +0200 Subject: [PATCH] fix: change default install directory to /usr/local/bin - Change default DIR from /home/jmeiracorbal/.local/bin to /usr/local/bin, doesn't work if is not present on PATH. - Add permission or checks if sudo is required for the installation. - Update README.md to reflect the new default directory. - Ensure directory creation if it doesn't exist. --- README.md | 8 +++++++- scripts/install_update_linux.sh | 35 ++++++++++++++++++++++++++++++--- 2 files changed, 39 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 0af77059..5210d674 100644 --- a/README.md +++ b/README.md @@ -131,7 +131,7 @@ Automated install/update, don't forget to always verify what you're piping into ```sh curl https://raw.githubusercontent.com/jesseduffield/lazydocker/master/scripts/install_update_linux.sh | bash ``` -The script installs downloaded binary to `$HOME/.local/bin` directory by default, but it can be changed by setting `DIR` environment variable. +The script installs downloaded binary to `/usr/local/bin` directory by default, but it can be changed by setting `DIR` environment variable. ### Go @@ -245,6 +245,12 @@ You can also use `go run main.go` to compile and run in one go (pun definitely i Call `lazydocker` in your terminal. I personally use this a lot so I've made an alias for it like so: +``` +echo "alias lzd='lazydocker'" >> ~/.bashrc +``` + +Or zsh: + ``` echo "alias lzd='lazydocker'" >> ~/.zshrc ``` diff --git a/scripts/install_update_linux.sh b/scripts/install_update_linux.sh index 33003c02..b2ca8a79 100755 --- a/scripts/install_update_linux.sh +++ b/scripts/install_update_linux.sh @@ -1,7 +1,18 @@ #!/bin/bash -# allow specifying different destination directory -DIR="${DIR:-"$HOME/.local/bin"}" +# change the default destination directory to be executable as a command +DIR="${DIR:-"/usr/local/bin"}" + +# check if requires sudo when the directory is not the default value +if [ ! -w "$DIR" ]; then + if [ "$EUID" -ne 0 ]; then + echo "Error: You need permissions to write in $DIR" + echo "Run the script with sudo or define DIR as a directory with write permissions:" + echo " sudo $0" + echo " DIR=\"\$HOME/.local/bin\" $0" + exit 1 + fi +fi # map different architecture variations to the available binaries ARCH=$(uname -m) @@ -20,5 +31,23 @@ GITHUB_URL="https://github.com/jesseduffield/lazydocker/releases/download/${GITH # install/update the local binary curl -L -o lazydocker.tar.gz $GITHUB_URL tar xzvf lazydocker.tar.gz lazydocker -install -Dm 755 lazydocker -t "$DIR" + +# create the directory if it doesn't exist, but requires sudo +if [ ! -d "$DIR" ]; then + if [ "$EUID" -eq 0 ]; then + mkdir -p "$DIR" + else + sudo mkdir -p "$DIR" + fi +fi + +# install with correct permissions +if [ "$EUID" -eq 0 ]; then + install -Dm 755 lazydocker -t "$DIR" +else + sudo install -Dm 755 lazydocker -t "$DIR" +fi + rm lazydocker lazydocker.tar.gz + +echo "lazydocker installed successfully in $DIR"