- GUI and CLI backup/restore functionality - Auto-detection of internal system drive - Smart drive classification (internal vs external) - Reboot integration for clean backups/restores - Portable tools that survive cloning operations - Tool preservation system for external M.2 SSD - Complete disaster recovery workflow - Safety features and multiple confirmations - Desktop integration and launcher scripts - Comprehensive documentation
205 lines
4.8 KiB
Bash
Executable File
205 lines
4.8 KiB
Bash
Executable File
#!/bin/bash
|
|
# Installation script for System Backup Tool
|
|
|
|
set -e
|
|
|
|
# Colors
|
|
RED='\033[0;31m'
|
|
GREEN='\033[0;32m'
|
|
YELLOW='\033[1;33m'
|
|
BLUE='\033[0;34m'
|
|
NC='\033[0m'
|
|
|
|
# Print colored output
|
|
print_status() {
|
|
echo -e "${BLUE}[INFO]${NC} $1"
|
|
}
|
|
|
|
print_success() {
|
|
echo -e "${GREEN}[SUCCESS]${NC} $1"
|
|
}
|
|
|
|
print_warning() {
|
|
echo -e "${YELLOW}[WARNING]${NC} $1"
|
|
}
|
|
|
|
print_error() {
|
|
echo -e "${RED}[ERROR]${NC} $1"
|
|
}
|
|
|
|
# Check if running as root
|
|
check_root() {
|
|
if [[ $EUID -eq 0 ]]; then
|
|
print_error "Do not run this installer as root. It will use sudo when needed."
|
|
exit 1
|
|
fi
|
|
}
|
|
|
|
# Check dependencies
|
|
check_dependencies() {
|
|
print_status "Checking dependencies..."
|
|
|
|
# Check Python 3
|
|
if ! command -v python3 &> /dev/null; then
|
|
print_error "Python 3 is required but not installed"
|
|
exit 1
|
|
fi
|
|
|
|
# Check tkinter
|
|
if ! python3 -c "import tkinter" &> /dev/null; then
|
|
print_warning "tkinter not available. Installing python3-tk..."
|
|
sudo apt update
|
|
sudo apt install -y python3-tk
|
|
fi
|
|
|
|
# Check for pv (progress viewer)
|
|
if ! command -v pv &> /dev/null; then
|
|
print_warning "pv (progress viewer) not found. Installing..."
|
|
sudo apt install -y pv
|
|
fi
|
|
|
|
print_success "All dependencies satisfied"
|
|
}
|
|
|
|
# Make scripts executable
|
|
setup_permissions() {
|
|
print_status "Setting up permissions..."
|
|
|
|
chmod +x backup_manager.py
|
|
chmod +x backup_script.sh
|
|
|
|
print_success "Permissions set"
|
|
}
|
|
|
|
# Create desktop entry
|
|
create_desktop_entry() {
|
|
print_status "Creating desktop entry..."
|
|
|
|
local desktop_dir="$HOME/Desktop"
|
|
local applications_dir="$HOME/.local/share/applications"
|
|
local script_path=$(realpath backup_manager.py)
|
|
local icon_path=$(realpath ".")
|
|
|
|
# Create applications directory if it doesn't exist
|
|
mkdir -p "$applications_dir"
|
|
|
|
# Create desktop entry content
|
|
local desktop_content="[Desktop Entry]
|
|
Version=1.0
|
|
Type=Application
|
|
Name=System Backup Manager
|
|
Comment=Clone internal drive to external M.2 SSD
|
|
Exec=python3 '$script_path'
|
|
Icon=drive-harddisk
|
|
Terminal=false
|
|
Categories=System;Utility;
|
|
StartupNotify=true"
|
|
|
|
# Create desktop file in applications
|
|
echo "$desktop_content" > "$applications_dir/system-backup.desktop"
|
|
chmod +x "$applications_dir/system-backup.desktop"
|
|
|
|
# Create desktop shortcut if Desktop directory exists
|
|
if [[ -d "$desktop_dir" ]]; then
|
|
echo "$desktop_content" > "$desktop_dir/System Backup.desktop"
|
|
chmod +x "$desktop_dir/System Backup.desktop"
|
|
print_success "Desktop shortcut created"
|
|
fi
|
|
|
|
print_success "Application entry created"
|
|
}
|
|
|
|
# Create systemd service (optional)
|
|
create_systemd_service() {
|
|
local service_dir="systemd"
|
|
local script_path=$(realpath backup_script.sh)
|
|
|
|
print_status "Creating systemd service template..."
|
|
|
|
mkdir -p "$service_dir"
|
|
|
|
cat > "$service_dir/backup-service.service" << EOF
|
|
[Unit]
|
|
Description=System Backup Service
|
|
After=multi-user.target
|
|
|
|
[Service]
|
|
Type=oneshot
|
|
ExecStart=$script_path --target /dev/sdb
|
|
User=root
|
|
StandardOutput=journal
|
|
StandardError=journal
|
|
|
|
[Install]
|
|
WantedBy=multi-user.target
|
|
EOF
|
|
|
|
cat > "$service_dir/README.md" << EOF
|
|
# Systemd Service for Backup
|
|
|
|
To install the systemd service:
|
|
|
|
1. Edit the service file to specify your target drive
|
|
2. Copy to systemd directory:
|
|
\`\`\`bash
|
|
sudo cp backup-service.service /etc/systemd/system/
|
|
\`\`\`
|
|
|
|
3. Enable and start:
|
|
\`\`\`bash
|
|
sudo systemctl daemon-reload
|
|
sudo systemctl enable backup-service
|
|
sudo systemctl start backup-service
|
|
\`\`\`
|
|
|
|
4. Check status:
|
|
\`\`\`bash
|
|
sudo systemctl status backup-service
|
|
\`\`\`
|
|
EOF
|
|
|
|
print_success "Systemd service template created in systemd/"
|
|
}
|
|
|
|
# Create log directory
|
|
setup_logging() {
|
|
print_status "Setting up logging..."
|
|
|
|
# Create log file with proper permissions
|
|
sudo touch /var/log/system_backup.log
|
|
sudo chmod 666 /var/log/system_backup.log
|
|
|
|
print_success "Log file created: /var/log/system_backup.log"
|
|
}
|
|
|
|
# Main installation function
|
|
main() {
|
|
echo ""
|
|
echo "======================================"
|
|
echo " System Backup Tool Installer"
|
|
echo "======================================"
|
|
echo ""
|
|
|
|
check_root
|
|
check_dependencies
|
|
setup_permissions
|
|
setup_logging
|
|
create_desktop_entry
|
|
create_systemd_service
|
|
|
|
echo ""
|
|
print_success "Installation completed successfully!"
|
|
echo ""
|
|
echo "You can now:"
|
|
echo " • Launch GUI: python3 backup_manager.py"
|
|
echo " • Use CLI: ./backup_script.sh --help"
|
|
echo " • Click desktop icon: System Backup Manager"
|
|
echo ""
|
|
print_warning "Remember to run the backup tool with appropriate privileges"
|
|
print_warning "Always verify your drive selections before starting backup"
|
|
echo ""
|
|
}
|
|
|
|
# Run installer
|
|
main "$@"
|