aboutsummaryrefslogtreecommitdiff
path: root/scripts/p7s/soju.py
blob: b41476e71145114c10543771bfb29e9da8f083b5 (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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import pathlib
import textwrap


def setup_soju():
    home = pathlib.Path.home()
    config = home / ".config" / "containers" / "systemd"
    config.mkdir(parents=True, exist_ok=True)
    (config / "soju.container").write_text(textwrap.dedent("""
        [Unit]
        Description=IRC Bouncer

        [Container]
        Image=codeberg.org/emersion/soju:latest
        Volume=/home/alex/.config/containers/systemd/soju_config:/soju-config
        Volume=/home/alex/.local/lib/soju/:/var/lib/soju
        # running this on an LXC container, which borks SecurityLabelDisable
        #SecurityLabelDisable=true
        Network=host

        Exec=soju

        [Service]
        # Extend Timeout to allow time to pull the image
        TimeoutStartSec=900

        [Install]
        # Start by default on boot
        WantedBy=multi-user.target default.target
    """).lstrip())

    (config / "soju_config").write_text(textwrap.dedent("""
        db sqlite3 /var/lib/soju/main.db
        message-store fs /var/lib/soju/logs/
        listen irc+insecure://0.0.0.0:6667
    """).lstrip())

    (home / ".local" / "lib" / "soju").mkdir(parents=True, exist_ok=True)

    sojudb_wrapper = (home / ".local" / "bin" / "sojudb")
    sojudb_wrapper.write_text(textwrap.dedent("""
        #!/bin/sh

        podman run -it --rm --security-opt label=disable -v ~/.config/containers/systemd/soju_config:/soju-config -v ~/.local/lib/soju/:/var/lib/soju codeberg.org/emersion/soju:latest sojudb "$@"
    """).lstrip())
    sojudb_wrapper.chmod(0o755)