fabrica/packer/provisioning/alpine/configure-onecontext.sh

54 lines
1.3 KiB
Bash

#!/usr/bin/env sh
set -xeo pipefail
# Install one-context
wget https://github.com/OpenNebula/addon-context-linux/releases/download/v5.8.0/one-context-5.8.0-r1.apk
apk add --allow-untrusted --no-cache one-context-5.8.0-r1.apk
apk add --no-cache e2fsprogs-extra
apk add --no-cache haveged
# Enable VM contextualization
rc-update add one-context default
rc-update add haveged boot
rc-status
# Add DNS hook in one-context
mkdir -p /usr/local/share/one-context/scripts
cat > /usr/local/share/one-context/scripts/dns-nebula <<'EOF'
#!/bin/sh
. /usr/share/one-context/scripts/utils.sh
dns_servers="$(getval ETH0_DNS)"
echo > /etc/resolv.conf
for nameserver_address in $dns_servers; do
echo "nameserver $nameserver_address" >> /etc/resolv.conf
done
EOF
chmod +x /usr/local/share/one-context/scripts/dns-nebula
ln -s /usr/local/share/one-context/scripts/dns-nebula /etc/one-context.d/01-dns-nebula
# Reset network interfaces
cat > /etc/network/interfaces <<EOF
auto lo
iface lo inet loopback
# BEGIN generated by /usr/share/one-context/scripts/network
# Do not modify this block, any modifications will be lost after reboot!
auto eth0
iface eth0 inet dhcp
# END generated
EOF
# Disable resolv.conf overwriting
mkdir -p /etc/udhcpc
echo 'RESOLV_CONF=NO' >> /etc/udhcpc/udhcpc.conf
# Clean up
rm -rf /root/*.apk
sync