Skip to content

Instantly share code, notes, and snippets.

@rezzafr33
Last active June 4, 2025 03:29
Show Gist options
  • Save rezzafr33/b471c3ce163a30d207dd5c9d082baa16 to your computer and use it in GitHub Desktop.
Save rezzafr33/b471c3ce163a30d207dd5c9d082baa16 to your computer and use it in GitHub Desktop.
Setup Green Tunnel container as systemd service (using podman's quadlet)

Green Tunnel Setup Script for Steam Deck

Overview

This script (setup-green-tunnel.sh) automates the setup of the Green Tunnel proxy as a Podman container on a Steam Deck, managed as a user-level systemd service. It pulls the Green Tunnel Docker image, configures necessary files, starts the service, and provides instructions for setting up the Steam Deck's HTTP proxy to use Green Tunnel.

Decky loader Web Browser opening https://one.one.one.one/help

What the Script Does

  1. Pulls the Green Tunnel Image:

    • Downloads docker.io/sadeghhayeri/green-tunnel using Podman.
    • Verifies the image is successfully pulled.
  2. Creates Directories:

    • Sets up ~/.config/containers/systemd and ~/.config/systemd/user/podman-user-wait-network-online.service.d.
  3. Manages Configuration Files:

    • Creates green-tunnel.container to define the Green Tunnel service (listens on port 8000).
    • Creates override.conf to set a 3-second timeout for network-online checks.
    • If either file exists:
      • Skips creation if the content matches the expected configuration.
      • Shows differences (diff -u) and prompts to replace if content differs, defaulting to keeping the existing file.
  4. Configures Systemd:

    • Reloads the user systemd daemon to process the .container file.
    • Verifies that green-tunnel.service is generated by Podman Quadlet.
    • Starts the service immediately.
  5. Configure Steam Deck Proxy:

    • Outputs steps to configure the Steam Deck's HTTP Proxy to use Green Tunnel on 127.0.0.1:8000.

Troubleshooting

  • Image Pull Fails:

    • Ensure internet connectivity and Podman is installed.
    • Run podman pull docker.io/sadeghhayeri/green-tunnel manually to debug.
  • Service Not Generated:

    • Check ~/.config/containers/systemd/green-tunnel.container for syntax errors.
    • Run systemd-analyze --user --generators=true verify green-tunnel.service to analyze generated service.
    • Run /usr/lib/systemd/system-generators/podman-system-generator --dryrun --user see if it shows any errors.
  • Service Fails to Start:

    • Run systemctl --user status green-tunnel.service or journalctl --user -u green-tunnel.service for logs.
    • Check for port conflicts on 8000 (or the port in green-tunnel.container) using ss -tuln | grep 8000.
  • Permission Errors:

    • Ensure your user has write permissions to ~/.config/.
    • Run chmod -R u+rw ~/.config/ if needed.
  • Proxy Not Working:

    • Verify the service is running (systemctl --user is-active green-tunnel.service).
    • Test connectivity with curl -s --connect-timeout 2 http://localhost:8000.
    • Ensure the correct port is used in Steam Deck's proxy settings.

Prerequisites

  • Podman installed by default in steamdeck.
  • Write permissions to ~/.config/ for creating directories and files.
  • Internet access to pull the Docker image.
  • A terminal to run the script (e.g., via Desktop Mode or SSH).

Usage

  1. Download the Script:

    • Save setup-green-tunnel.sh to a directory (e.g., ~/green-tunnel/).
  2. Make the Script Executable:

    chmod +x setup-green-tunnel.sh
  3. Run the Script:

    ./setup-green-tunnel.sh
    • The script will:
      • Pull the Green Tunnel image.
      • Create necessary directories and files.
      • Prompt you to replace existing green-tunnel.container or override.conf if their contents differ (press y to replace, or Enter/any other key to keep existing, which is the default).
      • Reload systemd, start the service, and verify it’s running.
      • Display Steam Deck proxy configuration instructions.
  4. Handle Prompts:

    • If green-tunnel.container or override.conf exists with different content, you’ll see a diff output and a prompt like:
      Do you want to replace ~/.config/containers/systemd/green-tunnel.container with the new content? (y/N, default: keep existing):
      
      • Press y to replace, or press Enter (or any other key) to keep the existing file.
  5. Configure Steam Deck Proxy:

    • Follow the script’s final instructions:
      To use Green Tunnel in Steam Deck's proxy settings:
      1. Open Settings on your Steam Deck.
      2. Navigate to Internet -> Http Proxy.
      3. In the Address field, enter: 127.0.0.1
      4. In the Port field, enter: 8000
      5. Save the settings to route traffic through Green Tunnel.
      
    • Note: If you kept an existing green-tunnel.container with a different port (e.g., 9000), use that port instead of 8000.

Steam Deck Proxy Settings

Notes

  • Idempotency: The script is idempotent, skipping unnecessary actions (e.g., recreating correct files or directories).
  • Non-Interactive Use: Prompts require user input. For automation, consider piping input (e.g., echo "n" | ./setup-green-tunnel.sh) or modifying the script for a timeout.
  • Custom Ports: If you keep an existing green-tunnel.container with a different port, update the Steam Deck proxy port accordingly.
  • Steam Deck Context: This script is tailored for Steam Deck’s user-level systemd environment. Adjust paths or settings for other systems.

For issues or feature requests, please report them in the project repository or contact the maintainer.

#!/bin/bash
# Exit on any error
set -e
# Pull the green-tunnel image using podman and verify it's downloaded
echo "Pulling docker.io/sadeghhayeri/green-tunnel..."
if ! podman pull docker.io/sadeghhayeri/green-tunnel; then
echo "Error: Failed to pull the image."
exit 1
fi
# Verify the image exists
if ! podman image exists docker.io/sadeghhayeri/green-tunnel; then
echo "Error: Image not found after pulling."
exit 1
fi
echo "Image successfully downloaded."
# Create the systemd containers directory
CONTAINERS_DIR=~/.config/containers/systemd
echo "Creating directory $CONTAINERS_DIR..."
mkdir -p "$CONTAINERS_DIR"
if ! test -d "$CONTAINERS_DIR"; then
echo "Error: Failed to create $CONTAINERS_DIR."
exit 1
fi
echo "Directory $CONTAINERS_DIR created or already exists."
# Check if green-tunnel.container exists and has correct content
CONTAINER_FILE="$CONTAINERS_DIR/green-tunnel.container"
EXPECTED_CONTAINER=$(mktemp)
cat << EOF > "$EXPECTED_CONTAINER"
[Unit]
Description=Green Tunnel Container
[Container]
Image=docker.io/sadeghhayeri/green-tunnel
PublishPort=8000:8000
[Install]
WantedBy=default.target
EOF
if [ -f "$CONTAINER_FILE" ]; then
if cmp -s "$CONTAINER_FILE" "$EXPECTED_CONTAINER"; then
echo "$CONTAINER_FILE exists with correct content, skipping creation."
else
echo "Differences found in $CONTAINER_FILE:"
diff -u "$CONTAINER_FILE" "$EXPECTED_CONTAINER" || true
echo -n "Do you want to replace $CONTAINER_FILE with the new content? (y/N, default: keep existing): "
read -r choice
if [[ "$choice" =~ ^[Yy]$ ]]; then
echo "Replacing $CONTAINER_FILE..."
mv "$EXPECTED_CONTAINER" "$CONTAINER_FILE"
if ! test -s "$CONTAINER_FILE"; then
echo "Error: Failed to replace $CONTAINER_FILE or file is empty."
exit 1
fi
echo "$CONTAINER_FILE replaced successfully."
else
echo "Keeping existing $CONTAINER_FILE (default behavior)."
fi
fi
else
echo "Creating $CONTAINER_FILE (file does not exist)..."
mv "$EXPECTED_CONTAINER" "$CONTAINER_FILE"
if ! test -s "$CONTAINER_FILE"; then
echo "Error: Failed to create $CONTAINER_FILE or file is empty."
exit 1
fi
echo "$CONTAINER_FILE created successfully."
fi
# Clean up temporary file if it still exists
[ -f "$EXPECTED_CONTAINER" ] && rm "$EXPECTED_CONTAINER"
# Create the systemd user override directory
OVERRIDE_DIR=~/.config/systemd/user/podman-user-wait-network-online.service.d
echo "Creating directory $OVERRIDE_DIR..."
mkdir -p "$OVERRIDE_DIR"
if ! test -d "$OVERRIDE_DIR"; then
echo "Error: Failed to create $OVERRIDE_DIR."
exit 1
fi
echo "Directory $OVERRIDE_DIR created or already exists."
# Check if override.conf exists and has correct content
OVERRIDE_FILE="$OVERRIDE_DIR/override.conf"
EXPECTED_OVERRIDE=$(mktemp)
cat << EOF > "$EXPECTED_OVERRIDE"
[Service]
TimeoutStartSec=3s
EOF
if [ -f "$OVERRIDE_FILE" ]; then
if cmp -s "$OVERRIDE_FILE" "$EXPECTED_OVERRIDE"; then
echo "$OVERRIDE_FILE exists with correct content, skipping creation."
else
echo "Differences found in $OVERRIDE_FILE:"
diff -u "$OVERRIDE_FILE" "$EXPECTED_OVERRIDE" || true
echo -n "Do you want to replace $OVERRIDE_FILE with the new content? (y/N, default: keep existing): "
read -r choice
if [[ "$choice" =~ ^[Yy]$ ]]; then
echo "Replacing $OVERRIDE_FILE..."
mv "$EXPECTED_OVERRIDE" "$OVERRIDE_FILE"
if ! test -s "$OVERRIDE_FILE"; then
echo "Error: Failed to replace $OVERRIDE_FILE or file is empty."
exit 1
fi
echo "$OVERRIDE_FILE replaced successfully."
else
echo "Keeping existing $OVERRIDE_FILE (default behavior)."
fi
fi
else
echo "Creating $OVERRIDE_FILE (file does not exist)..."
mv "$EXPECTED_OVERRIDE" "$OVERRIDE_FILE"
if ! test -s "$OVERRIDE_FILE"; then
echo "Error: Failed to create $OVERRIDE_FILE or file is empty."
exit 1
fi
echo "$OVERRIDE_FILE created successfully."
fi
# Clean up temporary file if it still exists
[ -f "$EXPECTED_OVERRIDE" ] && rm "$EXPECTED_OVERRIDE"
# Reload user systemd daemon to recognize new or updated files and generate the service
echo "Reloading systemd user daemon..."
if ! systemctl --user daemon-reload; then
echo "Error: Failed to reload systemd daemon."
exit 1
fi
echo "Systemd daemon reloaded successfully."
# Verify that green-tunnel.service was generated
echo "Verifying that green-tunnel.service was generated..."
if ! systemctl --user list-units --type=service | grep -q "green-tunnel.service"; then
echo "Error: green-tunnel.service was not generated. Check Podman Quadlet setup."
exit 1
fi
echo "green-tunnel.service successfully generated."
# Start the green-tunnel service immediately
echo "Starting green-tunnel.service..."
if ! systemctl --user start green-tunnel.service; then
echo "Error: Failed to start green-tunnel.service. Check with 'systemctl --user status green-tunnel.service'."
exit 1
fi
# Verify the service is running
if systemctl --user is-active green-tunnel.service > /dev/null; then
echo "Green Tunnel service is running."
else
echo "Error: Green Tunnel service failed to start. Check with 'systemctl --user status green-tunnel.service'."
exit 1
fi
# Instructions for configuring Steam Deck proxy settings
echo -e "\nTo use Green Tunnel in Steam Deck's proxy settings:"
echo "1. Open Settings on your Steam Deck."
echo "2. Navigate to Internet -> Http Proxy."
echo "3. In the Address field, enter: 127.0.0.1"
echo "4. In the Port field, enter: 8000"
echo "5. Save the settings to route traffic through Green Tunnel."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment