aboutsummaryrefslogtreecommitdiff
path: root/build.sh
diff options
context:
space:
mode:
Diffstat (limited to '')
-rwxr-xr-xbuild.sh129
1 files changed, 129 insertions, 0 deletions
diff --git a/build.sh b/build.sh
new file mode 100755
index 0000000..f79206c
--- /dev/null
+++ b/build.sh
@@ -0,0 +1,129 @@
+#!/bin/bash
+
+if [[ ! -z $SUDO_USER ]]; then
+ user=$SUDO_USER
+else
+ user=$USER
+fi
+
+if [[ ! -z $SUDO_USER ]]; then
+ user=$SUDO_USER
+elif [[ $USER == "root" ]]; then
+ user=$USER
+else
+ echo "Must be launch as root"
+ exit 1
+fi
+
+help () {
+ echo "$0 --net --qcow2 [size] --ssh [key_path]"
+ echo ""
+ echo " --net enable dhcpcd"
+ echo " --qcow2 create a qcow2 image instead an iso one"
+ echo " [size] the size of the image you want. By default it don't resize"
+ echo " --ssh enable ssh at boot"
+}
+
+while [ -n "$1" ]; do
+
+ case "$1" in
+
+ -h)
+ help
+ exit 0
+ ;;
+
+ --net)
+
+ net=1
+ ;;
+
+ --qcow2)
+
+ qcow2=1
+ if [[ $2 != --* ]]; then
+ qcow2_param="$2"
+ shift
+ fi
+ ;;
+
+ --ssh)
+
+ ssh=1
+ ;;
+
+ *)
+
+ invalid_option=1
+ error_msg="'$1' is not an recognized option"
+ ;;
+
+ esac
+
+ shift
+
+done
+
+if [[ $invalid_option -eq 1 ]]; then
+ echo $error_msg
+ help
+ exit 1
+fi
+
+rm -rf build
+mkdir build
+
+cp -r /usr/share/archiso/configs/baseline/ build/archlive
+
+if [[ $ssh -eq 1 ]]; then
+ mkdir -p build/archlive/airootfs/etc/systemd/system/multi-user.target.wants
+ ln -s /usr/lib/systemd/system/sshd.service build/archlive/airootfs/etc/systemd/system/multi-user.target.wants/
+fi
+
+install_package () {
+ package_name=$1
+ cat build/archlive/packages.x86_64 | grep "$package_name" > /dev/null
+ if [[ $? -eq 1 ]]; then
+ echo $package_name >> build/archlive/packages.x86_64
+ fi
+}
+
+install_package "cloud-init"
+
+mkdir -p build/archlive/airootfs/etc/systemd/system/cloud-init.target.wants
+ln -s /usr/lib/systemd/system/cloud-init.service build/archlive/airootfs/etc/systemd/system/cloud-init.target.wants/cloud-init.service
+
+if [[ $net -eq 1 ]]; then
+ install_package "dhcpcd"
+ ln -s /usr/lib/systemd/system/dhcpcd.service build/archlive/airootfs/etc/systemd/system/multi-user.target.wants/dhcpcd.service
+fi
+
+rm -rf build/out
+mkdir -p build/out
+rm -rf /tmp/archiso-tmp
+
+mkarchiso -v -w /tmp/archiso-tmp -o build/out build/archlive
+
+xorriso -as genisoimage -output build/seed.iso -volid CIDATA -joliet -rock cloudinit_seed/user-data cloudinit_seed/meta-data
+last_build=$(ls -tr build/out | tail -1)
+mv build/out/$last_build archlinux_cloud.iso
+
+rm -f archlinux_cloud.qcow2
+
+if [[ $qcow2 -eq 1 ]]; then
+ qemu-img convert -f raw -O qcow2 archlinux_cloud.iso archlinux_cloud.qcow2
+ rm archlinux_cloud.iso
+fi
+
+if [[ ! -z "$qcow2_param" ]]; then
+ qemu-img resize archlinux_cloud.qcow2 $qcow2_param
+fi
+
+chown -R $user: build
+chown -R $user: archlinux_cloud.*
+
+if [[ $qcow2 -eq 1 ]]; then
+ echo "Image build at archlinux_cloud.qcow2"
+else
+ echo "Image build at archlinux_cloud.iso"
+fi