Xenbuild.sh OS Compiler

MOAR IMAGES - https://hub.nspawn.org/images/

#!/bin/bash -e

if [ $UID -ne 0 ]; then
	echo "This script must be run as root" >&2
	exit 1
fi

if [ -z "$1" ]; then
	echo "Usage: $0 <container_name>" >&2
	exit 0
fi

container="$1"

echo
echo "[+] Installing required packages" && echo
apt update && apt install -y debootstrap systemd-container bridge-utils

echo
echo "[+] Creating necessary build directories and configuring permissions"
mkdir -p /var/lib/machines/"$container"
chown root:root /var/lib/machines
chmod 700 /var/lib/machines

echo
echo "[+] Building minimal Ubuntu 16.04 image at: /var/lib/machines/$container"
echo "[!] This might take a while" && echo
debootstrap --variant=minbase --include=binutils,make,gcc-5,build-essential xenial /var/lib/machines/"$container" http://archive.ubuntu.com/ubuntu
sed '/^root:/ s|\*||' -i "/var/lib/machines/$container/etc/shadow" # passwordless login
rm "/var/lib/machines/$container/etc/resolv.conf" # systemd configures this
# https://github.com/systemd/systemd/issues/852
[ -f "/var/lib/machines/$container/etc/securetty" ] && \
	printf 'pts/%d\n' $(seq 0 10) >>"/var/lib/machines/$container/etc/securetty"
echo "alias gcc='gcc-5'" >> /var/lib/machines/$container/root/.bash_aliases

size=$(du -h /var/lib/machines/"$container" | grep "$container"$)

echo
echo "################################################################################################"
echo
echo "[+] Ubuntu 16.04 container spawned successfully. To boot up, use the following command:" && echo
echo "    kali@kali:~$ systemd-nspawn -M $container" && echo
echo "[!] To exit out of the container, simply type exit and hit Enter"
echo "[!] Container size and location on disk: $size"
echo "[!] To remove the container from your system, use the following command:" && echo
echo "    kali@kali:~$ machinectl remove $container" && echo
echo "[!] You can always send a SIGKILL by pressing ^] three times within 1 second ( Ctrl + ]]] )"
echo
echo "################################################################################################"

Last updated