Skip to content

Instantly share code, notes, and snippets.

@s4lt3d
Created December 13, 2025 03:37
Show Gist options
  • Select an option

  • Save s4lt3d/cdcd8b701158601324351f4102ee7ca8 to your computer and use it in GitHub Desktop.

Select an option

Save s4lt3d/cdcd8b701158601324351f4102ee7ca8 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
set -e
echo "=== Syncthing on SteamOS background setup (distrobox) ==="
# -----------------------------
# CONFIG
# -----------------------------
BOX_NAME="syncthing-box"
SERVICE_NAME="syncthing.service"
SERVICE_DIR="$HOME/.config/systemd/user"
SERVICE_FILE="$SERVICE_DIR/$SERVICE_NAME"
USERNAME="$(whoami)"
# -----------------------------
# PRECHECKS
# -----------------------------
if ! command -v distrobox >/dev/null 2>&1; then
echo "ERROR: distrobox not found."
echo "Install distrobox first, then re-run this script."
exit 1
fi
if ! command -v systemctl >/dev/null 2>&1; then
echo "ERROR: systemctl not found."
exit 1
fi
# -----------------------------
# CLEAN UNINSTALL (SAFE)
# -----------------------------
echo "Removing SyncThingy Flatpak if present..."
if command -v flatpak >/dev/null 2>&1; then
flatpak uninstall -y com.github.com.zocker_160.SyncThingy >/dev/null 2>&1 || true
rm -rf "$HOME/.var/app/com.github.com.zocker_160.SyncThingy" || true
fi
# -----------------------------
# CREATE DISTROBOX
# -----------------------------
if distrobox list | grep -q "$BOX_NAME"; then
echo "Distrobox '$BOX_NAME' already exists. Reusing it."
else
echo "Creating distrobox '$BOX_NAME' (Arch Linux)..."
distrobox create \
--name "$BOX_NAME" \
--image archlinux:latest
fi
# -----------------------------
# INSTALL SYNCTHING IN BOX
# -----------------------------
echo "Installing Syncthing inside distrobox..."
distrobox enter "$BOX_NAME" -- sudo pacman -Syu --noconfirm syncthing
# -----------------------------
# CREATE SYSTEMD USER SERVICE
# -----------------------------
echo "Creating systemd user service..."
mkdir -p "$SERVICE_DIR"
cat > "$SERVICE_FILE" <<EOF
[Unit]
Description=Syncthing (distrobox)
After=network-online.target
Wants=network-online.target
[Service]
ExecStart=/usr/bin/distrobox enter $BOX_NAME -- syncthing --no-browser --no-restart
Restart=on-failure
RestartSec=5
[Install]
WantedBy=default.target
EOF
# -----------------------------
# ENABLE AND START SERVICE
# -----------------------------
echo "Enabling systemd user service..."
systemctl --user daemon-reload
systemctl --user enable "$SERVICE_NAME"
systemctl --user start "$SERVICE_NAME"
# -----------------------------
# ENABLE LINGER
# -----------------------------
echo "Enabling user lingering (requires sudo)..."
sudo loginctl enable-linger "$USERNAME"
# -----------------------------
# STATUS
# -----------------------------
echo
echo "=== STATUS ==="
systemctl --user status "$SERVICE_NAME" --no-pager || true
echo
echo "Setup complete."
echo "Syncthing will now start automatically in the background, including Steam Mode."
echo "Web UI: http://127.0.0.1:8384"
#!/usr/bin/env bash
set -e
SERVICE_DIR="$HOME/.config/systemd/user"
SERVICE_FILE="$SERVICE_DIR/syncthing.service"
USERNAME="$(whoami)"
mkdir -p "$SERVICE_DIR"
cat > "$SERVICE_FILE" <<EOF
[Unit]
Description=SyncThingy (Flatpak wrapper)
After=network-online.target
Wants=network-online.target
[Service]
ExecStart=/usr/bin/flatpak run com.github.com.zocker_160.SyncThingy
Restart=on-failure
RestartSec=5
[Install]
WantedBy=default.target
EOF
systemctl --user daemon-reload
systemctl --user enable syncthing.service
systemctl --user start syncthing.service
sudo loginctl enable-linger "$USERNAME"
systemctl --user status syncthing.service --no-pager
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment