summarylogtreecommitdiffstats
path: root/smp-server.install
blob: 26e8b2c77479205e85feea457dac1df350436887 (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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
post_install() {
    systemd-sysusers smp-server.conf 2>/dev/null || true
    systemd-tmpfiles --create smp-server.conf 2>/dev/null || true

    # Не перезаписываем конфиг если он уже существует
    if [[ ! -f /etc/opt/simplex/smp-server.ini ]]; then
        mv /etc/opt/simplex/smp-server.ini.new \
           /etc/opt/simplex/smp-server.ini 2>/dev/null || true
    else
        rm -f /etc/opt/simplex/smp-server.ini.new
    fi

    # Исправляем права на конфиги и ключи
    if [[ -d /etc/opt/simplex ]]; then
        chown -R smp:smp /etc/opt/simplex/ 2>/dev/null || true
        chmod 600 /etc/opt/simplex/*.key 2>/dev/null || true
        chmod 644 /etc/opt/simplex/*.crt 2>/dev/null || true
        chmod 644 /etc/opt/simplex/*.ini 2>/dev/null || true
    fi

    echo ""
    echo "======================================================================"
    echo " smp-server installed."
    echo "======================================================================"
    echo ""
    echo " MIGRATING FROM A MANUAL INSTALLATION?"
    echo " If you already have a running server with existing keys — DO NOT run"
    echo " smp-server init. Instead, restore your backup:"
    echo ""
    echo "    cp ca.crt ca.key ca.srl fingerprint /etc/opt/simplex/"
    echo "    cp server.crt server.csr /etc/opt/simplex/"
    echo "    cp openssl_ca.conf openssl_server.conf /etc/opt/simplex/"
    echo "    cp smp-server.ini /etc/opt/simplex/"
    echo "    chown -R smp:smp /etc/opt/simplex/"
    echo ""
    echo " Then start: systemctl enable --now smp-server"
    echo " Your server address (fingerprint) will remain the same."
    echo ""
    echo " ------------------------------------------------------------------"
    echo ""
    echo " FRESH INSTALLATION? Initialize first (replace with your domain):"
    echo ""
    echo "    sudo -u smp smp-server init -y --store-log \\"
    echo "        --fqdn=smp.example.com"
    echo ""
    echo "    With queue-creation password:"
    echo "    sudo -u smp smp-server init -y --store-log \\"
    echo "        --password='your-password' --fqdn=smp.example.com"
    echo ""
    echo " 1. Edit config:  /etc/opt/simplex/smp-server.ini"
    echo "    - [TRANSPORT] host: your domain"
    echo "    - [INFORMATION] fields for the server info page (optional)"
    echo ""
    echo " 2. Open firewall ports: 443/tcp and 8443/tcp"
    echo ""
    echo " 3. Start: systemctl enable --now smp-server"
    echo ""
    echo " 4. Get your server address:"
    echo "    journalctl -u smp-server | grep 'Server address'"
    echo ""
    echo " !! Back up and delete the CA key after init:"
    echo "    cp /etc/opt/simplex/ca.key ~/ca.key.backup"
    echo "    rm /etc/opt/simplex/ca.key"
    echo "======================================================================"
}

post_upgrade() {
    if [[ -d /etc/opt/simplex ]]; then
        chown -R smp:smp /etc/opt/simplex/ 2>/dev/null || true
        chmod 600 /etc/opt/simplex/*.key 2>/dev/null || true
        chmod 644 /etc/opt/simplex/*.crt 2>/dev/null || true
        chmod 644 /etc/opt/simplex/*.ini 2>/dev/null || true
    fi
    echo ""
    echo " smp-server upgraded — restart to apply: systemctl restart smp-server"
}

pre_remove() {
    systemctl stop smp-server.service 2>/dev/null || true
    systemctl disable smp-server.service 2>/dev/null || true
}

post_remove() {
    echo ""
    echo " Data preserved in /etc/opt/simplex/ and /var/opt/simplex/"
    echo " Remove manually if no longer needed."
    echo " To remove the 'smp' user: userdel smp"
}