-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathsyncbl
More file actions
executable file
·31 lines (24 loc) · 922 Bytes
/
Copy pathsyncbl
File metadata and controls
executable file
·31 lines (24 loc) · 922 Bytes
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/python3
# SPDX-License-Identifier: MIT
#
# Syncs latest badkeys blocklist from a remote host to the
# web server running https://updates.badkeys.info/
import os
import subprocess
import sys
import tomllib
VER = "v0"
with open(os.path.expanduser("~/.syncblrc"), "rb") as f:
conf = tomllib.load(f)
latest = subprocess.check_output(["ssh", conf["remotessh"], "cat", "~/blout/latest"],
env={"LC_ALL": "C"})
latest = str(int(latest))
tdir = os.path.join(os.path.expanduser(conf["webroot"]), VER)
target = os.path.join(tdir, latest)
if os.path.exists(target):
# Nothing to do
sys.exit(0)
subprocess.check_output(["scp", "-r", f"{conf['remotessh']}:{conf['remotepath']}/{latest}", tdir])
template = os.path.join(tdir, "badkeysdata.json")
# Python supports no atomic symlink overwrite...
subprocess.check_output(["ln", "-sf", f"{target}/badkeysdata.json", template])