fixed paths, created ci/cd workflow
Some checks failed
Compile apt-layer / compile (push) Failing after 2s
Some checks failed
Compile apt-layer / compile (push) Failing after 2s
This commit is contained in:
parent
14d7da71e8
commit
29b9675689
26 changed files with 7407 additions and 358 deletions
|
|
@ -1,12 +1,34 @@
|
|||
# Particle-OS apt-layer Tool - Changelog
|
||||
# apt-layer Tool - Changelog
|
||||
|
||||
All notable changes to the Particle-OS apt-layer Tool modular system will be documented in this file.
|
||||
All notable changes to the apt-layer Tool modular system will be documented in this file.
|
||||
|
||||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
||||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||
|
||||
## [Unreleased]
|
||||
|
||||
### [2025-07-14 UTC] - NAMING STANDARDIZATION: REMOVED ALL PARTICLE-OS/UBLUE REFERENCES FROM PATHS
|
||||
- **Complete path naming standardization**: Removed all references to "particle-os", "particle", "ublue", and "ucore" from path names throughout the entire codebase.
|
||||
- **Consistent apt-layer naming**: All persistent and runtime paths now use only "apt-layer" naming:
|
||||
- `/var/lib/apt-layer/` (was `/var/lib/particle-os/`)
|
||||
- `/var/log/apt-layer/` (was `/var/log/particle-os/`)
|
||||
- `/var/cache/apt-layer/` (was `/var/cache/particle-os/`)
|
||||
- `/usr/local/etc/apt-layer/` (was `/usr/local/etc/particle-os/`)
|
||||
- **Environment variable updates**: All environment variables updated to use `APT_LAYER_` prefix:
|
||||
- `APT_LAYER_WORKSPACE` (was `PARTICLE_WORKSPACE`)
|
||||
- `APT_LAYER_LOG_DIR` (was `PARTICLE_LOG_DIR`)
|
||||
- `APT_LAYER_CACHE_DIR` (was `PARTICLE_CACHE_DIR`)
|
||||
- **Configuration system updates**: Updated `paths.json` configuration to use `apt_layer_paths` key and consistent naming.
|
||||
- **Function naming updates**: All system functions updated to use apt-layer naming:
|
||||
- `initialize_apt_layer_system()` (was `initialize_particle_os_system()`)
|
||||
- `show_apt_layer_system_status()` (was `show_particle_system_status()`)
|
||||
- `reset_apt_layer_system()` (was `reset_particle_os_system()`)
|
||||
- **Compile script updates**: Updated compile.sh to use apt-layer naming in all output messages and examples.
|
||||
- **Live overlay fixes**: Fixed live overlay scriptlet to use correct path loading function (`load_path_config`).
|
||||
- **Testing validation**: Successfully tested in WSL environment with all directories created under `/var/lib/apt-layer/`.
|
||||
- **Documentation consistency**: All help text, examples, and user-facing messages updated to use apt-layer naming.
|
||||
- **Result**: Clean, consistent naming throughout the entire codebase that matches the tool name "apt-layer" without any legacy references.
|
||||
|
||||
### [2025-07-14 UTC] - SCOPE REDUCTION: FOCUS ON CORE RPM-OSTREE FEATURES ONLY
|
||||
- **Scope reduction completed**: Archived all advanced, enterprise, cloud, multi-tenant, admin, compliance, and security features.
|
||||
- **Now focused on core rpm-ostree-like features for apt/Debian systems only:**
|
||||
|
|
@ -23,7 +45,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||
- **Result**: Codebase is now a true rpm-ostree equivalent for apt/Debian systems, with no extra enterprise/cloud/advanced features.
|
||||
|
||||
### [2025-01-27 23:58 UTC] - DOCUMENTATION UPDATES AND WORKSPACE CLEANUP COMPLETED
|
||||
- **Comprehensive documentation updates completed**: Updated all major documentation files to reflect current Particle-OS capabilities and recent improvements.
|
||||
- **Comprehensive documentation updates completed**: Updated all major documentation files to reflect current apt-layer capabilities and recent improvements.
|
||||
- **Main documentation files updated**: Updated multiple documentation files to reflect new apt-layer atomic OSTree workflow and official ComposeFS tool integration:
|
||||
- `tools.md` - Updated to reflect atomic OSTree workflow, official ComposeFS integration, and overlay/dpkg improvements
|
||||
- `TODO.md` - Updated completion status and added new priorities for compilation system enhancements
|
||||
|
|
@ -59,7 +81,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||
- **Note**: Documentation is now fully up-to-date and workspace is clean and organized. All recent improvements including OSTree atomic workflow, official ComposeFS integration, and overlay/dpkg improvements are properly documented across all project files.
|
||||
|
||||
### [2025-01-27 23:55 UTC] - DKMS TESTING INFRASTRUCTURE COMPLETED
|
||||
- **DKMS testing infrastructure implemented**: Created comprehensive DKMS testing system to validate all DKMS functionality in Particle-OS.
|
||||
- **DKMS testing infrastructure implemented**: Created comprehensive DKMS testing system to validate all DKMS functionality in apt-layer.
|
||||
- **Comprehensive test suite created**: Created `test-dkms-functionality.sh` with 12 comprehensive test cases covering all DKMS functionality:
|
||||
- **Test 1**: DKMS status command validation
|
||||
- **Test 2**: DKMS list command validation
|
||||
|
|
@ -108,10 +130,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||
- Proper error handling for missing dependencies
|
||||
- Clear instructions for test execution
|
||||
- Comprehensive validation of all DKMS functionality
|
||||
- **Note**: DKMS testing infrastructure is now complete and ready for validation on target systems. The test suite provides comprehensive coverage of all DKMS functionality implemented in Particle-OS, ensuring reliability and proper operation of DKMS and NVIDIA support features.
|
||||
- **Note**: DKMS testing infrastructure is now complete and ready for validation on target systems. The test suite provides comprehensive coverage of all DKMS functionality implemented in apt-layer, ensuring reliability and proper operation of DKMS and NVIDIA support features.
|
||||
|
||||
### [2025-01-27 23:50 UTC] - DOCUMENTATION COMPLETION AND COMPILATION ENHANCEMENTS PLANNED
|
||||
- **Documentation work completed**: All documentation tasks have been successfully completed for Particle-OS.
|
||||
- **Documentation work completed**: All documentation tasks have been successfully completed for apt-layer.
|
||||
- **Main README comprehensive update**: Added complete DKMS and NVIDIA support documentation to main README.md:
|
||||
- Comprehensive DKMS features and capabilities overview
|
||||
- Complete NVIDIA driver support documentation with graphics-drivers PPA integration
|
||||
|
|
@ -242,11 +264,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||
- Transaction logging and audit trails
|
||||
- User permission validation
|
||||
- Comprehensive error handling and recovery
|
||||
- **Gaming variant support**: Prepared infrastructure for Particle-OS gaming variants:
|
||||
- Particle-OS Bazzite Gaming (NVIDIA) - Ubuntu 25.04 with gaming optimizations
|
||||
- Particle-OS Corona Gaming (NVIDIA) - Ubuntu 24.04 LTS with KDE Plasma
|
||||
- **Gaming variant support**: Prepared infrastructure for apt-layer gaming variants:
|
||||
- apt-layer Bazzite Gaming (NVIDIA) - Ubuntu 25.04 with gaming optimizations
|
||||
- apt-layer Corona Gaming (NVIDIA) - Ubuntu 24.04 LTS with KDE Plasma
|
||||
- Gaming performance tuning and Steam/Wine integration
|
||||
- **Note**: DKMS and NVIDIA support functions are implemented in the advanced package management system but command-line interface integration is pending. This provides the foundation for full DKMS and NVIDIA support in Particle-OS variants.
|
||||
- **Note**: DKMS and NVIDIA support functions are implemented in the advanced package management system but command-line interface integration is pending. This provides the foundation for full DKMS and NVIDIA support in apt-layer variants.
|
||||
|
||||
### [2025-01-27 22:00 UTC] - ROOT PRIVILEGE MANAGEMENT IMPLEMENTED
|
||||
- **Root privilege management implemented**: Added comprehensive privilege checking system to enforce proper security practices.
|
||||
|
|
@ -774,22 +796,22 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||
### Usage Examples
|
||||
```bash
|
||||
# Create traditional layer
|
||||
sudo ./apt-layer.sh ubuntu-ublue/base/24.04 ubuntu-ublue/gaming/24.04 steam wine
|
||||
sudo ./apt-layer.sh ubuntu-base/24.04 gaming/24.04 steam wine
|
||||
|
||||
# Create container-based layer (Apx-style) with ComposeFS base
|
||||
sudo ./apt-layer.sh --container ubuntu-ublue/base/24.04 ubuntu-ublue/dev/24.04 vscode git
|
||||
sudo ./apt-layer.sh --container ubuntu-base/24.04 dev/24.04 vscode git
|
||||
|
||||
# Create container-based layer with OCI base image
|
||||
sudo ./apt-layer.sh --container ubuntu:24.04 ubuntu-ublue/custom/24.04 my-package
|
||||
sudo ./apt-layer.sh --container ubuntu:24.04 custom/24.04 my-package
|
||||
|
||||
# List images
|
||||
sudo ./apt-layer.sh --list
|
||||
|
||||
# Show image information
|
||||
sudo ./apt-layer.sh --info ubuntu-ublue/gaming/24.04
|
||||
sudo ./apt-layer.sh --info gaming/24.04
|
||||
|
||||
# Remove image
|
||||
sudo ./apt-layer.sh --remove ubuntu-ublue/gaming/24.04
|
||||
sudo ./apt-layer.sh --remove gaming/24.04
|
||||
```
|
||||
|
||||
---
|
||||
|
|
|
|||
155
src/apt-layer/compile-installer.sh
Normal file
155
src/apt-layer/compile-installer.sh
Normal file
|
|
@ -0,0 +1,155 @@
|
|||
#!/bin/bash
|
||||
|
||||
# apt-layer Installer Compiler
|
||||
# Compiles install-apt-layer.sh with embedded paths.json configuration
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
# Colors for output
|
||||
RED='\033[0;31m'
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
BLUE='\033[0;34m'
|
||||
CYAN='\033[0;36m'
|
||||
NC='\033[0m'
|
||||
|
||||
# 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}================================${NC}"
|
||||
echo -e "${BLUE}$1${NC}"
|
||||
echo -e "${BLUE}================================${NC}"
|
||||
}
|
||||
|
||||
# Get script directory and project root
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
PROJECT_ROOT="$(dirname "$(dirname "$SCRIPT_DIR")")"
|
||||
CONFIG_FILE="$SCRIPT_DIR/config/paths.json"
|
||||
TEMPLATE_FILE="$SCRIPT_DIR/templates/install-apt-layer.template.sh"
|
||||
OUTPUT_FILE="$PROJECT_ROOT/install-apt-layer.sh"
|
||||
|
||||
# Parse command line arguments
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case $1 in
|
||||
-o|--output)
|
||||
OUTPUT_FILE="$2"
|
||||
shift 2
|
||||
;;
|
||||
-h|--help)
|
||||
echo "Usage: $0 [-o|--output OUTPUT_PATH]"
|
||||
echo " -o, --output Specify output file path (default: ../../install-apt-layer.sh)"
|
||||
echo " -h, --help Show this help message"
|
||||
exit 0
|
||||
;;
|
||||
*)
|
||||
print_error "Unknown option: $1"
|
||||
echo "Use -h or --help for usage information"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
print_header "apt-layer Installer Compiler"
|
||||
|
||||
# Check if config file exists
|
||||
if [[ ! -f "$CONFIG_FILE" ]]; then
|
||||
print_error "Configuration file not found: $CONFIG_FILE"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Check if template file exists
|
||||
if [[ ! -f "$TEMPLATE_FILE" ]]; then
|
||||
print_error "Template file not found: $TEMPLATE_FILE"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Validate JSON configuration
|
||||
print_status "Validating paths.json configuration..."
|
||||
if ! jq empty "$CONFIG_FILE" 2>/dev/null; then
|
||||
print_error "Invalid JSON in configuration file: $CONFIG_FILE"
|
||||
exit 1
|
||||
fi
|
||||
print_status "✅ Configuration validation passed"
|
||||
|
||||
# Ensure output directory exists
|
||||
OUTPUT_DIR="$(dirname "$OUTPUT_FILE")"
|
||||
if [[ ! -d "$OUTPUT_DIR" ]]; then
|
||||
print_status "Creating output directory: $OUTPUT_DIR"
|
||||
mkdir -p "$OUTPUT_DIR"
|
||||
fi
|
||||
|
||||
# Read the template file
|
||||
print_status "Reading template file..."
|
||||
template_content=$(cat "$TEMPLATE_FILE")
|
||||
|
||||
# Extract the JSON configuration
|
||||
print_status "Extracting current paths.json configuration..."
|
||||
current_config=$(cat "$CONFIG_FILE")
|
||||
|
||||
# Create the compiled installer
|
||||
print_status "Compiling installer with embedded configuration..."
|
||||
|
||||
# Create temporary file for processing
|
||||
temp_file=$(mktemp)
|
||||
|
||||
# Process the template and replace the placeholder
|
||||
{
|
||||
# Read template line by line
|
||||
while IFS= read -r line; do
|
||||
# Check if this line starts the here document
|
||||
if [[ "$line" == *"sudo tee \"\$config_dir/paths.json\""* ]]; then
|
||||
echo "$line"
|
||||
# Skip the next line (PATHS_JSON_PLACEHOLDER)
|
||||
read -r placeholder_line
|
||||
# Output the current configuration
|
||||
echo "$current_config"
|
||||
else
|
||||
echo "$line"
|
||||
fi
|
||||
done < "$TEMPLATE_FILE"
|
||||
} > "$temp_file"
|
||||
|
||||
# Move to final location
|
||||
mv "$temp_file" "$OUTPUT_FILE"
|
||||
|
||||
# Make it executable
|
||||
chmod +x "$OUTPUT_FILE"
|
||||
|
||||
# Validate the compiled script
|
||||
print_status "Validating compiled installer..."
|
||||
if bash -n "$OUTPUT_FILE"; then
|
||||
print_status "✅ Syntax validation passed"
|
||||
else
|
||||
print_error "❌ Syntax validation failed"
|
||||
print_error "Removing invalid script: $OUTPUT_FILE"
|
||||
rm -f "$OUTPUT_FILE"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
print_header "Installer Compilation Complete!"
|
||||
|
||||
print_status "Output file: $OUTPUT_FILE"
|
||||
print_status "File size: $(du -h "$OUTPUT_FILE" | cut -f1)"
|
||||
print_status "Lines of code: $(wc -l < "$OUTPUT_FILE")"
|
||||
|
||||
print_status ""
|
||||
print_status "The compiled install-apt-layer.sh now includes:"
|
||||
print_status "- Latest paths.json configuration embedded"
|
||||
print_status "- All installation and uninstallation functionality"
|
||||
print_status "- Dependency checking and installation"
|
||||
print_status "- System initialization"
|
||||
print_status "- Proper error handling and validation"
|
||||
print_status ""
|
||||
|
||||
print_status "Ready for distribution! 🚀"
|
||||
|
|
@ -1,8 +1,8 @@
|
|||
#!/bin/bash
|
||||
|
||||
# Particle-OS apt-layer Compiler
|
||||
# apt-layer Compiler
|
||||
# Merges multiple scriptlets into a single self-contained apt-layer.sh
|
||||
# Based on ParticleOS installer compile.sh and ComposeFS compile.sh
|
||||
# Based on apt-layer installer compile.sh and ComposeFS compile.sh
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
|
|
@ -156,7 +156,7 @@ if [[ ! -d "$OUTPUT_DIR" ]]; then
|
|||
mkdir -p "$OUTPUT_DIR"
|
||||
fi
|
||||
|
||||
print_header "Particle-OS apt-layer Compiler"
|
||||
print_header "apt-layer Compiler"
|
||||
|
||||
# Check dependencies first
|
||||
check_dependencies
|
||||
|
|
@ -191,14 +191,14 @@ header="#!/bin/bash
|
|||
# WARNING: This file is automatically generated #
|
||||
# DO NOT modify this file directly as it will be overwritten #
|
||||
# #
|
||||
# Particle-OS apt-layer Tool #
|
||||
# apt-layer Tool #
|
||||
# Generated on: $(date '+%Y-%m-%d %H:%M:%S') #
|
||||
# #
|
||||
################################################################################################################
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
# Particle-OS apt-layer Tool - Self-contained version
|
||||
# apt-layer Tool - Self-contained version
|
||||
# This script contains all components merged into a single file
|
||||
# Enhanced version with container support, multiple package managers, and LIVE SYSTEM LAYERING
|
||||
# Inspired by Vanilla OS Apx approach, ParticleOS apt-layer, and rpm-ostree live layering
|
||||
|
|
@ -210,7 +210,7 @@ script_content+=("$header")
|
|||
# Add version info
|
||||
update_progress "Adding: Version" 10
|
||||
version_info="# Version: $(date '+%y.%m.%d')
|
||||
# Particle-OS apt-layer Tool
|
||||
# apt-layer Tool
|
||||
# Enhanced with Container Support and LIVE SYSTEM LAYERING
|
||||
|
||||
"
|
||||
|
|
@ -267,16 +267,16 @@ log_transaction() {
|
|||
"
|
||||
script_content+=("$fallback_logging")
|
||||
|
||||
# Add Particle-OS configuration sourcing
|
||||
# Add apt-layer configuration sourcing
|
||||
update_progress "Adding: Configuration Sourcing" 12
|
||||
config_sourcing="# Source Particle-OS configuration (if available, skip for help commands)
|
||||
config_sourcing="# Source apt-layer configuration (if available, skip for help commands)
|
||||
# Skip configuration loading for help commands to avoid permission issues
|
||||
if [[ \"\${1:-}\" != \"--help\" && \"\${1:-}\" != \"-h\" && \"\${1:-}\" != \"--help-full\" && \"\${1:-}\" != \"--examples\" ]]; then
|
||||
if [[ -f \"/usr/local/etc/particle-config.sh\" ]]; then
|
||||
source \"/usr/local/etc/particle-config.sh\"
|
||||
log_info \"Loaded Particle-OS configuration\" \"apt-layer\"
|
||||
if [[ -f \"/usr/local/etc/apt-layer-config.sh\" ]]; then
|
||||
source \"/usr/local/etc/apt-layer-config.sh\"
|
||||
log_info \"Loaded apt-layer configuration\" \"apt-layer\"
|
||||
else
|
||||
log_warning \"Particle-OS configuration not found, using defaults\" \"apt-layer\"
|
||||
log_warning \"apt-layer configuration not found, using defaults\" \"apt-layer\"
|
||||
fi
|
||||
else
|
||||
log_info \"Skipping configuration loading for help command\" \"apt-layer\"
|
||||
|
|
@ -349,23 +349,26 @@ add_scriptlet "06-oci-integration.sh" "OCI Export/Import Integration"
|
|||
update_progress "Adding: Bootloader Integration" 46
|
||||
add_scriptlet "07-bootloader.sh" "Bootloader Integration (UEFI/GRUB/systemd-boot)"
|
||||
|
||||
update_progress "Adding: Atomic Deployment System" 51
|
||||
update_progress "Adding: System Initialization" 48
|
||||
add_scriptlet "08-system-init.sh" "System Initialization and Path Management"
|
||||
|
||||
update_progress "Adding: Atomic Deployment System" 52
|
||||
add_scriptlet "09-atomic-deployment.sh" "Atomic Deployment System"
|
||||
|
||||
update_progress "Adding: rpm-ostree Compatibility" 56
|
||||
update_progress "Adding: rpm-ostree Compatibility" 57
|
||||
add_scriptlet "10-rpm-ostree-compat.sh" "rpm-ostree Compatibility Layer"
|
||||
|
||||
update_progress "Adding: OSTree Atomic Package Management" 61
|
||||
update_progress "Adding: OSTree Atomic Package Management" 62
|
||||
add_scriptlet "15-ostree-atomic.sh" "OSTree Atomic Package Management"
|
||||
|
||||
update_progress "Adding: Direct dpkg Installation" 66
|
||||
update_progress "Adding: Direct dpkg Installation" 67
|
||||
add_scriptlet "24-dpkg-direct-install.sh" "Direct dpkg Installation (Performance Optimization)"
|
||||
|
||||
update_progress "Adding: Main Dispatch" 71
|
||||
update_progress "Adding: Main Dispatch" 72
|
||||
add_scriptlet "99-main.sh" "Main Dispatch and Help" "true"
|
||||
|
||||
# Add embedded configuration files if they exist
|
||||
update_progress "Adding: Embedded Configuration" 98
|
||||
update_progress "Adding: Embedded Configuration" 99
|
||||
if [[ -d "$SCRIPT_DIR/config" ]]; then
|
||||
script_content+=("# ============================================================================")
|
||||
script_content+=("# Embedded Configuration Files")
|
||||
|
|
@ -491,7 +494,7 @@ print_status "Lines of code: $(wc -l < "$OUTPUT_FILE")"
|
|||
|
||||
print_status ""
|
||||
print_status "The compiled apt-layer.sh is now self-contained and includes:"
|
||||
print_status "- Particle-OS configuration integration"
|
||||
print_status "- apt-layer configuration integration"
|
||||
print_status "- Transactional operations with automatic rollback"
|
||||
print_status "- Traditional chroot-based layer creation"
|
||||
print_status "- Container-based layer creation (Apx-style)"
|
||||
|
|
@ -506,12 +509,12 @@ print_status "- Comprehensive JSON configuration system"
|
|||
print_status "- Direct dpkg installation (Performance optimization)"
|
||||
print_status "- All dependencies merged into a single file"
|
||||
print_status ""
|
||||
print_status "Particle-OS apt-layer compilation complete with all core rpm-ostree-like features!"
|
||||
print_status "apt-layer compilation complete with all core rpm-ostree-like features!"
|
||||
|
||||
print_status ""
|
||||
print_status "Usage:"
|
||||
print_status " sudo ./apt-layer.sh particle-os/base/24.04 particle-os/gaming/24.04 steam wine"
|
||||
print_status " sudo ./apt-layer.sh --container particle-os/base/24.04 particle-os/dev/24.04 vscode git"
|
||||
print_status " sudo ./apt-layer.sh ubuntu-base/24.04 gaming/24.04 steam wine"
|
||||
print_status " sudo ./apt-layer.sh --container ubuntu-base/24.04 dev/24.04 vscode git"
|
||||
print_status " sudo ./apt-layer.sh --live-overlay start"
|
||||
print_status " sudo ./apt-layer.sh --live-install steam wine"
|
||||
print_status " sudo ./apt-layer.sh --live-overlay commit \"Add gaming packages\""
|
||||
|
|
|
|||
138
src/apt-layer/config/paths.json
Normal file
138
src/apt-layer/config/paths.json
Normal file
|
|
@ -0,0 +1,138 @@
|
|||
{
|
||||
"apt_layer_paths": {
|
||||
"description": "apt-layer system path configuration",
|
||||
"version": "1.0",
|
||||
"main_directories": {
|
||||
"workspace": {
|
||||
"path": "/var/lib/apt-layer",
|
||||
"description": "Main apt-layer workspace directory",
|
||||
"permissions": "755",
|
||||
"owner": "root:root"
|
||||
},
|
||||
"logs": {
|
||||
"path": "/var/log/apt-layer",
|
||||
"description": "apt-layer log files directory",
|
||||
"permissions": "755",
|
||||
"owner": "root:root"
|
||||
},
|
||||
"cache": {
|
||||
"path": "/var/cache/apt-layer",
|
||||
"description": "apt-layer cache directory",
|
||||
"permissions": "755",
|
||||
"owner": "root:root"
|
||||
}
|
||||
},
|
||||
"workspace_subdirectories": {
|
||||
"build": {
|
||||
"path": "/var/lib/apt-layer/build",
|
||||
"description": "Build artifacts and temporary files",
|
||||
"permissions": "755",
|
||||
"owner": "root:root"
|
||||
},
|
||||
"live_overlay": {
|
||||
"path": "/var/lib/apt-layer/live-overlay",
|
||||
"description": "Live overlay system for temporary changes",
|
||||
"permissions": "755",
|
||||
"owner": "root:root"
|
||||
},
|
||||
"composefs": {
|
||||
"path": "/var/lib/apt-layer/composefs",
|
||||
"description": "ComposeFS layers and metadata",
|
||||
"permissions": "755",
|
||||
"owner": "root:root"
|
||||
},
|
||||
"ostree_commits": {
|
||||
"path": "/var/lib/apt-layer/ostree-commits",
|
||||
"description": "OSTree commit history and metadata",
|
||||
"permissions": "755",
|
||||
"owner": "root:root"
|
||||
},
|
||||
"deployments": {
|
||||
"path": "/var/lib/apt-layer/deployments",
|
||||
"description": "Deployment directories and state",
|
||||
"permissions": "755",
|
||||
"owner": "root:root"
|
||||
},
|
||||
"history": {
|
||||
"path": "/var/lib/apt-layer/history",
|
||||
"description": "Deployment history and rollback data",
|
||||
"permissions": "755",
|
||||
"owner": "root:root"
|
||||
},
|
||||
"bootloader": {
|
||||
"path": "/var/lib/apt-layer/bootloader",
|
||||
"description": "Bootloader state and configuration",
|
||||
"permissions": "755",
|
||||
"owner": "root:root"
|
||||
},
|
||||
"transaction_state": {
|
||||
"path": "/var/lib/apt-layer/transaction-state",
|
||||
"description": "Transaction state and temporary data",
|
||||
"permissions": "755",
|
||||
"owner": "root:root"
|
||||
}
|
||||
},
|
||||
"files": {
|
||||
"deployment_db": {
|
||||
"path": "/var/lib/apt-layer/deployments.json",
|
||||
"description": "Deployment database file",
|
||||
"permissions": "644",
|
||||
"owner": "root:root"
|
||||
},
|
||||
"current_deployment": {
|
||||
"path": "/var/lib/apt-layer/current-deployment",
|
||||
"description": "Current deployment identifier file",
|
||||
"permissions": "644",
|
||||
"owner": "root:root"
|
||||
},
|
||||
"pending_deployment": {
|
||||
"path": "/var/lib/apt-layer/pending-deployment",
|
||||
"description": "Pending deployment identifier file",
|
||||
"permissions": "644",
|
||||
"owner": "root:root"
|
||||
},
|
||||
"transaction_log": {
|
||||
"path": "/var/lib/apt-layer/transaction.log",
|
||||
"description": "Transaction log file",
|
||||
"permissions": "644",
|
||||
"owner": "root:root"
|
||||
}
|
||||
},
|
||||
"fallback_paths": {
|
||||
"description": "Fallback paths for different environments",
|
||||
"wsl": {
|
||||
"workspace": "/mnt/wsl/apt-layer",
|
||||
"logs": "/mnt/wsl/apt-layer/logs",
|
||||
"cache": "/mnt/wsl/apt-layer/cache"
|
||||
},
|
||||
"container": {
|
||||
"workspace": "/tmp/apt-layer",
|
||||
"logs": "/tmp/apt-layer/logs",
|
||||
"cache": "/tmp/apt-layer/cache"
|
||||
},
|
||||
"test": {
|
||||
"workspace": "/tmp/apt-layer-test",
|
||||
"logs": "/tmp/apt-layer-test/logs",
|
||||
"cache": "/tmp/apt-layer-test/cache"
|
||||
}
|
||||
},
|
||||
"environment_variables": {
|
||||
"description": "Environment variable mappings",
|
||||
"APT_LAYER_WORKSPACE": "workspace",
|
||||
"APT_LAYER_LOG_DIR": "logs",
|
||||
"APT_LAYER_CACHE_DIR": "cache",
|
||||
"BUILD_DIR": "workspace_subdirectories.build",
|
||||
"LIVE_OVERLAY_DIR": "workspace_subdirectories.live_overlay",
|
||||
"COMPOSEFS_DIR": "workspace_subdirectories.composefs",
|
||||
"OSTREE_COMMITS_DIR": "workspace_subdirectories.ostree_commits",
|
||||
"DEPLOYMENTS_DIR": "workspace_subdirectories.deployments",
|
||||
"HISTORY_DIR": "workspace_subdirectories.history",
|
||||
"BOOTLOADER_STATE_DIR": "workspace_subdirectories.bootloader",
|
||||
"TRANSACTION_STATE": "workspace_subdirectories.transaction_state",
|
||||
"DEPLOYMENT_DB": "files.deployment_db",
|
||||
"CURRENT_DEPLOYMENT_FILE": "files.current_deployment",
|
||||
"PENDING_DEPLOYMENT_FILE": "files.pending_deployment",
|
||||
"TRANSACTION_LOG": "files.transaction_log"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,119 +1,127 @@
|
|||
#!/bin/bash
|
||||
# Transaction management for Particle-OS apt-layer Tool
|
||||
# Transaction management for apt-layer Tool
|
||||
# Provides atomic operations with automatic rollback and recovery
|
||||
|
||||
# System initialization functions
|
||||
initialize_particle_os_system() {
|
||||
log_info "Initializing Particle-OS system..." "apt-layer"
|
||||
initialize_apt_layer_system() {
|
||||
log_info "Initializing apt-layer system..." "apt-layer"
|
||||
|
||||
# Create configuration directory
|
||||
mkdir -p "/usr/local/etc/particle-os"
|
||||
|
||||
# Create workspace directory
|
||||
mkdir -p "/var/lib/particle-os"
|
||||
|
||||
# Create log directory
|
||||
mkdir -p "/var/log/particle-os"
|
||||
|
||||
# Create cache directory
|
||||
mkdir -p "/var/cache/particle-os"
|
||||
|
||||
# Create configuration file if it doesn't exist
|
||||
if [[ ! -f "/usr/local/etc/particle-config.sh" ]]; then
|
||||
create_default_configuration
|
||||
# Use the new system initialization function if available
|
||||
if command -v init_apt_layer_system >/dev/null 2>&1; then
|
||||
init_apt_layer_system
|
||||
else
|
||||
# Fallback to basic initialization
|
||||
log_info "Using fallback initialization..." "apt-layer"
|
||||
|
||||
# Create configuration directory
|
||||
mkdir -p "/usr/local/etc/apt-layer"
|
||||
|
||||
# Create workspace directory
|
||||
mkdir -p "/var/lib/apt-layer"
|
||||
|
||||
# Create log directory
|
||||
mkdir -p "/var/log/apt-layer"
|
||||
|
||||
# Create cache directory
|
||||
mkdir -p "/var/cache/apt-layer"
|
||||
|
||||
# Create configuration file if it doesn't exist
|
||||
if [[ ! -f "/usr/local/etc/apt-layer-config.sh" ]]; then
|
||||
create_default_configuration
|
||||
fi
|
||||
|
||||
# Set proper permissions
|
||||
chmod 755 "/var/lib/apt-layer"
|
||||
chmod 755 "/var/log/apt-layer"
|
||||
chmod 755 "/var/cache/apt-layer"
|
||||
chmod 644 "/usr/local/etc/apt-layer-config.sh"
|
||||
|
||||
log_success "apt-layer system initialized successfully (fallback)" "apt-layer"
|
||||
fi
|
||||
|
||||
# Set proper permissions
|
||||
chmod 755 "/var/lib/particle-os"
|
||||
chmod 755 "/var/log/particle-os"
|
||||
chmod 755 "/var/cache/particle-os"
|
||||
chmod 644 "/usr/local/etc/particle-config.sh"
|
||||
|
||||
log_success "Particle-OS system initialized successfully" "apt-layer"
|
||||
}
|
||||
|
||||
create_default_configuration() {
|
||||
log_info "Creating default configuration..." "apt-layer"
|
||||
|
||||
cat > "/usr/local/etc/particle-config.sh" << 'EOF'
|
||||
cat > "/usr/local/etc/apt-layer-config.sh" << 'EOF'
|
||||
#!/bin/bash
|
||||
# Particle-OS Configuration File
|
||||
# apt-layer Configuration File
|
||||
# Generated automatically on $(date)
|
||||
|
||||
# Core paths
|
||||
export PARTICLE_WORKSPACE="/var/lib/particle-os"
|
||||
export PARTICLE_CONFIG_DIR="/usr/local/etc/particle-os"
|
||||
export PARTICLE_LOG_DIR="/var/log/particle-os"
|
||||
export PARTICLE_CACHE_DIR="/var/cache/particle-os"
|
||||
export APT_LAYER_WORKSPACE="/var/lib/apt-layer"
|
||||
export APT_LAYER_CONFIG_DIR="/usr/local/etc/apt-layer"
|
||||
export APT_LAYER_LOG_DIR="/var/log/apt-layer"
|
||||
export APT_LAYER_CACHE_DIR="/var/cache/apt-layer"
|
||||
|
||||
# Build and temporary directories
|
||||
export PARTICLE_BUILD_DIR="$PARTICLE_WORKSPACE/build"
|
||||
export PARTICLE_TEMP_DIR="$PARTICLE_WORKSPACE/temp"
|
||||
export PARTICLE_BACKUP_DIR="$PARTICLE_WORKSPACE/backup"
|
||||
export APT_LAYER_BUILD_DIR="$APT_LAYER_WORKSPACE/build"
|
||||
export APT_LAYER_TEMP_DIR="$APT_LAYER_WORKSPACE/temp"
|
||||
export APT_LAYER_BACKUP_DIR="$APT_LAYER_WORKSPACE/backup"
|
||||
|
||||
# Layer management
|
||||
export PARTICLE_LAYERS_DIR="$PARTICLE_WORKSPACE/layers"
|
||||
export PARTICLE_IMAGES_DIR="$PARTICLE_WORKSPACE/images"
|
||||
export PARTICLE_MOUNTS_DIR="$PARTICLE_WORKSPACE/mounts"
|
||||
export APT_LAYER_LAYERS_DIR="$APT_LAYER_WORKSPACE/layers"
|
||||
export APT_LAYER_IMAGES_DIR="$APT_LAYER_WORKSPACE/images"
|
||||
export APT_LAYER_MOUNTS_DIR="$APT_LAYER_WORKSPACE/mounts"
|
||||
|
||||
# ComposeFS integration
|
||||
export PARTICLE_COMPOSEFS_DIR="$PARTICLE_WORKSPACE/composefs"
|
||||
export PARTICLE_COMPOSEFS_SCRIPT="/usr/local/bin/composefs-alternative.sh"
|
||||
export APT_LAYER_COMPOSEFS_DIR="$APT_LAYER_WORKSPACE/composefs"
|
||||
export APT_LAYER_COMPOSEFS_SCRIPT="/usr/local/bin/composefs-alternative.sh"
|
||||
|
||||
# Boot management
|
||||
export PARTICLE_BOOTC_SCRIPT="/usr/local/bin/bootc-alternative.sh"
|
||||
export PARTICLE_BOOTUPD_SCRIPT="/usr/local/bin/bootupd-alternative.sh"
|
||||
export APT_LAYER_BOOTC_SCRIPT="/usr/local/bin/bootc-alternative.sh"
|
||||
export APT_LAYER_BOOTUPD_SCRIPT="/usr/local/bin/bootupd-alternative.sh"
|
||||
|
||||
# Transaction management
|
||||
export PARTICLE_TRANSACTION_LOG="$PARTICLE_LOG_DIR/transactions.log"
|
||||
export PARTICLE_TRANSACTION_STATE="$PARTICLE_CACHE_DIR/transaction.state"
|
||||
export APT_LAYER_TRANSACTION_LOG="$APT_LAYER_LOG_DIR/transactions.log"
|
||||
export APT_LAYER_TRANSACTION_STATE="$APT_LAYER_CACHE_DIR/transaction.state"
|
||||
|
||||
# Logging configuration
|
||||
export PARTICLE_LOG_LEVEL="INFO"
|
||||
export PARTICLE_LOG_FILE="$PARTICLE_LOG_DIR/apt-layer.log"
|
||||
export APT_LAYER_LOG_LEVEL="INFO"
|
||||
export APT_LAYER_LOG_FILE="$APT_LAYER_LOG_DIR/apt-layer.log"
|
||||
|
||||
# Security settings
|
||||
export PARTICLE_SIGNING_ENABLED="false"
|
||||
export PARTICLE_VERIFY_SIGNATURES="false"
|
||||
export APT_LAYER_SIGNING_ENABLED="false"
|
||||
export APT_LAYER_VERIFY_SIGNATURES="false"
|
||||
|
||||
# Container settings
|
||||
export PARTICLE_CONTAINER_RUNTIME="podman"
|
||||
export PARTICLE_CHROOT_ENABLED="true"
|
||||
export APT_LAYER_CONTAINER_RUNTIME="podman"
|
||||
export APT_LAYER_CHROOT_ENABLED="true"
|
||||
|
||||
# Default package sources
|
||||
export PARTICLE_DEFAULT_SOURCES="main restricted universe multiverse"
|
||||
export APT_LAYER_DEFAULT_SOURCES="main restricted universe multiverse"
|
||||
|
||||
# Performance settings
|
||||
export PARTICLE_PARALLEL_JOBS="4"
|
||||
export PARTICLE_CACHE_ENABLED="true"
|
||||
export APT_LAYER_PARALLEL_JOBS="4"
|
||||
export APT_LAYER_CACHE_ENABLED="true"
|
||||
|
||||
# Load configuration if it exists
|
||||
if [[ -f "$PARTICLE_CONFIG_DIR/particle-config.sh" ]]; then
|
||||
source "$PARTICLE_CONFIG_DIR/particle-config.sh"
|
||||
if [[ -f "$APT_LAYER_CONFIG_DIR/apt-layer-config.sh" ]]; then
|
||||
source "$APT_LAYER_CONFIG_DIR/apt-layer-config.sh"
|
||||
fi
|
||||
EOF
|
||||
|
||||
log_success "Default configuration created: /usr/local/etc/particle-config.sh" "apt-layer"
|
||||
log_success "Default configuration created: /usr/local/etc/apt-layer-config.sh" "apt-layer"
|
||||
}
|
||||
|
||||
reset_particle_os_system() {
|
||||
log_warning "Resetting Particle-OS system..." "apt-layer"
|
||||
reset_apt_layer_system() {
|
||||
log_warning "Resetting apt-layer system..." "apt-layer"
|
||||
|
||||
# Backup existing configuration
|
||||
if [[ -f "/usr/local/etc/particle-config.sh" ]]; then
|
||||
cp "/usr/local/etc/particle-config.sh" "/usr/local/etc/particle-config.sh.backup.$(date +%Y%m%d_%H%M%S)"
|
||||
if [[ -f "/usr/local/etc/apt-layer-config.sh" ]]; then
|
||||
cp "/usr/local/etc/apt-layer-config.sh" "/usr/local/etc/apt-layer-config.sh.backup.$(date +%Y%m%d_%H%M%S)"
|
||||
log_info "Existing configuration backed up" "apt-layer"
|
||||
fi
|
||||
|
||||
# Remove existing directories
|
||||
rm -rf "/var/lib/particle-os"
|
||||
rm -rf "/var/log/particle-os"
|
||||
rm -rf "/var/cache/particle-os"
|
||||
rm -rf "/var/lib/apt-layer"
|
||||
rm -rf "/var/log/apt-layer"
|
||||
rm -rf "/var/cache/apt-layer"
|
||||
|
||||
# Reinitialize system
|
||||
initialize_particle_os_system
|
||||
initialize_apt_layer_system
|
||||
|
||||
log_success "Particle-OS system reset successfully" "apt-layer"
|
||||
log_success "apt-layer system reset successfully" "apt-layer"
|
||||
}
|
||||
|
||||
# Transaction management functions
|
||||
|
|
|
|||
|
|
@ -8,28 +8,37 @@
|
|||
# LIVE OVERLAY SYSTEM FUNCTIONS
|
||||
# =============================================================================
|
||||
|
||||
# Live overlay state file (with fallbacks for when particle-config.sh is not loaded)
|
||||
LIVE_OVERLAY_STATE_FILE="${UBLUE_ROOT:-/var/lib/particle-os}/live-overlay.state"
|
||||
LIVE_OVERLAY_MOUNT_POINT="${UBLUE_ROOT:-/var/lib/particle-os}/live-overlay/mount"
|
||||
LIVE_OVERLAY_PACKAGE_LOG="${UBLUE_LOG_DIR:-/var/log/particle-os}/live-overlay-packages.log"
|
||||
# Live overlay state file (with fallbacks for when load_path_config() is not available)
|
||||
# These will be overridden by load_path_config() when available
|
||||
LIVE_OVERLAY_STATE_FILE="${LIVE_OVERLAY_STATE_FILE:-/var/lib/apt-layer/live-overlay.state}"
|
||||
LIVE_OVERLAY_MOUNT_POINT="${LIVE_OVERLAY_MOUNT_POINT:-/var/lib/apt-layer/live-overlay/mount}"
|
||||
LIVE_OVERLAY_PACKAGE_LOG="${LIVE_OVERLAY_PACKAGE_LOG:-/var/log/apt-layer/live-overlay-packages.log}"
|
||||
LIVE_OVERLAY_DIR="${LIVE_OVERLAY_DIR:-/var/lib/apt-layer/live-overlay}"
|
||||
LIVE_OVERLAY_UPPER_DIR="${LIVE_OVERLAY_UPPER_DIR:-/var/lib/apt-layer/live-overlay/upper}"
|
||||
LIVE_OVERLAY_WORK_DIR="${LIVE_OVERLAY_WORK_DIR:-/var/lib/apt-layer/live-overlay/work}"
|
||||
|
||||
# Initialize live overlay system
|
||||
init_live_overlay_system() {
|
||||
log_info "Initializing live overlay system" "apt-layer"
|
||||
|
||||
# Load system paths if available
|
||||
if command -v load_path_config >/dev/null 2>&1; then
|
||||
load_path_config
|
||||
fi
|
||||
|
||||
# Create live overlay directories
|
||||
mkdir -p "${UBLUE_LIVE_OVERLAY_DIR:-/var/lib/particle-os/live-overlay}" "${UBLUE_LIVE_UPPER_DIR:-/var/lib/particle-os/live-overlay/upper}" "${UBLUE_LIVE_WORK_DIR:-/var/lib/particle-os/live-overlay/work}"
|
||||
mkdir -p "$LIVE_OVERLAY_DIR" "$LIVE_OVERLAY_UPPER_DIR" "$LIVE_OVERLAY_WORK_DIR"
|
||||
mkdir -p "$LIVE_OVERLAY_MOUNT_POINT"
|
||||
|
||||
# Set proper permissions (use sudo if needed)
|
||||
if [[ $EUID -eq 0 ]]; then
|
||||
# Running as root, use chmod directly
|
||||
chmod 755 "${UBLUE_LIVE_OVERLAY_DIR:-/var/lib/particle-os/live-overlay}" 2>/dev/null || true
|
||||
chmod 700 "${UBLUE_LIVE_UPPER_DIR:-/var/lib/particle-os/live-overlay/upper}" "${UBLUE_LIVE_WORK_DIR:-/var/lib/particle-os/live-overlay/work}" 2>/dev/null || true
|
||||
chmod 755 "$LIVE_OVERLAY_DIR" 2>/dev/null || true
|
||||
chmod 700 "$LIVE_OVERLAY_UPPER_DIR" "$LIVE_OVERLAY_WORK_DIR" 2>/dev/null || true
|
||||
else
|
||||
# Running as regular user, use sudo
|
||||
sudo chmod 755 "${UBLUE_LIVE_OVERLAY_DIR:-/var/lib/particle-os/live-overlay}" 2>/dev/null || true
|
||||
sudo chmod 700 "${UBLUE_LIVE_UPPER_DIR:-/var/lib/particle-os/live-overlay/upper}" "${UBLUE_LIVE_WORK_DIR:-/var/lib/particle-os/live-overlay/work}" 2>/dev/null || true
|
||||
sudo chmod 755 "$LIVE_OVERLAY_DIR" 2>/dev/null || true
|
||||
sudo chmod 700 "$LIVE_OVERLAY_UPPER_DIR" "$LIVE_OVERLAY_WORK_DIR" 2>/dev/null || true
|
||||
fi
|
||||
|
||||
# Initialize package log if it doesn't exist
|
||||
|
|
@ -143,7 +152,7 @@ start_live_overlay() {
|
|||
|
||||
# Create overlay mount
|
||||
log_info "Creating overlay mount" "apt-layer"
|
||||
if mount -t overlay overlay -o "lowerdir=/,upperdir=${UBLUE_LIVE_UPPER_DIR:-/var/lib/particle-os/live-overlay/upper},workdir=${UBLUE_LIVE_WORK_DIR:-/var/lib/particle-os/live-overlay/work}" "$LIVE_OVERLAY_MOUNT_POINT"; then
|
||||
if mount -t overlay overlay -o "lowerdir=/,upperdir=$LIVE_OVERLAY_UPPER_DIR,workdir=$LIVE_OVERLAY_WORK_DIR" "$LIVE_OVERLAY_MOUNT_POINT"; then
|
||||
log_success "Overlay mount created successfully" "apt-layer"
|
||||
|
||||
# Mark overlay as active
|
||||
|
|
@ -229,8 +238,8 @@ get_live_overlay_status() {
|
|||
log_info "Overlay mount point: $LIVE_OVERLAY_MOUNT_POINT" "apt-layer"
|
||||
|
||||
# Show overlay usage
|
||||
if [[ -d "${UBLUE_LIVE_UPPER_DIR:-/var/lib/particle-os/live-overlay/upper}" ]]; then
|
||||
local usage=$(du -sh "${UBLUE_LIVE_UPPER_DIR:-/var/lib/particle-os/live-overlay/upper}" 2>/dev/null | cut -f1 || echo "unknown")
|
||||
if [[ -d "$LIVE_OVERLAY_UPPER_DIR" ]]; then
|
||||
local usage=$(du -sh "$LIVE_OVERLAY_UPPER_DIR" 2>/dev/null | cut -f1 || echo "unknown")
|
||||
log_info "Overlay usage: $usage" "apt-layer"
|
||||
fi
|
||||
|
||||
|
|
@ -385,9 +394,9 @@ commit_live_overlay() {
|
|||
|
||||
# Check if overlay has changes
|
||||
has_overlay_changes() {
|
||||
if [[ -d "${UBLUE_LIVE_UPPER_DIR:-/var/lib/particle-os/live-overlay/upper}" ]]; then
|
||||
if [[ -d "$LIVE_OVERLAY_UPPER_DIR" ]]; then
|
||||
# Check if upper directory has any content
|
||||
if [[ -n "$(find "${UBLUE_LIVE_UPPER_DIR:-/var/lib/particle-os/live-overlay/upper}" -mindepth 1 -maxdepth 1 2>/dev/null)" ]]; then
|
||||
if [[ -n "$(find "$LIVE_OVERLAY_UPPER_DIR" -mindepth 1 -maxdepth 1 2>/dev/null)" ]]; then
|
||||
return 0
|
||||
fi
|
||||
fi
|
||||
|
|
@ -401,12 +410,12 @@ create_layer_from_overlay() {
|
|||
local message="$2"
|
||||
|
||||
# Create temporary directory for layer
|
||||
local temp_layer_dir="${UBLUE_TEMP_DIR:-/var/lib/particle-os/temp}/live-layer-${layer_name}"
|
||||
local temp_layer_dir="${TEMP_DIR:-/tmp/apt-layer}/live-layer-${layer_name}"
|
||||
mkdir -p "$temp_layer_dir"
|
||||
|
||||
# Copy overlay changes to temporary directory
|
||||
log_info "Copying overlay changes to temporary layer" "apt-layer"
|
||||
if ! cp -a "${UBLUE_LIVE_UPPER_DIR:-/var/lib/particle-os/live-overlay/upper}"/* "$temp_layer_dir/" 2>/dev/null; then
|
||||
if ! cp -a "$LIVE_OVERLAY_UPPER_DIR"/* "$temp_layer_dir/" 2>/dev/null; then
|
||||
log_error "Failed to copy overlay changes" "apt-layer"
|
||||
rm -rf "$temp_layer_dir"
|
||||
return 1
|
||||
|
|
@ -440,10 +449,10 @@ create_composefs_layer() {
|
|||
fi
|
||||
|
||||
# Fallback: create simple squashfs layer
|
||||
local layer_file="${UBLUE_BUILD_DIR:-/var/lib/particle-os/build}/${layer_name}.squashfs"
|
||||
local layer_file="${BUILD_DIR:-/var/lib/apt-layer/build}/${layer_name}.squashfs"
|
||||
mkdir -p "$(dirname "$layer_file")"
|
||||
|
||||
if mksquashfs "$source_dir" "$layer_file" -comp "${UBLUE_SQUASHFS_COMPRESSION:-xz}" -b "${UBLUE_SQUASHFS_BLOCK_SIZE:-1M}"; then
|
||||
if mksquashfs "$source_dir" "$layer_file" -comp "${SQUASHFS_COMPRESSION:-xz}" -b "${SQUASHFS_BLOCK_SIZE:-1M}"; then
|
||||
log_success "Created squashfs layer: $layer_file" "apt-layer"
|
||||
return 0
|
||||
else
|
||||
|
|
@ -499,7 +508,7 @@ clean_live_overlay() {
|
|||
fi
|
||||
|
||||
# Clean up overlay directories
|
||||
rm -rf "${UBLUE_LIVE_UPPER_DIR:-/var/lib/particle-os/live-overlay/upper}"/* "${UBLUE_LIVE_WORK_DIR:-/var/lib/particle-os/live-overlay/work}"/* 2>/dev/null
|
||||
rm -rf "$LIVE_OVERLAY_UPPER_DIR"/* "$LIVE_OVERLAY_WORK_DIR"/* 2>/dev/null
|
||||
|
||||
# Clean up package log
|
||||
rm -f "$LIVE_OVERLAY_PACKAGE_LOG"
|
||||
|
|
@ -517,7 +526,7 @@ clean_live_overlay() {
|
|||
# Initialize live overlay system on script startup
|
||||
init_live_overlay_on_startup() {
|
||||
# Only initialize if not already done
|
||||
if [[ ! -d "${UBLUE_LIVE_OVERLAY_DIR:-/var/lib/particle-os/live-overlay}" ]]; then
|
||||
if [[ ! -d "$LIVE_OVERLAY_DIR" ]]; then
|
||||
init_live_overlay_system
|
||||
fi
|
||||
}
|
||||
|
|
|
|||
341
src/apt-layer/scriptlets/08-system-init.sh
Normal file
341
src/apt-layer/scriptlets/08-system-init.sh
Normal file
|
|
@ -0,0 +1,341 @@
|
|||
#!/bin/bash
|
||||
|
||||
# System Initialization and Path Management for apt-layer
|
||||
# This scriptlet handles system initialization, path management, and directory creation
|
||||
|
||||
# Load path configuration
|
||||
load_path_config() {
|
||||
local config_file="/usr/local/etc/apt-layer/paths.json"
|
||||
|
||||
if [[ ! -f "$config_file" ]]; then
|
||||
log_error "Path configuration file not found: $config_file" "apt-layer"
|
||||
return 1
|
||||
fi
|
||||
|
||||
# Load configuration using jq
|
||||
if ! command -v jq >/dev/null 2>&1; then
|
||||
log_error "jq is required for path configuration loading" "apt-layer"
|
||||
return 1
|
||||
fi
|
||||
|
||||
# Export main directory paths
|
||||
export APT_LAYER_WORKSPACE=$(jq -r '.apt_layer_paths.main_directories.workspace.path' "$config_file")
|
||||
export APT_LAYER_LOG_DIR=$(jq -r '.apt_layer_paths.main_directories.logs.path' "$config_file")
|
||||
export APT_LAYER_CACHE_DIR=$(jq -r '.apt_layer_paths.main_directories.cache.path' "$config_file")
|
||||
|
||||
# Export workspace subdirectory paths
|
||||
export BUILD_DIR=$(jq -r '.apt_layer_paths.workspace_subdirectories.build.path' "$config_file")
|
||||
export LIVE_OVERLAY_DIR=$(jq -r '.apt_layer_paths.workspace_subdirectories.live_overlay.path' "$config_file")
|
||||
export COMPOSEFS_DIR=$(jq -r '.apt_layer_paths.workspace_subdirectories.composefs.path' "$config_file")
|
||||
export OSTREE_COMMITS_DIR=$(jq -r '.apt_layer_paths.workspace_subdirectories.ostree_commits.path' "$config_file")
|
||||
export DEPLOYMENTS_DIR=$(jq -r '.apt_layer_paths.workspace_subdirectories.deployments.path' "$config_file")
|
||||
export HISTORY_DIR=$(jq -r '.apt_layer_paths.workspace_subdirectories.history.path' "$config_file")
|
||||
export BOOTLOADER_STATE_DIR=$(jq -r '.apt_layer_paths.workspace_subdirectories.bootloader.path' "$config_file")
|
||||
export TRANSACTION_STATE=$(jq -r '.apt_layer_paths.workspace_subdirectories.transaction_state.path' "$config_file")
|
||||
|
||||
# Export file paths
|
||||
export DEPLOYMENT_DB=$(jq -r '.apt_layer_paths.files.deployment_db.path' "$config_file")
|
||||
export CURRENT_DEPLOYMENT_FILE=$(jq -r '.apt_layer_paths.files.current_deployment.path' "$config_file")
|
||||
export PENDING_DEPLOYMENT_FILE=$(jq -r '.apt_layer_paths.files.pending_deployment.path' "$config_file")
|
||||
export TRANSACTION_LOG=$(jq -r '.apt_layer_paths.files.transaction_log.path' "$config_file")
|
||||
|
||||
log_debug "Path configuration loaded from: $config_file" "apt-layer"
|
||||
return 0
|
||||
}
|
||||
|
||||
# Initialize apt-layer system directories
|
||||
initialize_apt_layer_system() {
|
||||
log_info "Initializing apt-layer system directories..." "apt-layer"
|
||||
|
||||
# Load path configuration
|
||||
if ! load_path_config; then
|
||||
log_error "Failed to load path configuration" "apt-layer"
|
||||
return 1
|
||||
fi
|
||||
|
||||
# Create main directories
|
||||
local main_dirs=("$APT_LAYER_WORKSPACE" "$APT_LAYER_LOG_DIR" "$APT_LAYER_CACHE_DIR")
|
||||
for dir in "${main_dirs[@]}"; do
|
||||
if [[ ! -d "$dir" ]]; then
|
||||
mkdir -p "$dir"
|
||||
chmod 755 "$dir"
|
||||
chown root:root "$dir"
|
||||
log_debug "Created directory: $dir" "apt-layer"
|
||||
fi
|
||||
done
|
||||
|
||||
# Create workspace subdirectories
|
||||
local subdirs=(
|
||||
"$BUILD_DIR"
|
||||
"$LIVE_OVERLAY_DIR"
|
||||
"$COMPOSEFS_DIR"
|
||||
"$OSTREE_COMMITS_DIR"
|
||||
"$DEPLOYMENTS_DIR"
|
||||
"$HISTORY_DIR"
|
||||
"$BOOTLOADER_STATE_DIR"
|
||||
"$TRANSACTION_STATE"
|
||||
)
|
||||
|
||||
for dir in "${subdirs[@]}"; do
|
||||
if [[ ! -d "$dir" ]]; then
|
||||
mkdir -p "$dir"
|
||||
chmod 755 "$dir"
|
||||
chown root:root "$dir"
|
||||
log_debug "Created subdirectory: $dir" "apt-layer"
|
||||
fi
|
||||
done
|
||||
|
||||
# Create live overlay subdirectories
|
||||
local overlay_dirs=(
|
||||
"$LIVE_OVERLAY_DIR/upper"
|
||||
"$LIVE_OVERLAY_DIR/work"
|
||||
"$LIVE_OVERLAY_DIR/mount"
|
||||
)
|
||||
|
||||
for dir in "${overlay_dirs[@]}"; do
|
||||
if [[ ! -d "$dir" ]]; then
|
||||
mkdir -p "$dir"
|
||||
chmod 700 "$dir"
|
||||
chown root:root "$dir"
|
||||
log_debug "Created overlay directory: $dir" "apt-layer"
|
||||
fi
|
||||
done
|
||||
|
||||
# Initialize deployment database if it doesn't exist
|
||||
if [[ ! -f "$DEPLOYMENT_DB" ]]; then
|
||||
echo '{"deployments": {}, "current": null, "history": []}' > "$DEPLOYMENT_DB"
|
||||
chmod 644 "$DEPLOYMENT_DB"
|
||||
chown root:root "$DEPLOYMENT_DB"
|
||||
log_debug "Initialized deployment database: $DEPLOYMENT_DB" "apt-layer"
|
||||
fi
|
||||
|
||||
log_success "apt-layer system directories initialized" "apt-layer"
|
||||
return 0
|
||||
}
|
||||
|
||||
# Reinitialize apt-layer system (force recreation)
|
||||
reinitialize_apt_layer_system() {
|
||||
log_info "Reinitializing apt-layer system (force recreation)..." "apt-layer"
|
||||
|
||||
# Load path configuration
|
||||
if ! load_path_config; then
|
||||
log_error "Failed to load path configuration" "apt-layer"
|
||||
return 1
|
||||
fi
|
||||
|
||||
# Remove existing directories
|
||||
local dirs_to_remove=(
|
||||
"$APT_LAYER_WORKSPACE"
|
||||
"$APT_LAYER_LOG_DIR"
|
||||
"$APT_LAYER_CACHE_DIR"
|
||||
)
|
||||
|
||||
for dir in "${dirs_to_remove[@]}"; do
|
||||
if [[ -d "$dir" ]]; then
|
||||
rm -rf "$dir"
|
||||
log_debug "Removed directory: $dir" "apt-layer"
|
||||
fi
|
||||
done
|
||||
|
||||
# Reinitialize
|
||||
if initialize_apt_layer_system; then
|
||||
log_success "apt-layer system reinitialized successfully" "apt-layer"
|
||||
return 0
|
||||
else
|
||||
log_error "Failed to reinitialize apt-layer system" "apt-layer"
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Remove apt-layer system (cleanup)
|
||||
remove_apt_layer_system() {
|
||||
log_info "Removing apt-layer system (cleanup)..." "apt-layer"
|
||||
|
||||
# Load path configuration
|
||||
if ! load_path_config; then
|
||||
log_error "Failed to load path configuration" "apt-layer"
|
||||
return 1
|
||||
fi
|
||||
|
||||
# Stop any running live overlay
|
||||
if is_live_overlay_active; then
|
||||
log_warning "Live overlay is active, stopping it first..." "apt-layer"
|
||||
stop_live_overlay
|
||||
fi
|
||||
|
||||
# Remove all apt-layer directories
|
||||
local dirs_to_remove=(
|
||||
"$APT_LAYER_WORKSPACE"
|
||||
"$APT_LAYER_LOG_DIR"
|
||||
"$APT_LAYER_CACHE_DIR"
|
||||
)
|
||||
|
||||
for dir in "${dirs_to_remove[@]}"; do
|
||||
if [[ -d "$dir" ]]; then
|
||||
rm -rf "$dir"
|
||||
log_debug "Removed directory: $dir" "apt-layer"
|
||||
fi
|
||||
done
|
||||
|
||||
log_success "apt-layer system removed successfully" "apt-layer"
|
||||
return 0
|
||||
}
|
||||
|
||||
# Show apt-layer system status
|
||||
show_apt_layer_system_status() {
|
||||
log_info "apt-layer System Status:" "apt-layer"
|
||||
|
||||
# Load path configuration
|
||||
if ! load_path_config; then
|
||||
log_error "Failed to load path configuration" "apt-layer"
|
||||
return 1
|
||||
fi
|
||||
|
||||
echo "=== Main Directories ==="
|
||||
local main_dirs=(
|
||||
["Workspace"]="$APT_LAYER_WORKSPACE"
|
||||
["Logs"]="$APT_LAYER_LOG_DIR"
|
||||
["Cache"]="$APT_LAYER_CACHE_DIR"
|
||||
)
|
||||
|
||||
for name in "${!main_dirs[@]}"; do
|
||||
local dir="${main_dirs[$name]}"
|
||||
if [[ -d "$dir" ]]; then
|
||||
local size=$(du -sh "$dir" 2>/dev/null | cut -f1)
|
||||
local perms=$(stat -c "%a" "$dir" 2>/dev/null)
|
||||
echo "✅ $name: $dir ($size, perms: $perms)"
|
||||
else
|
||||
echo "❌ $name: $dir (not found)"
|
||||
fi
|
||||
done
|
||||
|
||||
echo ""
|
||||
echo "=== Workspace Subdirectories ==="
|
||||
local subdirs=(
|
||||
["Build"]="$BUILD_DIR"
|
||||
["Live Overlay"]="$LIVE_OVERLAY_DIR"
|
||||
["ComposeFS"]="$COMPOSEFS_DIR"
|
||||
["OSTree Commits"]="$OSTREE_COMMITS_DIR"
|
||||
["Deployments"]="$DEPLOYMENTS_DIR"
|
||||
["History"]="$HISTORY_DIR"
|
||||
["Bootloader"]="$BOOTLOADER_STATE_DIR"
|
||||
["Transaction State"]="$TRANSACTION_STATE"
|
||||
)
|
||||
|
||||
for name in "${!subdirs[@]}"; do
|
||||
local dir="${subdirs[$name]}"
|
||||
if [[ -d "$dir" ]]; then
|
||||
local count=$(find "$dir" -maxdepth 1 -type f 2>/dev/null | wc -l)
|
||||
echo "✅ $name: $dir ($count files)"
|
||||
else
|
||||
echo "❌ $name: $dir (not found)"
|
||||
fi
|
||||
done
|
||||
|
||||
echo ""
|
||||
echo "=== System Files ==="
|
||||
local files=(
|
||||
["Deployment DB"]="$DEPLOYMENT_DB"
|
||||
["Current Deployment"]="$CURRENT_DEPLOYMENT_FILE"
|
||||
["Pending Deployment"]="$PENDING_DEPLOYMENT_FILE"
|
||||
["Transaction Log"]="$TRANSACTION_LOG"
|
||||
)
|
||||
|
||||
for name in "${!files[@]}"; do
|
||||
local file="${files[$name]}"
|
||||
if [[ -f "$file" ]]; then
|
||||
local size=$(stat -c "%s" "$file" 2>/dev/null)
|
||||
echo "✅ $name: $file ($size bytes)"
|
||||
else
|
||||
echo "❌ $name: $file (not found)"
|
||||
fi
|
||||
done
|
||||
|
||||
echo ""
|
||||
echo "=== Live Overlay Status ==="
|
||||
if is_live_overlay_active; then
|
||||
echo "🟡 Live overlay is ACTIVE"
|
||||
echo " Mount point: $LIVE_OVERLAY_DIR/mount"
|
||||
echo " Upper dir: $LIVE_OVERLAY_DIR/upper"
|
||||
echo " Work dir: $LIVE_OVERLAY_DIR/work"
|
||||
else
|
||||
echo "🟢 Live overlay is INACTIVE"
|
||||
fi
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
# Validate path configuration
|
||||
validate_path_config() {
|
||||
log_debug "Validating path configuration..." "apt-layer"
|
||||
|
||||
local config_file="/usr/local/etc/apt-layer/paths.json"
|
||||
|
||||
if [[ ! -f "$config_file" ]]; then
|
||||
log_error "Path configuration file not found: $config_file" "apt-layer"
|
||||
return 1
|
||||
fi
|
||||
|
||||
# Validate JSON syntax
|
||||
if ! jq empty "$config_file" 2>/dev/null; then
|
||||
log_error "Invalid JSON in path configuration file" "apt-layer"
|
||||
return 1
|
||||
fi
|
||||
|
||||
# Validate required paths exist in config
|
||||
local required_paths=(
|
||||
".apt_layer_paths.main_directories.workspace.path"
|
||||
".apt_layer_paths.main_directories.logs.path"
|
||||
".apt_layer_paths.main_directories.cache.path"
|
||||
)
|
||||
|
||||
for path in "${required_paths[@]}"; do
|
||||
if ! jq -e "$path" "$config_file" >/dev/null 2>&1; then
|
||||
log_error "Required path not found in config: $path" "apt-layer"
|
||||
return 1
|
||||
fi
|
||||
done
|
||||
|
||||
log_debug "Path configuration validation passed" "apt-layer"
|
||||
return 0
|
||||
}
|
||||
|
||||
# Handle system initialization commands
|
||||
handle_system_init_commands() {
|
||||
case "$1" in
|
||||
"--init")
|
||||
if initialize_apt_layer_system; then
|
||||
log_success "apt-layer system initialized successfully" "apt-layer"
|
||||
return 0
|
||||
else
|
||||
log_error "Failed to initialize apt-layer system" "apt-layer"
|
||||
return 1
|
||||
fi
|
||||
;;
|
||||
"--reinit")
|
||||
if reinitialize_apt_layer_system; then
|
||||
log_success "apt-layer system reinitialized successfully" "apt-layer"
|
||||
return 0
|
||||
else
|
||||
log_error "Failed to reinitialize apt-layer system" "apt-layer"
|
||||
return 1
|
||||
fi
|
||||
;;
|
||||
"--rm-init")
|
||||
if remove_apt_layer_system; then
|
||||
log_success "apt-layer system removed successfully" "apt-layer"
|
||||
return 0
|
||||
else
|
||||
log_error "Failed to remove apt-layer system" "apt-layer"
|
||||
return 1
|
||||
fi
|
||||
;;
|
||||
"--status")
|
||||
show_apt_layer_system_status
|
||||
return $?
|
||||
;;
|
||||
*)
|
||||
return 1
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
|
@ -54,8 +54,11 @@ Image Management:
|
|||
--oci-import Import OCI image
|
||||
|
||||
System Management:
|
||||
--init Initialize Particle-OS system
|
||||
--reset Reset Particle-OS system
|
||||
--init Initialize apt-layer system
|
||||
--reinit Reinitialize apt-layer system (force recreation)
|
||||
--rm-init Remove apt-layer system (cleanup)
|
||||
--reset Reset apt-layer system
|
||||
--status Show apt-layer system status
|
||||
--help-full Show detailed help
|
||||
--examples Show usage examples
|
||||
|
||||
|
|
@ -78,7 +81,7 @@ EOF
|
|||
# Show full detailed usage information
|
||||
show_full_usage() {
|
||||
cat << 'EOF'
|
||||
Particle-OS apt-layer Tool - Enhanced with Container Support and LIVE SYSTEM LAYERING
|
||||
apt-layer Tool - Enhanced with Container Support and LIVE SYSTEM LAYERING
|
||||
Like rpm-ostree + Vanilla OS Apx for Ubuntu/Debian, now ComposeFS-based
|
||||
|
||||
BASIC LAYER CREATION:
|
||||
|
|
@ -178,14 +181,14 @@ IMAGE MANAGEMENT:
|
|||
|
||||
SYSTEM MANAGEMENT:
|
||||
apt-layer --init
|
||||
# Initialize Particle-OS system
|
||||
# Initialize apt-layer system
|
||||
|
||||
apt-layer --reset
|
||||
# Reset Particle-OS system
|
||||
# Reset apt-layer system
|
||||
|
||||
EXAMPLES:
|
||||
apt-layer particle-os/base/24.04 particle-os/gaming/24.04 steam wine
|
||||
apt-layer --container particle-os/base/24.04 particle-os/dev/24.04 vscode git
|
||||
apt-layer ubuntu-base/24.04 gaming/24.04 steam wine
|
||||
apt-layer --container ubuntu-base/24.04 dev/24.04 vscode git
|
||||
apt-layer --dpkg-install curl wget
|
||||
apt-layer --live-install firefox
|
||||
apt-layer install steam wine
|
||||
|
|
@ -221,8 +224,8 @@ BASIC LAYER CREATION:
|
|||
# Update packages with rollback capability and backup creation
|
||||
|
||||
Examples:
|
||||
apt-layer particle-os/base/24.04 particle-os/gaming/24.04 steam wine
|
||||
apt-layer --container particle-os/base/24.04 particle-os/dev/24.04 vscode git
|
||||
apt-layer ubuntu-base/24.04 gaming/24.04 steam wine
|
||||
apt-layer --container ubuntu-base/24.04 dev/24.04 vscode git
|
||||
apt-layer --dpkg-install curl wget
|
||||
apt-layer --advanced-install firefox
|
||||
EOF
|
||||
|
|
@ -761,20 +764,50 @@ main() {
|
|||
check_incomplete_transactions
|
||||
|
||||
# Check if system needs initialization (skip for help and initialization commands)
|
||||
if [[ "${1:-}" != "--init" && "${1:-}" != "--reset" && "${1:-}" != "--help" && "${1:-}" != "-h" && "${1:-}" != "--help-full" && "${1:-}" != "--examples" && "${1:-}" != "--version" ]]; then
|
||||
if [[ "${1:-}" != "--init" && "${1:-}" != "--reinit" && "${1:-}" != "--rm-init" && "${1:-}" != "--reset" && "${1:-}" != "--status" && "${1:-}" != "--help" && "${1:-}" != "-h" && "${1:-}" != "--help-full" && "${1:-}" != "--examples" && "${1:-}" != "--version" ]]; then
|
||||
check_initialization_needed
|
||||
fi
|
||||
|
||||
# Parse command line arguments first (before dependency checks)
|
||||
case "${1:-}" in
|
||||
--init)
|
||||
# Initialize Particle-OS system
|
||||
initialize_particle_os_system
|
||||
# Initialize apt-layer system
|
||||
initialize_apt_layer_system
|
||||
exit 0
|
||||
;;
|
||||
--reinit)
|
||||
# Reinitialize apt-layer system (force recreation)
|
||||
if command -v reinitialize_apt_layer_system >/dev/null 2>&1; then
|
||||
reinitialize_apt_layer_system
|
||||
else
|
||||
log_error "Reinit function not available" "apt-layer"
|
||||
exit 1
|
||||
fi
|
||||
exit 0
|
||||
;;
|
||||
--rm-init)
|
||||
# Remove apt-layer system (cleanup)
|
||||
if command -v remove_apt_layer_system >/dev/null 2>&1; then
|
||||
remove_apt_layer_system
|
||||
else
|
||||
log_error "Remove init function not available" "apt-layer"
|
||||
exit 1
|
||||
fi
|
||||
exit 0
|
||||
;;
|
||||
--status)
|
||||
# Show apt-layer system status
|
||||
if command -v show_apt_layer_system_status >/dev/null 2>&1; then
|
||||
show_apt_layer_system_status
|
||||
else
|
||||
log_error "Status function not available" "apt-layer"
|
||||
exit 1
|
||||
fi
|
||||
exit 0
|
||||
;;
|
||||
--reset)
|
||||
# Reset Particle-OS system
|
||||
reset_particle_os_system
|
||||
# Reset apt-layer system
|
||||
reset_apt_layer_system
|
||||
exit 0
|
||||
;;
|
||||
--help|-h)
|
||||
|
|
|
|||
337
src/apt-layer/templates/install-apt-layer.template.sh
Normal file
337
src/apt-layer/templates/install-apt-layer.template.sh
Normal file
|
|
@ -0,0 +1,337 @@
|
|||
#!/bin/bash
|
||||
|
||||
# apt-layer Installation Script
|
||||
# This script installs the apt-layer tool, its dependencies, creates necessary directories and files,
|
||||
# and sets up the system to use apt-layer. If already installed, it will update the tool.
|
||||
#
|
||||
# Usage:
|
||||
# ./install-apt-layer.sh # Install or update apt-layer
|
||||
# ./install-apt-layer.sh --uninstall # Remove apt-layer and all its files
|
||||
# ./install-apt-layer.sh --reinstall # Remove and reinstall (reset to default state)
|
||||
# ./install-apt-layer.sh --help # Show this help message
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
# Colors for output
|
||||
RED='\033[0;31m'
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
BLUE='\033[0;34m'
|
||||
CYAN='\033[0;36m'
|
||||
NC='\033[0m'
|
||||
|
||||
# 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}================================${NC}"
|
||||
echo -e "${BLUE}$1${NC}"
|
||||
echo -e "${BLUE}================================${NC}"
|
||||
}
|
||||
|
||||
# Function to show help
|
||||
show_help() {
|
||||
cat << 'EOF'
|
||||
apt-layer Installation Script
|
||||
|
||||
This script installs the apt-layer tool, its dependencies, creates necessary directories and files,
|
||||
and sets up the system to use apt-layer.
|
||||
|
||||
Usage:
|
||||
./install-apt-layer.sh # Install or update apt-layer
|
||||
./install-apt-layer.sh --uninstall # Remove apt-layer and all its files
|
||||
./install-apt-layer.sh --reinstall # Remove and reinstall (reset to default state)
|
||||
./install-apt-layer.sh --help # Show this help message
|
||||
|
||||
What this script does:
|
||||
- Downloads the latest apt-layer.sh from the repository
|
||||
- Installs required dependencies (jq, dos2unix, etc.)
|
||||
- Creates necessary directories (/var/lib/apt-layer, /var/log/apt-layer, etc.)
|
||||
- Sets up configuration files
|
||||
- Makes apt-layer executable and available system-wide
|
||||
- Initializes the apt-layer system
|
||||
|
||||
Dependencies:
|
||||
- curl or wget (for downloading)
|
||||
- jq (for JSON processing)
|
||||
- dos2unix (for Windows line ending conversion)
|
||||
- sudo (for system installation)
|
||||
|
||||
EOF
|
||||
}
|
||||
|
||||
# Function to check if running as root
|
||||
check_root() {
|
||||
if [[ $EUID -eq 0 ]]; then
|
||||
print_error "This script should not be run as root. Use sudo for specific commands."
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to check dependencies
|
||||
check_dependencies() {
|
||||
print_status "Checking dependencies..."
|
||||
|
||||
local missing_deps=()
|
||||
|
||||
# Check for curl or wget
|
||||
if ! command -v curl >/dev/null 2>&1 && ! command -v wget >/dev/null 2>&1; then
|
||||
missing_deps+=("curl or wget")
|
||||
fi
|
||||
|
||||
# Check for jq
|
||||
if ! command -v jq >/dev/null 2>&1; then
|
||||
missing_deps+=("jq")
|
||||
fi
|
||||
|
||||
# Check for dos2unix
|
||||
if ! command -v dos2unix >/dev/null 2>&1; then
|
||||
missing_deps+=("dos2unix")
|
||||
fi
|
||||
|
||||
if [[ ${#missing_deps[@]} -gt 0 ]]; then
|
||||
print_error "Missing required dependencies: ${missing_deps[*]}"
|
||||
print_status "Installing missing dependencies..."
|
||||
|
||||
# Try to install dependencies
|
||||
if command -v apt-get >/dev/null 2>&1; then
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y "${missing_deps[@]}"
|
||||
elif command -v dnf >/dev/null 2>&1; then
|
||||
sudo dnf install -y "${missing_deps[@]}"
|
||||
elif command -v yum >/dev/null 2>&1; then
|
||||
sudo yum install -y "${missing_deps[@]}"
|
||||
else
|
||||
print_error "Could not automatically install dependencies. Please install manually:"
|
||||
print_error " ${missing_deps[*]}"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
print_success "All dependencies satisfied"
|
||||
}
|
||||
|
||||
# Function to download apt-layer
|
||||
download_apt_layer() {
|
||||
print_status "Downloading apt-layer..."
|
||||
|
||||
local download_url="https://git.raines.xyz/robojerk/particle-os-tools/raw/branch/main/apt-layer.sh"
|
||||
local temp_file="/tmp/apt-layer.sh"
|
||||
|
||||
# Download using curl or wget
|
||||
if command -v curl >/dev/null 2>&1; then
|
||||
if curl -L -o "$temp_file" "$download_url"; then
|
||||
print_success "Downloaded apt-layer using curl"
|
||||
else
|
||||
print_error "Failed to download apt-layer using curl"
|
||||
return 1
|
||||
fi
|
||||
elif command -v wget >/dev/null 2>&1; then
|
||||
if wget -O "$temp_file" "$download_url"; then
|
||||
print_success "Downloaded apt-layer using wget"
|
||||
else
|
||||
print_error "Failed to download apt-layer using wget"
|
||||
return 1
|
||||
fi
|
||||
else
|
||||
print_error "No download tool available (curl or wget)"
|
||||
return 1
|
||||
fi
|
||||
|
||||
# Verify the downloaded file
|
||||
if [[ ! -f "$temp_file" ]] || [[ ! -s "$temp_file" ]]; then
|
||||
print_error "Downloaded file is empty or missing"
|
||||
return 1
|
||||
fi
|
||||
|
||||
# Convert line endings if needed
|
||||
if command -v dos2unix >/dev/null 2>&1; then
|
||||
dos2unix "$temp_file" 2>/dev/null || true
|
||||
fi
|
||||
|
||||
# Make executable
|
||||
chmod +x "$temp_file"
|
||||
|
||||
print_success "apt-layer downloaded and prepared"
|
||||
}
|
||||
|
||||
# Function to install apt-layer
|
||||
install_apt_layer() {
|
||||
print_status "Installing apt-layer..."
|
||||
|
||||
local temp_file="/tmp/apt-layer.sh"
|
||||
local install_dir="/usr/local/bin"
|
||||
local config_dir="/usr/local/etc/apt-layer"
|
||||
|
||||
# Create installation directory if it doesn't exist
|
||||
sudo mkdir -p "$install_dir"
|
||||
|
||||
# Install apt-layer
|
||||
sudo cp "$temp_file" "$install_dir/apt-layer"
|
||||
sudo chmod +x "$install_dir/apt-layer"
|
||||
|
||||
# Create configuration directory
|
||||
sudo mkdir -p "$config_dir"
|
||||
|
||||
# Create paths.json configuration
|
||||
sudo tee "$config_dir/paths.json" >/dev/null << 'PATHS_JSON_PLACEHOLDER'
|
||||
PATHS_JSON_PLACEHOLDER
|
||||
|
||||
# Set proper permissions
|
||||
sudo chmod 644 "$config_dir/paths.json"
|
||||
|
||||
# Initialize apt-layer system
|
||||
print_status "Initializing apt-layer system..."
|
||||
if sudo apt-layer --init; then
|
||||
print_success "apt-layer system initialized"
|
||||
else
|
||||
print_warning "apt-layer system initialization failed, but installation completed"
|
||||
fi
|
||||
|
||||
# Clean up temporary file
|
||||
rm -f "$temp_file"
|
||||
|
||||
print_success "apt-layer installed successfully"
|
||||
print_status "You can now use 'apt-layer --help' to see available commands"
|
||||
}
|
||||
|
||||
# Function to uninstall apt-layer
|
||||
uninstall_apt_layer() {
|
||||
print_status "Uninstalling apt-layer..."
|
||||
|
||||
local install_dir="/usr/local/bin"
|
||||
local config_dir="/usr/local/etc/apt-layer"
|
||||
|
||||
# Remove apt-layer binary
|
||||
if [[ -f "$install_dir/apt-layer" ]]; then
|
||||
sudo rm -f "$install_dir/apt-layer"
|
||||
print_status "Removed apt-layer binary"
|
||||
fi
|
||||
|
||||
# Remove configuration directory
|
||||
if [[ -d "$config_dir" ]]; then
|
||||
sudo rm -rf "$config_dir"
|
||||
print_status "Removed configuration directory"
|
||||
fi
|
||||
|
||||
# Remove apt-layer directories (optional - ask user)
|
||||
if [[ -d "/var/lib/apt-layer" ]] || [[ -d "/var/log/apt-layer" ]] || [[ -d "/var/cache/apt-layer" ]]; then
|
||||
echo -e "${YELLOW}Do you want to remove all apt-layer data directories? (y/N)${NC}"
|
||||
read -r response
|
||||
if [[ "$response" =~ ^[Yy]$ ]]; then
|
||||
sudo rm -rf "/var/lib/apt-layer" "/var/log/apt-layer" "/var/cache/apt-layer"
|
||||
print_status "Removed all apt-layer data directories"
|
||||
else
|
||||
print_status "Keeping apt-layer data directories"
|
||||
fi
|
||||
fi
|
||||
|
||||
print_success "apt-layer uninstalled successfully"
|
||||
}
|
||||
|
||||
# Function to reinstall apt-layer
|
||||
reinstall_apt_layer() {
|
||||
print_status "Reinstalling apt-layer..."
|
||||
|
||||
# Uninstall first
|
||||
uninstall_apt_layer
|
||||
|
||||
# Install again
|
||||
install_apt_layer
|
||||
|
||||
print_success "apt-layer reinstalled successfully"
|
||||
}
|
||||
|
||||
# Function to check if apt-layer is installed
|
||||
is_apt_layer_installed() {
|
||||
command -v apt-layer >/dev/null 2>&1
|
||||
}
|
||||
|
||||
# Function to check if apt-layer is up to date
|
||||
check_for_updates() {
|
||||
print_status "Checking for updates..."
|
||||
|
||||
if ! is_apt_layer_installed; then
|
||||
return 0 # Not installed, so no update needed
|
||||
fi
|
||||
|
||||
# For now, we'll always download the latest version
|
||||
# In the future, this could check version numbers or timestamps
|
||||
return 1 # Update needed
|
||||
}
|
||||
|
||||
# Main installation function
|
||||
main_install() {
|
||||
print_header "apt-layer Installation"
|
||||
|
||||
# Check if running as root
|
||||
check_root
|
||||
|
||||
# Check dependencies
|
||||
check_dependencies
|
||||
|
||||
# Check if already installed
|
||||
if is_apt_layer_installed; then
|
||||
print_status "apt-layer is already installed"
|
||||
if check_for_updates; then
|
||||
print_status "apt-layer is up to date"
|
||||
return 0
|
||||
else
|
||||
print_status "Updating apt-layer..."
|
||||
fi
|
||||
else
|
||||
print_status "Installing apt-layer..."
|
||||
fi
|
||||
|
||||
# Download and install
|
||||
if download_apt_layer && install_apt_layer; then
|
||||
print_success "apt-layer installation completed successfully"
|
||||
print_status "You can now use 'apt-layer --help' to see available commands"
|
||||
return 0
|
||||
else
|
||||
print_error "apt-layer installation failed"
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Main function
|
||||
main() {
|
||||
case "${1:-}" in
|
||||
--help|-h)
|
||||
show_help
|
||||
exit 0
|
||||
;;
|
||||
--uninstall)
|
||||
print_header "apt-layer Uninstallation"
|
||||
uninstall_apt_layer
|
||||
exit 0
|
||||
;;
|
||||
--reinstall)
|
||||
print_header "apt-layer Reinstallation"
|
||||
reinstall_apt_layer
|
||||
exit 0
|
||||
;;
|
||||
"")
|
||||
main_install
|
||||
exit $?
|
||||
;;
|
||||
*)
|
||||
print_error "Unknown option: $1"
|
||||
show_help
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
# Run main function with all arguments
|
||||
main "$@"
|
||||
Loading…
Add table
Add a link
Reference in a new issue