Skip to content

Instantly share code, notes, and snippets.

@naranyala
Created November 7, 2024 04:51
Show Gist options
  • Save naranyala/753577690c32493418047eef29ede16b to your computer and use it in GitHub Desktop.
Save naranyala/753577690c32493418047eef29ede16b to your computer and use it in GitHub Desktop.
#!/bin/bash
# Get the application directory from the command line argument
APP_DIR="$1"
# Set installation path
INSTALL_DIR="/opt" # Standard directory for optional apps
BIN_PATH="/usr/local/bin" # Path where we symlink the executable
# Check if APP_DIR was provided
if [[ -z "$APP_DIR" ]]; then
echo "Usage: $0 /path/to/your-app-directory"
exit 1
fi
# Ensure APP_DIR exists
if [[ ! -d "$APP_DIR" ]]; then
echo "Error: Directory $APP_DIR does not exist."
exit 1
fi
# Get the app directory name and main binary path
APP_NAME=$(basename "$APP_DIR")
MAIN_BINARY="$APP_DIR/your-main-binary" # Change to your actual binary's name
# Check if the main binary exists in the directory
if [[ ! -f "$MAIN_BINARY" ]]; then
echo "Error: Main binary $MAIN_BINARY not found in $APP_DIR."
exit 1
fi
# Copy the entire application directory to the install location
sudo cp -r "$APP_DIR" "$INSTALL_DIR/$APP_NAME"
# Ensure the main binary is executable
sudo chmod +x "$INSTALL_DIR/$APP_NAME/$(basename "$MAIN_BINARY")"
# Create a symlink for easy access
sudo ln -sf "$INSTALL_DIR/$APP_NAME/$(basename "$MAIN_BINARY")" "$BIN_PATH/$APP_NAME"
# Verify the installation
if command -v "$APP_NAME" &> /dev/null; then
echo "$APP_NAME installed successfully! You can now run it from anywhere."
else
echo "Installation failed. Please check permissions and paths."
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment