sureshanaparti commented on code in PR #1:
URL: 
https://github.com/apache/cloudstack-installer/pull/1#discussion_r2469258037


##########
installer.sh:
##########
@@ -0,0 +1,2315 @@
+#!/usr/bin/env bash
+# c8k.in/installer.sh - Easiest Apache CloudStack Installer
+# Install with this command (from your Ubuntu/EL host):
+#
+# curl -sSfL https://c8k.in/stall.sh | bash
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+# 
+#   http://www.apache.org/licenses/LICENSE-2.0
+# 
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+
+set -euo pipefail  # Exit on error, undefined vars, pipe failures
+
+# Global variables
+SCRIPT_NAME="CloudStack Installer"
+CS_LOGFILE="/tmp/cloudstack-install.log"
+TRACKER_FILE="$HOME/cloudstack-installer-tracker.conf"
+
+OS_TYPE=""
+PACKAGE_MANAGER=""
+SELECTED_COMPONENTS=()
+ZONE_TYPE=""
+MYSQL_SERVICE=""
+MYSQL_CONF_DIR=""
+
+BRIDGE=cloudbr0
+HOST_IP=
+GATEWAY=
+DNS="8.8.8.8"
+NETMASK="255.255.255.0"
+
+# Colors for output
+RED='\033[0;31m'
+GREEN='\033[0;32m'
+YELLOW='\033[1;33m'
+BLUE='\033[0;34m'
+NC='\033[0m' # No Color
+
+# 1 = Prompt mode (interactive), 0 = Silent (non-interactive)
+PROMPT=1
+is_interactive() { (( PROMPT )); }
+is_silent()      { (( !PROMPT )); }
+
+# Logging function
+log() {
+    echo "$(date '+%Y-%m-%d %H:%M:%S') - $1" >> "$CS_LOGFILE"
+}
+
+# Error handling function
+error_exit() {
+    echo -e "${RED}ERROR: $1${NC}" >&2
+    log "ERROR: $1"
+    exit 1
+}
+
+# Success message function
+success_msg() {
+    echo -e "${GREEN}SUCCESS: $1${NC}"
+    log "SUCCESS: $1"
+}
+
+# Warning message function
+warn_msg() {
+    echo -e "${YELLOW}WARNING: $1${NC}"
+    log "WARNING: $1"
+}
+
+# Info message function
+info_msg() {
+    echo -e "${BLUE}INFO: $1${NC}"
+    log "INFO: $1"
+}
+
+
+declare -A tracker_values
+
+load_tracker() {
+    if [[ ! -f "$TRACKER_FILE" ]]; then
+        echo "# CloudStack Installer Tracker Config" > "$TRACKER_FILE"
+        echo "# Created on: $(date)" >> "$TRACKER_FILE"
+        return 0
+    fi
+
+    while IFS='=' read -r key value; do
+        [[ -z "$key" || "$key" =~ ^# ]] && continue
+        tracker_values["$key"]="$value"
+    done < "$TRACKER_FILE"
+}
+
+get_tracker_field() {
+    local key="$1"
+    echo "${tracker_values[$key]:-}"
+}
+
+is_configured() {
+    local key="$1"
+    [[ -n "${tracker_values[$key]:-}" ]]
+}
+
+# Save or update a field in the tracker file
+set_tracker_field() {
+    local key="$1"
+    local value="$2"
+
+    # Update associative array
+    tracker_values["$key"]="$value"
+
+    # Update or append key=value in tracker file
+    if grep -q "^$key=" "$TRACKER_FILE"; then
+        sed -i.bak "s|^$key=.*|$key=$value|" "$TRACKER_FILE"
+    else
+        echo "$key=$value" >> "$TRACKER_FILE"
+    fi
+}
+
+# Check if running as root
+check_root() {
+    if [[ $EUID -ne 0 ]]; then
+        error_exit "This script must be run as root. Please use 'sudo $0'"
+    fi
+}
+
+check_system_resources() {
+    MIN_RAM_KB=$((8 * 1024 * 1024))  # 8 GB in KB
+    TOTAL_RAM_KB=$(grep MemTotal /proc/meminfo | awk '{print $2}')
+
+    # Check if RAM is within the desired range
+    if [ "$TOTAL_RAM_KB" -ge "$MIN_RAM_KB" ]; then
+        success_msg "RAM check passed: $(awk "BEGIN {printf \"%.2f\", 
$TOTAL_RAM_KB/1024/1024}") GB"
+    else
+        error_exit "RAM check failed: System has $(awk "BEGIN {printf 
\"%.2f\", $TOTAL_RAM_KB/1024/1024}") GB RAM"
+    fi
+
+    MIN_DISK_GB=75  # Minimum disk space in GB
+    TOTAL_DISK_GB=$(df / | tail -1 | awk '{print $2}' | awk '{printf "%.0f", 
$1/1024/1024}')
+
+    # Check if disk space is within the desired range
+    if [ "$TOTAL_DISK_GB" -ge "$MIN_DISK_GB" ]; then
+        success_msg "Disk space check passed: $TOTAL_DISK_GB GB available"
+    else
+        error_exit "Disk space check failed: System has only $TOTAL_DISK_GB GB 
available"
+    fi
+}
+
+check_kvm_support() {
+    info_msg "Checking KVM prerequisites..."
+    if ! grep -E 'vmx|svm' /proc/cpuinfo >/dev/null; then
+        error_exit "CPU does not support hardware virtualization (agent)"
+    fi
+    success_msg "✓ CPU virtualization support detected"
+
+    if ! lsmod | grep -q kvm; then
+        error_exit "KVM kernel module is not loaded"
+    fi
+    success_msg "✓ KVM kernel module loaded"
+}
+
+# Function to detect the OS type and pkg mgr
+detect_os() {
+    if [[ ! -f /etc/os-release ]]; then
+        error_exit "Cannot detect operating system. /etc/os-release not found."
+    fi
+    
+    source /etc/os-release
+    OS_TYPE=$ID
+    OS_VERSION=$VERSION_ID
+    VERSION_CODENAME=${VERSION_CODENAME:-}
+    
+    case "$OS_TYPE" in
+        ubuntu|debian)
+            PACKAGE_MANAGER="apt"
+            MYSQL_SERVICE="mysql"
+            MYSQL_CONF_DIR="/etc/mysql/mysql.conf.d"
+            ;;
+        rhel|centos|ol|rocky|almalinux)
+            PACKAGE_MANAGER="dnf"
+            MYSQL_SERVICE="mysqld"
+            MYSQL_CONF_DIR="/etc/my.cnf.d"
+            ;;
+        *)
+            echo "Unsupported OS: $OS_TYPE"
+            exit 1
+            ;;
+    esac
+
+    log "OS Detection: $OS_TYPE with package manager: $PACKAGE_MANAGER"
+}
+
+get_ubuntu_codename_for_debian() {
+    case "$1" in
+        buster|bullseye)
+            echo "focal"
+            ;;
+        bookworm|trixie)
+            echo "jammy"
+            ;;
+        *)
+            echo "ERROR: Unsupported Debian codename '$1'" >&2
+            return 1
+            ;;
+    esac
+}
+
+update_system() {
+    {
+        echo "10"
+        echo "# Updating package cache..."
+        case "$PACKAGE_MANAGER" in
+            apt)
+                apt-get update 2>&1 | while IFS= read -r line; do
+                    echo "XXX"
+                    echo "30"
+                    echo "# Updating package lists...\n\n$line"
+                    echo "XXX"
+                done
+
+                echo "# Installing system updates..."
+                apt-get upgrade -y 2>&1 | while IFS= read -r line; do
+                    echo "XXX"
+                    echo "75"
+                    echo "# Installing updates...\n\n$line"
+                    echo "XXX"
+                done
+                ;;
+            dnf)
+                dnf clean all 2>&1 | while IFS= read -r line; do
+                    echo "XXX"
+                    echo "20"
+                    echo "# Cleaning package cache...\n\n$line"
+                    echo "XXX"
+                done
+
+                dnf makecache 2>&1 | while IFS= read -r line; do
+                    echo "XXX"
+                    echo "40"
+                    echo "# Updating package cache...\n\n$line"
+                    echo "XXX"
+                done
+
+                dnf update -y 2>&1 | while IFS= read -r line; do
+                    echo "XXX"
+                    echo "75"
+                    echo "# Installing system updates...\n\n$line"
+                    echo "XXX"
+                done
+                ;;
+        esac
+
+        echo "XXX"
+        echo "100"
+        echo "# System update complete!"
+        echo "XXX"
+        sleep 2
+    } | dialog --backtitle "$SCRIPT_NAME" \
+               --title "System Update" \
+               --gauge "Updating system packages..." 15 70 0
+
+    # Verify update success
+    if [[ $? -eq 0 ]]; then
+        show_dialog info "System Update" "System packages have been 
successfully updated." 2
+    else
+        dialog --backtitle "$SCRIPT_NAME" \
+               --title "Error" \
+               --msgbox "Failed to update system packages. Please check the 
logs." 6 50
+        return 1
+    fi
+}
+
+normalize_repo_url_path() {
+    local url="$1"
+    # Remove duplicate slashes, then fix protocol
+    url=$(echo "$url" | sed 's#//*#/#g; s#https:/#https://#g; 
s#http:/#http://#g')
+    # Trim any trailing slash
+    url="${url%/}"
+    echo "$url"
+}
+
+validate_repo_entry() {
+    local os_type="$1"
+    local entry="$2"
+
+    # Basic check: not empty
+    if [[ -z "$entry" ]]; then
+        error_exit "CloudStack Repository entry cannot be empty."
+        return 1
+    fi
+
+    # Debian/Ubuntu repo line example:
+    # deb [signed-by=...] https://download.cloudstack.org/ubuntu noble 4.20
+    if [[ "$os_type" =~ ^(ubuntu|debian)$ ]]; then
+        if [[ ! "$entry" =~ https?:// ]]; then
+            error_exit "Invalid Repository entry must include a valid URL 
(http or https)."
+            return 1
+        fi
+    fi
+
+    # RHEL-family example:
+    # https://download.cloudstack.org/centos/9/4.20/
+    if [[ "$os_type" =~ ^(rhel|centos|rocky|almalinux|ol)$ ]]; then
+        if [[ ! "$entry" =~ ^https?:// ]]; then
+            error_exit "Invalid Repository baseurl must start with http:// or 
https://.";
+            return 1
+        fi
+    fi
+
+    # Optional: check version (warn, not fatal)
+    if [[ ! "$entry" =~ 4\.([1-9][0-9]) ]]; then
+        dialog --backtitle "$SCRIPT_NAME" \
+               --title "Warning" \
+               --msgbox "The repository entry does not appear to contain a 
known CloudStack version (4.xx). Please verify before proceeding." 8 70
+    fi
+
+    return 0
+}
+
+configure_cloudstack_repo() {
+    local repo_file=""
+    local repo_entry=""
+    case "$OS_TYPE" in
+        ubuntu|debian)
+            repo_file="/etc/apt/sources.list.d/cloudstack.list"
+            if [[ -f "$repo_file" ]]; then
+                repo_entry=$(grep -E '^deb ' "$repo_file" | sed -E 's/^.*] //')
+            fi
+            ;;
+        rhel|centos|ol|rocky|almalinux)
+            repo_file="/etc/yum.repos.d/cloudstack.repo"
+            if [[ -f "$repo_file" ]]; then
+                repo_entry=$(grep -E '^baseurl=' "$repo_file" | cut -d'=' -f2-)
+            fi
+            ;;
+        *)
+            dialog --msgbox "Unsupported OS: $OS_TYPE" 6 50
+            exit 1
+            ;;
+    esac
+    # If repo already exists, show info and exit gracefully
+    if [[ -n "$repo_entry" ]]; then
+        show_dialog "info" \
+            "CloudStack Repository Configuration" \
+            "CloudStack repository is already configured:\n\n$repo_entry"
+
+        set_tracker_field "repo_url" "$repo_entry"
+        return 0
+    fi
+
+    local default_repo_url="https://download.cloudstack.org";
+    local default_cs_version="4.21"

Review Comment:
   can operator mention custom repo and version while installation?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to