- Added support for Debian 14 (Forky) testing release - Created examples for both Debian 13 (Trixie) and Debian 14 (Forky) - Added comprehensive multi-version documentation - Created automated version switching script with backup/restore - Updated README with version-specific configuration examples - Added migration guidance between Debian versions This enables users to build images for both stable (Trixie) and testing (Forky) releases with easy switching between versions.
270 lines
7.3 KiB
Bash
Executable file
270 lines
7.3 KiB
Bash
Executable file
#!/bin/bash
|
|
|
|
# particle-os Debian Version Switcher
|
|
# This script helps you switch between different Debian versions in your manifests
|
|
|
|
set -e
|
|
|
|
# Colors for output
|
|
RED='\033[0;31m'
|
|
GREEN='\033[0;32m'
|
|
YELLOW='\033[1;33m'
|
|
BLUE='\033[0;34m'
|
|
NC='\033[0m' # No Color
|
|
|
|
# Function to print colored output
|
|
print_status() {
|
|
echo -e "${GREEN}[INFO]${NC} $1"
|
|
}
|
|
|
|
print_warning() {
|
|
echo -e "${YELLOW}[WARNING]${NC} $1"
|
|
}
|
|
|
|
print_error() {
|
|
echo -e "${RED}[ERROR]${NC} $1"
|
|
}
|
|
|
|
print_header() {
|
|
echo -e "${BLUE}=== $1 ===${NC}"
|
|
}
|
|
|
|
# Function to show usage
|
|
show_usage() {
|
|
cat << EOF
|
|
Usage: $0 [OPTIONS] <manifest-file>
|
|
|
|
Options:
|
|
-v, --version <version> Debian version to switch to (trixie, forky)
|
|
-b, --backup Create backup of original manifest
|
|
-r, --restore Restore from backup
|
|
-l, --list List supported Debian versions
|
|
-h, --help Show this help message
|
|
|
|
Examples:
|
|
$0 -v forky examples/debian-basic.json
|
|
$0 -v trixie examples/debian-forky-basic.json
|
|
$0 -b -v forky examples/debian-basic.json
|
|
$0 -r examples/debian-basic.json
|
|
|
|
Supported Debian Versions:
|
|
trixie - Debian 13 (current stable)
|
|
forky - Debian 14 (testing, future stable)
|
|
EOF
|
|
}
|
|
|
|
# Function to list supported versions
|
|
list_versions() {
|
|
cat << EOF
|
|
Supported Debian Versions:
|
|
|
|
1. trixie (Debian 13)
|
|
- Status: Current stable release
|
|
- Use case: Production deployments
|
|
- Security: Regular security patches
|
|
- Example: examples/debian-basic.json
|
|
|
|
2. forky (Debian 14)
|
|
- Status: Testing release
|
|
- Use case: Development and testing
|
|
- Security: Security patches from unstable
|
|
- Example: examples/debian-forky-basic.json
|
|
|
|
Version Mapping:
|
|
trixie -> Debian 13 (stable)
|
|
forky -> Debian 14 (testing)
|
|
EOF
|
|
}
|
|
|
|
# Function to backup manifest
|
|
backup_manifest() {
|
|
local manifest_file="$1"
|
|
local backup_file="${manifest_file}.backup.$(date +%Y%m%d_%H%M%S)"
|
|
|
|
if cp "$manifest_file" "$backup_file"; then
|
|
print_status "Backup created: $backup_file"
|
|
echo "$backup_file" > "${manifest_file}.backup"
|
|
else
|
|
print_error "Failed to create backup"
|
|
exit 1
|
|
fi
|
|
}
|
|
|
|
# Function to restore from backup
|
|
restore_manifest() {
|
|
local manifest_file="$1"
|
|
local backup_file
|
|
|
|
if [[ -f "${manifest_file}.backup" ]]; then
|
|
backup_file=$(cat "${manifest_file}.backup")
|
|
if [[ -f "$backup_file" ]]; then
|
|
if cp "$backup_file" "$manifest_file"; then
|
|
print_status "Restored from backup: $backup_file"
|
|
rm "${manifest_file}.backup"
|
|
else
|
|
print_error "Failed to restore from backup"
|
|
exit 1
|
|
fi
|
|
else
|
|
print_error "Backup file not found: $backup_file"
|
|
exit 1
|
|
fi
|
|
else
|
|
print_error "No backup found for: $manifest_file"
|
|
exit 1
|
|
fi
|
|
}
|
|
|
|
# Function to switch Debian version
|
|
switch_version() {
|
|
local manifest_file="$1"
|
|
local target_version="$2"
|
|
|
|
# Validate target version
|
|
case "$target_version" in
|
|
trixie|forky)
|
|
;;
|
|
*)
|
|
print_error "Unsupported Debian version: $target_version"
|
|
print_error "Supported versions: trixie, forky"
|
|
exit 1
|
|
;;
|
|
esac
|
|
|
|
# Check if manifest file exists
|
|
if [[ ! -f "$manifest_file" ]]; then
|
|
print_error "Manifest file not found: $manifest_file"
|
|
exit 1
|
|
fi
|
|
|
|
# Create backup if requested
|
|
if [[ "$CREATE_BACKUP" == "true" ]]; then
|
|
backup_manifest "$manifest_file"
|
|
fi
|
|
|
|
# Determine source version from current manifest
|
|
local current_version
|
|
current_version=$(grep -o '"suite": *"[^"]*"' "$manifest_file" | head -1 | cut -d'"' -f4)
|
|
|
|
if [[ -z "$current_version" ]]; then
|
|
print_warning "Could not determine current Debian version from manifest"
|
|
print_warning "Proceeding with version switch..."
|
|
else
|
|
print_status "Current Debian version: $current_version"
|
|
fi
|
|
|
|
print_status "Switching to Debian version: $target_version"
|
|
|
|
# Update suite references
|
|
sed -i "s/\"suite\": \"[^\"]*\"/\"suite\": \"$target_version\"/g" "$manifest_file"
|
|
|
|
# Update security sources
|
|
sed -i "s/debian-security [a-z]*-security/debian-security ${target_version}-security/g" "$manifest_file"
|
|
|
|
# Update update sources
|
|
sed -i "s/debian-updates [a-z]*-updates/debian-updates ${target_version}-updates/g" "$manifest_file"
|
|
|
|
# Update OSTree branch names
|
|
sed -i "s/debian\/[a-z]*\/x86_64/debian\/${target_version}\/x86_64/g" "$manifest_file"
|
|
|
|
# Update subject lines
|
|
sed -i "s/Debian [A-Za-z]* OSTree/Debian ${target_version^} OSTree/g" "$manifest_file"
|
|
sed -i "s/Debian [A-Za-z]* System/Debian ${target_version^} System/g" "$manifest_file"
|
|
|
|
# Update filename if it contains version
|
|
if grep -q "debian-[a-z]*-ostree" "$manifest_file"; then
|
|
sed -i "s/debian-[a-z]*-ostree/debian-${target_version}-ostree/g" "$manifest_file"
|
|
fi
|
|
|
|
print_status "Successfully switched to Debian $target_version"
|
|
print_status "Manifest updated: $manifest_file"
|
|
|
|
# Show summary of changes
|
|
echo
|
|
print_header "Summary of Changes"
|
|
echo "Suite: $target_version"
|
|
echo "Security sources: ${target_version}-security"
|
|
echo "Update sources: ${target_version}-updates"
|
|
echo "OSTree branch: debian/${target_version}/x86_64"
|
|
echo "Subject: Debian ${target_version^} OSTree System"
|
|
}
|
|
|
|
# Main script logic
|
|
main() {
|
|
local manifest_file=""
|
|
local target_version=""
|
|
local CREATE_BACKUP="false"
|
|
local RESTORE_BACKUP="false"
|
|
local LIST_VERSIONS="false"
|
|
|
|
# Parse command line arguments
|
|
while [[ $# -gt 0 ]]; do
|
|
case $1 in
|
|
-v|--version)
|
|
target_version="$2"
|
|
shift 2
|
|
;;
|
|
-b|--backup)
|
|
CREATE_BACKUP="true"
|
|
shift
|
|
;;
|
|
-r|--restore)
|
|
RESTORE_BACKUP="true"
|
|
shift
|
|
;;
|
|
-l|--list)
|
|
LIST_VERSIONS="true"
|
|
shift
|
|
;;
|
|
-h|--help)
|
|
show_usage
|
|
exit 0
|
|
;;
|
|
-*)
|
|
print_error "Unknown option: $1"
|
|
show_usage
|
|
exit 1
|
|
;;
|
|
*)
|
|
manifest_file="$1"
|
|
shift
|
|
;;
|
|
esac
|
|
done
|
|
|
|
# Handle list versions
|
|
if [[ "$LIST_VERSIONS" == "true" ]]; then
|
|
list_versions
|
|
exit 0
|
|
fi
|
|
|
|
# Handle restore
|
|
if [[ "$RESTORE_BACKUP" == "true" ]]; then
|
|
if [[ -z "$manifest_file" ]]; then
|
|
print_error "Manifest file required for restore operation"
|
|
show_usage
|
|
exit 1
|
|
fi
|
|
restore_manifest "$manifest_file"
|
|
exit 0
|
|
fi
|
|
|
|
# Validate required arguments
|
|
if [[ -z "$target_version" ]]; then
|
|
print_error "Target Debian version is required"
|
|
show_usage
|
|
exit 1
|
|
fi
|
|
|
|
if [[ -z "$manifest_file" ]]; then
|
|
print_error "Manifest file is required"
|
|
show_usage
|
|
exit 1
|
|
fi
|
|
|
|
# Perform version switch
|
|
switch_version "$manifest_file" "$target_version"
|
|
}
|
|
|
|
# Run main function with all arguments
|
|
main "$@"
|