235 lines
No EOL
6.5 KiB
Bash
235 lines
No EOL
6.5 KiB
Bash
#!/bin/bash
|
|
|
|
# Particle-OS Installation Script
|
|
# Installs all Particle-OS tools to /usr/local/bin/ with standardized names
|
|
|
|
set -euo pipefail
|
|
|
|
# Colors for output
|
|
RED='\033[0;31m'
|
|
GREEN='\033[0;32m'
|
|
YELLOW='\033[1;33m'
|
|
BLUE='\033[0;34m'
|
|
NC='\033[0m' # No Color
|
|
|
|
# Installation paths
|
|
INSTALL_DIR="/usr/local/bin"
|
|
CONFIG_DIR="/usr/local/etc"
|
|
|
|
# Script mappings (source -> destination)
|
|
declare -A SCRIPTS=(
|
|
["apt-layer.sh"]="apt-layer"
|
|
["composefs-alternative.sh"]="composefs"
|
|
["bootc-alternative.sh"]="bootc"
|
|
["bootupd-alternative.sh"]="bootupd"
|
|
["../orchestrator/orchestrator.sh"]="particle-orchestrator"
|
|
["oci-integration.sh"]="particle-oci"
|
|
["particle-logrotate.sh"]="particle-logrotate"
|
|
)
|
|
|
|
# Function to print colored output
|
|
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"
|
|
}
|
|
|
|
# Function to check if running as root
|
|
check_root() {
|
|
if [[ $EUID -ne 0 ]]; then
|
|
log_error "This script must be run as root (use sudo)"
|
|
exit 1
|
|
fi
|
|
}
|
|
|
|
# Function to check if source scripts exist
|
|
check_source_scripts() {
|
|
log_info "Checking for source scripts..."
|
|
local missing=()
|
|
|
|
for source_script in "${!SCRIPTS[@]}"; do
|
|
if [[ ! -f "$source_script" ]]; then
|
|
missing+=("$source_script")
|
|
fi
|
|
done
|
|
|
|
if [[ ${#missing[@]} -gt 0 ]]; then
|
|
log_error "Missing source scripts: ${missing[*]}"
|
|
log_error "Please run this script from the Particle-OS tools directory"
|
|
exit 1
|
|
fi
|
|
|
|
log_success "All source scripts found"
|
|
}
|
|
|
|
# Function to backup existing installations
|
|
backup_existing() {
|
|
log_info "Checking for existing installations..."
|
|
local backed_up=()
|
|
|
|
for dest_name in "${SCRIPTS[@]}"; do
|
|
local dest_path="$INSTALL_DIR/$dest_name"
|
|
if [[ -f "$dest_path" ]]; then
|
|
local backup_path="$dest_path.backup.$(date +%Y%m%d_%H%M%S)"
|
|
log_warning "Backing up existing $dest_name to $backup_path"
|
|
cp "$dest_path" "$backup_path"
|
|
backed_up+=("$dest_name -> $backup_path")
|
|
fi
|
|
done
|
|
|
|
if [[ ${#backed_up[@]} -gt 0 ]]; then
|
|
log_info "Backed up existing installations:"
|
|
for backup in "${backed_up[@]}"; do
|
|
echo " $backup"
|
|
done
|
|
fi
|
|
}
|
|
|
|
# Function to install scripts
|
|
install_scripts() {
|
|
log_info "Installing Particle-OS tools to $INSTALL_DIR..."
|
|
|
|
for source_script in "${!SCRIPTS[@]}"; do
|
|
local dest_name="${SCRIPTS[$source_script]}"
|
|
local dest_path="$INSTALL_DIR/$dest_name"
|
|
|
|
log_info "Installing $source_script as $dest_name..."
|
|
|
|
# Copy script
|
|
cp "$source_script" "$dest_path"
|
|
|
|
# Make executable
|
|
chmod +x "$dest_path"
|
|
|
|
# Set ownership to root:root
|
|
chown root:root "$dest_path"
|
|
|
|
log_success "Installed $dest_name"
|
|
done
|
|
}
|
|
|
|
# Function to create configuration directory
|
|
create_config_dir() {
|
|
log_info "Creating configuration directory..."
|
|
mkdir -p "$CONFIG_DIR"
|
|
log_success "Configuration directory ready: $CONFIG_DIR"
|
|
}
|
|
|
|
# Function to install configuration file
|
|
install_config() {
|
|
if [[ -f "particle-config.sh" ]]; then
|
|
log_info "Installing configuration file..."
|
|
cp "particle-config.sh" "$CONFIG_DIR/"
|
|
chmod 644 "$CONFIG_DIR/particle-config.sh"
|
|
chown root:root "$CONFIG_DIR/particle-config.sh"
|
|
log_success "Configuration installed to $CONFIG_DIR/particle-config.sh"
|
|
else
|
|
log_warning "particle-config.sh not found - skipping configuration installation"
|
|
fi
|
|
}
|
|
|
|
# Function to verify installation
|
|
verify_installation() {
|
|
log_info "Verifying installation..."
|
|
local issues=()
|
|
|
|
for dest_name in "${SCRIPTS[@]}"; do
|
|
local dest_path="$INSTALL_DIR/$dest_name"
|
|
|
|
if [[ ! -f "$dest_path" ]]; then
|
|
issues+=("$dest_name not found at $dest_path")
|
|
elif [[ ! -x "$dest_path" ]]; then
|
|
issues+=("$dest_name not executable at $dest_path")
|
|
fi
|
|
done
|
|
|
|
if [[ ${#issues[@]} -gt 0 ]]; then
|
|
log_error "Installation verification failed:"
|
|
for issue in "${issues[@]}"; do
|
|
echo " $issue"
|
|
done
|
|
exit 1
|
|
fi
|
|
|
|
log_success "Installation verification passed"
|
|
}
|
|
|
|
# Function to show installation summary
|
|
show_summary() {
|
|
echo
|
|
log_success "Particle-OS installation completed successfully!"
|
|
echo
|
|
echo "Installed tools:"
|
|
for dest_name in "${SCRIPTS[@]}"; do
|
|
echo " $dest_name -> $INSTALL_DIR/$dest_name"
|
|
done
|
|
echo
|
|
echo "Available commands:"
|
|
echo " apt-layer - Package layer management"
|
|
echo " composefs - ComposeFS image management"
|
|
echo " bootc - Bootable container management"
|
|
echo " bootupd - Bootloader management"
|
|
echo " particle-orchestrator - System orchestration"
|
|
echo " particle-oci - OCI integration"
|
|
echo " particle-logrotate - Log rotation management"
|
|
echo
|
|
echo "Next steps:"
|
|
echo " 1. Run 'sudo apt-layer --init' to initialize the system"
|
|
echo " 2. Run 'particle-orchestrator help' to see available commands"
|
|
echo " 3. Check the documentation for usage examples"
|
|
echo
|
|
}
|
|
|
|
# Function to show uninstall information
|
|
show_uninstall_info() {
|
|
echo
|
|
log_info "To uninstall Particle-OS tools:"
|
|
echo " sudo rm -f $INSTALL_DIR/apt-layer"
|
|
echo " sudo rm -f $INSTALL_DIR/composefs"
|
|
echo " sudo rm -f $INSTALL_DIR/bootc"
|
|
echo " sudo rm -f $INSTALL_DIR/bootupd"
|
|
echo " sudo rm -f $INSTALL_DIR/particle-orchestrator"
|
|
echo " sudo rm -f $INSTALL_DIR/particle-oci"
|
|
echo " sudo rm -f $INSTALL_DIR/particle-logrotate"
|
|
echo " sudo rm -f $CONFIG_DIR/particle-config.sh"
|
|
echo
|
|
}
|
|
|
|
# Main installation function
|
|
main() {
|
|
echo "Particle-OS Installation Script"
|
|
echo "================================"
|
|
echo
|
|
|
|
check_root
|
|
check_source_scripts
|
|
backup_existing
|
|
install_scripts
|
|
create_config_dir
|
|
install_config
|
|
verify_installation
|
|
|
|
# Initialize Particle-OS system
|
|
log_info "Initializing Particle-OS system..."
|
|
if sudo apt-layer --init; then
|
|
log_success "✓ Particle-OS system initialized"
|
|
else
|
|
log_warning "System initialization failed, but tools are installed"
|
|
fi
|
|
|
|
show_summary
|
|
show_uninstall_info
|
|
}
|
|
|
|
# Run main function
|
|
main "$@" |