#!/bin/bash # Version Management Script for WebSSH # Automatically updates version numbers in help.html and build scripts set -e # Configuration ROOT_DIR="$(cd "$(dirname "$0")/../.." && pwd)" VERSION_FILE="$ROOT_DIR/src/help.html" BUILD_SCRIPT="$ROOT_DIR/deployment/scripts/docker-build-and-push.sh" GITHUB_WORKFLOW="$ROOT_DIR/.github/workflows/build-and-publish.yml" # Colors RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' BLUE='\033[0;34m' NC='\033[0m' echo -e "${BLUE}🔧 WebSSH Version Management${NC}" echo -e "${BLUE}=================================${NC}" # Function to get current version get_current_version() { if [[ -f "$VERSION_FILE" ]]; then grep -o 'WebSSH Multi-Connection Terminal v' "$VERSION_FILE" | sed 's/.*v\([0-9.]\+\).*/\1/' else echo "0.0.0" fi } # Function to update version in help.html update_help_version() { local new_version=$1 echo -e "${GREEN}📝 Updating $VERSION_FILE to v$new_version${NC}" # Update version in help.html sed -i "s/WebSSH Multi-Connection Terminal v[0-9.]\+\.[0-9]\+/WebSSH Multi-Connection Terminal v$new_version/" "$VERSION_FILE" echo -e "${GREEN}✅ $VERSION_FILE updated to v$new_version${NC}" } # Function to update version in build script update_build_version() { local new_version=$1 echo -e "${GREEN}🔨 Updating $BUILD_SCRIPT to v$new_version${NC}" # Update version in build script sed -i "s/VERSION=\"[0-9.]\+\.[0-9]\+\"/VERSION=\"$new_version\"/" "$BUILD_SCRIPT" echo -e "${GREEN}✅ $BUILD_SCRIPT updated to v$new_version${NC}" } # Function to update version in GitHub workflow update_github_workflow() { local new_version=$1 echo -e "${GREEN}🐙 Updating $GITHUB_WORKFLOW to v$new_version${NC}" # Update version in GitHub workflow sed -i "s/WebSSH Multi-Connection Terminal v[0-9.]\+\.[0-9]\+/WebSSH Multi-Connection Terminal v$new_version/" "$GITHUB_WORKFLOW" echo -e "${GREEN}✅ $GITHUB_WORKFLOW updated to v$new_version${NC}" } # Function to update version in Dockerfile (if needed) update_dockerfile_version() { local new_version=$1 echo -e "${GREEN}đŸŗ Checking if Dockerfile needs version update...${NC}" # Check if Dockerfile has version comment if [[ -f "Dockerfile" ]] && grep -q "# Production-ready Dockerfile for WebSSH" "Dockerfile"; then echo -e "${YELLOW}â„šī¸ Dockerfile already has version comment${NC}" else echo -e "${YELLOW}âš ī¸ Dockerfile missing version comment${NC}" echo -e "${BLUE}â„šī¸ Consider adding version comment to Dockerfile${NC}" fi } # Function to validate version format validate_version() { local version=$1 if [[ ! "$version" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then echo -e "${RED}❌ Invalid version format: $version. Use format: X.Y.Z${NC}" return 1 fi return 0 } # Main menu show_menu() { echo -e "${YELLOW}Current version: $(get_current_version)${NC}" echo "" echo -e "${BLUE}Choose an option:${NC}" echo "1) Set new version" echo "2) Patch version (increment last digit)" echo "3) Minor version (increment middle digit)" echo "4) Major version (increment first digit)" echo "5) Show current files" echo "6) Exit" echo "" read -p "Enter choice [1-6]: " choice } # Function to show current files show_current_files() { echo -e "${BLUE}📁 Current version information:${NC}" echo -e "${GREEN} help.html: v$(get_current_version)${NC}" echo -e "${GREEN} ${BUILD_SCRIPT}: v$(grep -o 'VERSION="[0-9.]\\+"' "${BUILD_SCRIPT}" | head -1 | sed 's/VERSION="\([0-9.]\+\)"/\1/')${NC}" echo -e "${GREEN} ${GITHUB_WORKFLOW}: v$(grep -o 'WebSSH Multi-Connection Terminal v[0-9.]\\+' "${GITHUB_WORKFLOW}" | sed 's/.*v\([0-9.]\+\)/\1/')${NC}" echo "" } # Main logic main() { while true; do show_menu case $choice in 1) read -p "Enter new version (X.Y.Z): " new_version if validate_version "$new_version"; then update_help_version "$new_version" update_build_version "$new_version" update_github_workflow "$new_version" update_dockerfile_version "$new_version" echo -e "${GREEN}🎉 All files updated to v$new_version${NC}" fi ;; 2) current=$(get_current_version) if [[ "$current" =~ ^([0-9]+)\.([0-9]+)\.([0-9]+)$ ]]; then major=${BASH_REMATCH[1]} minor=${BASH_REMATCH[2]} patch=$((${BASH_REMATCH[3]} + 1)) new_version="${major}.${minor}.${patch}" update_help_version "$new_version" update_build_version "$new_version" update_github_workflow "$new_version" update_dockerfile_version "$new_version" echo -e "${GREEN}🎉 Patch version updated to v$new_version${NC}" else echo -e "${RED}❌ Could not parse current version${NC}" fi ;; 3) current=$(get_current_version) if [[ "$current" =~ ^([0-9]+)\.([0-9]+)\.([0-9]+)$ ]]; then major=${BASH_REMATCH[1]} minor=$((${BASH_REMATCH[2]} + 1)) patch=0 new_version="${major}.${minor}.${patch}" update_help_version "$new_version" update_build_version "$new_version" update_github_workflow "$new_version" update_dockerfile_version "$new_version" echo -e "${GREEN}🎉 Minor version updated to v$new_version${NC}" else echo -e "${RED}❌ Could not parse current version${NC}" fi ;; 4) current=$(get_current_version) if [[ "$current" =~ ^([0-9]+)\.([0-9]+)\.([0-9]+)$ ]]; then major=$((${BASH_REMATCH[1]} + 1)) minor=0 patch=0 new_version="${major}.${minor}.${patch}" update_help_version "$new_version" update_build_version "$new_version" update_github_workflow "$new_version" update_dockerfile_version "$new_version" echo -e "${GREEN}🎉 Major version updated to v$new_version${NC}" else echo -e "${RED}❌ Could not parse current version${NC}" fi ;; 5) show_current_files ;; 6) echo -e "${GREEN}👋 Goodbye!${NC}" exit 0 ;; *) echo -e "${RED}❌ Invalid choice. Please try again.${NC}" ;; esac echo "" read -p "Press Enter to continue..." -r done } # Check if files exist if [[ ! -f "$VERSION_FILE" ]]; then echo -e "${RED}❌ $VERSION_FILE not found${NC}" exit 1 fi if [[ ! -f "$BUILD_SCRIPT" ]]; then echo -e "${RED}❌ $BUILD_SCRIPT not found${NC}" exit 1 fi if [[ ! -f "$GITHUB_WORKFLOW" ]]; then echo -e "${RED}❌ $GITHUB_WORKFLOW not found${NC}" exit 1 fi # Run main function main