Skip to content

Instantly share code, notes, and snippets.

@alexrios
Created January 2, 2024 20:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexrios/e7b1fe2c9a2a92ec0e94b1c818ee6610 to your computer and use it in GitHub Desktop.
Save alexrios/e7b1fe2c9a2a92ec0e94b1c818ee6610 to your computer and use it in GitHub Desktop.
Installing flipt from releases
#!/bin/bash
# Set default values if not already set
: ${FLIPT_VERSION:="1.34.0"}
: ${ARCH:="linux_x86_64"}
# Check if the script is running as root (sudo)
if [ "$(id -u)" != "0" ]; then
echo "This script must be run as root. Please use sudo."
exit 1
fi
# Function to validate the version format
validate_version() {
if [[ $1 =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
return 0 # Valid version format
else
echo "Invalid version format. Please use MAJOR.MINOR.PATCH."
exit 1
fi
}
# If a version is provided as an argument, validate and use that version instead
if [ "$#" -eq 1 ]; then
validate_version "$1"
FLIPT_VERSION=$1
fi
# Define the download URL
DOWNLOAD_URL="https://github.com/flipt-io/flipt/releases/download/v${FLIPT_VERSION}/flipt_${ARCH}.tar.gz"
TEMP_DIR="/tmp/flipt-${FLIPT_VERSION}"
TEMP_TAR="${TEMP_DIR}/flipt.tar.gz"
# Create a temporary directory
mkdir -p "$TEMP_DIR"
# Download the specified version of Flipt
wget "$DOWNLOAD_URL" -O "$TEMP_TAR"
# Check if download was successful
if [ $? -ne 0 ]; then
echo "Download failed. Please check the provided version and your internet connection."
rm -rf "$TEMP_DIR"
exit 1
fi
# Extract only the 'flipt' binary from the tar.gz file into the temporary directory
tar -xzf "$TEMP_TAR" -C "$TEMP_DIR" flipt
# Move the binary to /usr/bin and set execute permission
mv "${TEMP_DIR}/flipt" /usr/bin/flipt
chmod +x /usr/bin/flipt
# Clean up temporary directory
rm -rf "$TEMP_DIR"
echo "Flipt version ${FLIPT_VERSION} installed successfully."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment