libdevuansdk

common library for devuan's simple distro kits
git clone https://git.parazyd.org/libdevuansdk
Log | Files | Refs | Submodules | README | LICENSE

commit fd2f5ec4ecba4e7753b3943e4d9cc6100584a992
parent 0fe5c9f3a3ae58115005273fe61c5e31eca41ed6
Author: parazyd <parazyd@dyne.org>
Date:   Sat, 15 Apr 2017 17:36:40 +0200

Merge branch 'next'

Diffstat:
Mconfig | 13+++++++++----
Mlibdevuansdk | 2+-
Mzlibs/bootstrap | 40+++++++++++++++++++++++++++-------------
Mzlibs/helpers | 97++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---------
Mzlibs/imaging | 40++++++++++++++++++++++++++++------------
Mzlibs/iso | 16+++++++++-------
Mzlibs/kernel | 44+++++++++++---------------------------------
Mzlibs/rsync | 15++++++---------
Mzlibs/sysconf | 2+-
Mzlibs/vm | 47+++++++++++++++++++++++++++++------------------
10 files changed, 207 insertions(+), 109 deletions(-)

diff --git a/config b/config @@ -20,22 +20,27 @@ ## libdevuansdk configuration vars+=(release version mirror section blend_name image_name vm_name) +vars+=(arch earch) +vars+=(usercredentials rootcredentials) + arrs+=(core_packages base_packages purge_packages blend_packages) + os="devuan" release="jessie" -version="1.0.0-beta2" +version="1.0.0-RC" mirror="http://auto.mirror.devuan.org/merged" section="main" image_name="${os}_${release}_${version}_${arch}" -[[ -n $blend_name ]] && image_name="${image_name}_${blend_name}" -[[ -n $device_name ]] && image_name="${image_name}_${device_name}" +[[ -n "$blend_name" ]] && image_name="${image_name}_${blend_name}" +[[ -n "$device_name" ]] && image_name="${image_name}_${device_name}" vm_name="${os}_${release}_${version}_${arch}_vagrant" [[ -n $blend_name ]] && vm_name="${image_name}_${blend_name}" rootcredentials="root:toor" +usercredentials="devuan:devuan" core_packages=( devuan-keyring @@ -71,7 +76,7 @@ base_packages=( zsh rsync git-core - haveged + mlocate ) purge_packages+=( diff --git a/libdevuansdk b/libdevuansdk @@ -17,7 +17,7 @@ # 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/>. -libdevuansdk_version="0.4" +libdevuansdk_version="0.5" LIBPATH=${LIBPATH:-$(dirname $0)} source $LIBPATH/config diff --git a/zlibs/bootstrap b/zlibs/bootstrap @@ -45,6 +45,9 @@ bootstrap_complete_base() { [[ $arch =~ "^arm.." ]] && { qemu_install_user || zerr } + sudo mkdir -p $strapdir/tmp + sudo chmod 1777 $strapdir/tmp + ## debootstrap stage 2 notice "running debootstrap stage 2" sudo -E chroot $strapdir \ @@ -52,13 +55,13 @@ bootstrap_complete_base() { ## write all system configuration notice "writing system configuration" - conf_print_debconf | sudo tee $strapdir/debconf.set >/dev/null - conf_print_fstab | sudo tee $strapdir/etc/fstab >/dev/null - conf_print_hostname | sudo tee $strapdir/etc/hostname >/dev/null - conf_print_hosts | sudo tee $strapdir/etc/hosts >/dev/null - conf_print_netifaces | sudo tee $strapdir/etc/network/interfaces >/dev/null - conf_print_resolvconf | sudo tee $strapdir/etc/resolv.conf >/dev/null - conf_print_sourceslist | sudo tee $strapdir/etc/apt/sources.list >/dev/null + conf_print_debconf | sudo tee $strapdir/debconf.set >/dev/null + conf_print_fstab | sudo tee $strapdir/etc/fstab >/dev/null + conf_print_hostname | sudo tee $strapdir/etc/hostname >/dev/null + conf_print_hosts | sudo tee $strapdir/etc/hosts >/dev/null + conf_print_netifaces | sudo tee $strapdir/etc/network/interfaces >/dev/null + conf_print_resolvconf | sudo tee $strapdir/etc/resolv.conf >/dev/null + conf_print_sourceslist | sudo tee $strapdir/etc/apt/sources.list >/dev/null conf_print_locales | sudo tee $strapdir/etc/profile.d/locales.sh >/dev/null ## write third-stage for chroot @@ -68,12 +71,9 @@ bootstrap_complete_base() { ## debootstrap stage 3 notice "running debootstrap stage 3" - devprocsys mount $strapdir || zerr chroot-script -d thirdstage || zerr - sleep 1 - devprocsys umount $strapdir || zerr bootstrap_tar_pack || zerr bootstrap_tar_unpack $strapdir || zerr @@ -151,18 +151,32 @@ bootstrap_tar_unpack() { cat <<EOF | sudo tee ${strapdir}/postunpack >/dev/null #!/bin/sh apt-get update + +## check if all our extra_packages exist +allpkgs="\$(apt-cache search '.' | cut -d' ' -f1)" +for i in ${extra_packages} ; do + printf "%s" "\$allpkgs" | grep -q "^\$i$" || missing="\$missing \$i" +done + +[ -n "\$missing" ] && { + printf "\033[1;31m[!!] some extra packages don't exist\033[0m\n" + printf "%s\n" "\$missing" + exit 1 +} + apt-get --yes --force-yes upgrade apt-get --yes --force-yes install ${extra_packages} apt-get --yes --force-yes autoremove apt-get clean EOF - devprocsys mount $strapdir chroot-script -d postunpack || zerr - devprocsys umount $strapdir ## below typically used in arm-sdk - [[ -n "$inittab" ]] && { print $inittab | sudo tee -a $strapdir/etc/inittab >/dev/null } + [[ -n "$inittab" ]] && { + print $inittab | sudo tee -a $strapdir/etc/inittab >/dev/null + } + for i in $custmodules; do print $i | sudo tee -a $strapdir/etc/modules >/dev/null done || return 0 diff --git a/zlibs/helpers b/zlibs/helpers @@ -33,8 +33,6 @@ build_image_dist() { notice "building complete dist image" act "$image_name" - ## TODO: add blend_prebuild; blend_midbuild; blend_postbuild - bootstrap_complete_base || zerr blend_preinst || zerr image_prepare_raw || zerr @@ -51,7 +49,6 @@ build_iso_dist() { ckreq || return 1 notice "building complete iso image" - ## XXX: TODO: upstream existing heads code bootstrap_complete_base || zerr blend_preinst || zerr @@ -86,7 +83,27 @@ build_vagrant_dist() { getfield() { fn getfield $* - print "$1" | grep "^$2=" | sed -e 's:.*=\(.*\)$:\1:g' | sed -e 's:^"\(.*\)"$:\1:g' + print "$1" | \ + grep "^$2=" | \ + sed -e 's:.*=\(.*\)$:\1:g' | \ + sed -e 's:^"\(.*\)"$:\1:g' +} + +add-user() { + fn add-user $* + local user="$1" + local pass="$2" + req=(strapdir user pass) + ckreq || return 1 + + notice "adding user $user:$pass" + + cat <<EOF | sudo tee ${strapdir}/adduser +#!/bin/sh +useradd -m ${user} +echo "${user}:${pass}" | chpasswd +EOF + chroot-script adduser || zerr } devprocsys() { @@ -120,11 +137,13 @@ findloopmapp() { notice "finding a free loopdevice" loopdevice=$(sudo losetup -f --show $workdir/${image_name}.img) - mappdevice=$(sudo kpartx -va $loopdevice | sed -E 's/.*(loop[0-9])p.*/\1/g' | sed 1q) + mappdevice=$(sudo kpartx -va $loopdevice | \ + sed -E 's/.*(loop[0-9])p.*/\1/g' | sed 1q) + func "loopdevice: $loopdevice" func "mappdevice: $mappdevice" - silly sleep 4 + silly sleep 2 } findfreenbd() { @@ -210,7 +229,7 @@ EOF install-custdebs() { fn install-custdebs - req=(R strapdir) + req=(R strapdir custom_deb_packages) ckreq || return 1 sudo mkdir -p $strapdir/debs @@ -218,10 +237,12 @@ install-custdebs() { cat <<EOF | sudo tee ${strapdir}/install-debs >/dev/null #!/bin/sh -for deb in /debs/*.deb; do +cd /debs +for deb in ${custom_deb_packages}; do dpkg -i \$deb apt-get --yes --force-yes -f install done +cd / apt-get autoremove apt-get clean rm -rf /debs @@ -231,27 +252,81 @@ EOF chroot-script() { fn chroot-script "$@" + req=(strapdir) + ckreq || return 1 + mkdir -p "$R/log" case "x$1" in x-d) local script="$2" - dpkgdivert on "$strapdir" + devprocsys mount "$strapdir" || zerr + dpkgdivert on "$strapdir" || zerr + + ## logging + sudo sed -i "$strapdir/$script" \ + -e 's@#!/bin/sh@#!/bin/sh\'$'\nset -x ; exec 2>/'$script'.log@' notice "chrooting to execute $script..." - sudo chmod +x "$strapdir/$script" || zerr + sudo chmod +x "$strapdir/$script" || zerr sudo -E chroot "$strapdir" "/$script" || zerr - dpkgdivert off "$strapdir" + sudo mv -f "$strapdir/${script}.log" "$R/log/" + + dpkgdivert off "$strapdir" || zerr + devprocsys umount "$strapdir" || zerr ;; *) local script="$1" + + ## logging + sudo sed -i "$strapdir/$script" \ + -e 's@#!/bin/sh@#!/bin/sh\'$'\nset -x ; exec 2>/'$script'.log@' + notice "chrooting to execute $script..." sudo chmod +x "$strapdir/$script" || zerr sudo -E chroot "$strapdir" "/$script" || zerr + sudo mv -f "$strapdir/${script}.log" "$R/log/" ;; esac sudo rm -f $strapdir/$script } +install_fake_package() { + fn install_fake_package "$@" + req=(strapdir pkgname pkgver section) + local pkgname="$1" + local pkgver="$2" + local section="$3" + ckreq || return 1 + + local _tmp="$strapdir/tmp" + sudo mkdir -p "$_tmp/$pkgname" + + cat <<EOF | sudo tee ${_tmp}/${pkgname}/${pkgname}_${pkgver}.control >/dev/null +Section: ${section} +Priority: optional +Homepage: https://devuan.org/ +Standards-Version: 3.9.6 + +Package: ${pkgname} +Version: ${pkgver} +Maintainer: Devuan developers <onelove@devuan.org> +Architecture: all +Description: (Fake) ${pkgname} + Dummy package used to meet some dependencies without installing the + real ${pkgname} package. +EOF + + cat <<EOF | sudo tee ${strapdir}/install-fake-package >/dev/null +#!/bin/sh +cd /tmp/${pkgname} +equivs-build ${pkgname}_${pkgver}.control \ + && dpkg -i ${pkgname}_${pkgver}_all.deb || exit 1 +cd /tmp +rm -rf ${pkgname} +EOF + chroot-script install-fake-package || zerr +} + blend_preinst() { fn blend_preinst func "not overriden" diff --git a/zlibs/imaging b/zlibs/imaging @@ -73,7 +73,8 @@ image_partition_raw_gpt() { -l kernel -S 1 -T 5 -P 10 $workdir/${image_name}.img cgpt add -i 2 -t data -b ${gpt_root[1]} \ - -s $(expr $(cgpt show $workdir/${image_name}.img | awk '/Sec GPT table/ {print $1}') - ${gpt_root[1]}) \ + -s $(expr $(cgpt show $workdir/${image_name}.img | \ + awk '/Sec GPT table/ {print $1}') - ${gpt_root[1]}) \ -l Root $workdir/${image_name}.img findloopmapp @@ -104,13 +105,21 @@ image_pack_dist() { sleep 1 } - sudo kpartx -dv $loopdevice || { die "kpartx failed to remove $loopdevice"; zerr } - sudo losetup -d $loopdevice || { die "losetup failed to remove $loopdevice"; zerr } + sudo kpartx -dv $loopdevice || { + die "kpartx failed to remove $loopdevice" + zerr + } + sudo losetup -d $loopdevice || { + die "losetup failed to remove $loopdevice" + zerr + } - notice "compressing image with xz" + _xz="xz -zv" + [[ $(command -v pixz) ]] && _xz=pixz + notice "compressing image with $_xz" silly pushd $workdir - xz -zv ${image_name}.img + ${=_xz} ${image_name}.img notice "generating sha256 for ${image_name}.img.xz" sha256sum ${image_name}.img.xz > ${image_name}.img.xz.sha @@ -133,9 +142,14 @@ image_raw_mount() { ckreq || return 1 mkdir -p $workdir/mnt - sudo mount $rootpart $workdir/mnt && act "mounted root partition" || zerr - sudo mkdir $workdir/mnt/boot - sudo mount $bootpart $workdir/mnt/boot && act "mounted boot partition" || zerr + sudo mount $rootpart $workdir/mnt && \ + act "mounted root partition" || zerr + + [[ "$parted_type" == gpt ]] || { + sudo mkdir $workdir/mnt/boot + sudo mount $bootpart $workdir/mnt/boot && \ + act "mounted boot partition" || zerr + } } image_raw_umount() { @@ -143,8 +157,10 @@ image_raw_umount() { req=(workdir bootpart rootpart) ckreq || return 1 - sudo umount $workdir/mnt/boot && act "unmounted boot partition" || zerr - sleep 1 + [[ "$parted_type" == gpt ]] || { + sudo umount $workdir/mnt/boot && act "unmounted boot partition" || zerr + sleep 1 + } sudo umount $workdir/mnt && act "unmounted root partition" || zerr } @@ -167,7 +183,7 @@ image_raw_as_strapdir() { notice "mounting raw image to strapdir" sudo mount ${loopdevice}p1 $strapdir - echo 1 | sudo tee ${strapdir}/.keep >/dev/null ## hack? XXX: bootstrap_tar_unpack couldn't see it + echo 1 | sudo tee ${strapdir}/.keep >/dev/null popd } @@ -193,6 +209,6 @@ image_qcow2_as_strapdir() { notice "mounting qcow2 image to strapdir" sudo mount ${loopdevice}p1 $strapdir || zerr - echo 1 | sudo tee ${strapdir}/.keep >/dev/null ## hack? XXX: bootstrap_tar_unpack couldn't see it + echo 1 | sudo tee ${strapdir}/.keep >/dev/null popd } diff --git a/zlibs/iso b/zlibs/iso @@ -31,12 +31,12 @@ iso_prepare_strap() { cat <<EOF | sudo tee ${strapdir}/isoprep >/dev/null #!/bin/sh apt-get update -apt-get --yes --force-yes install dialog live-boot +apt-get --yes --force-yes install dialog live-boot live-boot-initramfs-tools apt-get --yes --force-yes autoremove apt-get clean EOF - chroot-script -d isoprep || zerr + chroot-script -d isoprep || zerr } iso_setup_isolinux() { @@ -53,9 +53,9 @@ iso_setup_isolinux() { sudo cp $strapdir/boot/initrd* binary/live/initrd sudo cp /usr/share/live/build/bootloaders/isolinux/isolinux.bin \ - binary/isolinux + binary/isolinux || zerr sudo cp /usr/share/live/build/bootloaders/isolinux/*.c32 \ - binary/isolinux + binary/isolinux || zerr popd } @@ -72,7 +72,7 @@ menu title ${os} boot menu timeout 300 label live-${arch} -menu label ^${os} Live (${arch}) +menu label ^${os} live (${arch}) menu default linux /live/vmlinuz append initrd=/live/initrd boot=live @@ -89,7 +89,8 @@ iso_squash_strap() { notice "creating squashfs out of strapdir" pushd $workdir - sudo mksquashfs $strapdir binary/live/filesystem.squashfs -comp xz -e boot + sudo mksquashfs $strapdir binary/live/filesystem.squashfs \ + -noappend -comp xz || zerr popd } @@ -101,6 +102,7 @@ iso_xorriso_build() { notice "building iso..." isoname="${image_name}-live.iso" + mkdir -p $R/dist pushd $workdir sudo xorriso -as mkisofs -r -J -joliet-long -l \ -isohybrid-mbr /usr/lib/ISOLINUX/isohdpfx.bin \ @@ -112,7 +114,7 @@ iso_xorriso_build() { -boot-load-size 4 \ -boot-info-table \ -o $R/dist/$isoname \ - binary + binary || zerr popd } diff --git a/zlibs/kernel b/zlibs/kernel @@ -19,44 +19,22 @@ ## all windows users are suckers -build_kernel_amd64() { - fn build_kernel_amd64 +build_kernel_${arch}() { + fn build_kernel_${arch} req=(strapdir arch) - #freq=($strapdir/.keep) ckreq || return 1 local kernel_base="linux-image" - local kernel="${kernel_base}-amd64" + case "$arch" in + amd64) local kernel="${kernel_base}-amd64";; + i386) local kernel="${kernel_base}-586";; + esac notice "installing stock kernel for $arch" - dpkgdivert on $strapdir - devprocsys mount $strapdir - - sudo -E chroot $strapdir \ - apt-get --yes --force-yes install $kernel - - devprocsys umount $strapdir - dpkgdivert off $strapdir -} - -build_kernel_i386() { - fn build_kernel_i386 - req=(strapdir arch) - #freq=($strapdir/.keep) - ckreq || return 1 - - local kernel_base="linux-image" - local kernel="${kernel_base}-586" - - notice "installing stock kernel for $arch" - - dpkgdivert on $strapdir - devprocsys mount $strapdir - - sudo -E chroot $strapdir \ - apt-get --yes --force-yes install $kernel - - devprocsys umount $strapdir - dpkgdivert off $strapdir + cat <<EOF | sudo tee ${strapdir}/install-linux +#!/bin/sh +apt-get --yes --force-yes install ${kernel} +EOF + chroot-script -d install-linux || zerr } diff --git a/zlibs/rsync b/zlibs/rsync @@ -26,17 +26,14 @@ rsync_to_raw_image() { notice "rsyncing strapdir to raw image..." image_raw_mount - sleep 1 + silly sleep 1 - silly pushd $strapdir - #sudo rm -f .done - - sudo rsync -HPavz -q ./* $workdir/mnt || { - image_raw_umount - die "not enough space, please report a bug" - zerr - } + sudo rsync -HPavz -q ./* $workdir/mnt || { + image_raw_umount + die "not enough space, please report a bug" + zerr + } popd image_raw_umount diff --git a/zlibs/sysconf b/zlibs/sysconf @@ -76,7 +76,7 @@ conf_print_netifaces() { # For static IP, consult /etc/dhcpcd.conf and 'man dhcpcd.conf' # Include files from /etc/network/interfaces.d: -source-directory /etc/network/interfaces.d +# source-directory /etc/network/interfaces.d auto lo iface lo inet loopback diff --git a/zlibs/vm b/zlibs/vm @@ -27,7 +27,7 @@ vm_inject_overrides() { ckreq || return 1 notice "injecting rootfs overrides" - cat <<EOF | sudo -E tee ${strapdir}/etc/rc.local >/dev/null + cat <<EOF | sudo tee ${strapdir}/etc/rc.local >/dev/null #!/bin/sh # rc.local for base images @@ -39,7 +39,8 @@ EOF print "rootfs / rootfs rw 0 0" | sudo tee ${strapdir}/etc/fstab >/dev/null - sudo sed -i -e 's/without-password/yes/' ${strapdir}/etc/ssh/sshd_config || zerr + sudo sed -i ${strapdir}/etc/ssh/sshd_config \ + -e 's/without-password/yes/' || zerr } vm_setup_grub() { @@ -54,13 +55,12 @@ export DEBIAN_FRONTEND=noninteractive apt-get --yes --force-yes install linux-image-amd64 grub-pc sed -e 's:GRUB_TIMEOUT=5:GRUB_TIMEOUT=1:' -i /etc/default/grub update-grub -grub-install --no-floppy --recheck --modules="biosdisk part_msdos" ${loopdevice} +grub-install --no-floppy --recheck --modules="biosdisk part_msdos" \ + ${loopdevice} sed -e 's:${loopdevice}p1:/dev/sda1:g' -i /boot/grub/grub.cfg sync; sync; sync EOF - devprocsys mount $strapdir || zerr chroot-script -d setupgrub || zerr - devprocsys umount $strapdir || zerr } vm_umount_${imageformat}() { @@ -70,10 +70,11 @@ vm_umount_${imageformat}() { notice "remounting ${imageformat} image" sudo mount -o remount,ro $strapdir || zerr - sync + notice "flushing bytes and buffers" sudo blockdev --flushbufs $loopdevice || zerr - sudo python -c 'import os; os.fsync(open("'${loopdevice}'", "r+b"))' || zerr + sudo python -c 'import os;os.fsync(open("'${loopdevice}'", "r+b"))' || zerr + notice "unmounting ${imageformat} image from strapdir" sudo umount $strapdir || zerr silly sleep 1 @@ -101,22 +102,27 @@ vm_vbox_setup() { notice "converting ${imageformat} image to vdi" pushd $workdir - qemu-img convert -f ${imageformat} -O vdi base.${imageformat} base.vdi || zerr - #sudo chown $USER base.vdi || zerr + qemu-img convert \ + -f ${imageformat} \ + -O vdi \ + base.${imageformat} \ + base.vdi || zerr VBoxManage modifyhd base.vdi --type immutable --compact || zerr - #act "removing old raw image" - #rm -f base.raw vmname="${os}-${release}-prevagrant" notice "importing base.vdi to a VBox" act "creating vm" VBoxManage createvm --name "$vmname" --ostype Debian_64 --register || zerr + act "setting up ram and group" VBoxManage modifyvm "$vmname" --memory 256 --groups /vmsdk || zerr + act "setting up storage" VBoxManage storagectl "$vmname" --name "IDE Controller" --add ide || zerr + act "attaching storage" - VBoxManage storageattach "$vmname" --storagectl "IDE Controller" --port 0 --device 0 --type hdd --medium base.vdi || zerr + VBoxManage storageattach "$vmname" --storagectl "IDE Controller" --port 0 \ + --device 0 --type hdd --medium base.vdi || zerr vminfo="$(VBoxManage showvminfo "$vmname" --machinereadable)" diskuuid="$(getfield "$vminfo" '"IDE Controller-ImageUUID-0-0"')" @@ -155,7 +161,8 @@ EOF } EOF notice "actually packaging..." - vagrant package --base "$vmname" --output ${vm_name}.box --include metadata.json --vagrantfile Vagrantfile || zerr + vagrant package --base "$vmname" --output ${vm_name}.box \ + --include metadata.json --vagrantfile Vagrantfile || zerr popd } @@ -168,15 +175,19 @@ vm_pack_dist() { mkdir -p $R/dist mv $workdir/${vm_name}.box $R/dist mv $workdir/base.${imageformat} $R/dist/${vm_name}.${imageformat} + act "calculating sha256 sums..." silly - sha256sum $R/dist/${vm_name}.box > $R/dist/${vm_name}.box.sha - sha256sum $R/dist/${vm_name}.${imageformat} > $R/dist/${vm_name}.${imageformat}.sha + sha256sum $R/dist/${vm_name}.box > \ + $R/dist/${vm_name}.box.sha + sha256sum $R/dist/${vm_name}.${imageformat} > \ + $R/dist/${vm_name}.${imageformat}.sha + notice "cleaning up virtualbox leftovers" pushd "$workdir" - VBoxManage unregistervm "$vmname" --delete - rm -f metadata.json Vagrantfile - rm -rf .vagrant + VBoxManage unregistervm "$vmname" --delete + rm -f metadata.json Vagrantfile + rm -rf .vagrant popd rm -rf "$workdir" rm -rf "$HOME/VirtualBox VMs/vmsdk"