- Add docs/README.md with project overview and current status - Add docs/architecture.md with detailed architecture documentation - Add docs/development.md with development guide for contributors - Update .notes/todo.md to reflect architecture fix completion - Update .notes/plan.md with completed phases and next priorities Architecture fixes (daemon and dbus), bubblewrap integration are now complete. Ready for OCI integration phase.
324 lines
No EOL
12 KiB
Bash
324 lines
No EOL
12 KiB
Bash
#!/bin/bash
|
|
# Complete apt-ostree Daemon and D-Bus Fix Script
|
|
# This script consolidates all fixes for daemon startup, D-Bus access, and service configuration
|
|
|
|
set -e
|
|
|
|
# --- Helper Functions ---
|
|
|
|
# Function to check if the script is run as root
|
|
check_root() {
|
|
if [[ $EUID -ne 0 ]]; then
|
|
echo "ERROR: This script must be run as root."
|
|
echo "Please run: sudo ./$(basename "$0")"
|
|
exit 1
|
|
fi
|
|
}
|
|
|
|
# Function to safely remove files or directories with status messages
|
|
safe_rm() {
|
|
local item="$1"
|
|
if [[ -e "$item" ]]; then
|
|
echo " $item Found."
|
|
if rm -rf "$item"; then
|
|
echo " $item successfully rm'd."
|
|
else
|
|
echo " Fail to rm $item."
|
|
fi
|
|
else
|
|
echo " $item not found, skipping removal."
|
|
fi
|
|
}
|
|
|
|
# --- Main Script Execution ---
|
|
|
|
echo "=== Complete apt-ostree Daemon and D-Bus Fix ==="
|
|
echo
|
|
|
|
# Ensure the script is run as root
|
|
check_root
|
|
|
|
echo "Killing all apt-ostree related processes..."
|
|
pkill -f apt-ostree || true
|
|
pkill -f apt-ostreed || true
|
|
pkill -f apt-ostree-bootstatus || true
|
|
pkill -f apt-ostree-countme || true
|
|
echo "Processes killed or not found."
|
|
echo
|
|
|
|
# --- PHASE 1: STOPPING AND DISABLING ALL SERVICES ---
|
|
echo "=== PHASE 1: STOPPING AND DISABLING ALL SERVICES ==="
|
|
|
|
echo "1. Stopping all apt-ostree services..."
|
|
systemctl stop apt-ostreed.service 2>/dev/null || echo " apt-ostreed.service not running or found."
|
|
systemctl stop apt-ostree-bootstatus.service 2>/dev/null || echo " apt-ostree-bootstatus.service not running or found."
|
|
systemctl stop apt-ostree-countme.service 2>/dev/null || echo " apt-ostree-countme.service not running or found."
|
|
systemctl stop apt-ostreed-automatic.service 2>/dev/null || echo " apt-ostreed-automatic.service not running or found."
|
|
echo "Services stopped."
|
|
|
|
echo "2. Disabling all apt-ostree services..."
|
|
systemctl disable apt-ostreed.service 2>/dev/null || echo " apt-ostreed.service not enabled."
|
|
systemctl disable apt-ostree-bootstatus.service 2>/dev/null || echo " apt-ostree-bootstatus.service not enabled."
|
|
systemctl disable apt-ostree-countme.service 2>/dev/null || echo " apt-ostree-countme.service not enabled."
|
|
systemctl disable apt-ostree-countme.timer 2>/dev/null || echo " apt-ostree-countme.timer not enabled."
|
|
systemctl disable apt-ostreed-automatic.service 2>/dev/null || echo " apt-ostreed-automatic.service not enabled."
|
|
systemctl disable apt-ostreed-automatic.timer 2>/dev/null || echo " apt-ostreed-automatic.timer not enabled."
|
|
echo "Services disabled."
|
|
echo
|
|
|
|
# --- PHASE 2: REMOVING OLD SERVICE AND CONFIGURATION FILES ---
|
|
echo "=== PHASE 2: REMOVING OLD SERVICE AND CONFIGURATION FILES ==="
|
|
|
|
echo "3. Removing systemd service files..."
|
|
safe_rm /etc/systemd/system/apt-ostreed.service
|
|
safe_rm /etc/systemd/system/apt-ostree-bootstatus.service
|
|
safe_rm /etc/systemd/system/apt-ostree-countme.service
|
|
safe_rm /etc/systemd/system/apt-ostree-countme.timer
|
|
safe_rm /etc/systemd/system/apt-ostreed-automatic.service
|
|
safe_rm /etc/systemd/system/apt-ostreed-automatic.timer
|
|
echo "Systemd service files processed."
|
|
|
|
echo "4. Removing ALL D-Bus policy files (including old ones)..."
|
|
safe_rm /etc/dbus-1/system.d/org.aptostree.dev.conf
|
|
safe_rm /etc/dbus-1/system.d/org.aptostree*.conf
|
|
safe_rm /etc/dbus-1/system.d/org.debian.aptostree1.conf.old_python
|
|
safe_rm /etc/dbus-1/system.d/org.projectatomic.aptostree1.conf
|
|
echo "D-Bus policy files processed."
|
|
|
|
echo "5. Removing D-Bus service files..."
|
|
safe_rm /usr/share/dbus-1/system-services/org.aptostree.dev.service
|
|
safe_rm /usr/share/dbus-1/system-services/org.aptostree*.service
|
|
echo "D-Bus service files processed."
|
|
|
|
echo "6. Removing ALL Polkit policy files..."
|
|
safe_rm /usr/share/polkit-1/actions/org.aptostree.dev.policy
|
|
safe_rm /usr/share/polkit-1/actions/org.aptostree*.policy
|
|
echo "Polkit policy files processed."
|
|
|
|
echo "7. Removing ALL old configuration directory and files..."
|
|
safe_rm /etc/apt-ostree/
|
|
echo "Old configuration processed."
|
|
|
|
# --- PHASE 3: REMOVING OLD BINARIES ---
|
|
echo "=== PHASE 3: REMOVING OLD BINARIES ==="
|
|
|
|
echo "8. Removing old binaries..."
|
|
safe_rm /usr/libexec/apt-ostreed
|
|
safe_rm /usr/bin/apt-ostree
|
|
safe_rm /usr/bin/apt-ostreed
|
|
echo "Old binaries processed."
|
|
echo
|
|
|
|
# --- PHASE 4: RELOADING SYSTEMD AND D-BUS AFTER CLEANUP ---
|
|
echo "=== PHASE 4: RELOADING SYSTEMD AND D-BUS AFTER CLEANUP ==="
|
|
|
|
echo "9. Reloading systemd daemon..."
|
|
systemctl daemon-reload
|
|
echo "Systemd daemon reloaded."
|
|
|
|
echo "10. Reloading D-Bus daemon..."
|
|
systemctl reload dbus
|
|
echo "D-Bus daemon reloaded."
|
|
|
|
echo "11. Waiting for cleanup to complete and daemons to settle..."
|
|
sleep 2
|
|
echo "Wait complete."
|
|
echo
|
|
|
|
# --- PHASE 5: BUILDING PROJECT ---
|
|
echo "=== PHASE 5: BUILDING PROJECT ==="
|
|
|
|
echo "12. Building project (as current user if sudo, else trying common paths)..."
|
|
# Use the user's environment to find cargo
|
|
if [[ -n "$SUDO_USER" ]]; then
|
|
echo " Attempting build as user: $SUDO_USER"
|
|
if ! sudo -u "$SUDO_USER" cargo build --release; then
|
|
echo "ERROR: Build failed for user $SUDO_USER. Please check your Rust environment."
|
|
echo "Please run 'cargo build --release' manually as user, then re-run this script."
|
|
exit 1
|
|
fi
|
|
else
|
|
echo " Attempting build with current user's cargo in PATH or common locations..."
|
|
# Try common cargo locations
|
|
if command -v cargo >/dev/null 2>&1; then
|
|
if ! cargo build --release; then
|
|
echo "ERROR: Build failed. Please check your Rust environment."
|
|
echo "Please run 'cargo build --release' manually as user, then re-run this script."
|
|
exit 1
|
|
fi
|
|
elif [[ -f "/home/$USER/.cargo/bin/cargo" ]]; then
|
|
if ! "/home/$USER/.cargo/bin/cargo" build --release; then
|
|
echo "ERROR: Build failed using user's cargo path. Please check your Rust environment."
|
|
echo "Please run 'cargo build --release' manually as user, then re-run this script."
|
|
exit 1
|
|
fi
|
|
elif [[ -f "/usr/local/bin/cargo" ]]; then
|
|
if ! /usr/local/bin/cargo build --release; then
|
|
echo "ERROR: Build failed using /usr/local/bin/cargo. Please check your Rust environment."
|
|
echo "Please run 'cargo build --release' manually as user, then re-run this script."
|
|
exit 1
|
|
fi
|
|
else
|
|
echo "ERROR: cargo not found in PATH or common locations."
|
|
echo "Please run 'cargo build --release' manually as user, then re-run this script."
|
|
exit 1
|
|
fi
|
|
fi
|
|
echo "✓ Project built successfully."
|
|
echo
|
|
|
|
# --- PHASE 6: INSTALLING FRESH BINARIES AND SERVICE FILES ---
|
|
echo "=== PHASE 6: INSTALLING FRESH BINARIES AND SERVICE FILES ==="
|
|
|
|
echo "13. Installing fresh binaries..."
|
|
cp target/release/apt-ostreed /usr/libexec/
|
|
cp target/release/apt-ostree /usr/bin/
|
|
chmod +x /usr/libexec/apt-ostreed /usr/bin/apt-ostree
|
|
echo "Binaries installed and permissions set."
|
|
|
|
echo "14. Installing fresh systemd service files..."
|
|
cp src/daemon/apt-ostreed.service /etc/systemd/system/
|
|
cp src/daemon/apt-ostree-bootstatus.service /etc/systemd/system/
|
|
cp src/daemon/apt-ostree-countme.service /etc/systemd/system/
|
|
cp src/daemon/apt-ostree-countme.timer /etc/systemd/system/
|
|
cp src/daemon/apt-ostreed-automatic.service /etc/systemd/system/
|
|
cp src/daemon/apt-ostreed-automatic.timer /etc/systemd/system/
|
|
echo "Systemd service files installed."
|
|
|
|
echo "15. Installing and configuring fresh D-Bus service file..."
|
|
# Copy the file first
|
|
cp src/daemon/org.aptostree.dev.service /usr/share/dbus-1/system-services/
|
|
# Then use tee to ensure its content includes User=root and SystemdService=apt-ostreed.service
|
|
tee /usr/share/dbus-1/system-services/org.aptostree.dev.service > /dev/null << 'EOF'
|
|
[D-BUS Service]
|
|
Name=org.aptostree.dev
|
|
Exec=/usr/libexec/apt-ostreed
|
|
User=root
|
|
SystemdService=apt-ostreed.service
|
|
EOF
|
|
echo "D-Bus service file installed and configured to run as root."
|
|
|
|
echo "16. Installing fresh Polkit policy file..."
|
|
cp src/daemon/org.aptostree.dev.policy /usr/share/polkit-1/actions/
|
|
echo "Polkit policy file installed."
|
|
|
|
echo "17. Creating configuration directory and installing fresh configuration..."
|
|
mkdir -p /etc/apt-ostree
|
|
cp src/daemon/apt-ostreed.conf /etc/apt-ostree/
|
|
echo "Configuration installed."
|
|
echo
|
|
|
|
# --- PHASE 7: FIXING SERVICE TYPE AND D-BUS POLICY ---
|
|
echo "=== PHASE 7: FIXING SERVICE TYPE AND D-BUS POLICY ==="
|
|
|
|
echo "18. Updating service file with simple type (no systemd notify requirement)..."
|
|
tee /etc/systemd/system/apt-ostreed.service > /dev/null << 'EOF'
|
|
[Unit]
|
|
Description=apt-ostree System Management Daemon
|
|
Documentation=man:apt-ostree(1)
|
|
|
|
[Service]
|
|
Type=simple
|
|
ExecStart=/usr/libexec/apt-ostreed
|
|
Restart=on-failure
|
|
RestartSec=1
|
|
StandardOutput=journal
|
|
StandardError=journal
|
|
|
|
# Basic security settings (minimal for development)
|
|
NoNewPrivileges=true
|
|
|
|
[Install]
|
|
WantedBy=multi-user.target
|
|
EOF
|
|
echo "Service file updated with simple type."
|
|
|
|
echo "19. Creating very permissive D-Bus policy for development..."
|
|
tee /etc/dbus-1/system.d/org.aptostree.dev.conf > /dev/null << 'EOF'
|
|
<!DOCTYPE busconfig PUBLIC
|
|
"-//freedesktop//DTD D-BUS Bus Configuration 1.0//EN"
|
|
"http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd">
|
|
<busconfig>
|
|
<!-- Very permissive policy for development -->
|
|
<policy context="default">
|
|
<allow own="org.aptostree.dev"/>
|
|
<allow send_destination="org.aptostree.dev"/>
|
|
<allow receive_sender="org.aptostree.dev"/>
|
|
<allow send_interface="*"/>
|
|
<allow receive_interface="*"/>
|
|
</policy>
|
|
</busconfig>
|
|
EOF
|
|
echo "D-Bus policy updated with very permissive settings."
|
|
|
|
echo "20. Setting correct permissions for all files..."
|
|
chmod 644 /etc/dbus-1/system.d/org.aptostree.dev.conf
|
|
chmod 644 /usr/share/dbus-1/system-services/org.aptostree.dev.service
|
|
chmod 644 /usr/share/polkit-1/actions/org.aptostree.dev.policy
|
|
chmod 644 /etc/apt-ostree/apt-ostreed.conf
|
|
chown root:root /etc/dbus-1/system.d/org.aptostree.dev.conf
|
|
chown root:root /usr/share/dbus-1/system-services/org.aptostree.dev.service
|
|
chown root:root /usr/share/polkit-1/actions/org.aptostree.dev.policy
|
|
chown root:root /etc/apt-ostree/apt-ostreed.conf
|
|
echo "Permissions set for all files."
|
|
echo
|
|
|
|
# --- PHASE 8: ENABLING AND STARTING SERVICES ---
|
|
echo "=== PHASE 8: ENABLING AND STARTING SERVICES ==="
|
|
|
|
echo "21. Reloading systemd and D-Bus one more time to pick up new configurations..."
|
|
systemctl daemon-reload
|
|
systemctl reload dbus
|
|
echo "Systemd and D-Bus reloaded."
|
|
|
|
echo "22. Enabling services to start on boot..."
|
|
systemctl enable apt-ostreed.service
|
|
systemctl enable apt-ostree-bootstatus.service
|
|
systemctl enable apt-ostree-countme.timer
|
|
systemctl enable apt-ostreed-automatic.timer
|
|
echo "Services enabled."
|
|
|
|
echo "23. Starting main apt-ostree daemon..."
|
|
systemctl start apt-ostreed.service
|
|
echo "Daemon start command issued."
|
|
|
|
echo "24. Waiting for daemon to fully start..."
|
|
sleep 3
|
|
echo "Wait complete."
|
|
echo
|
|
|
|
# --- PHASE 9: VERIFICATION ---
|
|
echo "=== PHASE 9: VERIFICATION ==="
|
|
|
|
echo "25. Checking main daemon status..."
|
|
if systemctl is-active --quiet apt-ostreed.service; then
|
|
echo "✓ Daemon is running successfully!"
|
|
else
|
|
echo "✗ Daemon failed to start."
|
|
echo "Daemon status:"
|
|
systemctl status apt-ostreed.service --no-pager
|
|
echo
|
|
echo "Last 10 lines of daemon logs:"
|
|
journalctl -u apt-ostreed.service --no-pager -n 10
|
|
exit 1
|
|
fi
|
|
|
|
echo "26. Testing D-Bus communication (Introspection and Ping)..."
|
|
echo " Testing introspection:"
|
|
gdbus introspect --system --dest org.aptostree.dev --object-path /org/aptostree/dev/Daemon 2>&1 || echo " Introspection failed."
|
|
|
|
echo " Testing ping (lowercase):"
|
|
gdbus call --system --dest org.aptostree.dev --object-path /org/aptostree/dev/Daemon --method org.aptostree.dev.Daemon.ping 2>&1 || echo " D-Bus ping failed."
|
|
|
|
echo "27. Testing client-daemon communication..."
|
|
echo " Testing client ping:"
|
|
apt-ostree daemon-ping || echo " Client ping failed."
|
|
|
|
echo " Testing client status:"
|
|
apt-ostree daemon-status || echo " Client status failed."
|
|
echo "Client-daemon communication tests complete."
|
|
echo
|
|
|
|
echo "=== APT-OSTREE COMPLETE FIX SUCCESSFUL ==="
|
|
echo "All daemon startup, D-Bus access, and service configuration issues have been resolved."
|
|
echo "apt-ostree should now be fully functional with stable daemon-client communication." |