Files
cloudron-box/baseimage/initializeBaseUbuntuImage.sh

115 lines
4.5 KiB
Bash
Raw Normal View History

2015-08-04 16:29:49 -07:00
#!/bin/bash
set -euv -o pipefail
readonly USER=yellowtent
readonly USER_HOME="/home/${USER}"
readonly INSTALLER_SOURCE_DIR="${USER_HOME}/installer"
readonly INSTALLER_REVISION="${1:-master}"
2016-10-21 12:58:01 -07:00
readonly PROVIDER="${2:-generic}"
2015-08-04 16:29:49 -07:00
2015-08-12 19:52:43 -07:00
readonly SOURCE_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
2016-01-22 10:33:34 -08:00
function die {
echo $1
exit 1
}
2016-04-29 19:18:31 -07:00
[[ "$(systemd --version 2>&1)" == *"systemd 229"* ]] || die "Expecting systemd to be 229"
2016-01-22 10:33:34 -08:00
2015-08-04 16:29:49 -07:00
echo "==== Create User ${USER} ===="
if ! id "${USER}"; then
useradd "${USER}" -m
fi
export DEBIAN_FRONTEND=noninteractive
echo "=== Upgrade ==="
2016-11-08 15:35:51 +05:30
apt-get -o Dpkg::Options::="--force-confdef" update -y
apt-get -o Dpkg::Options::="--force-confdef" dist-upgrade -y
apt-get install -y curl iptables
2015-08-04 16:29:49 -07:00
2015-11-01 08:46:28 -08:00
echo "==== Install btrfs tools ==="
apt-get -y install btrfs-tools
2015-08-04 16:29:49 -07:00
echo "==== Install docker ===="
# install docker from binary to pin it to a specific version. the current debian repo does not allow pinning
2016-08-11 16:29:03 -07:00
# IMPORTANT: docker 1.11.x breaks the --dns option hack that we use below
2016-03-01 10:13:44 -08:00
curl https://get.docker.com/builds/Linux/x86_64/docker-1.10.2 > /usr/bin/docker
apt-get -y install aufs-tools
chmod +x /usr/bin/docker
groupadd docker
usermod "${USER}" -a -G docker
2015-08-04 16:29:49 -07:00
2015-08-24 22:33:35 -07:00
echo "=== Enable memory accounting =="
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
2015-08-24 22:33:35 -07:00
echo "==== Install nodejs ===="
# Cannot use anything above 4.1.1 - https://github.com/nodejs/node/issues/3803
mkdir -p /usr/local/node-4.1.1
curl -sL https://nodejs.org/dist/v4.1.1/node-v4.1.1-linux-x64.tar.gz | tar zxvf - --strip-components=1 -C /usr/local/node-4.1.1
ln -s /usr/local/node-4.1.1/bin/node /usr/bin/node
ln -s /usr/local/node-4.1.1/bin/npm /usr/bin/npm
apt-get install -y python # Install python which is required for npm rebuild
[[ "$(python --version 2>&1)" == "Python 2.7."* ]] || die "Expecting python version to be 2.7.x"
2015-08-04 16:29:49 -07:00
echo "==== Downloading docker images ===="
if [ -f ${SOURCE_DIR}/infra_version.js ]; then
2016-08-20 10:24:29 -07:00
images=$(node -e "var i = require('${SOURCE_DIR}/infra_version.js'); console.log(i.baseImages.join(' '), Object.keys(i.images).map(function (x) { return i.images[x].tag; }).join(' '));")
echo "Pulling images: ${images}"
for image in ${images}; do
docker pull "${image}"
done
else
echo "No infra_versions.js found, skipping image download"
fi
2015-08-04 16:29:49 -07:00
echo "==== Install nginx ===="
apt-get -y install nginx-full
2016-04-29 19:38:06 -07:00
[[ "$(nginx -v 2>&1)" == *"nginx/1.10."* ]] || die "Expecting nginx version to be 1.10.x"
2015-08-04 16:29:49 -07:00
echo "==== Install build-essential ===="
apt-get -y install build-essential rcconf
echo "==== Install mysql ===="
debconf-set-selections <<< 'mysql-server mysql-server/root_password password password'
debconf-set-selections <<< 'mysql-server mysql-server/root_password_again password password'
2016-04-29 19:12:20 -07:00
apt-get -y install mysql-server-5.7
[[ "$(mysqld --version 2>&1)" == *"5.7."* ]] || die "Expecting mysql version to be 5.7.x"
2015-08-04 16:29:49 -07:00
2016-04-08 23:58:07 -07:00
echo "==== Install pwgen and swaks awscli ===="
apt-get -y install pwgen swaks awscli
2015-08-04 16:29:49 -07:00
echo "==== Install collectd ==="
2016-01-05 15:12:58 -08:00
if ! apt-get install -y 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. 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
2015-08-04 16:29:49 -07:00
update-rc.d -f collectd remove
# this simply makes it explicit that we run logrotate via cron. it's already part of base ubuntu
echo "==== Install logrotate ==="
apt-get install -y cron logrotate
systemctl enable cron
echo "=== Prepare installer revision - ${INSTALLER_REVISION}) ==="
rm -rf /tmp/box && mkdir -p /tmp/box
2016-10-21 16:14:50 -07:00
curl "https://git.cloudron.io/cloudron/box/repository/archive.tar.gz?ref=${INSTALLER_REVISION}" | tar zxvf - --strip-components=1 -C /tmp/box
mkdir -p "${INSTALLER_SOURCE_DIR}"
cp -rf /tmp/box/installer/* "${INSTALLER_SOURCE_DIR}" && rm -rf /tmp/box
2015-08-26 16:01:45 -07:00
chown "${USER}:${USER}" -R "${INSTALLER_SOURCE_DIR}"
echo "${INSTALLER_REVISION}" > "${INSTALLER_SOURCE_DIR}/REVISION"
2015-08-04 16:29:49 -07:00
2015-11-23 11:32:05 -08:00
apt-get -y install acl
2016-12-06 18:41:06 +01:00
# DO uses Google nameservers by default. This causes RBL queries to fail (host 2.0.0.127.zen.spamhaus.org)
# We do not use dnsmasq because it is not a recursive resolver and defaults to the value in the interfaces file (which is Google DNS!)
echo "==== Install unbound DNS ==="
apt-get -y install unbound
2016-06-10 14:10:59 +02:00
echo "==== Install ssh ==="
apt-get -y install openssh-server