Skip to content

Instantly share code, notes, and snippets.

@shiponcs
Created October 4, 2024 11:08
Show Gist options
  • Save shiponcs/7ec719e8e282da84afe9e1101fd406ae to your computer and use it in GitHub Desktop.
Save shiponcs/7ec719e8e282da84afe9e1101fd406ae to your computer and use it in GitHub Desktop.
#!/bin/bash
# Ensure ENVOY_DOCKER_BUILD_DIR is set
if [[ -z "$ENVOY_DOCKER_BUILD_DIR" ]]; then
echo "[ERROR] The ENVOY_DOCKER_BUILD_DIR environment variable is not set."
echo "Please set it using: export ENVOY_DOCKER_BUILD_DIR=/path/to/build/directory"
exit 1
fi
echo "[INFO] Build directory is set to: $ENVOY_DOCKER_BUILD_DIR"
# Define the expected .tar.zst file in the build directory
TAR_FILE="$ENVOY_DOCKER_BUILD_DIR/envoy/x64/bin/release.tar.zst"
echo "[INFO] Checking for the presence of the .tar.zst file: $TAR_FILE"
# Verify that the .tar.zst file exists
if [[ -f "$TAR_FILE" ]]; then
echo "[SUCCESS] Found the build archive: $TAR_FILE"
else
echo "[ERROR] Build failed or $TAR_FILE not found."
exit 1
fi
# Define the target extraction directory
TARGET_DIR="/home/matin/bins"
echo "[INFO] Target extraction directory is set to: $TARGET_DIR"
# Create the target directory if it doesn't exist
if [[ ! -d "$TARGET_DIR" ]]; then
echo "[INFO] Creating the target directory: $TARGET_DIR"
mkdir -p "$TARGET_DIR" || { echo "[ERROR] Failed to create directory: $TARGET_DIR"; exit 1; }
echo "[SUCCESS] Created the directory: $TARGET_DIR"
fi
# Check if the directory already contains previous binaries and clean up if necessary
if [[ -d "$TARGET_DIR" && "$(ls -A $TARGET_DIR)" ]]; then
echo "[INFO] Target directory $TARGET_DIR is not empty."
echo "[INFO] Removing old files in $TARGET_DIR to prepare for fresh extraction..."
rm -rf "$TARGET_DIR"/* || { echo "[ERROR] Failed to remove old files in $TARGET_DIR"; exit 1; }
echo "[SUCCESS] Cleaned up old files in $TARGET_DIR."
fi
# Extract the .tar.zst file using `zstdcat` piped to `tar` into the target directory
echo "[INFO] Extracting $TAR_FILE to $TARGET_DIR..."
if command -v zstdcat > /dev/null; then
zstdcat "$TAR_FILE" | tar -C "$TARGET_DIR" -xf - || { echo "[ERROR] Failed to extract $TAR_FILE to $TARGET_DIR"; exit 1; }
else
echo "[ERROR] zstdcat command not found. Please install zstd."
exit 1
fi
echo "[SUCCESS] Extraction completed to $TARGET_DIR."
# Confirm the main binary exists in the extracted directory
EXECUTABLE="$TARGET_DIR/envoy-contrib"
echo "[INFO] Checking for the main binary: $EXECUTABLE"
if [[ -f "$EXECUTABLE" ]]; then
echo "[SUCCESS] Found the main binary: $EXECUTABLE"
else
echo "[ERROR] Main executable $EXECUTABLE not found in $TARGET_DIR."
exit 1
fi
# Set executable permissions for all files in the target directory
echo "[INFO] Setting executable permissions for files in $TARGET_DIR..."
chmod +x "$TARGET_DIR"/* || { echo "[ERROR] Failed to set permissions for files in $TARGET_DIR"; exit 1; }
echo "[SUCCESS] Executable permissions set for all files in $TARGET_DIR."
# Run the main binary with the provided configuration file
echo "[INFO] Running the main executable: $EXECUTABLE"
"$EXECUTABLE" -c ~/tls.yaml --component-log-level filter:debug || { echo "[ERROR] Failed to execute $EXECUTABLE"; exit 1; }
echo "[SUCCESS] Main binary executed successfully."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment