Last active
July 21, 2025 00:43
-
-
Save SolomonHD/dcd3cf9587cef4751a96a80967b5d598 to your computer and use it in GitHub Desktop.
Jekyll GitHub Pages Tools Installer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# jekyll-ghpages-installer | |
# Installer script for Jekyll GitHub Pages utilities | |
# Downloads and installs jekyll-ghpages-setup and jekyll-ghpages-deploy | |
# | |
# Documentation: https://gist.github.com/SolomonHD/1391d973b86c0aeb3e901cceeb34650f | |
set -euo pipefail # Exit on error, undefined vars, pipe failures | |
# Configuration - Gist URLs for the Jekyll GitHub Pages tools | |
readonly SETUP_GIST_URL="https://gist.githubusercontent.com/SolomonHD/ff209f45c80f1ec0068f6b39203a302d/raw/jekyll-ghpages-setup.sh" | |
readonly DEPLOY_GIST_URL="https://gist.githubusercontent.com/SolomonHD/3450847185c4749b7d7612d9725cef44/raw/jekyll-ghpages-deploy.sh" | |
readonly INSTALL_DIR="/usr/local/bin" # Alternative to /usr/bin that doesn't require sudo on many systems | |
readonly SETUP_SCRIPT="jekyll-ghpages-setup" | |
readonly DEPLOY_SCRIPT="jekyll-ghpages-deploy" | |
# Colors for output | |
readonly RED='\033[0;31m' | |
readonly GREEN='\033[0;32m' | |
readonly YELLOW='\033[1;33m' | |
readonly BLUE='\033[0;34m' | |
readonly CYAN='\033[0;36m' | |
readonly BOLD='\033[1m' | |
readonly NC='\033[0m' # No Color | |
# Helper functions | |
log_info() { | |
echo -e "${BLUE}[INFO]${NC} $1" | |
} | |
log_success() { | |
echo -e "${GREEN}[SUCCESS]${NC} $1" | |
} | |
log_warning() { | |
echo -e "${YELLOW}[WARNING]${NC} $1" | |
} | |
log_error() { | |
echo -e "${RED}[ERROR]${NC} $1" | |
} | |
log_step() { | |
echo -e "${CYAN}[STEP]${NC} $1" | |
} | |
print_header() { | |
echo -e "${BOLD}${CYAN}ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ${NC}" | |
echo -e "${BOLD}${CYAN}β Jekyll GitHub Pages Tools Installer β${NC}" | |
echo -e "${BOLD}${CYAN}β β${NC}" | |
echo -e "${BOLD}${CYAN}β Installs: jekyll-ghpages-setup & jekyll-ghpages-deploy β${NC}" | |
echo -e "${BOLD}${CYAN}ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ${NC}" | |
echo | |
} | |
# Check prerequisites | |
check_prerequisites() { | |
log_step "Checking prerequisites..." | |
# Check if curl is available | |
if ! command -v curl &> /dev/null; then | |
log_error "curl is required but not installed" | |
log_info "Please install curl and try again" | |
exit 1 | |
fi | |
# Check if we have write permissions to install directory | |
if [ ! -w "$INSTALL_DIR" ] && [ "$EUID" -ne 0 ]; then | |
log_warning "No write permission to $INSTALL_DIR" | |
log_info "You may need to run with sudo or choose a different install directory" | |
# Offer alternative install locations | |
echo | |
echo "Alternative install options:" | |
echo "1. Run with sudo: sudo $0" | |
echo "2. Install to user directory: $0 --user" | |
echo "3. Install to custom directory: $0 --dir /path/to/directory" | |
exit 1 | |
fi | |
log_success "Prerequisites check passed" | |
} | |
# Parse command line arguments | |
parse_arguments() { | |
FORCE_INSTALL=false | |
USER_INSTALL=false | |
CUSTOM_DIR="" | |
while [[ $# -gt 0 ]]; do | |
case $1 in | |
--force|-f) | |
FORCE_INSTALL=true | |
shift | |
;; | |
--user|-u) | |
USER_INSTALL=true | |
INSTALL_DIR="$HOME/.local/bin" | |
shift | |
;; | |
--dir|-d) | |
CUSTOM_DIR="$2" | |
INSTALL_DIR="$2" | |
shift 2 | |
;; | |
--help|-h) | |
show_help | |
exit 0 | |
;; | |
*) | |
log_error "Unknown option: $1" | |
echo "Use --help for usage information" | |
exit 1 | |
;; | |
esac | |
done | |
# Create install directory if it doesn't exist | |
if [ ! -d "$INSTALL_DIR" ]; then | |
log_info "Creating install directory: $INSTALL_DIR" | |
mkdir -p "$INSTALL_DIR" | |
fi | |
# Add to PATH if user install and not already there | |
if [ "$USER_INSTALL" = true ] && [[ ":$PATH:" != *":$INSTALL_DIR:"* ]]; then | |
log_warning "$INSTALL_DIR is not in your PATH" | |
log_info "Add this line to your ~/.bashrc or ~/.zshrc:" | |
echo -e "${YELLOW}export PATH=\"\$PATH:$INSTALL_DIR\"${NC}" | |
echo | |
fi | |
} | |
# Show help message | |
show_help() { | |
echo "Jekyll GitHub Pages Tools Installer" | |
echo | |
echo "Usage: $0 [OPTIONS]" | |
echo | |
echo "Options:" | |
echo " -f, --force Force install (overwrite existing files)" | |
echo " -u, --user Install to user directory (~/.local/bin)" | |
echo " -d, --dir DIR Install to custom directory" | |
echo " -h, --help Show this help message" | |
echo | |
echo "Default install directory: $INSTALL_DIR" | |
echo | |
echo "This installer downloads and installs:" | |
echo " β’ jekyll-ghpages-setup - Creates gh-pages branch with docs folder" | |
echo " β’ jekyll-ghpages-deploy - Builds and deploys Jekyll sites" | |
echo | |
} | |
# Check if scripts are already installed | |
check_existing_installation() { | |
log_step "Checking for existing installation..." | |
SETUP_EXISTS=false | |
DEPLOY_EXISTS=false | |
if [ -f "$INSTALL_DIR/$SETUP_SCRIPT" ]; then | |
SETUP_EXISTS=true | |
log_info "Found existing $SETUP_SCRIPT" | |
fi | |
if [ -f "$INSTALL_DIR/$DEPLOY_SCRIPT" ]; then | |
DEPLOY_EXISTS=true | |
log_info "Found existing $DEPLOY_SCRIPT" | |
fi | |
if [ "$SETUP_EXISTS" = true ] || [ "$DEPLOY_EXISTS" = true ]; then | |
log_warning "Jekyll GitHub Pages tools are already installed" | |
if [ "$SETUP_EXISTS" = true ]; then | |
echo " Found: $INSTALL_DIR/$SETUP_SCRIPT" | |
fi | |
if [ "$DEPLOY_EXISTS" = true ]; then | |
echo " Found: $INSTALL_DIR/$DEPLOY_SCRIPT" | |
fi | |
echo | |
if [ "$FORCE_INSTALL" = false ]; then | |
read -p "Do you want to reinstall/update them? (y/N): " -n 1 -r | |
echo | |
if [[ ! $REPLY =~ ^[Yy]$ ]]; then | |
log_info "Installation cancelled by user" | |
echo | |
echo -e "${BLUE}π‘ To force reinstall:${NC}" | |
echo " curl -sSL https://gist.githubusercontent.com/SolomonHD/dcd3cf9587cef4751a96a80967b5d598/raw/jekyll-ghpages-installer.sh | bash -s -- --force" | |
exit 0 | |
fi | |
else | |
log_info "Force install enabled - will overwrite existing files" | |
fi | |
fi | |
} | |
# Download and install a script | |
install_script() { | |
local script_name="$1" | |
local gist_url="$2" | |
local install_path="$INSTALL_DIR/$script_name" | |
log_step "Installing $script_name..." | |
# Download to temporary file first | |
local temp_file=$(mktemp) | |
if curl -sL "$gist_url" -o "$temp_file"; then | |
# Verify the download isn't empty or an error page | |
if [ ! -s "$temp_file" ]; then | |
log_error "Downloaded file is empty - check Gist URL" | |
rm "$temp_file" | |
return 1 | |
fi | |
# Check if it looks like a shell script | |
if ! head -1 "$temp_file" | grep -q '^#!/bin/bash'; then | |
log_error "Downloaded file doesn't appear to be a bash script" | |
log_info "Check if the Gist URL is correct: $gist_url" | |
rm "$temp_file" | |
return 1 | |
fi | |
# Move to final location and make executable with 777 permissions | |
mv "$temp_file" "$install_path" | |
chmod 777 "$install_path" | |
log_success "Installed $script_name to $install_path" | |
return 0 | |
else | |
log_error "Failed to download $script_name from $gist_url" | |
rm -f "$temp_file" | |
return 1 | |
fi | |
} | |
# Verify installation | |
verify_installation() { | |
log_step "Verifying installation..." | |
local all_good=true | |
for script in "$SETUP_SCRIPT" "$DEPLOY_SCRIPT"; do | |
if [ -x "$INSTALL_DIR/$script" ]; then | |
local version_info=$("$INSTALL_DIR/$script" --help 2>/dev/null | head -1 || echo "No version info") | |
log_success "$script is installed and executable" | |
else | |
log_error "$script installation failed" | |
all_good=false | |
fi | |
done | |
if [ "$all_good" = true ]; then | |
log_success "All scripts installed successfully!" | |
return 0 | |
else | |
log_error "Some scripts failed to install properly" | |
return 1 | |
fi | |
} | |
# Show post-installation information | |
show_completion_message() { | |
echo | |
echo -e "${BOLD}${GREEN}π Installation Complete!${NC}" | |
echo | |
echo -e "${BLUE}π¦ Installed Scripts:${NC}" | |
echo " β’ $INSTALL_DIR/$SETUP_SCRIPT" | |
echo " β’ $INSTALL_DIR/$DEPLOY_SCRIPT" | |
echo | |
echo -e "${BLUE}π Usage:${NC}" | |
echo " # First time setup (run once per repository)" | |
echo -e " ${YELLOW}cd /path/to/your/jekyll-repo${NC}" | |
echo -e " ${YELLOW}$SETUP_SCRIPT${NC}" | |
echo | |
echo " # Deploy your site (run anytime)" | |
echo -e " ${YELLOW}$DEPLOY_SCRIPT${NC}" | |
echo | |
echo " # Deploy with force rebuild (fixes 503 errors)" | |
echo -e " ${YELLOW}$DEPLOY_SCRIPT --rebuild${NC}" | |
echo | |
echo -e "${BLUE}π Help:${NC}" | |
echo -e " ${YELLOW}$SETUP_SCRIPT --help${NC}" | |
echo -e " ${YELLOW}$DEPLOY_SCRIPT --help${NC}" | |
echo | |
if [ "$USER_INSTALL" = true ] && [[ ":$PATH:" != *":$INSTALL_DIR:"* ]]; then | |
echo -e "${YELLOW}β οΈ Don't forget to add $INSTALL_DIR to your PATH!${NC}" | |
echo -e " ${CYAN}echo 'export PATH=\"\$PATH:$INSTALL_DIR\"' >> ~/.bashrc${NC}" | |
echo -e " ${CYAN}source ~/.bashrc${NC}" | |
echo | |
fi | |
echo -e "${BLUE}π To update in the future:${NC}" | |
echo -e " ${YELLOW}curl -sSL YOUR_INSTALLER_GIST_URL | bash${NC}" | |
echo | |
} | |
# Validate Gist URLs | |
validate_gist_urls() { | |
log_step "Validating Gist URLs..." | |
if [[ "$SETUP_GIST_URL" == *"YOUR_USERNAME"* ]] || [[ "$DEPLOY_GIST_URL" == *"YOUR_USERNAME"* ]]; then | |
log_error "Gist URLs are not configured!" | |
echo | |
echo "Please update the installer script with your actual Gist URLs:" | |
echo " SETUP_GIST_URL=\"https://gist.githubusercontent.com/SolomonHD/ff209f45c80f1ec0068f6b39203a302d/raw/jekyll-ghpages-setup.sh\"" | |
echo " DEPLOY_GIST_URL=\"https://gist.githubusercontent.com/SolomonHD/3450847185c4749b7d7612d9725cef44/raw/jekyll-ghpages-deploy.sh\"" | |
exit 1 | |
fi | |
log_success "Gist URLs look valid" | |
} | |
# Main execution | |
main() { | |
print_header | |
parse_arguments "$@" | |
validate_gist_urls | |
check_prerequisites | |
check_existing_installation | |
log_info "Installing to: $INSTALL_DIR" | |
echo | |
# Install both scripts | |
if install_script "$SETUP_SCRIPT" "$SETUP_GIST_URL" && \ | |
install_script "$DEPLOY_SCRIPT" "$DEPLOY_GIST_URL"; then | |
if verify_installation; then | |
show_completion_message | |
else | |
exit 1 | |
fi | |
else | |
log_error "Installation failed" | |
exit 1 | |
fi | |
} | |
# Run main function | |
main "$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment