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