|
| 1 | +#!/usr/bin/env bash |
| 2 | +set -euo pipefail |
| 3 | + |
| 4 | +URL="https://github.com/peterHoburg/DRYdock/releases/latest/download/drydock" |
| 5 | + |
| 6 | +BINARY_NAME="drydock" |
| 7 | +# Check if the binary is already installed in the PATH |
| 8 | +INSTALL_PATH=$(command -v "$BINARY_NAME" 2>/dev/null || true) |
| 9 | + |
| 10 | +if [ -n "$INSTALL_PATH" ]; then |
| 11 | + # Binary already exists, replace it where it is |
| 12 | + TARGET_DIR=$(dirname "$INSTALL_PATH") |
| 13 | + echo "Previous install found $TARGET_DIR. Replacing..." |
| 14 | +else |
| 15 | + # Binary not found, check if $HOME/bin or $HOME/.local/bin is in the PATH |
| 16 | + if [[ ":$PATH:" == *":$HOME/bin:"* ]]; then |
| 17 | + TARGET_DIR="$HOME/bin" |
| 18 | + elif [[ ":$PATH:" == *":$HOME/.local/bin:"* ]]; then |
| 19 | + TARGET_DIR="$HOME/.local/bin" |
| 20 | + else |
| 21 | + echo "Error: Neither \$HOME/bin nor \$HOME/.local/bin is in your PATH." |
| 22 | + echo "Please add one of them to PATH and re-run this script." |
| 23 | + exit 1 |
| 24 | + fi |
| 25 | +fi |
| 26 | + |
| 27 | +# Ensure the directory exists |
| 28 | +mkdir -p "$TARGET_DIR" |
| 29 | + |
| 30 | +# Check write permissions for the target directory |
| 31 | +if [ ! -w "$TARGET_DIR" ]; then |
| 32 | + echo "Directory $TARGET_DIR is not writable by the current user." |
| 33 | + echo "Please adjust directory permissions before re-running this script." |
| 34 | + exit 1 |
| 35 | +fi |
| 36 | + |
| 37 | +echo "Downloading $BINARY_NAME from $URL to $TARGET_DIR..." |
| 38 | +if ! curl -fLo "$TARGET_DIR/$BINARY_NAME" "$URL"; then |
| 39 | + echo "Failed to download $URL. Please check the URL and try again." |
| 40 | + exit 1 |
| 41 | +fi |
| 42 | + |
| 43 | +# Make the binary executable |
| 44 | +chmod u+x "$TARGET_DIR/$BINARY_NAME" |
| 45 | + |
| 46 | +echo "$BINARY_NAME successfully installed in $TARGET_DIR." |
0 commit comments