aboutsummaryrefslogtreecommitdiffstats
path: root/install.sh
blob: 3716798622e02a7824a28d6fb735c41bf2628387 (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
#!/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 $*"
}

do_chown()
{
    info "chown $*"
    chown "$@" || die "Failed to chown $*"
}

do_chmod()
{
    info "chmod $*"
    chmod "$@" || die "Failed to chmod $*"
}

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

do_chown()
{
    info "chown $*"
    chown "$@" || die "Failed to chown $*"
}

do_chmod()
{
    info "chmod $*"
    chmod "$@" || die "Failed to chmod $*"
}

entry_checks()
{
    [ -d "$target" ] || die "feedreader is not built! Run ./build.sh"
    [ "$(id -u)" = "0" ] || die "Must be root to install feedreader."
}

stop_services()
{
    try_systemctl stop feedsd.service
    try_systemctl disable feedsd.service
}

start_services()
{
    do_systemctl start feedsd.service
}

install_dirs()
{
    do_install \
        -o root -g root -m 0755 \
        -d /opt/feedreader/bin

    do_install \
        -o root -g root -m 0755 \
        -d /opt/feedreader/lib/cgi-bin

    do_install \
        -o root -g root -m 0755 \
        -d /opt/feedreader/var/lib

    do_install \
        -o root -g www-data -m 0775 \
        -d /opt/feedreader/var/lib/feedreader

    do_install \
        -o root -g root -m 0755 \
        -d /opt/feedreader/share/feedreader
}

install_feedsd()
{
    do_install \
        -o root -g root -m 0755 \
        "$target/feedsd" \
        /opt/feedreader/bin/

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

    do_systemctl enable feedsd.service
}

install_feeds()
{
    do_install \
        -o root -g root -m 0755 \
        "$target/feeds" \
        /opt/feedreader/lib/cgi-bin/

    do_install \
        -o root -g root -m 0644 \
        "$basedir/resources/icon.png" \
        /opt/feedreader/share/feedreader/

    do_install \
        -o root -g root -m 0644 \
        "$basedir/resources/style.css" \
        /opt/feedreader/share/feedreader/
}

install_feedscli()
{
    do_install \
        -o root -g root -m 0755 \
        "$target/feedscli" \
        /opt/feedreader/bin/
}

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_feedsd
install_feeds
install_feedscli
start_services

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