summarylogtreecommitdiffstats
path: root/cellframe-node.install
blob: a8b45f870943b71b1f5d612ceb05a3f520a56622 (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
INSTALLATION_PATH="/opt/cellframe-node"

_showmsg() {
BOLD=$(tput bold)
NORMAL=$(tput sgr0)

echo -e "
${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() {
    local wheel_dir="$INSTALLATION_PATH/share/wheels"
    if ! _is_python_and_pip_ok; then
        echo ":: Python or pip not found, skipping wheel installation..."
        return
    fi
    if ! ls "$wheel_dir"/*.whl > /dev/null 2>&1; then
        echo ":: No wheel packages found, skipping..."
        return
    fi
    echo ":: Installing Python wheel packages..."
    "$PIP_BIN" install "$wheel_dir"/*.whl &> /dev/null \
        && echo ":: Installed wheel packages" \
        || echo ":: Failed to install wheel packages"
}

_setup_default_configuration() {
    echo ":: Setting up default configuration..."
    cellframe-node-config -i "$INSTALLATION_PATH/share/default.setup" > /dev/null 2>&1  \
    && echo ":: Default configuration setup complete" \
    || echo ":: Failed to set up default configuration"
}

post_install() {
    _post_install_wheels
    _setup_default_configuration
    _showmsg
}

post_upgrade() {
    _post_install_wheels
    echo ":: Executing systemctl daemon-reload..."
    systemctl daemon-reload
    systemctl is-active --quiet cellframe-node.service \
    && _setup_default_configuration \
    && 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
}