Skip to content

Commit

Permalink
Add colored logs
Browse files Browse the repository at this point in the history
  • Loading branch information
hellovai authored Sep 7, 2023
1 parent c2ee9b7 commit dba7cc9
Showing 1 changed file with 24 additions and 9 deletions.
33 changes: 24 additions & 9 deletions install-gloo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,39 @@
set -e
set -o pipefail

# Define the URL of the ZIP file
# Define color codes
GREEN=$(tput setaf 2)
RED=$(tput setaf 1)
RESET=$(tput sgr0)

# Define the URL of the tar.gz file
URL="https://github.com/GlooHQ/homebrew-gloo/releases/download/v0.2.1/gloo-linux-x86_64.tar.gz"
BINARY_NAME="gloo"
LOG_FILE="install_log.txt"

# Create a temporary directory
TEMP_DIR=$(mktemp -d)

# Function to log messages
log_message() {
echo "$(date '+%Y-%m-%d %H:%M:%S') - $1" | tee -a $LOG_FILE
local message="$1"
local color="$2"
echo "$(date '+%Y-%m-%d %H:%M:%S') - ${color}${message}${RESET}" | tee -a $LOG_FILE
}

# Error trap function
handle_error() {
log_message "Error: An error occurred in the script"
log_message "Error: An error occurred in the script" $RED
exit 1
}

# Set the error trap
trap 'handle_error' ERR

# Download the ZIP file
# Change to temp directory
cd $TEMP_DIR

# Download the tar.gz file
curl -L -O $URL

# Get the file name from the URL
Expand All @@ -39,12 +52,14 @@ mv $BINARY_NAME /usr/local/bin/

# Verify installation
if which $BINARY_NAME > /dev/null; then
log_message "$BINARY_NAME installed successfully"
VERSION=$($BINARY_NAME --version)
log_message "$BINARY_NAME installed successfully, version: $VERSION" $GREEN
else
log_message "Error: Failed to install $BINARY_NAME"
log_message "Error: Failed to install $BINARY_NAME" $RED
exit 1
fi

# Run --version to verify the binary works
$BINARY_NAME --version
log_message "Installation completed successfully"
# Cleanup temporary directory
rm -rf $TEMP_DIR

log_message "Installation completed successfully" $GREEN

0 comments on commit dba7cc9

Please sign in to comment.