diff options
| author | Sam Scholten | 2026-03-30 09:48:28 +1000 |
|---|---|---|
| committer | Sam Scholten | 2026-03-30 09:48:28 +1000 |
| commit | d0dc77e9f289bf078112e2ee818f11fb89296ef2 (patch) | |
| tree | 1c6dc6be64016d6e3ae8a055b86e393d7c700d56 /wsl-fix.sh | |
| parent | 48f28ef3e78eadebd9dcd4698d9a9e78866122f9 (diff) | |
| download | drestic-d0dc77e9f289bf078112e2ee818f11fb89296ef2.tar.gz drestic-d0dc77e9f289bf078112e2ee818f11fb89296ef2.zip | |
refactor: extract WSL fix to standalone script and add documentationmain
Diffstat (limited to 'wsl-fix.sh')
| -rwxr-xr-x | wsl-fix.sh | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/wsl-fix.sh b/wsl-fix.sh new file mode 100755 index 0000000..06e532a --- /dev/null +++ b/wsl-fix.sh @@ -0,0 +1,76 @@ +#!/bin/bash +set -euo pipefail + +# WSL Systemd Fix Script +# Run this once per WSL restart to enable systemd user sessions + +# Detect if running on WSL +if [[ ! -f /proc/version ]] || ! grep -qi microsoft /proc/version; then + echo "Not running on WSL - nothing to do" + exit 0 +fi + +USER_ID=$(id -u) +USER_NAME=$(id -un) +USER_GROUP=$(id -gn) +RUNTIME_DIR="/run/user/${USER_ID}" + +echo "=== WSL Systemd User Session Setup ===" +echo "User: ${USER_NAME} (UID: ${USER_ID})" +echo "Runtime directory: ${RUNTIME_DIR}" +echo "" + +# Check if already set up +if [[ -d "${RUNTIME_DIR}" ]] && [[ -S "${RUNTIME_DIR}/bus" ]]; then + echo "Runtime directory already exists and dbus socket is present." + echo "Setting environment variables..." + export XDG_RUNTIME_DIR="${RUNTIME_DIR}" + export DBUS_SESSION_BUS_ADDRESS="unix:path=${RUNTIME_DIR}/bus" + echo "" + echo "Environment set. You can now use: make status, make backup-now, etc." + exit 0 +fi + +# Create runtime directory (requires sudo) +if [[ ! -d "${RUNTIME_DIR}" ]]; then + echo "Creating runtime directory (requires sudo)..." + sudo mkdir -p "${RUNTIME_DIR}" + sudo chmod 700 "${RUNTIME_DIR}" + sudo chown "${USER_NAME}:${USER_GROUP}" "${RUNTIME_DIR}" + echo "✓ Runtime directory created" +fi + +# Start user systemd service (requires sudo) +echo "Starting systemd user session (requires sudo)..." +sudo systemctl start "user@${USER_ID}.service" 2>/dev/null || true +echo "✓ Systemd user session started" + +# Wait a moment for dbus socket to be created +echo "Waiting for dbus socket..." +for i in {1..10}; do + if [[ -S "${RUNTIME_DIR}/bus" ]]; then + break + fi + sleep 0.5 +done + +if [[ ! -S "${RUNTIME_DIR}/bus" ]]; then + echo "Warning: dbus socket not found, systemd may not be fully initialized" +fi + +# Set environment variables +export XDG_RUNTIME_DIR="${RUNTIME_DIR}" +export DBUS_SESSION_BUS_ADDRESS="unix:path=${RUNTIME_DIR}/bus" + +# Reload systemd daemon +systemctl --user daemon-reexec 2>/dev/null || true + +echo "" +echo "=== Setup Complete ===" +echo "Environment variables set for current session:" +echo " XDG_RUNTIME_DIR=${XDG_RUNTIME_DIR}" +echo " DBUS_SESSION_BUS_ADDRESS=${DBUS_SESSION_BUS_ADDRESS}" +echo "" +echo "You can now use: make status, make backup-now, make check-now, etc." +echo "" +echo "Note: Run 'make fix-wsl' again after each WSL restart." |
