2015-08-04 16:29:49 -07:00
#!/bin/bash
2022-03-29 22:11:43 -07:00
# This script is run on the base ubuntu. Put things here which are managed by ubuntu
2022-07-12 16:14:40 +05:30
# This script is also run after ubuntu upgrade
2022-03-29 22:11:43 -07:00
2015-08-04 16:29:49 -07:00
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
2022-04-21 11:07:43 -07:00
case " ${ ubuntu_version } " in
16.04)
gpg_package = "gnupg"
mysql_package = "mysql-server-5.7"
ntpd_package = ""
python_package = "python2.7"
2022-04-27 10:22:31 -07:00
nginx_package = "" # we use custom package for TLS v1.3 support
2022-04-21 11:07:43 -07:00
; ;
18.04)
gpg_package = "gpg"
mysql_package = "mysql-server-5.7"
ntpd_package = ""
python_package = "python2.7"
2022-04-27 10:22:31 -07:00
nginx_package = "" # we use custom package for TLS v1.3 support
2022-04-21 11:07:43 -07:00
; ;
20.04)
gpg_package = "gpg"
mysql_package = "mysql-server-8.0"
ntpd_package = "systemd-timesyncd"
python_package = "python3.8"
2022-04-27 10:22:31 -07:00
nginx_package = "nginx-full"
2022-04-21 11:07:43 -07:00
; ;
22.04)
gpg_package = "gpg"
mysql_package = "mysql-server-8.0"
ntpd_package = "systemd-timesyncd"
python_package = "python3.10"
2022-04-27 10:22:31 -07:00
nginx_package = "nginx-full"
2022-04-21 11:07:43 -07:00
; ;
esac
2020-11-25 10:02:43 -08:00
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 \
2022-04-21 11:07:43 -07:00
lib${ python_package } \
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 \
2022-04-27 13:11:20 -07:00
$nginx_package \
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
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
2022-04-21 11:07:43 -07:00
apt-get install -y --no-install-recommends $python_package # Install python which is required for npm rebuild
2015-08-04 16:29:49 -07: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 "==> Install collectd"
2021-01-03 14:39:02 -08:00
# without this, libnotify4 will install gnome-shell
2022-05-06 18:48:23 -07:00
apt-get install -y libnotify4 libcurl3-gnutls --no-install-recommends
2020-09-15 23:19:04 -07:00
# https://bugs.launchpad.net/ubuntu/+source/collectd/+bug/1872281
2022-05-06 18:48:23 -07:00
if [ [ " ${ ubuntu_version } " = = "22.04" ] ] ; then
readonly launchpad = "https://launchpad.net/ubuntu/+source/collectd/5.12.0-9/+build/23189375/+files"
cd /tmp && wget -q " ${ launchpad } /collectd_5.12.0-9_amd64.deb " " ${ launchpad } /collectd-utils_5.12.0-9_amd64.deb " " ${ launchpad } /collectd-core_5.12.0-9_amd64.deb " " ${ launchpad } /libcollectdclient1_5.12.0-9_amd64.deb "
cd /tmp && apt install -y --no-install-recommends ./libcollectdclient1_5.12.0-9_amd64.deb ./collectd-core_5.12.0-9_amd64.deb ./collectd_5.12.0-9_amd64.deb ./collectd-utils_5.12.0-9_amd64.deb && rm -f /tmp/collectd_*.deb
2022-04-21 11:07:43 -07:00
echo -e "\nLD_PRELOAD=/usr/lib/python3.10/config-3.10-x86_64-linux-gnu/libpython3.10.so" >> /etc/default/collectd
2022-05-06 18:48:23 -07:00
else
2022-05-25 15:10:04 -07:00
if ! apt-get install -y --no-install-recommends collectd collectd-utils; then
# FQDNLookup is true in default debian config. The box code has a custom collectd.conf that fixes this
echo "Failed to install collectd, continuing anyway. Presumably because of http://mailman.verplant.org/pipermail/collectd/2015-March/006491.html"
fi
2022-05-06 18:48:23 -07:00
if [ [ " ${ ubuntu_version } " = = "20.04" ] ] ; then
echo -e "\nLD_PRELOAD=/usr/lib/python3.8/config-3.8-x86_64-linux-gnu/libpython3.8.so" >> /etc/default/collectd
fi
2022-04-21 11:07:43 -07:00
fi
2022-07-25 17:01:49 +02:00
sed -e 's/^FQDNLookup true/FQDNLookup false/' -i /etc/collectd/collectd.conf
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"
2022-05-25 15:10:04 -07:00
if [ [ -f "/etc/default/motd-news" ] ] ; then
2020-09-04 10:49:07 +02:00
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
2022-03-02 19:36:20 -08:00
ufw disable || true
2022-02-09 19:50:51 -08:00
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-07-26 17:17:30 +02:00
echo -e "server:\n\tinterface: 127.0.0.1\n" > /etc/unbound/unbound.conf.d/cloudron-network.conf
2020-11-25 10:02:43 -08:00
systemctl restart unbound
2022-03-29 21:41:46 -07:00
2022-04-27 17:49:29 -07:00
# Ubuntu 22 has private home directories by default (https://discourse.ubuntu.com/t/private-home-directories-for-ubuntu-21-04-onwards/)
sed -e 's/^HOME_MODE\([[:space:]]\+\).*$/HOME_MODE\10755/' -i /etc/login.defs
2022-03-30 14:27:39 -07:00
# create the yellowtent user. system user has different numeric range, no age and won't show in login/gdm UI
# the nologin will also disable su/login
2022-03-29 21:41:46 -07:00
if ! id yellowtent 2>/dev/null; then
2022-03-30 14:27:39 -07:00
useradd --system --comment "Cloudron Box" --create-home --shell /usr/sbin/nologin yellowtent
fi
# add support user (no password, sudo)
if ! id cloudron-support 2>/dev/null; then
useradd --system --comment "Cloudron Support (support@cloudron.io)" --create-home --no-user-group --shell /bin/bash cloudron-support
2022-03-29 21:41:46 -07:00
fi