summarylogtreecommitdiffstats
path: root/bartoc.install
blob: 0fec7e0c6d644cb79a279b7cb1589925f2e5024a (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
47
48
49
50
51
52
53
54
55
56
57
58
59
post_install() {
    echo ""
    echo "==> bartoc installed successfully!"
    echo ""
    echo "    Before starting the service, configure the bartos connection:"
    echo "    1. Copy and edit the example config:"
    echo "         mkdir -p ~/.config/bartoc"
    echo "         cp /usr/share/doc/bartoc/examples/bartoc.toml.example ~/.config/bartoc/bartoc.toml"
    echo "         \$EDITOR ~/.config/bartoc/bartoc.toml"
    echo "    2. Store secrets — choose one method:"
    echo ""
    echo "       A) Systemd user credentials (recommended for lingering services started at boot):"
    echo "            bartoc-secrets-init"
    echo "         Adds SetCredentialEncrypted= lines to:"
    echo "            ~/.config/systemd/user/bartoc.service.d/secrets.conf"
    echo ""
    echo "       B) Platform keychain (suitable when user is always logged in at service start):"
    echo "            barto-cli secrets set BARTOC_HMAC_KEY"
    echo "            barto-cli secrets set BARTOC_SERVER_PUBLIC_KEY   # if using Ed25519 signing"
    echo "            barto-cli secrets set BARTOC_BARTOS__API_KEY      # if using Bearer token auth"
    echo ""
    echo "    3. Enable lingering so bartoc starts at boot (optional but recommended):"
    echo "         loginctl enable-linger \$USER"
    echo "    4. Enable and start the service:"
    echo "         systemctl --user daemon-reload"
    echo "         systemctl --user enable --now bartoc"
    echo "    5. Enable daily log rotation:"
    echo "         systemctl --user enable --now bartoc-logrotate.timer"
    echo "    Optional: TLS & Certificate Pinning"
    echo "         Certificate pinning:  set ca_cert in [bartos] to pin your bartos CA cert."
    echo "         Mutual TLS:           set client_cert and client_key in [bartos]."
    echo "         See SECRETS.md and: https://github.com/rustyhorde/barto#secrets-management"
    echo ""
}

post_upgrade() {
    local _user="${SUDO_USER:-}"
    if [ -n "$_user" ]; then
        systemctl --user -M "${_user}@.host" daemon-reload 2>/dev/null || true
        if systemctl --user -M "${_user}@.host" is-enabled --quiet bartoc 2>/dev/null; then
            echo "==> Restarting bartoc service for ${_user}..."
            systemctl --user -M "${_user}@.host" restart bartoc
            echo "==> bartoc restarted successfully."
        elif systemctl --user -M "${_user}@.host" is-enabled --quiet bartoc-age 2>/dev/null; then
            echo "==> Restarting bartoc-age service for ${_user}..."
            systemctl --user -M "${_user}@.host" restart bartoc-age
            echo "==> bartoc-age restarted successfully."
        else
            echo ""
            echo "==> bartoc upgraded to $1."
            echo "    Run 'systemctl --user daemon-reload && systemctl --user enable --now bartoc' when ready."
            echo ""
        fi
        if systemctl --user -M "${_user}@.host" is-enabled --quiet bartoc-logrotate.timer 2>/dev/null; then
            echo "==> Restarting bartoc-logrotate.timer for ${_user}..."
            systemctl --user -M "${_user}@.host" restart bartoc-logrotate.timer 2>/dev/null || true
        fi
    fi
}