~brianlbaird/charms/trusty/pcrf/trunk

« back to all changes in this revision

Viewing changes to scripts/install_docker.sh

  • Committer: brianlbaird at gmail
  • Date: 2016-02-05 22:23:46 UTC
  • Revision ID: brianlbaird@gmail.com-20160205222346-4mv1208rduhngpbu
update pcrf relation in metadata

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/bin/sh
 
2
set -e
 
3
 
 
4
url='https://get.docker.com/'
 
5
 
 
6
command_exists() {
 
7
        command -v "$@" > /dev/null 2>&1
 
8
}
 
9
 
 
10
echo_docker_as_nonroot() {
 
11
        if command_exists docker && [ -e /var/run/docker.sock ]; then
 
12
                (
 
13
                        set -x
 
14
                        $sh_c 'docker version'
 
15
                ) || true
 
16
        fi
 
17
    status-set active "Docker installed and ready"
 
18
        your_user=your-user
 
19
        [ "$user" != 'root' ] && your_user="$user"
 
20
        # intentionally mixed spaces and tabs here -- tabs are stripped by "<<-EOF", spaces are kept in the output
 
21
        cat <<-EOF
 
22
 
 
23
        If you would like to use Docker as a non-root user, you should now consider
 
24
        adding your user to the "docker" group with something like:
 
25
 
 
26
          sudo usermod -aG docker $your_user
 
27
 
 
28
        Remember that you will have to log out and back in for this to take effect!
 
29
 
 
30
        EOF
 
31
}
 
32
 
 
33
get_debian_dist_version() {
 
34
        dist_version=''
 
35
        case "$@" in
 
36
                8)
 
37
                        dist_version="jessie"
 
38
                        ;;
 
39
                7)
 
40
                        dist_version="wheezy"
 
41
                        ;;
 
42
        esac
 
43
        echo "$dist_version"
 
44
}
 
45
 
 
46
do_install() {
 
47
        case "$(uname -m)" in
 
48
                *64)
 
49
                        ;;
 
50
                *)
 
51
                        cat >&2 <<-'EOF'
 
52
                        Error: you are not using a 64bit platform.
 
53
                        Docker currently only supports 64bit platforms.
 
54
                        EOF
 
55
                        exit 1
 
56
                        ;;
 
57
        esac
 
58
 
 
59
        user="$(id -un 2>/dev/null || true)"
 
60
 
 
61
        sh_c='sh -c'
 
62
        if [ "$user" != 'root' ]; then
 
63
                if command_exists sudo; then
 
64
                        sh_c='sudo -E sh -c'
 
65
                elif command_exists su; then
 
66
                        sh_c='su -c'
 
67
                else
 
68
                        cat >&2 <<-'EOF'
 
69
                        Error: this installer needs the ability to run commands as root.
 
70
                        We are unable to find either "sudo" or "su" available to make this happen.
 
71
                        EOF
 
72
                        exit 1
 
73
                fi
 
74
        fi
 
75
 
 
76
        curl=''
 
77
        if command_exists curl; then
 
78
                curl='curl -sSL'
 
79
        elif command_exists wget; then
 
80
                curl='wget -qO-'
 
81
        elif command_exists busybox && busybox --list-modules | grep -q wget; then
 
82
                curl='busybox wget -qO-'
 
83
        fi
 
84
 
 
85
        # check to see which repo they are trying to install from
 
86
        repo='main'
 
87
        if [ "https://test.docker.com/" = "$url" ]; then
 
88
                repo='testing'
 
89
        elif [ "https://experimental.docker.com/" = "$url" ]; then
 
90
                repo='experimental'
 
91
        fi
 
92
 
 
93
        # perform some very rudimentary platform detection
 
94
        lsb_dist=''
 
95
        dist_version=''
 
96
        if command_exists lsb_release; then
 
97
                lsb_dist="$(lsb_release -si)"
 
98
        fi
 
99
        if [ -z "$lsb_dist" ] && [ -r /etc/lsb-release ]; then
 
100
                lsb_dist="$(. /etc/lsb-release && echo "$DISTRIB_ID")"
 
101
        fi
 
102
        if [ -z "$lsb_dist" ] && [ -r /etc/debian_version ]; then
 
103
                lsb_dist='debian'
 
104
        fi
 
105
        if [ -z "$lsb_dist" ]; then
 
106
                if [ -r /etc/centos-release ] || [ -r /etc/redhat-release ]; then
 
107
                        lsb_dist='centos'
 
108
                fi
 
109
        fi
 
110
        if [ -z "$lsb_dist" ] && [ -r /etc/os-release ]; then
 
111
                lsb_dist="$(. /etc/os-release && echo "$ID")"
 
112
        fi
 
113
 
 
114
        lsb_dist="$(echo "$lsb_dist" | tr '[:upper:]' '[:lower:]')"
 
115
 
 
116
        case "$lsb_dist" in
 
117
 
 
118
                ubuntu)
 
119
                        if command_exists lsb_release; then
 
120
                                dist_version="$(lsb_release --codename | cut -f2)"
 
121
                        fi
 
122
                        if [ -z "$dist_version" ] && [ -r /etc/lsb-release ]; then
 
123
                                dist_version="$(. /etc/lsb-release && echo "$DISTRIB_CODENAME")"
 
124
                        fi
 
125
                ;;
 
126
 
 
127
                debian)
 
128
                        dist_version="$(cat /etc/debian_version | sed 's/\/.*//' | sed 's/\..*//')"
 
129
                        case "$dist_version" in
 
130
                                8)
 
131
                                        dist_version="jessie"
 
132
                                ;;
 
133
                                7)
 
134
                                        dist_version="wheezy"
 
135
                                ;;
 
136
                        esac
 
137
                ;;
 
138
 
 
139
                centos)
 
140
                        dist_version="$(rpm -q --whatprovides redhat-release --queryformat "%{VERSION}\n" | sed 's/\/.*//' | sed 's/\..*//')"
 
141
                ;;
 
142
 
 
143
                *)
 
144
                        if command_exists lsb_release; then
 
145
                                dist_version="$(lsb_release --codename | cut -f2)"
 
146
                        fi
 
147
                        if [ -z "$dist_version" ] && [ -r /etc/os-release ]; then
 
148
                                dist_version="$(. /etc/os-release && echo "$VERSION_ID")"
 
149
                        fi
 
150
                ;;
 
151
 
 
152
 
 
153
        esac
 
154
 
 
155
        case "$lsb_dist" in
 
156
                amzn)
 
157
                        (
 
158
                        set -x
 
159
                        $sh_c 'sleep 3; yum -y -q install docker'
 
160
                        )
 
161
                        echo_docker_as_nonroot
 
162
                        exit 0
 
163
                        ;;
 
164
 
 
165
                ubuntu|debian)
 
166
                        export DEBIAN_FRONTEND=noninteractive
 
167
            status-set maintenance "Updating package list"
 
168
                        did_apt_get_update=
 
169
                        apt_get_update() {
 
170
                                if [ -z "$did_apt_get_update" ]; then
 
171
                                        ( set -x; $sh_c 'sleep 3; apt-get update' )
 
172
                                        did_apt_get_update=1
 
173
                                fi
 
174
                        }
 
175
 
 
176
                        # aufs is preferred over devicemapper; try to ensure the driver is available.
 
177
                        if ! grep -q aufs /proc/filesystems && ! $sh_c 'modprobe aufs'; then
 
178
                status-set maintenance "Installing kernel modules to support union filesystem"
 
179
                                if uname -r | grep -q -- '-generic' && dpkg -l 'linux-image-*-generic' | grep -q '^ii' 2>/dev/null; then
 
180
                                        kern_extras="linux-image-extra-$(uname -r) linux-image-extra-virtual"
 
181
 
 
182
                                        apt_get_update
 
183
                                        ( set -x; $sh_c 'sleep 3; apt-get install -y -q '"$kern_extras" ) || true
 
184
 
 
185
                                        if ! grep -q aufs /proc/filesystems && ! $sh_c 'modprobe aufs'; then
 
186
                                                echo >&2 'Warning: tried to install '"$kern_extras"' (for AUFS)'
 
187
                                                echo >&2 ' but we still have no AUFS.  Docker may not work. Proceeding anyways!'
 
188
                                                ( set -x; sleep 10 )
 
189
                                        fi
 
190
                                else
 
191
                                        echo >&2 'Warning: current kernel is not supported by the linux-image-extra-virtual'
 
192
                                        echo >&2 ' package.  We have no AUFS support.  Consider installing the packages'
 
193
                                        echo >&2 ' linux-image-virtual kernel and linux-image-extra-virtual for AUFS support.'
 
194
                                        ( set -x; sleep 10 )
 
195
                                fi
 
196
                        fi
 
197
 
 
198
                        # install apparmor utils if they're missing and apparmor is enabled in the kernel
 
199
                        # otherwise Docker will fail to start
 
200
                        if [ "$(cat /sys/module/apparmor/parameters/enabled 2>/dev/null)" = 'Y' ]; then
 
201
                status-set maintenance "Installing apparmor security policies"
 
202
                                if command -v apparmor_parser >/dev/null 2>&1; then
 
203
                                        echo 'apparmor is enabled in the kernel and apparmor utils were already installed'
 
204
                                else
 
205
                                        echo 'apparmor is enabled in the kernel, but apparmor_parser missing'
 
206
                                        apt_get_update
 
207
                                        ( set -x; $sh_c 'sleep 3; apt-get install -y -q apparmor' )
 
208
                                fi
 
209
                        fi
 
210
 
 
211
                        if [ ! -e /usr/lib/apt/methods/https ]; then
 
212
                status-set maintenance "Installing HTTPS support"
 
213
                                apt_get_update
 
214
                                ( set -x; $sh_c 'sleep 3; apt-get install -y -q apt-transport-https ca-certificates' )
 
215
                        fi
 
216
                        if [ -z "$curl" ]; then
 
217
                                apt_get_update
 
218
                                ( set -x; $sh_c 'sleep 3; apt-get install -y -q curl ca-certificates' )
 
219
                                curl='curl -sSL'
 
220
                        fi
 
221
                        (
 
222
            status-set maintenance "Adding PPA and installing docker"
 
223
                        set -x
 
224
                        $sh_c "apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D"
 
225
                        $sh_c "mkdir -p /etc/apt/sources.list.d"
 
226
                        $sh_c "echo deb https://apt.dockerproject.org/repo ${lsb_dist}-${dist_version} ${repo} > /etc/apt/sources.list.d/docker.list"
 
227
                        $sh_c 'sleep 3; apt-get update; apt-get install -y -q docker-engine'
 
228
            )
 
229
 
 
230
            echo_docker_as_nonroot
 
231
                        exit 0
 
232
                        ;;
 
233
 
 
234
                centos)
 
235
            status-set maintenance "Installing docker"
 
236
                        $sh_c "cat >/etc/yum.repos.d/docker-${repo}.repo" <<-EOF
 
237
                        [docker-${repo}-repo]
 
238
                        name=Docker ${repo} Repository
 
239
                        baseurl=https://yum.dockerproject.org/repo/${repo}/${lsb_dist}/${dist_version}
 
240
                        enabled=1
 
241
                        gpgcheck=1
 
242
                        gpgkey=https://yum.dockerproject.org/gpg
 
243
                        EOF
 
244
                        if [ "$lsb_dist" = "fedora" ] && [ "$dist_version" -ge "22" ]; then
 
245
                                (
 
246
                                        set -x
 
247
                                        $sh_c 'sleep 3; dnf -y -q install docker-engine'
 
248
                                )
 
249
                        else
 
250
                                (
 
251
                                        set -x
 
252
                                        $sh_c 'sleep 3; yum -y -q install docker-engine'
 
253
                                )
 
254
                        fi
 
255
                        echo_docker_as_nonroot
 
256
                        exit 0
 
257
                        ;;
 
258
        esac
 
259
 
 
260
        # intentionally mixed spaces and tabs here -- tabs are stripped by "<<-'EOF'", spaces are kept in the output
 
261
        cat >&2 <<-'EOF'
 
262
 
 
263
          Either your platform is not easily detectable, is not supported by this
 
264
          installer script (yet - PRs welcome! [hack/install.sh]), or does not yet have
 
265
          a package for Docker.  Please visit the following URL for more detailed
 
266
          installation instructions:
 
267
 
 
268
            https://docs.docker.com/en/latest/installation/
 
269
 
 
270
        EOF
 
271
        exit 1
 
272
}
 
273
 
 
274
do_install
 
275