summarylogtreecommitdiffstats
path: root/cellframe-node.install
blob: 990cef2d02842ef83d97f14cc1319d801bd1086a (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
_showmsg() {
BOLD=$(tput bold)
NORMAL=$(tput sgr0)

echo -e "
${BOLD}NODE CONFIGURATION FILES${NORMAL}

    By default, no configuration files are provided. For enabling sane default configuration, run (as root):

    ${BOLD}cellframe-node-config -i /opt/cellframe-node/share/default.setup${NORMAL}

    For enabling diagtool (which is used by Cellframe Wallet), run (as root):

    ${BOLD}systemctl enable --now cellframe-diagtool.service${NORMAL}

${BOLD}STARTING CELLFRAME NODE${NORMAL}

    Use the provided systemd unit file and launch node with cellframe-node-config tool (as root):

    ${BOLD}cellframe-node-config -e service enable${NORMAL}
    ${BOLD}cellframe-node-config -e service start${NORMAL}

${BOLD}RUNNING A MASTERNODE${NORMAL}

    View the prerequisites and instructions at:

    ${BOLD}https://wiki.cellframe.net/02.+Learn/Cellframe+Node/Master+Node+Manual+Setup${NORMAL}\n"
}

_is_python_and_pip_ok() {
    PYTHON_BIN=/opt/cellframe-node/python/bin/python3.10
    PIP_BIN=/opt/cellframe-node/python/bin/pip3

    [[ -f "$PYTHON_BIN" && ! -x "$PYTHON_BIN" ]] && chmod +x "$PYTHON_BIN"
    [[ -f "$PIP_BIN" && ! -x "$PIP_BIN" ]] && chmod +x "$PIP_BIN"

    if [[ -x "$PYTHON_BIN" && -x "$PIP_BIN" ]]; then
        return 0
    else
        return 1
    fi
}

_post_install_wheels() {
    if _is_python_and_pip_ok; then
        WHEEL_DIR="/opt/cellframe-node/share/wheels"
        WHEELS=("$WHEEL_DIR"/*.whl)

        echo ":: Installing Python wheel packages..."
        /opt/cellframe-node/python/bin/pip3 install "${WHEELS[@]}" &> /dev/null && echo ":: Installed wheel packages for Python development" \
            || echo ":: Failed to install Python wheel packages"
        rm "$WHEEL_DIR"/*.whl && echo ":: Removed wheel packages" || echo ":: Failed to remove wheel packages"
    else
        echo ":: Python or pip not found, skipping wheel installation..."
    fi
}


post_install() {
    _post_install_wheels
    _showmsg
}

post_upgrade() {
    _post_install_wheels
    echo ":: Executing systemctl daemon-reload..."
    systemctl daemon-reload
    systemctl is-active --quiet cellframe-node.service \
    && echo ":: Restarting cellframe-node.service..." \
    && systemctl restart cellframe-node.service \
    || echo ":: cellframe-node.service not enabled, skipping restart..."
}

pre_remove() {
    systemctl is-active --quiet cellframe-node.service \
    && systemctl stop cellframe-node.service \
    && systemctl disable cellframe-node.service \
    || true
    systemctl is-active --quiet cellframe-diagtool.service \
    && systemctl stop cellframe-diagtool.service \
    && systemctl disable cellframe-diagtool.service \
    || true
    systemctl daemon-reload
}