diff --git a/.gitignore b/.gitignore index 792f31b7..2875c0b8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +build/ context-windows/out/ context-windows/*.msi context-windows/rhsrvany.exe diff --git a/Makefile b/Makefile new file mode 100644 index 00000000..38b93eb5 --- /dev/null +++ b/Makefile @@ -0,0 +1,115 @@ +# load targets config +-include Makefile.distros + +# load variables and makefile config +-include Makefile.config + +#------------------------------------------------------------------------------ +# All, alliases +#------------------------------------------------------------------------------ +all: $(patsubst %, all-%, $(DISTROS)) + @: + +# allow individual distribution targets (e.g., "make debian11") +$(DISTROS): %: all-% ; + +# pattern rule for dependencies +all-%: download-% installer-% customize-% + @${INFO} "All done for ${*}" + +#------------------------------------------------------------------------------ +# Download +# - download to build/01_base/$DISTRO +# - no file suffix, could be iso, qcow2 whatever +# - TODO: add chesksum verfication somehow +#------------------------------------------------------------------------------ +download: $(patsubst %, download-%, $(DISTROS)) + +download-%: ${DIR_BASE}/%.img + @${INFO} "Download ${*} done" + +${DIR_BASE}/%.img: validate-% + @${INFO} "Starting $* download" + curl -sS -L -f -o "$@" "${URL_${*}}" + +#------------------------------------------------------------------------------ +# Install (optional) +# - run distro installer if cloud/virt image is not available +# - execute packer/$DISTRO/run.sh which runs packet +# - or packer/skip.sh to only create target symlink to base image +#------------------------------------------------------------------------------ +installer: $(patsubst %, installer-%, $(DISTROS)) + +installer-%: ${DIR_INSTALL}/%.qcow2 + @${INFO} "Installer ${*} done" + +${DIR_INSTALL}/%.qcow2: ${DIR_BASE}/%.img + @${INFO} "Starting ${*} installer" + @if [ -f "packer/${*}/run.sh" ]; then \ + packer/${*}/run.sh ${*} ${@}; \ + else \ + packer/skip.sh ${*}; \ + fi + +#------------------------------------------------------------------------------ +# Customize +# - execute customize/$DISTRO/run.sh which: +# - run guestfish customzation scripts +# - TODO: sysprep +# - TODO: sparsify +# - export final image +#------------------------------------------------------------------------------ +customize: $(patsubst %, customize-%, $(DISTROS)) + +customize-%: context-linux ${DIR_EXPORT}/%-${VERSION}-${RELEASE}.qcow2 + @${INFO} "Customize $* done" + +${DIR_EXPORT}/%-${VERSION}-${RELEASE}.qcow2: ${DIR_INSTALL}/%.qcow2 + @${INFO} "Starting $* customization" + @guestfish/run.sh ${*} ${@} + +#------------------------------------------------------------------------------ +# clean +#------------------------------------------------------------------------------ +clean: + -rm -rf ${DIR_BASE}/* + -rm -rf ${DIR_INSTALL}/* + -rm -rf ${DIR_EXPORT}/* + +#------------------------------------------------------------------------------ +# context-linux +#------------------------------------------------------------------------------ +context-linux: $(patsubst %, context-linux/out/%, $(LINUX_CONTEXT_PACKAGES)) + @${INFO} "Generate context-linux done" + +context-linux/out/%: + cd context-linux; ./generate-all.sh + +#------------------------------------------------------------------------------ +# validate before download +#------------------------------------------------------------------------------ +validate-%: + @if [[ ! "$(DISTROS)" == *"${*}"* ]]; then \ + echo "[ERROR] Unknown distro ${*}"; \ + exit 1; \ + fi + +#------------------------------------------------------------------------------ +# help +#------------------------------------------------------------------------------ +help: + @echo 'Available distros:' + @echo ' $(DISTROS)' + @echo + @echo 'Usage examples:' + @echo ' make -- build all distros' + @echo ' make download -- download all base images' + @echo ' make installer -- run installer (unnecessary for some)' + @echo ' make customize -- run customization (install context etc)' + @echo + @echo ' make -- build just one distro' + @echo ' make download- -- download just one' + @echo ' make installer- -- download just one' + @echo ' make customize- -- download just one' + @echo ' make context-linux -- build context linux packages' + diff --git a/Makefile.config b/Makefile.config new file mode 100644 index 00000000..6055fcce --- /dev/null +++ b/Makefile.config @@ -0,0 +1,64 @@ +# context version +VERSION ?= 6.6.1 +RELEASE ?= 1 + +# log +VERBOSE ?= 1 +PACKER_LOG ?= 1 +LIBGUESTFS_DEBUG ?= 1 +LIBGUESTFS_TRACE ?= 0 +LIBGUESTFS_MEMSIZE ?= 3072 +TTY ?= $(shell tty) + +# default directories +DIR_BUILD ?= build +DIR_BASE ?= $(DIR_BUILD)/01_base +DIR_INSTALL ?= $(DIR_BUILD)/02_installer +DIR_EXPORT ?= $(DIR_BUILD)/03_export +DIR_PACKER ?= $(DIR_BUILD)/_packer + +# create them if not present +$(shell \ + mkdir -p ${DIR_BASE} \ + mkdir -p ${DIR_INSTALL} \ + mkdir -p ${DIR_EXPORT} \ +) + +# # don't delete downloaded or installed images +.SECONDARY: $(patsubst %, $(DIR_BASE)/%, $(DISTROS)) +.SECONDARY: $(patsubst %, $(DIR_INSTALL)/%.qcow2, $(DISTROS)) + +.PHONY: context-linux download installer customize help + +# this needs to match context-linux/generate-all.sh products +LINUX_CONTEXT_PACKAGES := one-context_${VERSION}-${RELEASE}.deb \ + one-context-${VERSION}-${RELEASE}.el6.noarch.rpm \ + one-context-${VERSION}-${RELEASE}.el7.noarch.rpm \ + one-context-${VERSION}-${RELEASE}.el8.noarch.rpm \ + one-context-${VERSION}-${RELEASE}.el9.noarch.rpm \ + one-context-${VERSION}-${RELEASE}.suse.noarch.rpm \ + one-context-${VERSION}_${RELEASE}.txz \ + one-context-${VERSION}-alt${RELEASE}.noarch.rpm \ + one-context-${VERSION}-r${RELEASE}.apk \ + one-context-linux-${VERSION}-${RELEASE}.iso + +LINUX_CONTEXT_PACKAGES_FULL := $(patsubst %, context-linux/out/%, $(LINUX_CONTEXT_PACKAGES)) + + +# discover some binaries +QEMU_BINARY ?= $(shell \ + for _qb in /usr/bin/qemu-system-x86_64 \ + /usr/libexec/qemu-kvm \ + /usr/bin/qemu-kvm; do \ + \ + if [ -e "$$_qb" ]; then \ + echo $$_qb && exit; \ + fi; \ + done ) + +# logging func +INFO=sh -c 'if [ $(VERBOSE) = 1 ]; then echo [INFO] $$1; fi' INFO + +# export all variables +export + diff --git a/Makefile.distros b/Makefile.distros new file mode 100644 index 00000000..ae9024de --- /dev/null +++ b/Makefile.distros @@ -0,0 +1,10 @@ +DISTROS := alpine316 alpine317 debian11 debian12 + +# URLS +URL_alpine316 ?= https://dl-cdn.alpinelinux.org/alpine/v3.16/releases/x86_64/alpine-virt-3.16.7-x86_64.iso +URL_alpine317 ?= https://dl-cdn.alpinelinux.org/alpine/v3.17/releases/x86_64/alpine-virt-3.17.5-x86_64.iso +URL_debian11 ?= https://cdimage.debian.org/cdimage/cloud/bullseye/latest/debian-11-generic-amd64.qcow2 +URL_debian11 ?= https://cdimage.debian.org/cdimage/cloud/bullseye/latest/debian-11-generic-amd64.qcow2 +URL_debian12 ?= https://cdimage.debian.org/cdimage/cloud/bookworm/latest/debian-12-generic-amd64.qcow2 + + diff --git a/guestfish/alpine316/scripts/10-upgrade-distro.sh b/guestfish/alpine316/scripts/10-upgrade-distro.sh new file mode 100644 index 00000000..66c003df --- /dev/null +++ b/guestfish/alpine316/scripts/10-upgrade-distro.sh @@ -0,0 +1,20 @@ +#!/usr/bin/env sh + +# (Auto)Removes unneeded packages and upgrades +# the distro. + +exec 1>&2 +set -ex + +# Ensure packages needed for post-processing scripts do exist. +apk --no-cache add bash curl gawk grep jq sed + +gawk -i inplace -f- /etc/apk/repositories <<'EOF' +/community$/ && !/edge/ { gsub(/^#\s*/, "") } +{ print } +EOF + +apk update +apk upgrade + +sync diff --git a/guestfish/alpine316/scripts/11-update-boot.sh b/guestfish/alpine316/scripts/11-update-boot.sh new file mode 100644 index 00000000..4fc16c3a --- /dev/null +++ b/guestfish/alpine316/scripts/11-update-boot.sh @@ -0,0 +1,21 @@ +#!/usr/bin/env bash + +# Updates various settings that require reboot. + +exec 1>&2 +set -o errexit -o nounset -o pipefail +set -x + +gawk -i inplace -f- /etc/inittab <<'EOF' +/^ttyS/ { $0 = "#" $0 } +{ print } +EOF + +gawk -i inplace -f- /boot/extlinux.conf <<'EOF' +BEGIN { update = "TIMEOUT 3" } +/^TIMEOUT\s/ { $0 = update; found = 1 } +{ print } +END { if (!found) print update >> FILENAME } +EOF + +sync diff --git a/guestfish/alpine316/scripts/80-install-context.sh b/guestfish/alpine316/scripts/80-install-context.sh new file mode 100644 index 00000000..21d600c1 --- /dev/null +++ b/guestfish/alpine316/scripts/80-install-context.sh @@ -0,0 +1,28 @@ +#!/usr/bin/env bash + +# Downloads and installs the latest one-context package. + +exec 1>&2 +set -o errexit -o nounset -o pipefail +set -x + +: "${CTX_SUFFIX:=.apk}" + +set -o errexit -o nounset -o pipefail +set -x + +if ! stat /context/one-context*$CTX_SUFFIX; then ( + install -d /context/ && cd /context/ + curl -fsSL https://api.github.com/repos/OpenNebula/addon-context-linux/releases \ + | jq -r ".[0].assets[].browser_download_url | select(endswith(\"$CTX_SUFFIX\"))" \ + | xargs -r -n1 curl -fsSLO +) fi + +apk --no-cache add tzdata haveged open-vm-tools-plugins-all +apk --no-cache add --allow-untrusted /context/one-context*$CTX_SUFFIX + +rc-update add qemu-guest-agent default +rc-update add open-vm-tools default +rc-update add haveged boot + +sync diff --git a/guestfish/alpine316/scripts/81-configure-ssh.sh b/guestfish/alpine316/scripts/81-configure-ssh.sh new file mode 100644 index 00000000..ca55c22b --- /dev/null +++ b/guestfish/alpine316/scripts/81-configure-ssh.sh @@ -0,0 +1,30 @@ +#!/usr/bin/env bash + +# Configures critical settings for OpenSSH server. + +exec 1>&2 +set -o errexit -o nounset -o pipefail +set -x + +gawk -i inplace -f- /etc/ssh/sshd_config <<'EOF' +BEGIN { update = "PasswordAuthentication no" } +/^[#\s]*PasswordAuthentication\s*/ { $0 = update; found = 1 } +{ print } +END { if (!found) print update >> FILENAME } +EOF + +gawk -i inplace -f- /etc/ssh/sshd_config <<'EOF' +BEGIN { update = "PermitRootLogin without-password" } +/^[#\s]*PermitRootLogin\s*/ { $0 = update; found = 1 } +{ print } +END { if (!found) print update >> FILENAME } +EOF + +gawk -i inplace -f- /etc/ssh/sshd_config <<'EOF' +BEGIN { update = "UseDNS no" } +/^[#\s]*UseDNS\s*/ { $0 = update; found = 1 } +{ print } +END { if (!found) print update >> FILENAME } +EOF + +sync diff --git a/guestfish/alpine316/scripts/98-collect-garbage.sh b/guestfish/alpine316/scripts/98-collect-garbage.sh new file mode 100644 index 00000000..90a37560 --- /dev/null +++ b/guestfish/alpine316/scripts/98-collect-garbage.sh @@ -0,0 +1,15 @@ +#!/usr/bin/env bash + +# Cleans APK caches, removes temporary files / logs, +# removes leftover / temporary unneeded packages. + +exec 1>&2 +set -o errexit -o nounset -o pipefail +set -x + +rm -f /etc/motd + +rm -rf /var/cache/apk/* +rm -rf /context/ + +sync diff --git a/guestfish/alpine316/scripts/test1.sh b/guestfish/alpine316/scripts/test1.sh new file mode 100644 index 00000000..f85a613a --- /dev/null +++ b/guestfish/alpine316/scripts/test1.sh @@ -0,0 +1,4 @@ +#!/usr/bin/env sh +# +echo 111 + diff --git a/guestfish/debian11/scripts/10-upgrade-distro.sh b/guestfish/debian11/scripts/10-upgrade-distro.sh new file mode 100644 index 00000000..9fa165a2 --- /dev/null +++ b/guestfish/debian11/scripts/10-upgrade-distro.sh @@ -0,0 +1,28 @@ +#!/usr/bin/env bash + +# (Auto)Removes unneeded packages and upgrades +# the distro. + +policy_rc_d_disable() (echo "exit 101" >/usr/sbin/policy-rc.d && chmod a+x /usr/sbin/policy-rc.d) +policy_rc_d_enable() (echo "exit 0" >/usr/sbin/policy-rc.d && chmod a+x /usr/sbin/policy-rc.d) + +exec 1>&2 +set -o errexit -o nounset -o pipefail +set -x + +export DEBIAN_FRONTEND=noninteractive + +apt-get update -y + +policy_rc_d_disable + +apt-get install -y --fix-broken + +apt-get upgrade -y -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" + +# Ensure packages needed for post-processing scripts do exist. +apt-get install -y curl gawk grep jq + +policy_rc_d_enable + +sync diff --git a/guestfish/debian11/scripts/11-update-grub.sh b/guestfish/debian11/scripts/11-update-grub.sh new file mode 100644 index 00000000..f65d0902 --- /dev/null +++ b/guestfish/debian11/scripts/11-update-grub.sh @@ -0,0 +1,54 @@ +#!/usr/bin/env bash + +# Sets kernel command line (net.ifnames=0 is particularily important), +# then updates initramfs/initrd and grub2. + +exec 1>&2 +set -o errexit -o nounset -o pipefail +set -x + +rm -rf /etc/default/grub.d/ + +# Drop unwanted. + +# NOTE: console=ttyS*, earlyprintk=ttyS* may cause kernel panic during first boot. +# The exact problem is identical to https://github.com/dmacvicar/terraform-provider-libvirt/issues/948. +# A correct workaround is described here: https://bugs.launchpad.net/ubuntu/+source/cloud-initramfs-tools/+bug/1123220. + +gawk -i inplace -f- /etc/default/grub <<'EOF' +/^GRUB_CMDLINE_LINUX[^=]*=/ { gsub(/\/, "") } +/^GRUB_CMDLINE_LINUX[^=]*=/ { gsub(/\/, "") } +/^GRUB_CMDLINE_LINUX[^=]*=/ { gsub(/\/, "") } +/^GRUB_CMDLINE_LINUX[^=]*=/ { gsub(/\/, "") } +/^GRUB_TERMINAL=/ { gsub(/\/, "") } +{ print } +EOF + +# Ensure required. + +gawk -i inplace -f- /etc/default/grub <<'EOF' +/^GRUB_CMDLINE_LINUX=/ { found = 1 } +/^GRUB_CMDLINE_LINUX=/ && !/net.ifnames=0/ { gsub(/"$/, " net.ifnames=0\"") } +/^GRUB_CMDLINE_LINUX=/ && !/biosdevname=0/ { gsub(/"$/, " biosdevname=0\"") } +{ print } +END { if (!found) print "GRUB_CMDLINE_LINUX=\" net.ifnames=0 biosdevname=0\"" >> FILENAME } +EOF + +gawk -i inplace -f- /etc/default/grub <<'EOF' +BEGIN { update = "GRUB_TIMEOUT=0" } +/^GRUB_TIMEOUT=/ { $0 = update; found = 1 } +{ print } +END { if (!found) print update >> FILENAME } +EOF + +# Cleanup. + +gawk -i inplace -f- /etc/default/grub <<'EOF' +{ gsub(/(" *| *")/, "\""); gsub(/ */, " ") } +{ print } +EOF + +update-initramfs -vu +update-grub2 + +sync diff --git a/guestfish/debian11/scripts/80-install-context.sh b/guestfish/debian11/scripts/80-install-context.sh new file mode 100644 index 00000000..b0b36971 --- /dev/null +++ b/guestfish/debian11/scripts/80-install-context.sh @@ -0,0 +1,40 @@ +#!/usr/bin/env bash + +# Downloads and installs the latest one-context package. + +: "${CTX_SUFFIX:=.deb}" + +policy_rc_d_disable() (echo "exit 101" >/usr/sbin/policy-rc.d && chmod a+x /usr/sbin/policy-rc.d) +policy_rc_d_enable() (echo "exit 0" >/usr/sbin/policy-rc.d && chmod a+x /usr/sbin/policy-rc.d) + +exec 1>&2 +set -o errexit -o nounset -o pipefail +set -x + +export DEBIAN_FRONTEND=noninteractive + +if ! stat /context/one-context*$CTX_SUFFIX; then ( + install -d /context/ && cd /context/ + curl -fsSL https://api.github.com/repos/OpenNebula/addon-context-linux/releases \ + | jq -r ".[0].assets[].browser_download_url | select(endswith(\"$CTX_SUFFIX\"))" \ + | xargs -r -n1 curl -fsSLO +) fi + +policy_rc_d_disable + +dpkg -i /context/one-context*$CTX_SUFFIX || apt-get install -y -f +dpkg -i /context/one-context*$CTX_SUFFIX + +apt-get install -y haveged open-vm-tools + +systemctl enable haveged + +# >>> Apply only on one-context >= 6.1 >>> +if ! dpkg-query -W --showformat '${Version}' one-context | grep -E '^([1-5]\.|6\.0\.)'; then + apt-get install -y --no-install-recommends --no-install-suggests netplan.io network-manager +fi +# <<< Apply only on one-context >= 6.1 <<< + +policy_rc_d_enable + +sync diff --git a/guestfish/debian11/scripts/81-configure-ssh.sh b/guestfish/debian11/scripts/81-configure-ssh.sh new file mode 100644 index 00000000..ca55c22b --- /dev/null +++ b/guestfish/debian11/scripts/81-configure-ssh.sh @@ -0,0 +1,30 @@ +#!/usr/bin/env bash + +# Configures critical settings for OpenSSH server. + +exec 1>&2 +set -o errexit -o nounset -o pipefail +set -x + +gawk -i inplace -f- /etc/ssh/sshd_config <<'EOF' +BEGIN { update = "PasswordAuthentication no" } +/^[#\s]*PasswordAuthentication\s*/ { $0 = update; found = 1 } +{ print } +END { if (!found) print update >> FILENAME } +EOF + +gawk -i inplace -f- /etc/ssh/sshd_config <<'EOF' +BEGIN { update = "PermitRootLogin without-password" } +/^[#\s]*PermitRootLogin\s*/ { $0 = update; found = 1 } +{ print } +END { if (!found) print update >> FILENAME } +EOF + +gawk -i inplace -f- /etc/ssh/sshd_config <<'EOF' +BEGIN { update = "UseDNS no" } +/^[#\s]*UseDNS\s*/ { $0 = update; found = 1 } +{ print } +END { if (!found) print update >> FILENAME } +EOF + +sync diff --git a/guestfish/debian11/scripts/98-collect-garbage.sh b/guestfish/debian11/scripts/98-collect-garbage.sh new file mode 100644 index 00000000..2cd3ffe9 --- /dev/null +++ b/guestfish/debian11/scripts/98-collect-garbage.sh @@ -0,0 +1,27 @@ +#!/usr/bin/env bash + +# Cleans APT caches, removes temporary files / logs, +# removes leftover / temporary unneeded packages. + +exec 1>&2 +set -o errexit -o nounset -o pipefail +set -x + +export DEBIAN_FRONTEND=noninteractive + +apt-get purge -y cloud-init fwupd snapd + +apt-get autoremove -y + +apt-get clean -y && rm -rf /var/lib/apt/lists/* + +rm -f /etc/hostname +rm -f /etc/network/cloud-ifupdown-helper +rm -f /etc/network/cloud-interfaces-template +rm -f /etc/network/if-post-down.d/cloud_inet6 +rm -f /etc/network/if-pre-up.d/cloud_inet6 +rm -f /etc/udev/rules.d/75-cloud-ifupdown.rules + +rm -rf /context/ + +sync diff --git a/guestfish/debian12 b/guestfish/debian12 new file mode 120000 index 00000000..03bf5ea0 --- /dev/null +++ b/guestfish/debian12 @@ -0,0 +1 @@ +debian11 \ No newline at end of file diff --git a/guestfish/run.sh b/guestfish/run.sh new file mode 100755 index 00000000..17598901 --- /dev/null +++ b/guestfish/run.sh @@ -0,0 +1,35 @@ +#!/bin/bash + +DISTRO=$1 +DST_IMG=$2 +SRC_IMG=${DIR_INSTALL}/$DISTRO.qcow2 +DIR_CURR=$(dirname "$0") + +if [ -d "${DIR_CURR}/$DISTRO/scripts" ]; then + # distro specific scripts + SCRIPTS="$(echo ${DIR_CURR}/$DISTRO/scripts/*.sh)" +else + # scripts_defaults + SCRIPTS="$(echo ${DIR_CURR}/scripts_defaults/*.sh)" +fi + +RUN_SCRIPTS_CMD="" +for S in $SCRIPTS; do + RUN_SCRIPTS_CMD+=" : command /guestfish/$(basename $S) " +done + +GUESTFISH_CMD="guestfish --add ${SRC_IMG} \ + --inspector --network echo $DST_IMG \ + : rm-rf /context/ \ + : mkdir-p /context/ \ + : copy-in ./context-linux/out/. /context/ \ + : rm-rf /guestfish/ \ + : mkdir-p /guestfish/ \ + : copy-in $SCRIPTS /guestfish/ \ + : glob chmod 0755 /guestfish/* \ +$RUN_SCRIPTS_CMD \ + : rm-rf /guestfish/" + +eval "$GUESTFISH_CMD" + +qemu-img convert -c -O qcow2 ${SRC_IMG} ${DST_IMG} diff --git a/guestfish/scripts_defaults/10-test.sh b/guestfish/scripts_defaults/10-test.sh new file mode 100644 index 00000000..2310d887 --- /dev/null +++ b/guestfish/scripts_defaults/10-test.sh @@ -0,0 +1,2 @@ +#!/bin/bash +echo 1 diff --git a/packer/alpine316/alpine.json b/packer/alpine316/alpine.json new file mode 100644 index 00000000..9e2e169f --- /dev/null +++ b/packer/alpine316/alpine.json @@ -0,0 +1,45 @@ +{ + "variables": { + "appliance_name": "alpine", + "product_arch": "amd64", + "serial": "stdio", + "shutdown_command": "poweroff" + }, + "builders": [ + { + "type": "qemu", + "name": "qemu", + "accelerator": "kvm", + "headless": false, + "disk_size": 256, + "output_directory": "{{ user `output_dir` }}", + "format": "qcow2", + "iso_url": "{{ user `alpine_base_image` }}", + "iso_checksum": "none", + "ssh_username": "root", + "ssh_password": "B3lWXnhu1Q5Get61tcct", + "ssh_port": 22, + "ssh_wait_timeout": "300s", + "shutdown_command": "{{user `shutdown_command`}}", + "http_directory": "{{user `http_dir`}}", + "net_device": "virtio-net", + "disk_interface": "virtio", + "vm_name": "{{ user `appliance_name` }}", + "boot_wait": "10s", + "boot_command": [ + "root", + "ifconfig eth0 up && udhcpc -i eth0", + + "wget -qO alpine.sh http://{{.HTTPIP}}:{{.HTTPPort}}/alpine.sh", + + "/bin/ash alpine.sh" + ], + "qemu_binary": "{{ user `qemu_binary`}}", + "qemuargs": [ + [ "-m", "1G" ], + [ "-serial", "{{ user `serial` }}" ], + ["-cpu", "host"] + ] + } + ] +} diff --git a/packer/alpine316/alpine.sh b/packer/alpine316/alpine.sh new file mode 100644 index 00000000..1e2b19be --- /dev/null +++ b/packer/alpine316/alpine.sh @@ -0,0 +1,57 @@ +#!/bin/ash + +# set root password +passwd root <<'EOF' +B3lWXnhu1Q5Get61tcct +B3lWXnhu1Q5Get61tcct +EOF + +cat > answers.txt < /dev/vda + +sed -i '/cdrom\|usbdisk/d' /mnt/etc/fstab + +# enable haveged to prevent slow boot due missing to entropy +chroot /mnt apk --no-cache add haveged +chroot /mnt rc-update add haveged default + +# enable root+password login temporarily (will be disabled in post-processing) +echo 'PermitRootLogin yes' >> /mnt/etc/ssh/sshd_config + +reboot diff --git a/packer/alpine316/run.sh b/packer/alpine316/run.sh new file mode 100755 index 00000000..b4391182 --- /dev/null +++ b/packer/alpine316/run.sh @@ -0,0 +1,19 @@ +#!/bin/bash +echo "running packer" + +DISTRO=$1 +DST=$2 +DIR_CURR=$(dirname $0) +DIR_OUT=$DIR_INSTALL +BASE_IMAGE=$DIR_BASE/$DISTRO.img + +packer build -force \ + -var "alpine_base_image=${BASE_IMAGE}" \ + -var "qemu_binary=${QEMU_BINARY}" \ + -var "appliance_name=${DISTRO}" \ + -var "distro=${DISTRO}" \ + -var "http_dir=${DIR_CURR}" \ + -var "output_dir=${DIR_PACKER}" \ + $DIR_CURR/alpine.json + +mv $DIR_PACKER/$DISTRO $DST diff --git a/packer/alpine317 b/packer/alpine317 new file mode 120000 index 00000000..d8d6204b --- /dev/null +++ b/packer/alpine317 @@ -0,0 +1 @@ +alpine316 \ No newline at end of file diff --git a/packer/skip.sh b/packer/skip.sh new file mode 100755 index 00000000..35ac5039 --- /dev/null +++ b/packer/skip.sh @@ -0,0 +1,3 @@ +#!/bin/bash +echo "[INFO] Empty installer stage, creating symlink $DIR_INSTALL/$1.qcow2 -> $DIR_BASE/$1" +( cd $DIR_INSTALL; ln -f -s ../../$DIR_BASE/$1.img $1.qcow2 )