Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ You can easily download the latest release using the installation script:
curl -s https://raw.githubusercontent.com/alegrey91/harpoon/main/install | sudo sh
```

Alternatively, if you want to customize your installation, use the following flags:

```sh
curl -s https://raw.githubusercontent.com/alegrey91/harpoon/main/install | sudo sh -s -- --install-version v0.9 --install-dir ~/.local/bin/
```

(If your current version is `<= v0.8.2`, remove it from `/usr/local/bin/` before installing the new one).

### Build
Expand Down
60 changes: 47 additions & 13 deletions install
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,57 @@ set -e
BINARY_NAME="harpoon"
BINARY_RELEASE_NAME="${BINARY_NAME}"

cd /tmp
# Check if a version argument is provided
VERSION="latest"
INSTALL_DIR="/usr/sbin"

# download binary + checksum file
curl -s https://api.github.com/repos/alegrey91/harpoon/releases/latest | \
grep "browser_download_url" | \
cut -d : -f 2,3 | \
tr -d \" | \
wget -q -i -
# Parse optional flags
while [[ $# -gt 0 ]]; do
case $1 in
--install-version)
VERSION="$2"
shift 2
;;
--install-dir)
INSTALL_DIR="$2"
shift 2
;;
*)
echo "unknown option: $1"
exit 1
;;
esac
done

# check if binary has been downloaded, otherwise exit
if [ "$VERSION" == "latest" ]; then
# Download the latest release
DOWNLOAD_URL=$(curl -s https://api.github.com/repos/alegrey91/harpoon/releases/latest |
grep "browser_download_url" |
cut -d : -f 2,3 |
tr -d \" | \
grep "$BINARY_RELEASE_NAME$")
else
# Download the specified version
DOWNLOAD_URL=https://github.com/alegrey91/harpoon/releases/download/"$VERSION"/harpoon
fi

# Validate if the download URL is found
if [ -z "$DOWNLOAD_URL" ]; then
echo "error: unable to find the specified version or the latest release."
exit 1
fi

# Download the binary
wget -q ${DOWNLOAD_URL} -O "$BINARY_RELEASE_NAME"

# Check if the binary has been downloaded, otherwise exit
if [ ! -f "$BINARY_RELEASE_NAME" ]; then
echo "$BINARY_RELEASE_NAME doesn't exists."
echo "$BINARY_RELEASE_NAME doesn't exist."
exit 1
fi
printf "[download succeded]\n"
printf "[download succeeded]\n"

# install binary
# Install the binary
chmod +x "$BINARY_RELEASE_NAME"
mv "$BINARY_RELEASE_NAME" "/usr/sbin/$BINARY_NAME"
printf "[installation succeded]\n"
mv "$BINARY_RELEASE_NAME" "$INSTALL_DIR/$BINARY_NAME"
printf "[installation succeeded]\n"
Loading