193 lines
4.9 KiB
Bash
Executable File
193 lines
4.9 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# CMtec Universal Update System v3.0.0
|
|
# Main entry point for cross-platform system updates
|
|
|
|
set -e
|
|
|
|
# Get script directory
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
|
|
# Parse command line arguments
|
|
INTERACTIVE=false
|
|
HELP=false
|
|
|
|
while [[ $# -gt 0 ]]; do
|
|
case $1 in
|
|
-i|--interactive)
|
|
INTERACTIVE=true
|
|
shift
|
|
;;
|
|
-h|--help)
|
|
HELP=true
|
|
shift
|
|
;;
|
|
*)
|
|
echo "Unknown option: $1"
|
|
echo "Usage: $0 [-i|--interactive] [-h|--help]"
|
|
exit 1
|
|
;;
|
|
esac
|
|
done
|
|
|
|
if [ "$HELP" == "true" ]; then
|
|
echo "CMtec Universal Update System v3.0.0"
|
|
echo ""
|
|
echo "Usage: $0 [OPTIONS]"
|
|
echo ""
|
|
echo "OPTIONS:"
|
|
echo " -i, --interactive Enable interactive mode with confirmations"
|
|
echo " -h, --help Show this help message"
|
|
echo ""
|
|
echo "This script automatically detects your Linux distribution and applies"
|
|
echo "appropriate updates and software installations based on system roles."
|
|
exit 0
|
|
fi
|
|
|
|
# Source all library files
|
|
source "$SCRIPT_DIR/lib/core.sh"
|
|
source "$SCRIPT_DIR/lib/detect.sh"
|
|
source "$SCRIPT_DIR/lib/roles.sh"
|
|
source "$SCRIPT_DIR/lib/packages.sh"
|
|
|
|
# Initialize core system
|
|
init_core
|
|
|
|
# Ensure sudo access
|
|
sudo -v
|
|
|
|
# Detect system and hardware
|
|
detect_system
|
|
detect_hardware
|
|
|
|
# Show fancy distro-specific header
|
|
case "${SYSTEM_INFO[DISTRO]}" in
|
|
"arch")
|
|
show_arch_header "${SYSTEM_INFO[HOSTNAME]}"
|
|
;;
|
|
"ubuntu"|"debian")
|
|
show_ubuntu_header "${SYSTEM_INFO[HOSTNAME]}"
|
|
;;
|
|
*)
|
|
show_header "${SYSTEM_INFO[HOSTNAME]}" "${SYSTEM_INFO[PRETTY_NAME]}"
|
|
;;
|
|
esac
|
|
|
|
# Load and configure roles
|
|
load_roles
|
|
|
|
# Show system configuration
|
|
show_roles
|
|
|
|
# Run system health check
|
|
system_health_check
|
|
|
|
# Interactive confirmation
|
|
if [ "$INTERACTIVE" == "true" ]; then
|
|
if ! confirm "Proceed with system update?"; then
|
|
log INFO "Update cancelled by user"
|
|
exit 0
|
|
fi
|
|
interactive_role_selection
|
|
fi
|
|
|
|
echo -e "${GREEN}${CHECK} Starting update process...${RESET}\n"
|
|
|
|
# Initialize package managers
|
|
init_package_managers
|
|
setup_package_managers
|
|
|
|
# Create backup if timeshift is available
|
|
if package_installed timeshift; then
|
|
section_start=$(date +%s)
|
|
log SECTION "Creating system snapshot"
|
|
if confirm "Create Timeshift snapshot before update?"; then
|
|
(
|
|
sudo timeshift --create --comments "Universal update script $(date '+%Y-%m-%d %H:%M:%S')" 2>&1 | tee -a "$LOG_FILE"
|
|
) &
|
|
spinner $! "Creating system snapshot..."
|
|
wait
|
|
log SUCCESS "System snapshot created $(show_timer $section_start)"
|
|
else
|
|
log WARNING "System snapshot skipped"
|
|
fi
|
|
else
|
|
log WARNING "Timeshift not installed - no system snapshot created"
|
|
fi
|
|
|
|
# Update package databases and perform system upgrade
|
|
update_package_databases
|
|
system_upgrade
|
|
|
|
# Update AUR packages (Arch only)
|
|
if [ "$PACKAGE_MANAGER" == "pacman" ]; then
|
|
update_aur_packages
|
|
fi
|
|
|
|
# Update Flatpak and Snap packages
|
|
update_flatpak_apps
|
|
[ "$PACKAGE_MANAGER" == "apt" ] && update_snap_packages
|
|
|
|
# Install basic system packages
|
|
log SECTION "Installing essential system packages"
|
|
case "${SYSTEM_INFO[DISTRO]}" in
|
|
"arch")
|
|
install_packages base-devel linux-headers git bc cmake gawk wget gettext unzip curl inetutils python python-pip python-pipx rustup
|
|
;;
|
|
"ubuntu"|"debian")
|
|
install_packages build-essential git gawk imagemagick gpg ninja-build gettext cmake unzip curl libssl-dev libffi-dev file libudev-dev pkg-config locales btop ncdu ranger timeshift
|
|
;;
|
|
esac
|
|
|
|
# Create symbolic links for configuration files
|
|
log SECTION "Setting up configuration links"
|
|
mkdir -p ~/.local/bin ~/.config
|
|
|
|
# Link bash configuration
|
|
case "${SYSTEM_INFO[DISTRO]}" in
|
|
"arch")
|
|
ln -sf ~/linuxbox/bashrc_arch ~/.bashrc
|
|
;;
|
|
"ubuntu"|"debian")
|
|
if [ "${SYSTEM_INFO[WSL]}" == "yes" ]; then
|
|
ln -sf ~/linuxbox/bashrc_ubuntu ~/.bashrc
|
|
ln -sf ~/linuxbox/gitconfig.work ~/.gitconfig
|
|
else
|
|
ln -sf ~/linuxbox/bashrc_ubuntu ~/.bashrc
|
|
ln -sf ~/linuxbox/gitconfig ~/.gitconfig
|
|
fi
|
|
;;
|
|
esac
|
|
|
|
# Link common configuration files
|
|
ln -sf ~/linuxbox/update_wrapper.sh ~/.local/bin/update
|
|
|
|
# Set locale
|
|
case "${SYSTEM_INFO[DISTRO]}" in
|
|
"arch")
|
|
sudo localectl set-locale LANG=en_US.UTF-8
|
|
;;
|
|
"ubuntu"|"debian")
|
|
sudo locale-gen "en_US.UTF-8" || true
|
|
sudo update-locale LANG=en_US.UTF-8 || true
|
|
;;
|
|
esac
|
|
|
|
# Load and run distro-specific installation
|
|
case "${SYSTEM_INFO[DISTRO]}" in
|
|
"arch")
|
|
source "$SCRIPT_DIR/arch/arch.sh"
|
|
arch_install_all
|
|
;;
|
|
"ubuntu"|"debian")
|
|
source "$SCRIPT_DIR/ubuntu/ubuntu.sh"
|
|
ubuntu_install_all
|
|
;;
|
|
*)
|
|
log ERROR "Unsupported distribution: ${SYSTEM_INFO[DISTRO]}"
|
|
exit 1
|
|
;;
|
|
esac
|
|
|
|
# Final summary and reboot prompt
|
|
show_final_summary |