aboutsummaryrefslogtreecommitdiffstats
path: root/install-client.sh
blob: 0b6892d8eae50aa3afc5f693e00c65c24f282038 (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
#!/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_chown()
{
    info "chown $*"
    chown "$@" || die "Failed to chown $*"
}

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

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

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

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

install_conf()
{
    if [ -e /opt/letmein/etc/letmein.conf ]; then
        do_chown root:root /opt/letmein/etc/letmein.conf
        do_chmod 0644 /opt/letmein/etc/letmein.conf
    else
        do_install \
            -o root -g root -m 0644 \
            "$basedir/letmein/letmein.conf" \
            /opt/letmein/etc/letmein.conf
    fi
}

install_letmein()
{
    do_install \
        -o root -g root -m 0755 \
        "$target/letmein" \
        /opt/letmein/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
install_dirs
install_conf
install_letmein

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