From 6d400e3751a05b7778ede50a3fdf88755e69e00d Mon Sep 17 00:00:00 2001 From: Your Name Date: Sun, 25 May 2025 18:29:12 +1200 Subject: [PATCH] Tidy --- README.md | 4 ++-- install.sh | 36 +++++++++++++----------------------- 2 files changed, 15 insertions(+), 25 deletions(-) diff --git a/README.md b/README.md index 719f304..28630ac 100644 --- a/README.md +++ b/README.md @@ -4,11 +4,11 @@ Automated system-wide installation: ``` -curl -fsSL https://gitea.jde.nz/public/dehydrate/releases/download/latest/install.sh | bash +curl -fsSL https://gitea.jde.nz/public/dehydrate/releases/download/latest/install.sh | sudo bash ``` To download just the dehydrate executable: ``` -curl -fsSL -o dehydrate https://gitea.jde.nz/public/dehydrate/releases/download/latest/dehydrate.amd64 && chmod a+x bb64 +curl -fsSL -o dehydrate https://gitea.jde.nz/public/dehydrate/releases/download/latest/dehydrate.amd64 && chmod a+x dehydrate ``` ## How it Works diff --git a/install.sh b/install.sh index afa2a96..ddc7ac0 100755 --- a/install.sh +++ b/install.sh @@ -3,24 +3,23 @@ set -e PROJECT="dehydrate" +# RUN AS ROOT +if [[ $EUID -ne 0 ]]; then + echo "This script must be run as root" >&2 + exit 1 +fi + # 0. see if we were passed a folder to install to # ----------------------------------------------------------------------------- INSTALL_DIR="$1" if [[ -z "$INSTALL_DIR" ]]; then INSTALL_DIR="/usr/local/bin" else - echo "Installing $PROJECT to $INSTALL_DIR" if [[ ! -d "$INSTALL_DIR" ]]; then mkdir -p "$INSTALL_DIR" fi fi - -# 0. see if we were passed a user to chown to -# ----------------------------------------------------------------------------- -CHOWN_USER="$2" -if [[ -z "$CHOWN_USER" ]]; then - CHOWN_USER=$(id -u) -fi +echo "Installing $PROJECT to $INSTALL_DIR" # 1. Determine architecture # ----------------------------------------------------------------------------- @@ -35,27 +34,18 @@ else exit 1 fi -# 3. Download the appropriate binary to a temp directory +# 3. Download the appropriate binary # ----------------------------------------------------------------------------- -TMPDIR=$(mktemp -d) -trap 'rm -rf "$TMPDIR"' EXIT -URL="https://gitea.jde.nz/public/$PROJECT/releases/download/latest/$BIN" -echo "Downloading $BIN from $URL..." -curl -fsSL -o "$TMPDIR/$PROJECT" "$URL" +URL="https://gitea.jde.nz/public/$PROJECT/releases/download/latest/$BIN" +echo "Downloading $BIN from $URL to $TMPDIR..." + +curl -fsSL -o "$INSTALL_DIR/$PROJECT" "$URL" # 4. Make it executable # ----------------------------------------------------------------------------- -chmod +x "$TMPDIR/$PROJECT" - -# 5. Move to /usr/local/bin -# ----------------------------------------------------------------------------- -docker run --rm -v "$TMPDIR:/tmp" -v "$INSTALL_DIR:/target" alpine sh -c "cp /tmp/$PROJECT /target/$PROJECT; chown $CHOWN_USER /target/$PROJECT" -rm "$TMPDIR/$PROJECT" +chmod +x "$INSTALL_DIR/$PROJECT" # 6. Print success message # ----------------------------------------------------------------------------- echo "$PROJECT installed successfully to $INSTALL_DIR/$PROJECT (arch $ARCH)" -echo " " -echo "Update $PROJECT in future with:" -echo " $PROJECT -u"