fabrica/.packer/recipes/ubuntu/18.04/scripts/provision-minimal.sh

60 lines
1.5 KiB
Bash

#!/bin/bash -e
set -xeo pipefail
# For SHASUM
apt-get -y install perl ifupdown
# Download OpenNebula context package
ONE_CONTEXT_VERSION=5.8.0
ONE_CONTEXT_BUILD_SUFFIX=-1
ONE_CONTEXT_SHASUM=cfcc8aa2e51396935e8d2a507f996838201515b5
ONE_CONTEXT_URL="https://github.com/OpenNebula/addon-context-linux/releases/download/v${ONE_CONTEXT_VERSION}/one-context_${ONE_CONTEXT_VERSION}${ONE_CONTEXT_BUILD_SUFFIX}.deb"
ONE_CONTEXT_PACKAGE_DEST=/tmp/one-context.deb
wget -O- "${ONE_CONTEXT_URL}" > "${ONE_CONTEXT_PACKAGE_DEST}"
echo "${ONE_CONTEXT_SHASUM} ${ONE_CONTEXT_PACKAGE_DEST}" | shasum -c
# Purge cloud-init
apt-get purge -y cloud-init perl
# Install onecontext
dpkg -i "${ONE_CONTEXT_PACKAGE_DEST}" || apt-get install -fy
# Update hostname
hostnamectl set-hostname "${VM_NAME}"
# Disable root login with password
# sed -i 's/^PermitRootLogin.*$/PermitRootLogin without-password/' /etc/ssh/sshd_config
# Run dhclient on one-context service failure
mkdir -p /etc/systemd/system/one-context.service.d
cat > /etc/systemd/system/one-context.service.d/dhclient-on-fail.conf <<EOF
[Unit]
OnFailure=one-dhclient.service
EOF
cat > /etc/systemd/system/one-dhclient.service <<EOF
[Unit]
Description=Execute dhclient
[Service]
ExecStart=/sbin/dhclient
EOF
chmod 664 /etc/systemd/system/one-dhclient.service
# Disable auto-upgrade
systemctl disable unattended-upgrades
systemctl disable apt-daily
systemctl disable apt-daily.timer
systemctl disable apt-daily-upgrade
apt-get install -y qemu-guest-agent
# Cleanup
rm -f "${ONE_CONTEXT_PACKAGE_DEST}"
apt-get -y clean
# Force sync
sync