default to $HOME/.local/bin

Signed-off-by: Michael Beemer <beeme1mr@users.noreply.github.com>
This commit is contained in:
Michael Beemer 2025-03-28 16:43:28 +00:00
parent c06bcebc52
commit c7e1075ff4
No known key found for this signature in database
GPG Key ID: 47B734C8FDEE96EE
1 changed files with 29 additions and 6 deletions

35
bin/install.sh Normal file → Executable file
View File

@ -3,13 +3,14 @@ set -e
# Adapted/Copied from https://github.com/daveshanley/vacuum/blob/main/bin/install.sh
# Default to /usr/local/bin, but fall back to $HOME/.local/bin if /usr/local/bin is not writable
if [ -w "/usr/local/bin" ]; then
DEFAULT_INSTALL_DIR="/usr/local/bin"
elif [ -d "$HOME/.local/bin" ] || mkdir -p "$HOME/.local/bin" 2>/dev/null; then
if [ -d "$HOME/.local/bin" ] || mkdir -p "$HOME/.local/bin" 2>/dev/null; then
DEFAULT_INSTALL_DIR="$HOME/.local/bin"
elif [ -w "/usr/local/bin" ]; then
DEFAULT_INSTALL_DIR="/usr/local/bin"
else
DEFAULT_INSTALL_DIR="/usr/local/bin" # Will attempt and prompt for sudo if needed
fmt_error "unable to write to $HOME/.local/bin or /usr/local/bin"
fmt_error "Please run this script with sudo or set INSTALL_DIR to a directory you can write to."
exit 1
fi
INSTALL_DIR=${INSTALL_DIR:-$DEFAULT_INSTALL_DIR}
@ -149,7 +150,29 @@ do_install_binary() {
(cd $tmp_dir && tar -xzf "$asset_name")
# Install binary
mv "$tmp_dir/$BINARY_NAME" $INSTALL_DIR
if [ -w "$INSTALL_DIR" ]; then
mv "$tmp_dir/$BINARY_NAME" "$INSTALL_DIR"
else
fmt_error "Unable to write to $INSTALL_DIR. Please run this script with sudo or set INSTALL_DIR to a directory you can write to."
exit 1
fi
# Make the binary executable
if [ -w "$INSTALL_DIR/$BINARY_NAME" ]; then
chmod +x "$INSTALL_DIR/$BINARY_NAME"
else
sudo chmod +x "$INSTALL_DIR/$BINARY_NAME" 2>/dev/null || {
fmt_error "Could not make $INSTALL_DIR/$BINARY_NAME executable"
exit 1
}
fi
# Check if the binary is executable
if [ ! -x "$INSTALL_DIR/$BINARY_NAME" ]; then
fmt_error "The binary is not executable. Please check your permissions."
exit 1
fi
echo "Installed the OpenFeature cli to $INSTALL_DIR"
# Add to PATH information if not already in PATH