summaryrefslogtreecommitdiffstats
path: root/net/etesync-server/files/81_setup-etesync-server
blob: b2f6911a480e0935bdcf3e1fe137f94079a4e970 (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
#!/bin/sh

[ "${PKG_UPGRADE}" = "1" ] && /etc/init.d/etesync-server stop

cd /usr/share/etesync-server || exit 1

python3 manage.pyc migrate --noinput || exit 1

# setup minimal ini for collectstatic:
mkdir -p /var/etc/etesync-server/ || exit 1
printf "[global]\nSTATIC_ROOT=/www/etesync/static" >etesync-server.ini || exit 1
python3 manage.pyc collectstatic --noinput || exit 1

ETESYNC_HAS_USER_PY3CMD="import sqlite3
c = sqlite3.connect('db.sqlite3').cursor()
c.execute('select * from auth_user')
if c.fetchone()==None: print('0')
else: print('1')"

echo

if [ "$(python3 -c "$ETESYNC_HAS_USER_PY3CMD" || exit 1)" = "0" ]
then
    echo "===== First, create a superuser of the Webinterface by ====="
    [ -t 0 ] && python3 manage.pyc createsuperuser ||
    echo "===== python3 $(pwd)/manage.pyc createsuperuser ====="
fi

chown -Rh etesync:nogroup . /www/etesync/ || exit 1

[ -x /etc/init.d/nginx ] || exit 1

/etc/init.d/nginx running && /etc/init.d/nginx reload || /etc/init.d/nginx start

router_ip() {
    local ifstat="$(ifstatus "lan")"

    for ip in $(echo "${ifstat}" | jsonfilter -e '@["ipv4-address"].*.address')
    do echo "${ip}" && return
    done

    for ip in $(echo "${ifstat}" | jsonfilter -e '@["ipv6-address"].*.address')
    do echo "[${ip}]" && return
    done

    for ip in $(echo "${ifstat}" | \
        jsonfilter -e '@["ipv6-prefix-assignment"].*["local-address"].address')
    do echo "[${ip}]" && return
    done

    echo '$ROUTER'
}

echo "===== You can add users by https://$(router_ip)/etesync/admin/login ====="

exit 0