summarylogtreecommitdiffstats
path: root/ckb-next.install
blob: 03029634c9739813afaf431186de615794fd8b67 (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
# Colored makepkg-like functions
msg_blue() {
  printf "${blue}==>${bold} $1${all_off}\n"
}

note() {
  printf "${blue}==>${yellow} NOTE:${bold} $1${all_off}\n"
}

all_off="$(tput sgr0)"
bold="${all_off}$(tput bold)"
blue="${bold}$(tput setaf 4)"
yellow="${bold}$(tput setaf 3)"

_as_service() {
    cat << EOF

You might want to run ckb-next-daemon as a systemd service:

    systemctl enable ckb-next-daemon.service
    systemctl start ckb-next-daemon.service

EOF
}

_disable_daemon() {
    running="$(systemctl is-enabled ckb-next-daemon.service)"
    if [[ "$running" = "enabled" ]]; then
        systemctl disable ckb-next-daemon.service
    fi
}

_terminate_gui_daemon() {
    msg_blue "Terminating ckb-next GUI"

    killall -TERM ckb 2>/dev/null
    killall -TERM ckb-next 2>/dev/null


    msg_blue "Terminating ckb-next daemon"

    running="$(systemctl is-active ckb-daemon.service)"
    if [[ "$running" = "active" ]]; then
        systemctl stop ckb-daemon.service
    fi

    running="$(systemctl is-active ckb-next-daemon.service)"
    if [[ "$running" = "active" ]]; then
        systemctl stop ckb-next-daemon.service
    fi

    running="$(systemctl is-enabled ckb-daemon.service)"
    if [[ "$running" = "enabled" ]]; then
        systemctl disable ckb-daemon.service
    fi
}

# arg 1:  the new package version
post_install() {
    _as_service
}

# arg 1:  the new package version
# arg 2:  the old package version
pre_upgrade() {
    _terminate_gui_daemon
}

# arg 1:  the new package version
# arg 2:  the old package version
post_upgrade() {
    systemctl daemon-reload
}

# arg 1:  the old package version
pre_remove() {
    _terminate_gui_daemon
    _disable_daemon
}

# arg 1:  the old package version
post_remove() {
    systemctl daemon-reload
}