2017-02-14 16:23:23 +00:00
|
|
|
#!/usr/bin/env zsh
|
2020-11-13 09:04:52 +00:00
|
|
|
# shellcheck shell=bash
|
2020-12-23 08:10:47 +00:00
|
|
|
# Copyright (c) 2016-2021 Ivan J. <parazyd@dyne.org>
|
2017-02-14 16:23:23 +00:00
|
|
|
# This file is part of libdevuansdk
|
|
|
|
#
|
|
|
|
# This source code is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This software is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this source code. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
vars+=(vmname)
|
|
|
|
|
2020-11-13 09:04:52 +00:00
|
|
|
vm_inject_overrides()
|
|
|
|
{
|
2017-02-14 16:23:23 +00:00
|
|
|
fn vm_inject_overrides
|
2021-01-13 17:59:16 +00:00
|
|
|
req=(strapdir bootfs rootfs bootpart rootpart)
|
2017-02-14 16:23:23 +00:00
|
|
|
ckreq || return 1
|
|
|
|
|
2020-11-13 09:04:52 +00:00
|
|
|
notice "Injecting rootfs overrides"
|
|
|
|
|
2021-01-13 17:59:16 +00:00
|
|
|
bootuuid="$(lsblk "$bootpart" -no UUID)"
|
|
|
|
rootuuid="$(lsblk "$rootpart" -no UUID)"
|
|
|
|
|
2020-11-13 10:26:10 +00:00
|
|
|
cat <<EOF | sudo tee -a "$strapdir/etc/fstab" >/dev/null
|
2021-01-13 17:59:16 +00:00
|
|
|
UUID=${rootuuid} / ${rootfs} defaults 0 1
|
|
|
|
UUID=${bootuuid} /boot ${bootfs} defaults 0 1
|
2020-11-13 10:26:10 +00:00
|
|
|
EOF
|
|
|
|
|
2020-11-13 09:04:52 +00:00
|
|
|
cat <<EOF | sudo tee "$strapdir/etc/rc.local" >/dev/null
|
2017-02-14 16:23:23 +00:00
|
|
|
#!/bin/sh
|
|
|
|
# rc.local for base images
|
|
|
|
|
2018-03-13 11:36:17 +00:00
|
|
|
[ -f /etc/ssh/ssh_host_rsa_key.pub ] || ssh-keygen -A
|
2017-02-14 16:23:23 +00:00
|
|
|
|
|
|
|
exit 0
|
|
|
|
EOF
|
2020-11-13 09:04:52 +00:00
|
|
|
sudo chmod +x "$strapdir/etc/rc.local"
|
2017-02-14 16:23:23 +00:00
|
|
|
|
2020-11-13 09:04:52 +00:00
|
|
|
sudo sed -i "$strapdir/etc/ssh/sshd_config" \
|
2018-03-13 11:36:17 +00:00
|
|
|
-e 's/#PermitRootLogin .*/PermitRootLogin yes/' \
|
2020-11-13 09:04:52 +00:00
|
|
|
-e 's/PermitRootLogin .*/PermitRootLogin yes/' || { zerr; return 1; }
|
2017-02-14 16:23:23 +00:00
|
|
|
}
|
|
|
|
|
2020-11-13 09:04:52 +00:00
|
|
|
vm_setup_grub()
|
|
|
|
{
|
2017-02-14 16:23:23 +00:00
|
|
|
fn vm_setup_grub
|
2020-11-13 09:04:52 +00:00
|
|
|
req=(workdir loopdevice bootfs)
|
2017-02-14 16:23:23 +00:00
|
|
|
ckreq || return 1
|
|
|
|
|
2020-11-13 09:04:52 +00:00
|
|
|
notice "Setting up grub"
|
|
|
|
|
|
|
|
cat <<EOF | sudo tee "$workdir/mnt/setupgrub" >/dev/null
|
2017-02-14 16:23:23 +00:00
|
|
|
#!/bin/sh
|
2020-11-13 09:04:52 +00:00
|
|
|
grub-install "${loopdevice}" || exit 1
|
|
|
|
grub-mkconfig -o /boot/grub/grub.cfg || exit 1
|
2017-02-14 16:23:23 +00:00
|
|
|
EOF
|
2020-11-13 09:04:52 +00:00
|
|
|
chroot-script -d "$workdir/mnt/setupgrub" || { zerr; return 1; }
|
2017-02-14 16:23:23 +00:00
|
|
|
}
|
|
|
|
|
2020-11-13 09:04:52 +00:00
|
|
|
vm_pack_dist()
|
2017-02-14 16:23:23 +00:00
|
|
|
{
|
2020-11-13 09:04:52 +00:00
|
|
|
fn vm_pack_dist
|
|
|
|
req=(R workdir image_name imageformat)
|
2018-10-08 10:36:15 +00:00
|
|
|
ckreq || return 1
|
|
|
|
|
2020-11-13 09:04:52 +00:00
|
|
|
notice "Packing up built images"
|
2018-10-08 10:36:15 +00:00
|
|
|
|
2020-11-13 09:04:52 +00:00
|
|
|
local _xzcomp=""
|
|
|
|
local _rsuffix="${imageformat}"
|
|
|
|
local _vsuffix="vdi"
|
2018-10-08 10:36:15 +00:00
|
|
|
|
2020-11-13 09:04:52 +00:00
|
|
|
if [[ -n "$COMPRESS_IMAGE" ]]; then
|
|
|
|
if command -v pixz >/dev/null; then
|
|
|
|
_xzcomp="$(command -v pixz)"
|
|
|
|
else
|
|
|
|
_xzcomp="$(command -v xz)"
|
|
|
|
fi
|
|
|
|
_rsuffix="${imageformat}.xz"
|
|
|
|
_vsuffix="vdi.xz"
|
|
|
|
fi
|
2018-10-08 10:36:15 +00:00
|
|
|
|
2020-11-13 09:04:52 +00:00
|
|
|
pushd "$workdir" || { zerr; return 1; }
|
2018-10-08 10:36:15 +00:00
|
|
|
|
2020-11-13 09:04:52 +00:00
|
|
|
if [[ -n "$COMPRESS_IMAGE" ]]; then
|
|
|
|
act "Compressing images with $_xzcomp"
|
|
|
|
silly
|
|
|
|
$_xzcomp "${image_name}.${imageformat}" || { zerr; return 1; }
|
|
|
|
$_xzcomp "${image_name}.vdi" || { zerr; return 1; }
|
|
|
|
fi
|
2018-10-08 10:36:15 +00:00
|
|
|
|
2020-11-13 10:21:31 +00:00
|
|
|
if [[ "$imageformat" != raw ]]; then
|
|
|
|
rm -f "${image_name}.img"
|
|
|
|
fi
|
|
|
|
|
2020-11-13 09:04:52 +00:00
|
|
|
act "Calculating sha256 checksums"
|
|
|
|
silly
|
|
|
|
sha256sum "${image_name}.${_rsuffix}" > "${image_name}.${_rsuffix}.sha256"
|
|
|
|
sha256sum "${image_name}.${_vsuffix}" > "${image_name}.${_vsuffix}.sha256"
|
2017-02-14 16:23:23 +00:00
|
|
|
|
2020-11-13 09:04:52 +00:00
|
|
|
mkdir -p "$R/dist"
|
|
|
|
mv -v "${image_name}".* "$R/dist" || { zerr; return 1; }
|
2017-03-18 20:30:58 +00:00
|
|
|
|
2020-11-13 09:04:52 +00:00
|
|
|
notice "Done! Thanks for being patient!"
|
2018-10-08 10:36:15 +00:00
|
|
|
|
2017-02-15 14:42:57 +00:00
|
|
|
popd
|
2017-02-14 16:23:23 +00:00
|
|
|
}
|