testsAndMisc/linux_configuration/fixes/fix_systemctl.sh
Krzysztof kuhy Rudnicki 4f2b0ccdf7 Dissolve linux_configuration/scripts/ and single_use/
Two levels of pure taxonomy carrying no information, and a 2-directory
cap leaves no room for them. Categories now sit directly under
linux_configuration/: features, fixes, utils, misc, fresh-install,
installers, diagnostics, gaming, boot_recovery, periodic_background, lib,
meta, tests. A script's own lib/ and tests/ are exempt from the cap, so
those stay put.

Depth violations 248 -> 139; roughly 40 of the remainder are inside
digital_wellbeing and hosts, deferred until the guard-lib repoint.

The moves are the easy half. What breaks is every path that counted
levels, and three classes of it had to be found by resolving paths rather
than reading diffs:

  - 52 relative `source` lines for lib/common.sh and lib/android.sh. The
    correct prefix differs per file: 40 were ../../ and 12 were ../../../,
    so a blanket replace would have fixed one set and broken the other.
  - REPO_ROOT in 7 fixes/lib/tests harnesses and setup_syncyomi_guard.sh,
    each walking up four levels from a directory now two levels shallower.
    This caused a real regression -- the fixes suite went red with
    "log_warn: command not found" -- caught by running it and comparing
    against the pre-move baseline worktree.
  - conftest.py's sys.path entries, which took the pytest gate down with
    14 collection errors, and the `# shellcheck source=` directives, which
    took shellcheck down with SC1091.

16 symlinks in $HOME broke, including the entire i3blocks bar. All
repointed, and cpu_monitor/memory/disk/time/volume were run to confirm
they emit real output rather than merely resolving.

Verified: 1798 tests pass at 100% coverage, 8 of 9 lib/tests suites pass
(the ninth needs the coverage jail, identically at baseline), pre-commit
is clean, and the two untracked secret configs are still ignored after
their gitignore paths changed.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PJrqKERAo5QUeEHWS5Asgp
2026-08-23 18:53:30 +02:00

95 lines
2.4 KiB
Bash
Executable File

#!/bin/bash
# Fix script for media-organizer.service
# The service was failing due to:
# 1. Corrupted ExecStart path (line break in the middle)
# 2. Wrong script path (missing 'utils/' directory)
# 3. User/Group set to root instead of actual user
set -euo pipefail
SERVICE_NAME="media-organizer"
SERVICE_FILE="/etc/systemd/system/${SERVICE_NAME}.service"
DEFAULT_ORGANIZE_SCRIPT="/home/kuhy/testsAndMisc/linux_configuration/utils/organize_downloads.sh"
LEGACY_ORGANIZE_SCRIPT="/home/kuhy/linux-configuration/scripts/utils/organize_downloads.sh"
if [[ -f $DEFAULT_ORGANIZE_SCRIPT ]]; then
ORGANIZE_SCRIPT="$DEFAULT_ORGANIZE_SCRIPT"
elif [[ -f $LEGACY_ORGANIZE_SCRIPT ]]; then
ORGANIZE_SCRIPT="$LEGACY_ORGANIZE_SCRIPT"
else
ORGANIZE_SCRIPT="$DEFAULT_ORGANIZE_SCRIPT"
fi
TARGET_USER="${SUDO_USER:-kuhy}"
log() {
echo "[$(date '+%Y-%m-%d %H:%M:%S')] $1"
}
# Check if running as root
if [[ $EUID -ne 0 ]]; then
log "This script needs to be run as root."
log "Re-executing with sudo..."
exec sudo "$0" "$@"
fi
log "Fixing media-organizer.service..."
# Verify the organize_downloads.sh script exists
if [[ ! -f $ORGANIZE_SCRIPT ]]; then
log "ERROR: organize_downloads.sh not found at $ORGANIZE_SCRIPT"
exit 1
fi
# Stop the service if running (ignore errors)
systemctl stop "$SERVICE_NAME.service" 2>/dev/null || true
# Recreate the service file with correct configuration
cat >"$SERVICE_FILE" <<EOF
[Unit]
Description=Media File Organizer
After=graphical-session.target
Wants=graphical-session.target
[Service]
Type=oneshot
User=$TARGET_USER
Group=$TARGET_USER
ExecStart=$ORGANIZE_SCRIPT
StandardOutput=journal
StandardError=journal
RemainAfterExit=no
[Install]
WantedBy=multi-user.target
EOF
log "Recreated service file: $SERVICE_FILE"
# Reload systemd daemon
systemctl daemon-reload
log "Reloaded systemd daemon"
# Reset the failed state
systemctl reset-failed "$SERVICE_NAME.service" 2>/dev/null || true
log "Reset failed state"
# Re-enable the service
systemctl enable "$SERVICE_NAME.service"
log "Service enabled"
# Optionally start the service to verify it works
log "Starting service to verify fix..."
if systemctl start "$SERVICE_NAME.service"; then
log "SUCCESS: media-organizer.service started successfully!"
else
log "WARNING: Service still has issues. Check: journalctl -u $SERVICE_NAME"
fi
# Show current status
log "Current service status:"
systemctl status "$SERVICE_NAME.service" --no-pager || true
log "Fix complete!"