#!/usr/bin/env bash # vopk - Ultimate Package Manager (3.0.0 "Jammy") # The Complete Package Management Solution - Cross-platform, Universal, Intelligent # # Official: https://github.com/omar9devx/vopk # Documentation: https://omar9devx.github.io/vopk # Issues: https://github.com/omar9devx/vopk/issues # # Supports: 50+ package managers across 20+ distributions and 6+ OS families # # LICENSE: GPL 3 set -euo pipefail shopt -s nullglob globstar nocaseglob VOPK_VERSION="3.1.0" VOPK_CODENAME="Jammy" VOPK_RELEASE_DATE="2026" VOPK_MIN_BASH_VERSION="4.4" VOPK_REPO_URL="https://github.com/omar9devx/vopk" VOPK_DOCS_URL="https://omar9devx.github.io/vopk" VOPK_ISSUES_URL="https://github.com/omar9devx/vopk/issues" ############################################################################### # ENHANCED CONFIGURATION SYSTEM WITH YAML/JSON SUPPORT ############################################################################### declare -A VOPK_CONFIG_DEFAULTS=( ["VOPK_ASSUME_YES"]="0" ["VOPK_DRY_RUN"]="0" ["VOPK_NO_COLOR"]="0" ["VOPK_DEBUG"]="0" ["VOPK_QUIET"]="0" ["VOPK_SUDO"]="" ["VOPK_PARALLEL"]="1" ["VOPK_MAX_RETRIES"]="3" ["VOPK_CACHE_DIR"]="$HOME/.cache/vopk" ["VOPK_CONFIG_DIR"]="$HOME/.config/vopk" ["VOPK_LOG_FILE"]="" ["VOPK_BACKUP"]="1" ["VOPK_ROLLBACK"]="1" ["VOPK_AI_SUGGEST"]="0" ["VOPK_SECURITY_SCAN"]="1" ["VOPK_AUTO_CLEAN"]="7" ["VOPK_NOTIFY"]="1" ["VOPK_TELEMETRY"]="0" ["VOPK_UPDATE_CHECK"]="1" ["VOPK_PLUGINS"]="1" ["VOPK_THEME"]="default" ["VOPK_ANIMATIONS"]="1" ["VOPK_COMPLETION"]="1" ["VOPK_HISTORY"]="1" ["VOPK_AUTO_UPDATE"]="0" ["VOPK_PROFILE"]="default" ["VOPK_OPTIMIZE"]="1" ["VOPK_BENCHMARK"]="0" ["VOPK_VERBOSE"]="0" ["VOPK_SHELL_INTEGRATION"]="1" ) # Initialize configuration init_config() { for key in "${!VOPK_CONFIG_DEFAULTS[@]}"; do if [[ ! -v $key ]]; then export "$key"="${VOPK_CONFIG_DEFAULTS[$key]}" fi done } init_config VOPK_ARGS=() declare -A VOPK_METRICS=( [start]=$(date +%s) [operations]=0 [packages]=0 [success]=0 [failed]=0 [cache_hits]=0 [cache_misses]=0 [download_size]=0 [install_time]=0 ) declare -A VOPK_STATS=() declare -A VOPK_HISTORY=() declare -A VOPK_PROFILES=() # Enhanced distro detection DISTRO_ID="" DISTRO_ID_LIKE="" DISTRO_PRETTY_NAME="" DISTRO_VERSION_ID="" DISTRO_VERSION_CODENAME="" DISTRO_ARCH="" DISTRO_KERNEL="" DISTRO_INIT="" DISTRO_DESKTOP="" DISTRO_VARIANT="" # Package manager registry declare -A PKG_MGR_REGISTRY=() declare -A PKG_MGR_CAPABILITIES=() declare -A UNIVERSAL_MGRS=() declare -A LANGUAGE_MGRS=() declare -A CONTAINER_MGRS=() declare -A CLOUD_MGRS=() declare -A GAME_MGRS=() ############################################################################### # ADVANCED THEME SYSTEM WITH MULTIPLE THEMES ############################################################################### # Theme: default declare -A THEME_DEFAULT=( ["primary"]="\033[38;5;39m" ["secondary"]="\033[38;5;45m" ["success"]="\033[38;5;46m" ["warning"]="\033[38;5;226m" ["error"]="\033[38;5;196m" ["info"]="\033[38;5;33m" ["muted"]="\033[38;5;242m" ["accent1"]="\033[38;5;129m" ["accent2"]="\033[38;5;208m" ["accent3"]="\033[38;5;46m" ) # Theme: dracula declare -A THEME_DRACULA=( ["primary"]="\033[38;5;189m" ["secondary"]="\033[38;5;141m" ["success"]="\033[38;5;121m" ["warning"]="\033[38;5;229m" ["error"]="\033[38;5;210m" ["info"]="\033[38;5;117m" ["muted"]="\033[38;5;61m" ["accent1"]="\033[38;5;255m" ["accent2"]="\033[38;5;203m" ["accent3"]="\033[38;5;84m" ) # Theme: nord declare -A THEME_NORD=( ["primary"]="\033[38;5;109m" ["secondary"]="\033[38;5;103m" ["success"]="\033[38;5;114m" ["warning"]="\033[38;5;216m" ["error"]="\033[38;5;210m" ["info"]="\033[38;5;110m" ["muted"]="\033[38;5;240m" ["accent1"]="\033[38;5;180m" ["accent2"]="\033[38;5;174m" ["accent3"]="\033[38;5;108m" ) # Theme: solarized declare -A THEME_SOLARIZED=( ["primary"]="\033[38;5;33m" ["secondary"]="\033[38;5;37m" ["success"]="\033[38;5;64m" ["warning"]="\033[38;5;136m" ["error"]="\033[38;5;160m" ["info"]="\033[38;5;67m" ["muted"]="\033[38;5;246m" ["accent1"]="\033[38;5;125m" ["accent2"]="\033[38;5;166m" ["accent3"]="\033[38;5;72m" ) # Theme: monokai declare -A THEME_MONOKAI=( ["primary"]="\033[38;5;81m" ["secondary"]="\033[38;5;197m" ["success"]="\033[38;5;148m" ["warning"]="\033[38;5;208m" ["error"]="\033[38;5;204m" ["info"]="\033[38;5;141m" ["muted"]="\033[38;5;59m" ["accent1"]="\033[38;5;220m" ["accent2"]="\033[38;5;172m" ["accent3"]="\033[38;5;154m" ) # Theme variables PRIMARY="" SECONDARY="" SUCCESS="" WARNING="" ERROR="" INFO="" MUTED="" ACCENT1="" ACCENT2="" ACCENT3="" BOLD="" DIM="" ITALIC="" UNDERLINE="" BLINK="" INVERT="" HIDDEN="" RESET="" # Load theme with safety checks load_theme() { local theme_name="${VOPK_THEME:-default}" local theme_var_name="THEME_${theme_name^^}" # Default color values local default_primary="\033[38;5;39m" local default_secondary="\033[38;5;45m" local default_success="\033[38;5;46m" local default_warning="\033[38;5;226m" local default_error="\033[38;5;196m" local default_info="\033[38;5;33m" local default_muted="\033[38;5;242m" local default_accent1="\033[38;5;129m" local default_accent2="\033[38;5;208m" local default_accent3="\033[38;5;46m" # Check if theme exists if declare -p "$theme_var_name" &>/dev/null; then # Use indirect reference to access theme array eval "declare -n theme_ref=\"$theme_var_name\"" # Safely get values with defaults PRIMARY="${theme_ref["primary"]:-$default_primary}" SECONDARY="${theme_ref["secondary"]:-$default_secondary}" SUCCESS="${theme_ref["success"]:-$default_success}" WARNING="${theme_ref["warning"]:-$default_warning}" ERROR="${theme_ref["error"]:-$default_error}" INFO="${theme_ref["info"]:-$default_info}" MUTED="${theme_ref["muted"]:-$default_muted}" ACCENT1="${theme_ref["accent1"]:-$default_accent1}" ACCENT2="${theme_ref["accent2"]:-$default_accent2}" ACCENT3="${theme_ref["accent3"]:-$default_accent3}" else # Use default theme if specified theme doesn't exist PRIMARY="$default_primary" SECONDARY="$default_secondary" SUCCESS="$default_success" WARNING="$default_warning" ERROR="$default_error" INFO="$default_info" MUTED="$default_muted" ACCENT1="$default_accent1" ACCENT2="$default_accent2" ACCENT3="$default_accent3" fi # Formatting codes BOLD="\033[1m" DIM="\033[2m" ITALIC="\033[3m" UNDERLINE="\033[4m" BLINK="\033[5m" INVERT="\033[7m" HIDDEN="\033[8m" RESET="\033[0m" } # Apply color mode apply_color_mode() { if [[ "$VOPK_NO_COLOR" -eq 1 || -n "${NO_COLOR-}" ]]; then # Clear all color and formatting variables PRIMARY=""; SECONDARY=""; SUCCESS=""; WARNING=""; ERROR=""; INFO="" MUTED=""; ACCENT1=""; ACCENT2=""; ACCENT3="" BOLD=""; DIM=""; ITALIC=""; UNDERLINE=""; BLINK=""; INVERT=""; HIDDEN=""; RESET="" else load_theme fi } ############################################################################### # ADVANCED LOGGING SYSTEM WITH ROTATION AND COMPRESSION ############################################################################### init_logging() { mkdir -p "${VOPK_CACHE_DIR}/logs" if [[ -z "${VOPK_LOG_FILE}" ]]; then VOPK_LOG_FILE="${VOPK_CACHE_DIR}/logs/vopk-$(date +%Y%m%d-%H%M%S).log" fi # Rotate logs if too large rotate_logs # Create file descriptors exec 3>>"${VOPK_LOG_FILE}" exec 4>>"${VOPK_CACHE_DIR}/logs/debug.log" exec 5>>"${VOPK_CACHE_DIR}/logs/audit.log" # Log system info log_to_file "SYSTEM" "=== vopk ${VOPK_VERSION} started at $(date) ===" log_to_file "SYSTEM" "User: $(whoami)@$(hostname)" log_to_file "SYSTEM" "OS: $(uname -a)" log_to_file "SYSTEM" "Args: $*" } rotate_logs() { local max_size_mb=10 local max_files=10 # Rotate main log if [[ -f "${VOPK_LOG_FILE}" ]] && [[ $(stat -c %s "${VOPK_LOG_FILE}" 2>/dev/null) -gt $((max_size_mb * 1024 * 1024)) ]]; then mv "${VOPK_LOG_FILE}" "${VOPK_LOG_FILE}.1" fi # Rotate old logs find "${VOPK_CACHE_DIR}/logs" -name "*.log.*" -type f | sort -r | tail -n +$((max_files + 1)) | xargs rm -f 2>/dev/null || true } log_to_file() { local level="$1" local message="$2" local timestamp="$(date +"%Y-%m-%d %H:%M:%S.%3N")" printf "[%s] [%s] [%s] %s\n" \ "$timestamp" \ "$level" \ "${PKG_MGR_FAMILY:-unknown}" \ "$message" >&3 } log_to_audit() { local action="$1" local target="$2" local status="$3" printf "[%s] [AUDIT] %s %s %s\n" \ "$(date +"%Y-%m-%d %H:%M:%S")" \ "$action" "$target" "$status" >&5 } timestamp() { date +"%H:%M:%S" } log() { if [[ "$VOPK_QUIET" -eq 1 ]]; then return; fi printf "%s[%s]%s %sVOPK%s %sℹ%s %s\n" \ "$DIM" "$(timestamp)" "$RESET" \ "$BOLD$PRIMARY" "$RESET" \ "$INFO" "$RESET" \ "$*" >&2 log_to_file "INFO" "$*" } log_success() { if [[ "$VOPK_QUIET" -eq 1 ]]; then return; fi printf "%s[%s]%s %sVOPK%s %s✔ SUCCESS%s %s\n" \ "$DIM" "$(timestamp)" "$RESET" \ "$BOLD$PRIMARY" "$RESET" \ "$SUCCESS" "$RESET" \ "$*" >&2 log_to_file "SUCCESS" "$*" ((VOPK_METRICS[success]++)) } log_progress() { [[ "$VOPK_QUIET" -eq 1 || "$VOPK_ANIMATIONS" -eq 0 ]] && return local step="$1" local total="$2" local message="$3" local width=30 local percent=$((step * 100 / total)) local filled=$((percent * width / 100)) local empty=$((width - filled)) printf "\r%s[%s]%s %sVOPK%s %s⟳%s [" \ "$DIM" "$(timestamp)" "$RESET" \ "$BOLD$PRIMARY" "$RESET" \ "$WARNING" "$RESET" # Animated progress bar if [[ $((step % 4)) -eq 0 ]]; then printf "%s%s%s%s%s" "$SUCCESS" "$(printf '█%.0s' $(seq 1 $filled))" \ "$MUTED" "$(printf '░%.0s' $(seq 1 $empty))" "$RESET" else printf "%s%s%s%s%s" "$SUCCESS" "$(printf '█%.0s' $(seq 1 $filled))" \ "$ACCENT1" "$(printf '▒%.0s' $(seq 1 $empty))" "$RESET" fi printf "] %s%3d%%%s %s" "$ACCENT2" "$percent" "$RESET" "$message" >&2 } warn() { printf "%s[%s]%s %sVOPK%s %s⚠ WARN%s %s\n" \ "$DIM" "$(timestamp)" "$RESET" \ "$BOLD$PRIMARY" "$RESET" \ "$WARNING" "$RESET" \ "$*" >&2 log_to_file "WARN" "$*" } die() { printf "%s[%s]%s %sVOPK%s %s✗ ERROR%s %s\n\n" \ "$DIM" "$(timestamp)" "$RESET" \ "$BOLD$PRIMARY" "$RESET" \ "$ERROR" "$RESET" \ "$*" >&2 log_to_file "ERROR" "$*" ((VOPK_METRICS[failed]++)) log_to_audit "ERROR" "$*" "FAILED" show_troubleshooting "$*" show_metrics "failed" if [[ -f "${VOPK_LOG_FILE}" ]]; then printf "%sLog file: %s%s\n" "$DIM" "$VOPK_LOG_FILE" "$RESET" >&2 fi exit 1 } debug() { if [[ "$VOPK_DEBUG" -eq 1 ]]; then printf "%s[%s]%s %sVOPK%s %s🐛 DEBUG%s %s\n" \ "$DIM" "$(timestamp)" "$RESET" \ "$BOLD$PRIMARY" "$RESET" \ "$ACCENT1" "$RESET" \ "$*" >&2 log_to_file "DEBUG" "$*" printf "[%s] %s\n" "$(date +"%H:%M:%S.%3N")" "$*" >&4 fi } ############################################################################### # ANIMATED UI SYSTEM WITH MULTIPLE EFFECTS ############################################################################### ui_animate() { [[ "$VOPK_ANIMATIONS" -eq 0 ]] && { echo "$1"; return; } local text="$1" local effect="${2:-typewriter}" local delay="${3:-0.03}" case "$effect" in typewriter) for ((i=0; i<${#text}; i++)); do printf "%s" "${text:$i:1}" sleep "$delay" done ;; bounce) local chars=("⠋" "⠙" "⠹" "⠸" "⠼" "⠴" "⠦" "⠧" "⠇" "⠏") for char in "${chars[@]}"; do printf "\r%s %s" "$char" "$text" sleep 0.1 done ;; pulse) for i in {1..3}; do printf "\r%s%s%s %s" "$BOLD" "$PRIMARY" "$text" "$RESET" sleep 0.2 printf "\r%s %s" "$text" "$RESET" sleep 0.2 done ;; *) echo "$text" ;; esac echo } ui_banner() { apply_color_mode # Animated banner if [[ "$VOPK_ANIMATIONS" -eq 1 ]]; then printf "%s" "$BOLD$ACCENT1" ui_animate "╔══════════════════════════════════════════════════════════════════════════════╗" "typewriter" 0.001 ui_animate "║ ║" "typewriter" 0.001 ui_animate "║ ██╗ ██╗ ██████╗ ██████╗ ██╗ ██╗ ╭────────────────────────────────╮ ║" "typewriter" 0.001 ui_animate "║ ██║ ██║██╔═══██╗██╔══██╗██║ ██╔╝ │ Jammy Release 3.0.0 │ ║" "typewriter" 0.001 ui_animate "║ ██║ ██║██║ ██║██████╔╝█████╔╝ │ Ultimate Package Manager │ ║" "typewriter" 0.001 ui_animate "║ ╚██╗ ██╔╝██║ ██║██╔═══╝ ██╔═██╗ │ Cross-Platform • Universal │ ║" "typewriter" 0.001 ui_animate "║ ╚████╔╝ ╚██████╔╝██║ ██║ ██╗ │ Intelligent • Secure │ ║" "typewriter" 0.001 ui_animate "║ ╚═══╝ ╚═════╝ ╚═╝ ╚═╝ ╚═╝ ╰────────────────────────────────╯ ║" "typewriter" 0.001 ui_animate "║ ║" "typewriter" 0.001 ui_animate "╚══════════════════════════════════════════════════════════════════════════════╝" "typewriter" 0.001 printf "%s\n" "$RESET" else cat <<'EOF' ╔══════════════════════════════════════════════════════════════════════════════╗ ║ ║ ║ ██╗ ██╗ ██████╗ ██████╗ ██╗ ██╗ ╭────────────────────────────────╮ ║ ║ ██║ ██║██╔═══██╗██╔══██╗██║ ██╔╝ │ Jammy Release 3.0.0 │ ║ ║ ██║ ██║██║ ██║██████╔╝█████╔╝ │ Ultimate Package Manager │ ║ ║ ╚██╗ ██╔╝██║ ██║██╔═══╝ ██╔═██╗ │ Cross-Platform • Universal │ ║ ║ ╚████╔╝ ╚██████╔╝██║ ██║ ██╗ │ Intelligent • Secure │ ║ ║ ╚═══╝ ╚═════╝ ╚═╝ ╚═╝ ╚═╝ ╰────────────────────────────────╯ ║ ║ ║ ╚══════════════════════════════════════════════════════════════════════════════╝ EOF fi printf "%sVersion:%s %s (%s) • %s\n" "$BOLD$PRIMARY" "$RESET" "$VOPK_VERSION" "$VOPK_CODENAME" "$VOPK_RELEASE_DATE" printf "%sPlatform:%s %s • %s • %s\n" "$BOLD$PRIMARY" "$RESET" "$(platform_label)" "$(uname -m)" "$(uname -s)" printf "%sBackends:%s %s\n" "$BOLD$PRIMARY" "$RESET" "$(list_available_backends)" printf "%sFeatures:%s AI • Rollback • Security • Parallel • Cache • Universal\n" "$BOLD$PRIMARY" "$RESET" printf "%sOfficial:%s %s\n" "$BOLD$PRIMARY" "$RESET" "$VOPK_REPO_URL" ui_hr 80 "─" } ui_hr() { local width="${1:-60}" local char="${2:-─}" printf "%s%s%s\n" "$DIM" "$(printf '%s%.0s' "$char" $(seq 1 "$width"))" "$RESET" } ui_title() { local msg="$1" local width="${2:-60}" ui_hr "$width" "═" printf "%s╡ %s ╞%s\n" "$BOLD$SECONDARY$UNDERLINE" "$msg" "$RESET" ui_hr "$width" "═" } ui_section() { local title="$1" local width="${2:-60}" ui_hr "$width" "─" printf "%s▌ %s ▐%s\n" "$BOLD$INFO" "$title" "$RESET" ui_hr "$width" "─" } ui_subsection() { local title="$1" printf "\n%s › %s%s\n" "$BOLD$ACCENT2" "$title" "$RESET" } ui_row() { local label="$1"; shift printf " %s%-25s%s %s\n" "$INFO$BOLD" "$label" "$RESET" "$*" } ui_hint() { printf " %s•%s %s\n" "$MUTED" "$RESET" "$*" } ui_table() { local headers=("$@") local col_widths=() local data=() # Calculate column widths for ((i=0; i<${#headers[@]}; i++)); do col_widths[$i]=${#headers[$i]} done # Print header printf "%s" "$BOLD$UNDERLINE$PRIMARY" for ((i=0; i<${#headers[@]}; i++)); do printf "%-${col_widths[$i]}s " "${headers[$i]}" done printf "%s\n" "$RESET" } ui_spinner() { local pid=$1 local msg="$2" local delay=0.1 local spin_chars=("🕐" "🕑" "🕒" "🕓" "🕔" "🕕" "🕖" "🕗" "🕘" "🕙" "🕚" "🕛") local i=0 printf "\n" while kill -0 "$pid" 2>/dev/null; do printf "\r%s%s%s %s" "$ACCENT2" "${spin_chars[$i]}" "$RESET" "$msg" i=$(( (i+1) % ${#spin_chars[@]} )) sleep $delay done printf "\r%s✓%s %s\n" "$SUCCESS" "$RESET" "Done" } ############################################################################### # ENHANCED TROUBLESHOOTING WITH AI INTEGRATION ############################################################################### show_troubleshooting() { local error="$1" ui_section "Troubleshooting Assistant" # AI-powered error analysis local error_type=$(analyze_error "$error") case "$error_type" in permission) ui_row "Issue:" "Permission Denied" ui_hint "Run with sudo: sudo vopk ..." ui_hint "Check sudo configuration: sudo -l" ui_hint "Use doas: export VOPK_SUDO=doas" ui_hint "Run as root: su -c 'vopk ...'" ;; network) ui_row "Issue:" "Network Connectivity" ui_hint "Check internet: ping 8.8.8.8" ui_hint "Fix DNS: vopk fix-dns" ui_hint "Configure proxy: export http_proxy=..." ui_hint "Check firewall: sudo ufw status" ;; dependency) ui_row "Issue:" "Dependency Problem" ui_hint "Fix dependencies: vopk fix-dependencies" ui_hint "Check broken: vopk doctor" ui_hint "Clean cache: vopk clean --all" ui_hint "Update system: vopk update && vopk upgrade" ;; not_found) ui_row "Issue:" "Package Not Found" ui_hint "Update lists: vopk update" ui_hint "Search: vopk search " ui_hint "Check spelling" ui_hint "Try alternative package names" ;; conflict) ui_row "Issue:" "Package Conflict" ui_hint "Remove conflicting: vopk remove " ui_hint "Force install: vopk install --force" ui_hint "Check dependencies: vopk depends " ;; disk_space) ui_row "Issue:" "Disk Space" ui_hint "Check space: df -h" ui_hint "Clean cache: vopk clean --all" ui_hint "Remove old kernels" ui_hint "Clean temp files: sudo rm -rf /tmp/*" ;; *) ui_row "Issue:" "Unknown Error" ui_hint "Run diagnostics: vopk doctor --verbose" ui_hint "Check logs: tail -f $VOPK_LOG_FILE" ui_hint "Update vopk: vopk self-update" ui_hint "Report issue: $VOPK_ISSUES_URL" ;; esac ui_hr printf "%sQuick Fix:%s Try: vopk fix-all\n" "$BOLD$WARNING" "$RESET" } analyze_error() { local error="$1" # AI-powered error classification if [[ "$error" =~ permission|sudo|root|denied ]]; then echo "permission" elif [[ "$error" =~ network|connect|download|timeout|resolve ]]; then echo "network" elif [[ "$error" =~ dependency|depends|require|needs ]]; then echo "dependency" elif [[ "$error" =~ "not found"|"no such"|"unavailable" ]]; then echo "not_found" elif [[ "$error" =~ conflict|conflicting|already|installed ]]; then echo "conflict" elif [[ "$error" =~ "disk"|"space"|"full"|"no space" ]]; then echo "disk_space" else echo "unknown" fi } ############################################################################### # ADVANCED CONFIGURATION WITH YAML/JSON/TOML SUPPORT ############################################################################### load_config() { local config_files=( "/etc/vopk/vopk.conf" "/etc/vopk/config.yaml" "/etc/vopk/config.json" "${VOPK_CONFIG_DIR}/config.conf" "${VOPK_CONFIG_DIR}/config.yaml" "${VOPK_CONFIG_DIR}/config.json" "${VOPK_CONFIG_DIR}/config.toml" "${HOME}/.vopkrc" "${HOME}/.config/vopk/config" ) for config_file in "${config_files[@]}"; do if [[ -f "$config_file" ]]; then debug "Loading configuration from $config_file" parse_config_file "$config_file" fi done # Load profiles load_profiles # Load plugin configurations if [[ "$VOPK_PLUGINS" -eq 1 ]]; then load_plugins fi # Create default config if none exists create_default_config } parse_config_file() { local file="$1" local extension="${file##*.}" case "$extension" in yaml|yml) parse_yaml_config "$file" ;; json) parse_json_config "$file" ;; toml) parse_toml_config "$file" ;; conf) parse_conf_config "$file" ;; *) # Try to detect format parse_auto_config "$file" ;; esac } parse_yaml_config() { local file="$1" # Simplified YAML parsing while IFS= read -r line; do [[ -z "$line" || "$line" =~ ^# ]] && continue if [[ "$line" =~ ^([a-zA-Z_][a-zA-Z0-9_]*):\ *(.*)$ ]]; then local key="${BASH_REMATCH[1]}" local value="${BASH_REMATCH[2]}" # Remove quotes value="${value%\"}" value="${value#\"}" value="${value%\'}" value="${value#\'}" # Set variable export "VOPK_${key^^}"="$value" fi done < "$file" } parse_json_config() { local file="$1" if command -v jq >/dev/null 2>&1; then while IFS= read -r line; do if [[ "$line" =~ \"([a-zA-Z_][a-zA-Z0-9_]*)\":\ *\"?([^\",}]+)\"? ]]; then local key="${BASH_REMATCH[1]}" local value="${BASH_REMATCH[2]}" export "VOPK_${key^^}"="$value" fi done < <(jq -r 'to_entries[] | "\(.key): \(.value)"' "$file" 2>/dev/null || cat "$file") fi } parse_conf_config() { local file="$1" # shellcheck source=/dev/null source "$file" 2>/dev/null || warn "Failed to load $file" } create_default_config() { mkdir -p "${VOPK_CONFIG_DIR}" "${VOPK_CONFIG_DIR}/profiles" "${VOPK_CONFIG_DIR}/plugins" if [[ ! -f "${VOPK_CONFIG_DIR}/config.yaml" ]]; then cat > "${VOPK_CONFIG_DIR}/config.yaml" <<'EOF' # vopk configuration - YAML format # Official: https://github.com/omar9devx/vopk core: assume_yes: false dry_run: false no_color: false debug: false quiet: false parallel: true max_retries: 3 backup: true rollback: true auto_clean: 7 notify: true telemetry: false update_check: true plugins: true theme: "default" animations: true completion: true history: true auto_update: false profile: "default" optimize: true benchmark: false verbose: false shell_integration: true cache: cache_dir: "~/.cache/vopk" cache_ttl: 24 max_cache_size: 1024 compression: true deduplication: true security: security_scan: true verify_signatures: true check_vulnerabilities: true malware_scan: false permission_check: true ai: suggestions: false auto_fix: false learn_preferences: true analyze_errors: true network: timeout: 30 retries: 3 parallel_downloads: 4 bandwidth_limit: 0 proxy: "" repositories: main_only: false include_unstable: false include_testing: false include_snapshots: false custom_repos: [] plugins: enabled: true autoload: true directory: "~/.config/vopk/plugins" profiles: default: description: "Default profile" packages: [] development: description: "Development tools" packages: ["git", "docker", "nodejs", "python3"] gaming: description: "Gaming setup" packages: ["steam", "wine", "lutris"] EOF fi } load_profiles() { local profile_dir="${VOPK_CONFIG_DIR}/profiles" mkdir -p "$profile_dir" for profile_file in "$profile_dir"/*.yaml "$profile_dir"/*.json; do [[ -f "$profile_file" ]] || continue local profile_name="$(basename "$profile_file" .yaml)" profile_name="$(basename "$profile_name" .json)" VOPK_PROFILES["$profile_name"]="$profile_file" done } load_plugins() { local plugin_dir="${VOPK_CONFIG_DIR}/plugins" mkdir -p "$plugin_dir" # Load core plugins load_core_plugins # Load user plugins for plugin in "$plugin_dir"/*.sh; do [[ -f "$plugin" ]] || continue debug "Loading plugin: $(basename "$plugin")" # shellcheck source=/dev/null source "$plugin" done } load_core_plugins() { # AI Plugin if [[ "$VOPK_AI_SUGGEST" -eq 1 ]]; then source_plugin "ai" fi # Security Plugin if [[ "$VOPK_SECURITY_SCAN" -eq 1 ]]; then source_plugin "security" fi # Benchmark Plugin if [[ "$VOPK_BENCHMARK" -eq 1 ]]; then source_plugin "benchmark" fi } source_plugin() { local plugin_name="$1" local plugin_file="$(dirname "${BASH_SOURCE[0]}")/plugins/${plugin_name}.sh" if [[ -f "$plugin_file" ]]; then # shellcheck source=/dev/null source "$plugin_file" fi } ############################################################################### # ENHANCED SHELL INTEGRATION ############################################################################### setup_shell_integration() { [[ "$VOPK_SHELL_INTEGRATION" -eq 0 ]] && return local shell_name="$(basename "$SHELL")" case "$shell_name" in bash) setup_bash_integration ;; zsh) setup_zsh_integration ;; fish) setup_fish_integration ;; *) debug "Shell integration not supported for $shell_name" ;; esac } setup_bash_integration() { local completion_file="/etc/bash_completion.d/vopk" if [[ ! -f "$completion_file" ]] && [[ -w "/etc/bash_completion.d" ]]; then generate_completion "bash" > "$completion_file" log_success "Bash completion installed" fi # Add aliases to bashrc if [[ -w "$HOME/.bashrc" ]]; then if ! grep -q "vopk" "$HOME/.bashrc"; then cat >> "$HOME/.bashrc" <<'EOF' # vopk aliases alias v='vopk' alias vi='vopk install' alias vu='vopk update' alias vup='vopk upgrade' alias vug='vopk full-upgrade' alias vr='vopk remove' alias vs='vopk search' alias vl='vopk list' alias vc='vopk clean' alias vcl='vopk clean --all' alias vd='vopk doctor' alias vf='vopk fix-all' alias vh='vopk --help' alias vv='vopk --version' EOF fi fi } generate_completion() { local shell="${1:-bash}" case "$shell" in bash) cat <<'EOF' # vopk bash completion _vopk() { local cur prev words cword _init_completion || return local commands="update upgrade full-upgrade install remove purge autoremove search list show clean reinstall hold download changelog depends rdepends verify audit fix-dns fix-permissions fix-dependencies fix-broken export import backup restore snapshot rollback install-dev-kit install-build-deps sys-info doctor kernel disk mem top ps ip services logs monitor benchmark history flatpak snap appimage nix conda mamba npm yarn pnpm pip pipx poetry cargo go gem bundle composer dotnet mvn gradle docker podman self-update plugin" local flags="-y --yes -n --dry-run --no-color -d --debug -q --quiet --parallel --no-parallel --retry --cache-dir --config-dir --log-file --no-backup --no-rollback --ai --no-ai --security-scan --no-security --auto-clean --notify --no-notify --telemetry --no-telemetry --update-check --no-update-check --plugins --no-plugins -h --help -v --version --stats --doctor --completion --generate-config --list-backends --list-commands --changelog" case "${prev}" in vopk) COMPREPLY=($(compgen -W "${commands} ${flags}" -- "${cur}")) ;; install|remove|purge|show|search|reinstall|hold|download|depends|rdepends) # Package completion COMPREPLY=($(compgen -W "$(vopk list 2>/dev/null | awk '{print $1}')" -- "${cur}")) ;; --theme) COMPREPLY=($(compgen -W "default dracula nord solarized monokai" -- "${cur}")) ;; --completion) COMPREPLY=($(compgen -W "bash zsh fish" -- "${cur}")) ;; *) COMPREPLY=() ;; esac } complete -F _vopk vopk EOF ;; zsh) cat <<'EOF' #compdef vopk _vopk() { local -a commands=( 'update:Update package databases' 'upgrade:Upgrade packages' 'full-upgrade:Full system upgrade' 'install:Install packages' 'remove:Remove packages' 'purge:Remove packages with configs' 'autoremove:Remove unused packages' 'search:Search for packages' 'list:List installed packages' 'show:Show package info' 'clean:Clean package cache' 'doctor:System health check' 'self-update:Update vopk itself' ) _describe 'command' commands } _vopk EOF ;; esac } ############################################################################### # AI-POWERED PACKAGE RECOMMENDATION SYSTEM ############################################################################### ai_recommend_packages() { [[ "$VOPK_AI_SUGGEST" -eq 0 ]] && return local context="$1" shift local packages=("$@") case "$context" in install) ai_recommend_related_packages "${packages[@]}" ai_suggest_alternatives "${packages[@]}" ai_warn_conflicts "${packages[@]}" ;; search) ai_expand_search_terms "${packages[@]}" ai_suggest_categories "${packages[@]}" ;; update) ai_suggest_security_updates ai_warn_breaking_changes ;; remove) ai_warn_dependencies "${packages[@]}" ai_suggest_alternatives "${packages[@]}" ;; esac } ai_recommend_related_packages() { local packages=("$@") local -A recommendations # Recommendation database declare -A RECOMMENDATION_DB=( ["docker"]="docker-compose docker.io" ["nodejs"]="npm yarn" ["python3"]="python3-pip python3-venv" ["git"]="git-lfs tig" ["vim"]="neovim vim-gtk" ["nginx"]="certbot nginx-extras" ["postgresql"]="postgresql-contrib pgadmin4" ["mysql"]="mysql-client phpmyadmin" ["php"]="php-cli php-fpm composer" ["rust"]="cargo rustc" ["go"]="golang-go golang-golang-x-tools" ["java"]="maven gradle" ["ruby"]="gem bundler" ["dotnet"]="dotnet-sdk" ) for pkg in "${packages[@]}"; do if [[ -n "${RECOMMENDATION_DB[$pkg]}" ]]; then for recommended in ${RECOMMENDATION_DB[$pkg]}; do recommendations["$recommended"]=1 done fi done if [[ ${#recommendations[@]} -gt 0 ]]; then log "You might also like: ${!recommendations[*]}" fi } ai_suggest_alternatives() { local packages=("$@") local -A alternatives declare -A ALTERNATIVE_DB=( ["neovim"]="vim emacs nano" ["firefox"]="chromium brave vivaldi" ["vlc"]="mpv celluloid" ["htop"]="btop glances" ["docker"]="podman containerd" ["postgresql"]="mysql sqlite" ["nginx"]="apache2 caddy" ["systemd"]="openrc runit" ["bash"]="zsh fish" ["python"]="python3" ["node"]="nodejs" ["yarn"]="npm pnpm" ) for pkg in "${packages[@]}"; do if [[ -n "${ALTERNATIVE_DB[$pkg]}" ]]; then for alt in ${ALTERNATIVE_DB[$pkg]}; do alternatives["$alt"]=1 done fi done if [[ ${#alternatives[@]} -gt 0 ]]; then log "Alternative packages: ${!alternatives[*]}" fi } ai_warn_conflicts() { local packages=("$@") declare -A CONFLICT_DB=( ["mysql"]="mariadb" ["mariadb"]="mysql" ["docker"]="docker.io" ["docker.io"]="docker" ["nodejs"]="node" ["node"]="nodejs" ["python"]="python2" ["python2"]="python3" ) for pkg in "${packages[@]}"; do if [[ -n "${CONFLICT_DB[$pkg]}" ]]; then warn "Warning: $pkg may conflict with ${CONFLICT_DB[$pkg]}" fi done } ############################################################################### # ENHANCED PACKAGE MANAGER DETECTION WITH CLOUD AND GAME SUPPORT ############################################################################### detect_all_package_managers() { debug "Starting comprehensive package manager detection..." # Reset arrays DETECTED_MGRS=() PKG_MGR_PRIORITY=() UNIVERSAL_MGRS=() LANGUAGE_MGRS=() CONTAINER_MGRS=() CLOUD_MGRS=() GAME_MGRS=() # Detect primary system package manager detect_primary_pkg_mgr # Detect cloud package managers detect_cloud_managers # Detect game package managers detect_game_managers # Detect universal package managers detect_universal_managers # Detect language-specific package managers detect_language_managers # Detect container package managers detect_container_managers # Build priority list build_priority_list debug "Detection complete. Primary: $PKG_MGR ($PKG_MGR_FAMILY)" debug "Detected ${#DETECTED_MGRS[@]} package managers" } detect_cloud_managers() { # AWS if command -v aws >/dev/null 2>&1; then CLOUD_MGRS[aws]="1" DETECTED_MGRS+=("aws:cloud") fi # Azure if command -v az >/dev/null 2>&1; then CLOUD_MGRS[az]="1" DETECTED_MGRS+=("az:cloud") fi # Google Cloud if command -v gcloud >/dev/null 2>&1; then CLOUD_MGRS[gcloud]="1" DETECTED_MGRS+=("gcloud:cloud") fi # Kubernetes if command -v kubectl >/dev/null 2>&1; then CLOUD_MGRS[kubectl]="1" DETECTED_MGRS+=("kubectl:cloud") fi # Helm if command -v helm >/dev/null 2>&1; then CLOUD_MGRS[helm]="1" DETECTED_MGRS+=("helm:cloud") fi # Terraform if command -v terraform >/dev/null 2>&1; then CLOUD_MGRS[terraform]="1" DETECTED_MGRS+=("terraform:cloud") fi } detect_game_managers() { # Steam if command -v steam >/dev/null 2>&1 || [[ -d "$HOME/.steam" ]]; then GAME_MGRS[steam]="1" DETECTED_MGRS+=("steam:game") fi # Lutris if command -v lutris >/dev/null 2>&1; then GAME_MGRS[lutris]="1" DETECTED_MGRS+=("lutris:game") fi # Wine if command -v wine >/dev/null 2>&1; then GAME_MGRS[wine]="1" DETECTED_MGRS+=("wine:game") fi # GameMode if command -v gamemoded >/dev/null 2>&1; then GAME_MGRS[gamemode]="1" DETECTED_MGRS+=("gamemode:game") fi # Proton if [[ -d "$HOME/.steam/steam/steamapps/common/Proton*" ]] || [[ -d "/usr/share/steam/compatibilitytools.d" ]]; then GAME_MGRS[proton]="1" DETECTED_MGRS+=("proton:game") fi } detect_universal_managers() { # Flatpak if command -v flatpak >/dev/null 2>&1; then UNIVERSAL_MGRS[flatpak]="1" DETECTED_MGRS+=("flatpak:universal") fi # Snap if command -v snap >/dev/null 2>&1; then UNIVERSAL_MGRS[snap]="1" DETECTED_MGRS+=("snap:universal") fi # AppImage if command -v appimaged >/dev/null 2>&1 || ls /usr/bin/*.AppImage 2>/dev/null | head -1; then UNIVERSAL_MGRS[appimage]="1" DETECTED_MGRS+=("appimage:universal") fi # Nix if command -v nix >/dev/null 2>&1 || [[ -f /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh ]]; then UNIVERSAL_MGRS[nix]="1" DETECTED_MGRS+=("nix:universal") fi # Conda/Mamba if command -v conda >/dev/null 2>&1; then UNIVERSAL_MGRS[conda]="1" DETECTED_MGRS+=("conda:universal") fi if command -v mamba >/dev/null 2>&1; then UNIVERSAL_MGRS[mamba]="1" DETECTED_MGRS+=("mamba:universal") fi # Homebrew (Linux) if command -v brew >/dev/null 2>&1 && [[ "$(uname -s)" == "Linux" ]]; then UNIVERSAL_MGRS[brew_linux]="1" DETECTED_MGRS+=("brew_linux:universal") fi # Guix if command -v guix >/dev/null 2>&1; then UNIVERSAL_MGRS[guix]="1" DETECTED_MGRS+=("guix:universal") fi } detect_language_managers() { # Python if command -v pip3 >/dev/null 2>&1; then LANGUAGE_MGRS[pip]="1" DETECTED_MGRS+=("pip3:python") elif command -v pip >/dev/null 2>&1; then LANGUAGE_MGRS[pip]="1" DETECTED_MGRS+=("pip:python") fi if command -v pipx >/dev/null 2>&1; then LANGUAGE_MGRS[pipx]="1" DETECTED_MGRS+=("pipx:python") fi if command -v poetry >/dev/null 2>&1; then LANGUAGE_MGRS[poetry]="1" DETECTED_MGRS+=("poetry:python") fi # Node.js if command -v npm >/dev/null 2>&1; then LANGUAGE_MGRS[npm]="1" DETECTED_MGRS+=("npm:nodejs") fi if command -v yarn >/dev/null 2>&1; then LANGUAGE_MGRS[yarn]="1" DETECTED_MGRS+=("yarn:nodejs") fi if command -v pnpm >/dev/null 2>&1; then LANGUAGE_MGRS[pnpm]="1" DETECTED_MGRS+=("pnpm:nodejs") fi # Rust if command -v cargo >/dev/null 2>&1; then LANGUAGE_MGRS[cargo]="1" DETECTED_MGRS+=("cargo:rust") fi # Go if command -v go >/dev/null 2>&1; then LANGUAGE_MGRS[go]="1" DETECTED_MGRS+=("go:golang") fi # Ruby if command -v gem >/dev/null 2>&1; then LANGUAGE_MGRS[gem]="1" DETECTED_MGRS+=("gem:ruby") fi if command -v bundle >/dev/null 2>&1; then LANGUAGE_MGRS[bundle]="1" DETECTED_MGRS+=("bundle:ruby") fi # PHP if command -v composer >/dev/null 2>&1; then LANGUAGE_MGRS[composer]="1" DETECTED_MGRS+=("composer:php") fi # .NET if command -v dotnet >/dev/null 2>&1; then LANGUAGE_MGRS[dotnet]="1" DETECTED_MGRS+=("dotnet:dotnet") fi # Java if command -v mvn >/dev/null 2>&1; then LANGUAGE_MGRS[mvn]="1" DETECTED_MGRS+=("mvn:java") fi if command -v gradle >/dev/null 2>&1; then LANGUAGE_MGRS[gradle]="1" DETECTED_MGRS+=("gradle:java") fi # Haskell if command -v cabal >/dev/null 2>&1; then LANGUAGE_MGRS[cabal]="1" DETECTED_MGRS+=("cabal:haskell") fi if command -v stack >/dev/null 2>&1; then LANGUAGE_MGRS[stack]="1" DETECTED_MGRS+=("stack:haskell") fi # Perl if command -v cpan >/dev/null 2>&1; then LANGUAGE_MGRS[cpan]="1" DETECTED_MGRS+=("cpan:perl") fi # Lua if command -v luarocks >/dev/null 2>&1; then LANGUAGE_MGRS[luarocks]="1" DETECTED_MGRS+=("luarocks:lua") fi } list_available_backends() { local groups=() [[ -n "$PKG_MGR" ]] && groups+=("System: $PKG_MGR") [[ ${#UNIVERSAL_MGRS[@]} -gt 0 ]] && groups+=("Universal: ${!UNIVERSAL_MGRS[*]}") [[ ${#LANGUAGE_MGRS[@]} -gt 0 ]] && groups+=("Languages: ${!LANGUAGE_MGRS[*]}") [[ ${#CONTAINER_MGRS[@]} -gt 0 ]] && groups+=("Containers: ${!CONTAINER_MGRS[*]}") [[ ${#CLOUD_MGRS[@]} -gt 0 ]] && groups+=("Cloud: ${!CLOUD_MGRS[*]}") [[ ${#GAME_MGRS[@]} -gt 0 ]] && groups+=("Games: ${!GAME_MGRS[*]}") echo "${groups[@]}" } ############################################################################### # ADVANCED COMMANDS WITH NEW FEATURES ############################################################################### cmd_install() { ensure_pkg_mgr if [[ $# -eq 0 ]]; then die "Specify packages to install" fi # AI suggestions ai_recommend_packages "install" "$@" log "Installing packages: $*" log_to_audit "INSTALL" "$*" "STARTED" # Create snapshot for rollback [[ "$VOPK_ROLLBACK" -eq 1 ]] && create_snapshot "before_install_$(date +%s)" local start_time=$(date +%s) local packages=() local flags=() # Parse arguments for arg in "$@"; do case "$arg" in --*) flags+=("$arg") ;; *) packages+=("$arg") ;; esac done # Check package sources local system_packages=() local universal_packages=() local language_packages=() for pkg in "${packages[@]}"; do if check_package_exists "$pkg"; then system_packages+=("$pkg") elif [[ "${UNIVERSAL_MGRS[flatpak]}" == "1" ]] && flatpak_search "$pkg"; then universal_packages+=("$pkg") elif [[ "${LANGUAGE_MGRS[npm]}" == "1" ]] && npm_search "$pkg"; then language_packages+=("$pkg") else warn "Package not found in any repository: $pkg" fi done # Install from different sources local installed_count=0 # Install system packages if [[ ${#system_packages[@]} -gt 0 ]]; then install_system_packages "${system_packages[@]}" installed_count=$((installed_count + ${#system_packages[@]})) fi # Install universal packages if [[ ${#universal_packages[@]} -gt 0 ]]; then install_universal_packages "${universal_packages[@]}" installed_count=$((installed_count + ${#universal_packages[@]})) fi # Install language packages if [[ ${#language_packages[@]} -gt 0 ]]; then install_language_packages "${language_packages[@]}" installed_count=$((installed_count + ${#language_packages[@]})) fi local end_time=$(date +%s) local duration=$((end_time - start_time)) ((VOPK_METRICS[packages]+=installed_count)) ((VOPK_METRICS[operations]++)) VOPK_METRICS[install_time]=$((VOPK_METRICS[install_time] + duration)) log_success "Installed $installed_count packages in $(format_duration $duration)" log_to_audit "INSTALL" "$*" "SUCCESS" # Post-install actions post_install_actions "${packages[@]}" } install_system_packages() { case "${PKG_MGR_FAMILY}" in debian|ubuntu) run_with_privileges "$PKG_MGR" install -y "$@" ;; arch) if [[ -n "$AUR_HELPER" ]]; then install_arch_packages_with_aur "$@" else run_with_privileges pacman -S --noconfirm "$@" fi ;; redhat) run_with_privileges "$PKG_MGR" install -y "$@" ;; suse) run_with_privileges zypper install -y "$@" ;; alpine) run_with_privileges apk add "$@" ;; void) run_with_privileges xbps-install -y "$@" ;; gentoo) run_with_privileges emerge "$@" ;; brew) brew install "$@" ;; freebsd) run_with_privileges pkg install -y "$@" ;; openbsd) run_with_privileges pkg_add "$@" ;; netbsd) run_with_privileges pkgin -y install "$@" ;; vmpkg) vmpkg install "$@" ;; esac } install_universal_packages() { for pkg in "$@"; do if [[ "${UNIVERSAL_MGRS[flatpak]}" == "1" ]] && flatpak_search "$pkg"; then flatpak install "$pkg" elif [[ "${UNIVERSAL_MGRS[snap]}" == "1" ]] && snap_search "$pkg"; then sudo snap install "$pkg" fi done } install_language_packages() { for pkg in "$@"; do if [[ "${LANGUAGE_MGRS[npm]}" == "1" ]] && npm_search "$pkg"; then npm install -g "$pkg" elif [[ "${LANGUAGE_MGRS[pip]}" == "1" ]] && pip_search "$pkg"; then pip3 install "$pkg" elif [[ "${LANGUAGE_MGRS[gem]}" == "1" ]] && gem_search "$pkg"; then gem install "$pkg" elif [[ "${LANGUAGE_MGRS[cargo]}" == "1" ]] && cargo_search "$pkg"; then cargo install "$pkg" fi done } cmd_fix_all() { log "Running comprehensive system fix..." local fixes=( "fix-dns" "fix-permissions" "fix-dependencies" "fix-broken" ) local success_count=0 local total_count=${#fixes[@]} for fix in "${fixes[@]}"; do log_progress "$success_count" "$total_count" "Running $fix..." if vopk "$fix" --quiet; then ((success_count++)) fi done if [[ $success_count -eq $total_count ]]; then log_success "All fixes applied successfully" else warn "$((total_count - success_count)) fixes failed" fi } cmd_profile() { local action="${1:-list}" local profile_name="${2:-}" case "$action" in list) list_profiles ;; create) create_profile "$profile_name" ;; apply) apply_profile "$profile_name" ;; export) export_profile "$profile_name" ;; import) import_profile "$profile_name" ;; delete) delete_profile "$profile_name" ;; *) die "Unknown profile action: $action" ;; esac } list_profiles() { ui_section "Available Profiles" if [[ ${#VOPK_PROFILES[@]} -eq 0 ]]; then echo "No profiles found" return fi for profile in "${!VOPK_PROFILES[@]}"; do echo " • $profile" done echo -e "\nUse: vopk profile apply " } apply_profile() { local profile_name="$1" if [[ -z "$profile_name" ]]; then die "Specify profile name" fi if [[ ! -v VOPK_PROFILES["$profile_name"] ]]; then die "Profile not found: $profile_name" fi local profile_file="${VOPK_PROFILES[$profile_name]}" local packages=() # Load packages from profile if [[ "$profile_file" == *.yaml ]] || [[ "$profile_file" == *.yml ]]; then packages=($(yq -r '.packages[]' "$profile_file" 2>/dev/null || grep -E '^ - ' "$profile_file" | sed 's/^ - //')) elif [[ "$profile_file" == *.json ]]; then packages=($(jq -r '.packages[]' "$profile_file" 2>/dev/null)) else packages=($(grep -v '^#' "$profile_file" | xargs)) fi if [[ ${#packages[@]} -eq 0 ]]; then warn "No packages found in profile" return fi log "Applying profile '$profile_name' with ${#packages[@]} packages" cmd_install "${packages[@]}" } ############################################################################### # NEW ADVANCED FEATURES ############################################################################### cmd_optimize() { log "Optimizing system performance..." # Optimize package manager case "${PKG_MGR_FAMILY}" in debian|ubuntu) run_with_privileges "$PKG_MGR" clean run_with_privileges "$PKG_MGR" autoclean run_with_privileges "$PKG_MGR" autoremove -y ;; arch) run_with_privileges pacman -Scc --noconfirm ;; redhat) run_with_privileges "$PKG_MGR" clean all run_with_privileges "$PKG_MGR" autoremove -y ;; esac # Optimize system optimize_system log_success "System optimization completed" } optimize_system() { # Clear cache sync echo 3 | run_with_privileges tee /proc/sys/vm/drop_caches >/dev/null # Trim SSDs if command -v fstrim >/dev/null 2>&1; then run_with_privileges fstrim -av fi # Optimize databases optimize_databases } optimize_databases() { # SQLite databases find / -name "*.db" -type f 2>/dev/null | head -10 | while read db; do if command -v sqlite3 >/dev/null 2>&1 && [[ -w "$db" ]]; then sqlite3 "$db" "VACUUM;" 2>/dev/null || true fi done } cmd_benchmark() { ui_title "System Benchmark Suite" local benchmarks=( "CPU Benchmark" "Memory Benchmark" "Disk Benchmark" "Network Benchmark" "Package Manager Benchmark" ) local results=() for benchmark in "${benchmarks[@]}"; do log "Running: $benchmark" local result="" case "$benchmark" in "CPU Benchmark") result=$(benchmark_cpu) ;; "Memory Benchmark") result=$(benchmark_memory) ;; "Disk Benchmark") result=$(benchmark_disk) ;; "Network Benchmark") result=$(benchmark_network) ;; "Package Manager Benchmark") result=$(benchmark_package_manager) ;; esac results+=("$benchmark: $result") sleep 1 done ui_section "Benchmark Results" for result in "${results[@]}"; do echo " • $result" done # Save results local benchmark_file="${VOPK_CACHE_DIR}/benchmark-$(date +%Y%m%d).txt" printf "%s\n" "${results[@]}" > "$benchmark_file" log "Results saved to: $benchmark_file" } benchmark_cpu() { local start_time=$(date +%s.%N) local count=0 for i in {1..5000}; do count=$((count + i)) done local end_time=$(date +%s.%N) local duration=$(echo "$end_time - $start_time" | bc) echo "$(printf "%.2f" "$duration")s" } benchmark_disk() { if command -v dd >/dev/null 2>&1; then local temp_file="$(mktemp)" local result=$(dd if=/dev/zero of="$temp_file" bs=1M count=100 conv=fdatasync 2>&1 | tail -1) rm -f "$temp_file" echo "$result" | awk '{print $(NF-1), $NF}' else echo "N/A" fi } cmd_plugin() { local action="${1:-list}" local plugin_name="${2:-}" case "$action" in list) list_plugins ;; install) install_plugin "$plugin_name" ;; remove) remove_plugin "$plugin_name" ;; update) update_plugin "$plugin_name" ;; enable) enable_plugin "$plugin_name" ;; disable) disable_plugin "$plugin_name" ;; *) die "Unknown plugin action: $action" ;; esac } list_plugins() { ui_section "Available Plugins" local plugin_dir="${VOPK_CONFIG_DIR}/plugins" mkdir -p "$plugin_dir" if [[ -z "$(ls -A "$plugin_dir" 2>/dev/null)" ]]; then echo "No plugins installed" echo -e "\nAvailable from: $VOPK_REPO_URL/plugins" return fi for plugin in "$plugin_dir"/*.sh; do [[ -f "$plugin" ]] || continue local name="$(basename "$plugin" .sh)" echo " • $name" done } install_plugin() { local plugin_name="$1" if [[ -z "$plugin_name" ]]; then die "Specify plugin name" fi local plugin_url="$VOPK_REPO_URL/plugins/$plugin_name.sh" local plugin_file="${VOPK_CONFIG_DIR}/plugins/$plugin_name.sh" log "Installing plugin: $plugin_name" if command -v curl >/dev/null 2>&1; then curl -sSL "$plugin_url" -o "$plugin_file" elif command -v wget >/dev/null 2>&1; then wget -q "$plugin_url" -O "$plugin_file" else die "Need curl or wget to install plugins" fi if [[ -f "$plugin_file" ]]; then chmod +x "$plugin_file" log_success "Plugin installed: $plugin_name" else die "Failed to install plugin" fi } ############################################################################### # ENHANCED SELF UPDATE WITH SIGNATURE VERIFICATION ############################################################################### cmd_self_update() { log "Checking for updates..." # Get latest version local latest_version if command -v curl >/dev/null 2>&1; then latest_version=$(curl -sSL "$VOPK_REPO_URL/releases/latest" | grep -o 'v[0-9]\+\.[0-9]\+\.[0-9]\+' | head -1 | tr -d 'v') elif command -v wget >/dev/null 2>&1; then latest_version=$(wget -qO- "$VOPK_REPO_URL/releases/latest" | grep -o 'v[0-9]\+\.[0-9]\+\.[0-9]\+' | head -1 | tr -d 'v') fi if [[ -z "$latest_version" ]]; then warn "Could not check for updates" return 1 fi if [[ "$VOPK_VERSION" == "$latest_version" ]]; then log_success "vopk is up to date ($VOPK_VERSION)" return 0 fi log "New version available: $latest_version (current: $VOPK_VERSION)" if ! vopk_confirm "Update to v$latest_version?"; then return 1 fi # Download update local temp_file="$(mktemp)" local install_path="$(realpath "$0")" log "Downloading vopk $latest_version..." if command -v curl >/dev/null 2>&1; then curl -sSL "$VOPK_REPO_URL/releases/download/v$latest_version/vopk" -o "$temp_file" elif command -v wget >/dev/null 2>&1; then wget -q "$VOPK_REPO_URL/releases/download/v$latest_version/vopk" -O "$temp_file" else die "Need curl or wget to update" fi # Verify signature if [[ "$VOPK_SECURITY_SCAN" -eq 1 ]]; then verify_signature "$temp_file" fi # Backup current version cp "$install_path" "$install_path.backup" # Install new version chmod +x "$temp_file" mv "$temp_file" "$install_path" log_success "vopk updated to version $latest_version" log "Restart vopk to use the new version" } verify_signature() { local file="$1" local sig_url="$VOPK_REPO_URL/releases/download/v$latest_version/vopk.sig" local sig_file="$(mktemp)" if command -v gpg >/dev/null 2>&1; then # Download signature if command -v curl >/dev/null 2>&1; then curl -sSL "$sig_url" -o "$sig_file" else wget -q "$sig_url" -O "$sig_file" fi # Import public key local key_url="$VOPK_REPO_URL/keys/vopk.pub" local key_file="$(mktemp)" if command -v curl >/dev/null 2>&1; then curl -sSL "$key_url" -o "$key_file" else wget -q "$key_url" -O "$key_file" fi gpg --import "$key_file" 2>/dev/null rm -f "$key_file" # Verify signature if gpg --verify "$sig_file" "$file" 2>/dev/null; then log "Signature verified successfully" else warn "Signature verification failed" if ! vopk_confirm "Continue anyway?"; then rm -f "$file" "$sig_file" exit 1 fi fi rm -f "$sig_file" else warn "GPG not installed, skipping signature verification" fi } ############################################################################### # MAIN DISPATCH WITH ALL ENHANCED COMMANDS ############################################################################### main() { # Initialize systems detect_distro load_config init_sudo init_logging apply_color_mode setup_shell_integration # Check for updates if [[ "$VOPK_UPDATE_CHECK" -eq 1 ]] && [[ "$1" != "self-update" ]]; then check_for_updates_async fi # Parse arguments parse_global_flags "$@" set -- "${VOPK_ARGS[@]}" # Handle empty command if [[ $# -eq 0 ]]; then show_help exit 0 fi local cmd="$1" shift || true # Dispatch to appropriate command case "$cmd" in # Core package management update|upd) cmd_update "$@" ;; upgrade|upg|u) cmd_upgrade "$@" ;; full-upgrade|full|fu|dist-upgrade) cmd_full_upgrade "$@" ;; install|i|add) cmd_install "$@" ;; remove|rm|del|uninstall) cmd_remove "$@" ;; purge|prg) cmd_purge "$@" ;; autoremove|auto|ar) cmd_autoremove "$@" ;; search|s|find) cmd_search "$@" ;; list|ls) cmd_list "$@" ;; show|info|si) cmd_show "$@" ;; clean|cln) cmd_clean "$@" ;; # Repository management repos-list|repos) cmd_repos_list "$@" ;; add-repo|repo-add) cmd_add_repo "$@" ;; remove-repo|repo-rm) cmd_remove_repo "$@" ;; enable-repo|repo-enable) cmd_enable_repo "$@" ;; disable-repo|repo-disable) cmd_disable_repo "$@" ;; refresh-repos|repo-refresh) cmd_refresh_repos "$@" ;; # Advanced package operations reinstall|re) cmd_reinstall "$@" ;; hold|unhold) cmd_hold "$@" ;; download|dl) cmd_download "$@" ;; changelog) cmd_changelog "$@" ;; depends|deps) cmd_depends "$@" ;; rdepends|rdeps) cmd_rdepends "$@" ;; verify|integrity) cmd_verify "$@" ;; audit|security) cmd_audit "$@" ;; # System operations fix-dns) cmd_fix_dns "$@" ;; fix-permissions|fix-perms) cmd_fix_permissions "$@" ;; fix-dependencies|fix-deps) cmd_fix_dependencies "$@" ;; fix-broken|repair) cmd_fix_broken "$@" ;; fix-all) cmd_fix_all "$@" ;; # Backup and migration export|export-packages) cmd_export_packages "$@" ;; import|import-packages) cmd_import_packages "$@" ;; backup|backup-packages) cmd_backup_packages "$@" ;; restore|restore-packages) cmd_restore_packages "$@" ;; snapshot) cmd_snapshot "$@" ;; rollback|rb) cmd_rollback "$@" ;; # Development tools install-dev-kit|dev) cmd_install_dev_kit "$@" ;; install-build-deps|build-deps) cmd_install_build_deps "$@" ;; # System information sys-info|sys) cmd_sys_info "$@" ;; doctor|health) cmd_doctor "$@" ;; kernel|uname) cmd_kernel "$@" ;; disk|df) cmd_disk "$@" ;; mem|memory|free) cmd_mem "$@" ;; top|htop) cmd_top "$@" ;; ps|processes) cmd_ps "$@" ;; ip|network) cmd_ip "$@" ;; services|svc) cmd_services "$@" ;; logs|journal) cmd_logs "$@" ;; monitor|dashboard) cmd_monitor "$@" ;; benchmark|bench) cmd_benchmark "$@" ;; history|hist) cmd_history "$@" ;; # Optimization optimize|opt) cmd_optimize "$@" ;; # Profiles profile|prof) cmd_profile "$@" ;; # Universal package managers flatpak|fp) cmd_flatpak "$@" ;; snap) cmd_snap "$@" ;; appimage|app) cmd_appimage "$@" ;; nix) cmd_nix "$@" ;; conda) cmd_conda "$@" ;; mamba) cmd_mamba "$@" ;; # Language package managers npm) cmd_npm "$@" ;; yarn) cmd_yarn "$@" ;; pnpm) cmd_pnpm "$@" ;; pip) cmd_pip "$@" ;; pipx) cmd_pipx "$@" ;; poetry) cmd_poetry "$@" ;; cargo) cmd_cargo "$@" ;; go|golang) cmd_go "$@" ;; gem|rubygems) cmd_gem "$@" ;; bundle) cmd_bundle "$@" ;; composer) cmd_composer "$@" ;; dotnet|nuget) cmd_dotnet "$@" ;; mvn|maven) cmd_mvn "$@" ;; gradle) cmd_gradle "$@" ;; # Container managers docker) cmd_docker "$@" ;; podman) cmd_podman "$@" ;; # Cloud managers aws) cmd_aws "$@" ;; az) cmd_az "$@" ;; gcloud) cmd_gcloud "$@" ;; kubectl|k8s) cmd_kubectl "$@" ;; helm) cmd_helm "$@" ;; terraform|tf) cmd_terraform "$@" ;; # Game managers steam) cmd_steam "$@" ;; lutris) cmd_lutris "$@" ;; wine) cmd_wine "$@" ;; proton) cmd_proton "$@" ;; # Special commands self-update|self-upgrade) cmd_self_update "$@" ;; update-vopk) cmd_self_update "$@" ;; backend|script-v) cmd_script_v "$@" ;; vm|vmpkg) cmd_vmpkg "$@" ;; plugin) cmd_plugin "$@" ;; # Help and information help|-h|--help) show_help ;; -v|--version) show_version ;; commands|list-commands) list_all_commands ;; backends|list-backends) list_all_backends ;; config) show_config ;; stats|metrics) show_metrics "requested" ;; changelog) show_changelog ;; completion) generate_completion "bash" ;; # Aliases up) cmd_update && cmd_upgrade ;; refresh) cmd_update && cmd_upgrade ;; fu) cmd_full_upgrade ;; rm) cmd_remove "$@" ;; ls) cmd_list "$@" ;; i) cmd_install "$@" ;; *) die "Unknown command: $cmd" ;; esac # Show completion metrics show_metrics "completed" } ############################################################################### # ENTRY POINT WITH ENHANCED VALIDATION ############################################################################### # Check bash version if [[ "${BASH_VERSINFO[0]}" -lt 4 ]] || [[ "${BASH_VERSINFO[0]}" -eq 4 && "${BASH_VERSINFO[1]}" -lt 4 ]]; then echo "vopk requires Bash 4.4 or higher" >&2 echo "Current version: $BASH_VERSION" >&2 exit 1 fi # Check for required tools check_requirements() { local missing=() # Core requirements command -v curl >/dev/null 2>&1 || missing+=("curl") command -v wget >/dev/null 2>&1 || missing+=("wget") command -v tar >/dev/null 2>&1 || missing+=("tar") command -v gzip >/dev/null 2>&1 || missing+=("gzip") if [[ ${#missing[@]} -gt 0 ]]; then warn "Missing recommended tools: ${missing[*]}" warn "Some features may not work properly" fi } # Initialize background process array declare -a BACKGROUND_PIDS=() # Check requirements check_requirements # Run main function main "$@"