We've made a change in the structure of our apt repositories.
[arvados.git] / tools / compute-images / scripts / base.sh
1 #!/bin/bash -euxo pipefail
2
3 # Copyright (C) The Arvados Authors. All rights reserved.
4 #
5 # SPDX-License-Identifier: Apache-2.0
6
7 SUDO=sudo
8
9 # Run apt-get update
10 $SUDO DEBIAN_FRONTEND=noninteractive apt-get --yes update
11
12 # Install gnupg and dirmgr or gpg key checks will fail
13 $SUDO DEBIAN_FRONTEND=noninteractive apt-get -qq --yes install \
14   gnupg \
15   dirmngr \
16   lsb-release
17
18 # For good measure, apt-get upgrade
19 $SUDO DEBIAN_FRONTEND=noninteractive apt-get -qq --yes upgrade
20
21 # Make sure cloud-init is installed
22 $SUDO DEBIAN_FRONTEND=noninteractive apt-get -qq --yes install cloud-init
23 if [[ ! -d /var/lib/cloud/scripts/per-boot ]]; then
24   mkdir -p /var/lib/cloud/scripts/per-boot
25 fi
26
27 TMP_LSB=`/usr/bin/lsb_release -c -s`
28 LSB_RELEASE_CODENAME=${TMP_LSB//[$'\t\r\n ']}
29
30 # Add the arvados apt repository
31 echo "# apt.arvados.org" |$SUDO tee --append /etc/apt/sources.list.d/apt.arvados.org.list
32 echo "deb http://apt.arvados.org/$LSB_RELEASE_CODENAME $LSB_RELEASE_CODENAME${REPOSUFFIX} main" |$SUDO tee --append /etc/apt/sources.list.d/apt.arvados.org.list
33
34 # Add the arvados signing key
35 cat /tmp/1078ECD7.asc | $SUDO apt-key add -
36 # Add the debian keys
37 $SUDO DEBIAN_FRONTEND=noninteractive apt-get install --yes debian-keyring debian-archive-keyring
38
39 # Fix locale
40 $SUDO /bin/sed -ri 's/# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/' /etc/locale.gen
41 $SUDO /usr/sbin/locale-gen
42
43 # Install some packages we always need
44 $SUDO DEBIAN_FRONTEND=noninteractive apt-get --yes update
45 $SUDO DEBIAN_FRONTEND=noninteractive apt-get -qq --yes install \
46   openssh-server \
47   apt-utils \
48   git \
49   curl \
50   libcurl3-gnutls \
51   libcurl4-openssl-dev \
52   lvm2 \
53   cryptsetup \
54   xfsprogs
55
56 # See if python3-distutils is installable, and if so install it. This is a
57 # temporary workaround for an Arvados packaging bug and should be removed once
58 # Arvados 2.0.4 or 2.1.0 is released, whichever comes first.
59 # See https://dev.arvados.org/issues/16611 for more information
60 if apt-cache -qq show python3-distutils >/dev/null 2>&1; then
61   $SUDO DEBIAN_FRONTEND=noninteractive apt-get -qq --yes install python3-distutils
62 fi
63
64 # Install the Arvados packages we need
65 $SUDO DEBIAN_FRONTEND=noninteractive apt-get -qq --yes install \
66   python-arvados-fuse \
67   crunch-run \
68   arvados-docker-cleaner \
69   docker.io
70
71 # Remove unattended-upgrades if it is installed
72 $SUDO DEBIAN_FRONTEND=noninteractive apt-get -qq --yes remove unattended-upgrades --purge
73
74 # Configure arvados-docker-cleaner
75 $SUDO mkdir -p /etc/arvados/docker-cleaner
76 $SUDO echo -e "{\n  \"Quota\": \"10G\",\n  \"RemoveStoppedContainers\": \"always\"\n}" > /etc/arvados/docker-cleaner/docker-cleaner.json
77
78 # Enable cgroup accounting
79 $SUDO sed -i 's/GRUB_CMDLINE_LINUX=""/GRUB_CMDLINE_LINUX="cgroup_enable=memory swapaccount=1"/g' /etc/default/grub
80 $SUDO update-grub
81
82 # Set a higher ulimit for docker
83 $SUDO sed -i "s/ExecStart=\(.*\)/ExecStart=\1 --default-ulimit nofile=10000:10000 --dns ${RESOLVER}/g" /lib/systemd/system/docker.service
84 $SUDO systemctl daemon-reload
85
86 # Make sure user_allow_other is set in fuse.conf
87 $SUDO sed -i 's/#user_allow_other/user_allow_other/g' /etc/fuse.conf
88
89 # Add crunch user with sudo powers
90 $SUDO adduser --disabled-password --gecos "Crunch user,,,," crunch
91 # Do not require a password to sudo
92 echo -e "# for the crunch user\ncrunch ALL=(ALL) NOPASSWD:ALL" | $SUDO tee /etc/sudoers.d/91-crunch
93
94 # Set up the ssh public key for the crunch user
95 $SUDO mkdir /home/crunch/.ssh
96 $SUDO mv /tmp/crunch-authorized_keys /home/crunch/.ssh/authorized_keys
97 $SUDO chown -R crunch:crunch /home/crunch/.ssh
98 $SUDO chmod 600 /home/crunch/.ssh/authorized_keys
99 $SUDO chmod 700 /home/crunch/.ssh/
100
101 # Make sure we resolve via the provided resolver IP. Prepending is good enough because
102 # unless 'rotate' is set, the nameservers are queried in order (cf. man resolv.conf)
103 $SUDO sed -i "s/#prepend domain-name-servers 127.0.0.1;/prepend domain-name-servers ${RESOLVER};/" /etc/dhcp/dhclient.conf
104
105 # Set up the cloud-init script that will ensure encrypted disks
106 $SUDO mv /tmp/usr-local-bin-ensure-encrypted-partitions.sh /usr/local/bin/ensure-encrypted-partitions.sh
107 $SUDO chmod 755 /usr/local/bin/ensure-encrypted-partitions.sh
108 $SUDO chown root:root /usr/local/bin/ensure-encrypted-partitions.sh
109 $SUDO mv /tmp/etc-cloud-cloud.cfg.d-07_compute_arvados_dispatch_cloud.cfg /etc/cloud/cloud.cfg.d/07_compute_arvados_dispatch_cloud.cfg
110 $SUDO chown root:root /etc/cloud/cloud.cfg.d/07_compute_arvados_dispatch_cloud.cfg