2015-08-04 16:29:49 -07:00
#!/bin/bash
set -euv -o pipefail
2015-08-12 19:52:43 -07:00
readonly SOURCE_DIR = " $( cd " $( dirname " ${ BASH_SOURCE [0] } " ) " && pwd ) "
2015-12-23 13:27:33 +01:00
2020-06-16 14:09:55 +02:00
readonly arg_infraversionpath = " ${ SOURCE_DIR } /../src "
2017-01-09 09:22:22 -08:00
2016-01-22 10:33:34 -08:00
function die {
echo $1
exit 1
}
2015-08-04 16:29:49 -07:00
export DEBIAN_FRONTEND = noninteractive
2020-06-26 14:52:52 -07:00
readonly ubuntu_codename = $( lsb_release -cs)
2020-07-16 16:42:15 +02:00
readonly ubuntu_version = $( lsb_release -rs)
2020-06-26 14:52:52 -07:00
2018-09-06 09:16:11 -07:00
# hold grub since updating it breaks on some VPS providers. also, dist-upgrade will trigger it
2018-08-28 14:01:47 -07:00
apt-mark hold grub* >/dev/null
2016-11-08 15:35:51 +05:30
apt-get -o Dpkg::Options::= "--force-confdef" update -y
2018-09-06 09:16:11 -07:00
apt-get -o Dpkg::Options::= "--force-confdef" upgrade -y
2018-08-28 14:01:47 -07:00
apt-mark unhold grub* >/dev/null
2015-08-26 09:23:30 -07:00
2016-12-27 14:12:31 -08:00
echo "==> Installing required packages"
debconf-set-selections <<< 'mysql-server mysql-server/root_password password password'
debconf-set-selections <<< 'mysql-server mysql-server/root_password_again password password'
2017-01-11 22:22:17 -08:00
# this enables automatic security upgrades (https://help.ubuntu.com/community/AutomaticSecurityUpdates)
2020-11-25 10:02:43 -08:00
# resolvconf is needed for unbound to work property after disabling systemd-resolved in 18.04
2019-01-11 09:43:27 -08:00
gpg_package = $( [ [ " ${ ubuntu_version } " = = "16.04" ] ] && echo "gnupg" || echo "gpg" )
2020-09-15 21:53:16 -07:00
mysql_package = $( [ [ " ${ ubuntu_version } " = = "20.04" ] ] && echo "mysql-server-8.0" || echo "mysql-server-5.7" )
2021-08-22 17:22:47 +02:00
ntpd_package = $( [ [ " ${ ubuntu_version } " = = "20.04" ] ] && echo "systemd-timesyncd" || echo "" )
2021-01-04 23:30:41 -08:00
apt-get -y install --no-install-recommends \
2016-12-27 14:12:31 -08:00
acl \
2021-01-10 20:00:49 +01:00
apparmor \
2016-12-27 14:12:31 -08:00
build-essential \
2019-09-23 12:21:34 +02:00
cifs-utils \
2016-12-27 14:12:31 -08:00
cron \
curl \
2019-03-27 14:16:53 -07:00
debconf-utils \
2017-02-06 11:32:08 -08:00
dmsetup \
2019-01-11 09:43:27 -08:00
$gpg_package \
2020-08-31 18:22:33 -07:00
ipset \
2016-12-27 14:12:31 -08:00
iptables \
2018-11-08 16:08:42 -08:00
libpython2.7 \
2019-09-23 12:21:34 +02:00
linux-generic \
2016-12-27 14:12:31 -08:00
logrotate \
2020-09-15 21:53:16 -07:00
$mysql_package \
2021-05-12 18:00:43 -07:00
nfs-common \
2021-08-22 17:22:47 +02:00
$ntpd_package \
2016-12-27 14:12:31 -08:00
openssh-server \
pwgen \
2020-11-25 10:02:43 -08:00
resolvconf \
2021-06-18 14:46:54 -07:00
sshfs \
2016-12-27 14:12:31 -08:00
swaks \
2019-06-06 12:42:06 -07:00
tzdata \
2017-01-11 22:22:17 -08:00
unattended-upgrades \
2017-08-13 23:15:23 -07:00
unbound \
2021-01-03 15:09:58 -08:00
unzip \
2017-08-13 23:15:23 -07:00
xfsprogs
2016-12-27 14:12:31 -08:00
2020-06-26 14:52:52 -07:00
echo "==> installing nginx for xenial for TLSv3 support"
2020-11-25 17:57:56 -08:00
curl -sL http://nginx.org/packages/ubuntu/pool/nginx/n/nginx/nginx_1.18.0-2~${ ubuntu_codename } _amd64.deb -o /tmp/nginx.deb
2020-06-26 14:52:52 -07:00
# apt install with install deps (as opposed to dpkg -i)
apt install -y /tmp/nginx.deb
rm /tmp/nginx.deb
2020-04-02 09:52:56 -07:00
2019-06-11 13:30:15 +02:00
# on some providers like scaleway the sudo file is changed and we want to keep the old one
2021-01-04 23:30:41 -08:00
apt-get -o Dpkg::Options::= "--force-confold" install -y --no-install-recommends sudo
2019-06-11 13:30:15 +02:00
2017-07-28 19:48:56 -07:00
# this ensures that unattended upgades are enabled, if it was disabled during ubuntu install time (see #346)
# debconf-set-selection of unattended-upgrades/enable_auto_updates + dpkg-reconfigure does not work
cp /usr/share/unattended-upgrades/20auto-upgrades /etc/apt/apt.conf.d/20auto-upgrades
2016-12-27 14:12:31 -08:00
echo "==> Installing node.js"
2021-12-14 20:49:10 -08:00
readonly node_version = 16.13.1
2021-02-04 10:41:47 -08:00
mkdir -p /usr/local/node-${ node_version }
curl -sL https://nodejs.org/dist/v${ node_version } /node-v${ node_version } -linux-x64.tar.gz | tar zxf - --strip-components= 1 -C /usr/local/node-${ node_version }
ln -sf /usr/local/node-${ node_version } /bin/node /usr/bin/node
ln -sf /usr/local/node-${ node_version } /bin/npm /usr/bin/npm
2021-01-04 23:30:41 -08:00
apt-get install -y --no-install-recommends python # Install python which is required for npm rebuild
2016-05-24 13:05:49 -07:00
[ [ " $( python --version 2>& 1) " = = "Python 2.7." * ] ] || die "Expecting python version to be 2.7.x"
2015-08-04 16:29:49 -07:00
2017-01-12 00:57:19 -08:00
# https://docs.docker.com/engine/installation/linux/ubuntulinux/
echo "==> Installing Docker"
2017-01-30 12:25:58 -08:00
2019-03-08 15:53:16 -08:00
# create systemd drop-in file. if you channge options here, be sure to fixup installer.sh as well
2017-01-30 12:25:58 -08:00
mkdir -p /etc/systemd/system/docker.service.d
2022-02-09 17:47:48 -08:00
echo -e "[Service]\nExecStart=\nExecStart=/usr/bin/dockerd -H fd:// --log-driver=journald --exec-opt native.cgroupdriver=cgroupfs --storage-driver=overlay2 --experimental --ip6tables" > /etc/systemd/system/docker.service.d/cloudron.conf
2017-01-30 12:25:58 -08:00
2019-02-21 13:36:46 -08:00
# there are 3 packages for docker - containerd, CLI and the daemon
2022-02-08 10:57:10 -08:00
readonly docker_version = 20.10.12
curl -sL " https://download.docker.com/linux/ubuntu/dists/ ${ ubuntu_codename } /pool/stable/amd64/containerd.io_1.4.9-1_amd64.deb " -o /tmp/containerd.deb
2021-02-04 10:45:29 -08:00
curl -sL " https://download.docker.com/linux/ubuntu/dists/ ${ ubuntu_codename } /pool/stable/amd64/docker-ce-cli_ ${ docker_version } ~3-0~ubuntu- ${ ubuntu_codename } _amd64.deb " -o /tmp/docker-ce-cli.deb
curl -sL " https://download.docker.com/linux/ubuntu/dists/ ${ ubuntu_codename } /pool/stable/amd64/docker-ce_ ${ docker_version } ~3-0~ubuntu- ${ ubuntu_codename } _amd64.deb " -o /tmp/docker.deb
2017-04-20 10:37:46 -07:00
# apt install with install deps (as opposed to dpkg -i)
2019-02-21 13:36:46 -08:00
apt install -y /tmp/containerd.deb /tmp/docker-ce-cli.deb /tmp/docker.deb
rm /tmp/containerd.deb /tmp/docker-ce-cli.deb /tmp/docker.deb
2017-04-18 10:59:52 -07:00
2017-01-30 15:36:33 -08:00
storage_driver = $( docker info | grep "Storage Driver" | sed 's/.*: //' )
2017-08-10 12:27:21 -07:00
if [ [ " ${ storage_driver } " != "overlay2" ] ] ; then
echo "Docker is using " ${ storage_driver } " instead of overlay2"
2017-01-30 15:36:33 -08:00
exit 1
fi
2017-01-12 00:57:19 -08:00
2018-09-06 09:16:11 -07:00
# do not upgrade grub because it might prompt user and break this script
echo "==> Enable memory accounting"
2021-01-04 23:30:41 -08:00
apt-get -y --no-upgrade --no-install-recommends install grub2-common
2018-09-06 09:16:11 -07:00
sed -e 's/^GRUB_CMDLINE_LINUX="\(.*\)"$/GRUB_CMDLINE_LINUX="\1 cgroup_enable=memory swapaccount=1 panic_on_oops=1 panic=5"/' -i /etc/default/grub
update-grub
2017-01-12 00:57:19 -08:00
2016-12-27 14:12:31 -08:00
echo "==> Downloading docker images"
2017-01-09 09:22:22 -08:00
if [ ! -f " ${ arg_infraversionpath } /infra_version.js " ] ; then
echo "No infra_versions.js found"
exit 1
2016-08-10 12:45:23 +02:00
fi
2015-08-04 16:29:49 -07:00
2018-10-26 16:58:18 -07:00
images = $( node -e " var i = require(' ${ arg_infraversionpath } /infra_version.js'); console.log(i.baseImages.map(function (x) { return x.tag; }).join(' '), Object.keys(i.images).map(function (x) { return i.images[x].tag; }).join(' ')); " )
2017-01-09 09:22:22 -08:00
echo -e " \tPulling docker images: ${ images } "
for image in ${ images } ; do
docker pull " ${ image } "
2018-10-26 15:32:34 -07:00
docker pull " ${ image %@sha256 : * } " # this will tag the image for readability
2017-01-09 09:22:22 -08:00
done
2016-12-27 14:12:31 -08:00
echo "==> Install collectd"
2021-01-03 14:39:02 -08:00
# without this, libnotify4 will install gnome-shell
apt-get install -y libnotify4 --no-install-recommends
2021-01-04 23:30:41 -08:00
if ! apt-get install -y --no-install-recommends libcurl3-gnutls collectd collectd-utils; then
2016-01-05 15:12:58 -08:00
# FQDNLookup is true in default debian config. The box code has a custom collectd.conf that fixes this
echo "Failed to install collectd. Presumably because of http://mailman.verplant.org/pipermail/collectd/2015-March/006491.html"
sed -e 's/^FQDNLookup true/FQDNLookup false/' -i /etc/collectd/collectd.conf
fi
2020-09-15 23:19:04 -07:00
# https://bugs.launchpad.net/ubuntu/+source/collectd/+bug/1872281
[ [ " ${ ubuntu_version } " = = "20.04" ] ] && echo -e "\nLD_PRELOAD=/usr/lib/python3.8/config-3.8-x86_64-linux-gnu/libpython3.8.so" >> /etc/default/collectd
2016-12-06 18:41:06 +01:00
2021-01-04 17:26:21 -08:00
# some hosts like atlantic install ntp which conflicts with timedatectl. https://serverfault.com/questions/1024770/ubuntu-20-04-time-sync-problems-and-possibly-incorrect-status-information
2018-10-26 10:57:19 -07:00
echo "==> Configuring host"
sed -e 's/^#NTP=/NTP=0.ubuntu.pool.ntp.org 1.ubuntu.pool.ntp.org 2.ubuntu.pool.ntp.org 3.ubuntu.pool.ntp.org/' -i /etc/systemd/timesyncd.conf
2021-01-04 17:26:21 -08:00
if systemctl is-active ntp; then
systemctl stop ntp
apt purge -y ntp
fi
2018-10-26 10:57:19 -07:00
timedatectl set-ntp 1
2019-03-22 15:12:30 -07:00
# mysql follows the system timezone
2018-10-26 10:57:19 -07:00
timedatectl set-timezone UTC
2019-12-13 11:32:36 -08:00
echo "==> Adding sshd configuration warning"
2020-09-15 14:46:22 -07:00
sed -e '/Port 22/ i # NOTE: Cloudron only supports moving SSH to port 202. See https://docs.cloudron.io/security/#securing-ssh-access' -i /etc/ssh/sshd_config
2019-12-13 11:32:36 -08:00
2020-01-05 15:25:13 -08:00
# https://bugs.launchpad.net/ubuntu/+source/base-files/+bug/1701068
echo "==> Disabling motd news"
2020-09-04 10:49:07 +02:00
if [ -f "/etc/default/motd-news" ] ; then
sed -i 's/^ENABLED=.*/ENABLED=0/' /etc/default/motd-news
fi
2020-01-05 15:25:13 -08:00
2022-02-09 12:17:42 -08:00
# If privacy extensions are not disabled on server, this breaks IPv6 detection
# https://bugs.launchpad.net/ubuntu/+source/procps/+bug/1068756
if [ [ ! -f /etc/sysctl.d/99-cloudimg-ipv6.conf ] ] ; then
echo "==> Disable temporary address (IPv6)"
echo -e "# See https://bugs.launchpad.net/ubuntu/+source/procps/+bug/1068756\nnet.ipv6.conf.all.use_tempaddr = 0\nnet.ipv6.conf.default.use_tempaddr = 0\n\n" > /etc/sysctl.d/99-cloudimg-ipv6.conf
fi
2021-12-07 09:42:25 -08:00
# Disable exim4 (1blu.de)
systemctl stop exim4 || true
systemctl disable exim4 || true
2020-11-22 23:51:21 -08:00
# Disable bind for good measure (on online.net, kimsufi servers these are pre-installed)
2017-03-25 17:36:08 -07:00
systemctl stop bind9 || true
systemctl disable bind9 || true
2017-05-16 16:33:43 -07:00
2020-11-25 10:02:43 -08:00
# on ovh images dnsmasq seems to run by default
systemctl stop dnsmasq || true
systemctl disable dnsmasq || true
2018-02-07 09:07:49 -08:00
# on ssdnodes postfix seems to run by default
systemctl stop postfix || true
systemctl disable postfix || true
2020-11-25 10:02:43 -08:00
# on ubuntu 18.04 and 20.04, this is the default. this requires resolvconf for DNS to work further after the disable
systemctl stop systemd-resolved || true
systemctl disable systemd-resolved || true
2022-02-09 19:50:51 -08:00
# on vultr, ufw is enabled by default. we have our own firewall
ufw disable
2020-11-25 10:02:43 -08:00
# we need unbound to work as this is required for installer.sh to do any DNS requests
2022-02-09 19:53:19 -08:00
echo -e "server:\n\tinterface: 127.0.0.1\n\tdo-ip6: no" > /etc/unbound/unbound.conf.d/cloudron-network.conf
2020-11-25 10:02:43 -08:00
systemctl restart unbound