summaryrefslogtreecommitdiff
path: root/docker/debian/apt-bitmask.sh
blob: 68430affb1bac254268bf9a0134b808c3dfe168f (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
#!/bin/bash
set -euo pipefail
IFS=$'\n\t'

distro(){
    # for ubuntu/mint:
    name=`lsb_release -a 2>&1 | grep Codename | cut -f2`

    # for debian:
    [[ -z $name ]] && name=`grep -oP "VERSION=.*\(\K\w+" /etc/os-release`

    # for debian sid
    [[ -z $name ]] && name=`grep -o sid /etc/debian_version`

    declare -A distros
    distros=(
        ['nadia']='quantal'
        ['olivia']='raring'
        ['petra']='saucy'
        ['qiana']='trusty'
        ['rebecca']='trusty'
        ['rafaela']='trusty'
    )

    # if name is in the above list -> replace
    [ ${distros[$name]+abc} ] && name=${distros[$name]}

    echo $name | tr "[A-Z]" "[a-z]"
}

is_supported(){
    distros=(
        'wheezy'  # Debian 7 - stable
        'jessie'  # Debian 8 - testing
        'sid'     # Debian unstable
        'quantal' # Ubuntu 12.10
        'raring'  # Ubuntu 13.04
        'saucy'   # Ubuntu 13.10
        'trusty'  # Ubuntu 14.04
        'utopic'  # Ubuntu 14.10
        'vivid'   # Ubuntu 15.04
    )

    my_distro=`distro`

    for p in "${distros[@]}"; do
        if [[ $my_distro = ${p}* ]]; then
            echo true
            return
        fi
    done
    echo false
}

if [[ `is_supported` == "false" ]]; then
    echo "ERROR: Sorry, your distro (`distro`) is currently not supported."
    exit 1
fi;

help() {
    echo ">> Bitmask .deb automatic installer helper"
    echo "This script does all the needed stuff in order to get bitmask stable or unstable into your machine."
    echo
    echo "Usage: $0 ( stable | unstable | help )"
    echo
    echo "   stable : Install the stable bitmask package."
    echo " unstable : Install the unstable bitmask package."
    echo "     help : Show this help"
    echo
    echo "NOTE: you need to run this with root privileges."
    echo
}

case ${1:-} in
    stable)
        REPO='debian'
        ;;
    unstable)
        REPO='experimental'
        ;;
    *)
        help
        exit 1
        ;;
esac

if [[ $EUID -ne 0 ]]; then
   echo "This script must be run as root" 1>&2
   exit 1
fi

# -------------------------------
# instructions from http://deb.leap.se/experimental/
# run this with admin privileges

DISTRO=`distro`

if [[ $REPO == 'debian' ]]; then
    # stable
    # wget -O- https://dl.bitmask.net/apt.key | apt-key add -

    # HACK: do this twice since the first one fails due to gpg not having a configuration
    gpg --recv-key 0x1E34A1828E207901 &> /dev/null || true
    gpg --recv-key 0x1E34A1828E207901

    gpg --armor --export 0x1E34A1828E207901  | apt-key add -
else  # $REPO == 'experimental'
    if [[ ! -f "leap-experimental.key" ]]; then
        echo "ERROR: you need to copy the leap-experimental.key file into this directory."
        exit 1
    fi

    # sha256sum leap-experimental.key
    echo "ed3f4f3e3e0835a044457451755ae743741d7bafa55bcd31cc464a54e8c5e7f9  leap-experimental.key" | sha256sum -c -
    apt-key add leap-experimental.key
fi

echo "deb http://deb.leap.se/$REPO $DISTRO main" > /etc/apt/sources.list.d/bitmask.list
echo "deb-src http://deb.leap.se/$REPO $DISTRO main" >> /etc/apt/sources.list.d/bitmask.list

apt-get update
apt-get install -y bitmask