🗝
summary refs log tree commit diff
path: root/misc/searxng.py
blob: db56c2124fc6dfc272e5695494c8dc52f3f1f592 (plain) (blame)
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
import random
import string

from commia.bearer import get_key, has_key, keys, set_key
from commia.prelude import *
from commia.ssh import ssh_args, ssh_opt_args, ssh_prewarm
from commia.util import with_written

ssh_prewarm("asylum", "secrets@bearer")

if not has_key(keys.searxng.secret_key):
    print("initializing secret key")
    key = ""
    for _ in range(64):
        key += random.choice(string.ascii_letters + string.digits + "-_=+")
    set_key(keys.searxng.secret_key, key)

secret_key = get_key(keys.searxng.secret_key)
searxng_conf = Path("misc/searxng.yml").read_text().replace("%SECRET_KEY%", secret_key)

with_written(
    searxng_conf,
    lambda path: run_sc(
        ["scp", *ssh_opt_args(), path, "asylum:/etc/searxng/settings.yml"]
    ),
)

run_check(p([*ssh_args(), "systemctl", "restart", "searxng"]))