The Problem

Scripts that run on a production VPS were being written and edited in place. There was no version control, no linting and nowhere safe to test a change before it hit a live server running backups, certificate checks, monitoring and a WireGuard endpoint.

The goal was a test environment on Windows that:

  • Runs bash exactly as the VPS would, with the same packages
  • Avoids Docker, to stay light on a laptop
  • Lives as one Git repo alongside other projects in Dev\
  • Never connects to the VPS. Everything moves by manual export and deploy.

The Design

ComponentRuns InPurpose
BashWSL Debian 13 (trixie)Same release as the VPS, same package list
PowerShellNative pwsh 7Windows-only modules (AD, WMI, registry)
PythonRepo .venvIsolated dependencies
EditorVS CodeShellCheck inline, one-key test task
SyncPrivate GitHub repoIdentical setup on laptop and main PC
Script-Lab/
├── bash/
│   ├── _lab/                    lab tooling
│   │   ├── apt-packages.txt
│   │   ├── sync-vps-packages/
│   │   ├── new-bash-script/
│   │   └── import-vps-scripts/
│   └── NAME/                    one folder per script
│       ├── NAME.sh
│       ├── deps/apt.txt
│       └── output/
├── python/  powershell/  docs/
└── .vscode/ (settings.json, tasks.json)

Every script gets its own folder holding its dependencies and its output. With dozens of scripts over time, nothing ends up scattered across the repo.

Matching WSL to the VPS

The VPS’s manually installed package list is exported by hand:

apt-mark showmanual | sort > /Backup_Data/vps-apt-manual.txt
cat /etc/os-release > /Backup_Data/vps-os.txt

The files are copied to the PC, and a sync script builds the WSL list. It also:

  • Strips server-only packages (kernel, grub, cloud-init)
  • Strips packages from third-party repos WSL does not have (CrowdSec, Netdata, Tailscale, Webmin)
  • Merges every script’s deps/apt.txt
  • Drops anything apt-cache cannot find
  • Installs only when passed --install
bash bash/_lab/sync-vps-packages/sync-vps-packages.sh --install

The first raw install failed on exactly those seven third-party packages, which is what drove the filter.

Testing a Script

A single committed tasks.json lints and runs whichever script is open:

"command": "wsl",
"args": ["bash", "-c", "f=$(wslpath '${file}'); shellcheck \"$f\" && bash \"$f\" ${input:args}"]

VS Code passes the Windows path, wslpath converts it, ShellCheck lints it, and the script only runs if the lint is clean. A prompt collects arguments, so --dry-run can be passed in.

Finding and Importing Existing Scripts

Scripts on the VPS were found by checking candidate files against the dpkg database. Anything no package owns was added by hand:

find "$d" -xdev -type f -size -1024k ... | while read -r f; do
  dpkg -S "$f" >/dev/null 2>&1 && continue
  echo "$f"
done

The first run returned zero results. find -size -1M rounds every file up to a whole MiB, so it only matches empty files. Switching to -size -1024k found 39 files. After filtering out Warp terminal helpers and .bak copies, 18 real scripts remained, five of them live in cron and systemd.

A secrets grep flagged two files. Both turned out to read keys and tokens at runtime from config files that are never exported. The scripts were bundled, hash-checked, copied down and bulk-imported into their own folders, keeping their original names so cron and systemd entries still match on deployment.

Deploying Back

Deployment stays manual:

tar --exclude='output/*' -czf NAME.tar.gz NAME      # WSL
sudo tar -xzf NAME.tar.gz -C /opt/scripts           # VPS
sudo chown -R root:root /opt/scripts/NAME
sudo chmod 750 /opt/scripts/NAME/NAME.sh
sudo /opt/scripts/NAME/NAME.sh --dry-run

Ownership has to be reset every time, because tar preserves the WSL user’s UID.

What WSL Cannot Reproduce

AreaWhy
Firewall and networkWSL sits behind Windows NAT
Disks and mountsNo real block devices
Live servicesThird-party tools are not installed
CronNot used in WSL, and cron’s minimal PATH is a common failure

Read-only and reporting scripts transfer 1:1. Anything that changes the system is only proven by its first dry run on the VPS.

Lessons

  • Git in WSL is separate from Windows Git and needs its own identity. gh auth login plus gh auth setup-git is the cleanest way to sign it in.
  • Mixed line endings break bash on Linux. .gitattributes enforces LF for .sh, .txt, .json and .md, and CRLF for .ps1.
  • Moving a script one level deeper broke its internal paths. Resolving paths from $(dirname "$0") and checking them with grep -nE '^(HERE|LAB|OUT)=' caught it.
  • Long heredoc pastes get truncated in the terminal. Shipping scripts as files was more reliable.

References