summarylogtreecommitdiffstats
path: root/gogs.install
blob: 1d8fb4b61e0b6f2e54219be6d2c7c8816606d45a (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
_start_if_enabled() {
    if systemctl -q is-enabled gogs.service ;then
        echo "Starting gogs service"
        systemctl start gogs.service
    fi
}

_stop_if_active() {
    if systemctl -q is-active gogs.service ;then
        echo "Stoping gogs service"
        systemctl stop gogs.service
    fi
}

_disable_if_enabled() {
    if systemctl -q is-enabled gogs.service 2>/dev/null ;then
        echo "Disabling gogs service"
        systemctl disable gogs.service
    fi
}

pre_install() {
    if ! getent group gogs >/dev/null; then
        groupadd --system gogs
    fi
    if ! getent passwd gogs >/dev/null; then
        useradd -r -c 'Gogs service user' -g gogs -d /srv/gogs -s /bin/bash gogs
        passwd -l gogs
    else
        local _OldHome="$( getent passwd gogs | cut -d: -f6 )"
        if [[ ${_OldHome} != "/srv/gogs" ]]; then
            echo
            echo "Setting gogs home directory to /srv/gogs"
            usermod -c 'Gogs service user' -g gogs -d /srv/gogs -L -s /bin/bash gogs
            echo
            echo "You must migrate from ${_OldHome}"
            echo "before starting or re-enabling service"
            echo
            _disable_if_enabled
        fi
    fi
}

post_install(){
    systemctl daemon-reload
}

pre_upgrade() {
    _stop_if_active
    pre_install
}


post_upgrade() {
    post_install

    local _CustConf=/srv/gogs/custom/conf/app.ini
    local _OldConf=/etc/gogs/app.ini

    if  [[ -f ${_OldConf}.pacsave ]] && [[ ! -f ${_CustConf} ]] ; then
        install -Dm0750 -d -o gogs -g gogs /srv/gogs
        install -Dm0750 -d -o gogs -g gogs /srv/gogs/custom
        install -Dm0750 -d -o gogs -g gogs /srv/gogs/custom/conf
        install -Dm0640 -T -o gogs -g gogs ${_OldConf}.pacsave ${_CustConf}
        echo
        echo "${_OldConf} moved to"
        echo "${_CustConf}."
        echo "You may need to manually delete"
        echo "an old config dir /etc/gogs"
        echo
    fi
    _start_if_enabled
}

pre_remove() {
    _stop_if_active
    _disable_if_enabled
}

post_remove() {
    if getent passwd gogs >/dev/null; then
        userdel gogs
    fi
    if getent group gogs >/dev/null; then
        groupdel gogs
    fi
    systemctl daemon-reload
    echo
    echo "You may need to manually delete an old workdir /srv/gogs"
    echo
}