aboutsummaryrefslogtreecommitdiffstats
path: root/make-local.py
blob: 366935c103b69f07f35befec09029a7ead23696f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/usr/bin/env python3
# Copyright (C) 2026 Danilo M. <danix@danix.xyz>
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License version 2 as published
# by the Free Software Foundation. See the LICENSE file for details.

# Run on the VM, as root, BEFORE installing the new slackrepo_SBo-danix.conf:
# copies the site values out of the old config into SBo-danix.local (mode 600).
# Prints only which keys it found, never their values.
import os, re, sys
old, dest = sys.argv[1], sys.argv[2]
if os.path.exists(dest):
    sys.exit(f"{dest} exists, left alone")
s = open(old).read()
found = {
    "SB_RSYNC_TARGET": re.search(r"local rsync_target='([^']*)'", s),
    "SB_RSYNC_EXCLUDES": re.search(r"local rsync_excludes='([^']*)'", s),
    "SB_RSYNC_PASSWORD_FILE": re.search(r"local rsync_password_file='([^']*)'", s),
    "SB_GOTIFY_KEY": re.search(r'X-Gotify-Key: ([^"]*)"', s),
    "SB_GOTIFY_URL": re.search(r'\n\s*"(https?://[^"]*)" >/dev/null', s),
}
missing = [k for k, m in found.items() if not m]
if missing:
    sys.exit(f"not found in {old}: {', '.join(missing)}")
fd = os.open(dest, os.O_WRONLY | os.O_CREAT | os.O_EXCL, 0o600)
with os.fdopen(fd, "w") as f:
    f.write("# site settings for slackrepo_SBo-danix.conf and sb-publish (root-only)\n")
    for k, m in found.items():
        f.write(f"{k}='{m.group(1)}'\n")
print(f"wrote {dest}: {', '.join(found)}")