aboutsummaryrefslogtreecommitdiffstats
path: root/install.sh
blob: 0cfe421b4a70d68849c2310f9cbeec5a55319e7e (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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
#!/bin/sh
# -*- coding: utf-8 -*-

basedir="$(realpath "$0" | xargs dirname)"

info()
{
    echo "--- $*"
}

error()
{
    echo "=== ERROR: $*" >&2
}

warning()
{
    echo "=== WARNING: $*" >&2
}

die()
{
    error "$*"
    exit 1
}

do_install()
{
    info "install $*"
    install "$@" || die "Failed install $*"
}

do_systemctl()
{
    info "systemctl $*"
    systemctl "$@" || die "Failed to systemctl $*"
}

try_systemctl()
{
    info "systemctl $*"
    systemctl "$@" 2>/dev/null
}

entry_checks()
{
    [ -d "$target" ] ||\
        die "CMS is not built! Run ./build.sh"

    [ "$(id -u)" = "0" ] ||\
        die "Must be root to install CMS."
}

stop_services()
{
    try_systemctl stop apache2
    try_systemctl stop cms-backd.socket
    try_systemctl stop cms-backd.service
    try_systemctl stop cms-postd.socket
    try_systemctl stop cms-postd.service
    try_systemctl stop cms-fsd.socket
    try_systemctl stop cms-fsd.service
    try_systemctl disable cms-backd.socket
    try_systemctl disable cms-backd.service
    try_systemctl disable cms-postd.socket
    try_systemctl disable cms-postd.service
    try_systemctl disable cms-fsd.socket
    try_systemctl disable cms-fsd.service
}

start_services()
{
    do_systemctl start cms-fsd.socket
    do_systemctl start cms-postd.socket
    do_systemctl start cms-backd.socket
    do_systemctl start apache2
}

install_dirs()
{
    rm -rf /opt/cms/bin
    rm -rf /opt/cms/lib
    rm -rf /opt/cms/libexec
    rm -rf /opt/cms/share

    do_install \
        -o root -g root -m 0755 \
        -d /opt/cms/bin

    do_install \
        -o root -g root -m 0755 \
        -d /opt/cms/etc/cms

    do_install \
        -o root -g root -m 0755 \
        -d /opt/cms/libexec/cms-cgi
}

install_fsd()
{
    do_install \
        -o root -g root -m 0755 \
        "$target/cms-fsd" \
        /opt/cms/bin/

    do_install \
        -o root -g root -m 0644 \
        "$basedir/cms-fsd/cms-fsd.service" \
        /etc/systemd/system/

    do_install \
        -o root -g root -m 0644 \
        "$basedir/cms-fsd/cms-fsd.socket" \
        /etc/systemd/system/

    do_systemctl enable cms-fsd.service
    do_systemctl enable cms-fsd.socket
}

install_postd()
{
    do_install \
        -o root -g root -m 0755 \
        "$target/cms-postd" \
        /opt/cms/bin/

    do_install \
        -o root -g root -m 0644 \
        "$basedir/cms-postd/cms-postd.service" \
        /etc/systemd/system/

    do_install \
        -o root -g root -m 0644 \
        "$basedir/cms-postd/cms-postd.socket" \
        /etc/systemd/system/

    do_systemctl enable cms-postd.service
    do_systemctl enable cms-postd.socket
}

install_cgi()
{
    do_install \
        -o root -g root -m 0755 --no-target-directory \
        "$target/cms-cgi" \
        /opt/cms/libexec/cms-cgi/cms.cgi
}

install_backd()
{
    do_install \
        -o root -g root -m 0755 \
        "$target/cms-backd" \
        /opt/cms/bin/

    do_install \
        -o root -g root -m 0644 \
        "$basedir/cms-backd/cms-backd.service" \
        /etc/systemd/system/

    do_install \
        -o root -g root -m 0644 \
        "$basedir/cms-backd/cms-backd.socket" \
        /etc/systemd/system/

    do_systemctl enable cms-backd.service
    do_systemctl enable cms-backd.socket
}

install_conf()
{
    if ! [ -f /opt/cms/etc/cms/backd.conf ]; then
        do_install \
            -o root -g cms-backd -m 0640 \
            "$basedir/example/backd.conf" \
            /opt/cms/etc/cms/
    fi
}

release="release"
while [ $# -ge 1 ]; do
    case "$1" in
        --debug|-d)
            release="debug"
            ;;
        --release|-r)
            release="release"
            ;;
        *)
            die "Invalid option: $1"
            ;;
    esac
    shift
done
target="$basedir/target/$release"

entry_checks
stop_services
install_dirs
install_fsd
install_postd
install_cgi
install_backd
install_conf
start_services

# vim: ts=4 sw=4 expandtab
bues.ch cgit interface