libdevuansdk

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

commit 0fe5c9f3a3ae58115005273fe61c5e31eca41ed6
parent 9a22ddaad19c06a2ed824c2d8f7c2f763ab40499
Author: parazyd <parazyd@dyne.org>
Date:   Wed, 22 Feb 2017 14:21:39 +0100

Merge branch 'next'

Diffstat:
MREADME.md | 2+-
Mconfig | 20+++++++++++++-------
Mlibdevuansdk | 9++++++---
Mzlibs/bootstrap | 76+++++++++++++++++++++++++++-------------------------------------------------
Mzlibs/helpers | 164+++++++++++++++++++++++++++++++++++++------------------------------------------
Mzlibs/imaging | 69++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-----------
Mzlibs/iso | 21++++++++++-----------
Mzlibs/kernel | 6+++---
Mzlibs/rsync | 18++++++------------
Mzlibs/sysconf | 20+++++++++++++++++---
Azlibs/vm | 186+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
11 files changed, 404 insertions(+), 187 deletions(-)

diff --git a/README.md b/README.md @@ -37,7 +37,7 @@ Devuan's SDK was originally conceived during a period of residency at the Schumacher college in Dartington, UK. Greatly inspired by the laborious and mindful atmosphere of its wonderful premises. -The Devuan SDK is Copyright (c) 2015-2016 by the Dyne.org Foundation +The Devuan SDK is Copyright (c) 2015-2017 by the Dyne.org Foundation Devuan SDK components are designed, written and maintained by: diff --git a/config b/config @@ -1,5 +1,5 @@ #!/usr/bin/env zsh -# Copyright (c) 2016 Dyne.org Foundation +# Copyright (c) 2016-2017 Dyne.org Foundation # libdevuansdk is maintained by Ivan J. <parazyd@dyne.org> # # This file is part of libdevuansdk @@ -19,7 +19,7 @@ ## libdevuansdk configuration -vars+=(release version mirror section blend_name) +vars+=(release version mirror section blend_name image_name vm_name) arrs+=(core_packages base_packages purge_packages blend_packages) os="devuan" @@ -32,6 +32,11 @@ image_name="${os}_${release}_${version}_${arch}" [[ -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" + core_packages=( devuan-keyring debian-keyring @@ -41,8 +46,8 @@ core_packages=( bzip2 curl less - vim-tiny - nano-tiny + vim + nano sysvinit ) @@ -54,8 +59,9 @@ base_packages=( sudo alsa-base alsa-utils - gawk + mawk tmux + screen openntpd wpasupplicant wireless-tools @@ -65,9 +71,9 @@ base_packages=( zsh rsync git-core + haveged ) -purge_packages=( +purge_packages+=( dbus - nano ) diff --git a/libdevuansdk b/libdevuansdk @@ -1,5 +1,5 @@ #!/usr/bin/env zsh -# Copyright (c) 2016 Dyne.org Foundation +# Copyright (c) 2016-2017 Dyne.org Foundation # libdevuansdk maintained by Ivan J. <parazyd@dyne.org> # # This file is part of libdevuansdk @@ -17,8 +17,8 @@ # 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.3" -LIBPATH=${LIBPATH:-`dirname $0`} +libdevuansdk_version="0.4" +LIBPATH=${LIBPATH:-$(dirname $0)} source $LIBPATH/config source $LIBPATH/zlibs/bootstrap @@ -28,8 +28,11 @@ source $LIBPATH/zlibs/iso source $LIBPATH/zlibs/kernel source $LIBPATH/zlibs/rsync source $LIBPATH/zlibs/sysconf +source $LIBPATH/zlibs/vm vars+=(libdevuansdk_version) vars+=(LIBPATH) +setopt pushdsilent + act "libdevuansdk v$libdevuansdk_version loaded" diff --git a/zlibs/bootstrap b/zlibs/bootstrap @@ -1,5 +1,5 @@ #!/usr/bin/env zsh -# Copyright (c) 2016 Dyne.org Foundation +# Copyright (c) 2016-2017 Dyne.org Foundation # libdevuansdk maintained by Ivan J. <parazyd@dyne.org> # # This file is part of libdevuansdk @@ -52,17 +52,17 @@ bootstrap_complete_base() { ## write all system configuration notice "writing system configuration" - conf_print_debconf | sudo tee $strapdir/debconf.set - conf_print_fstab | sudo tee $strapdir/etc/fstab - conf_print_hostname | sudo tee $strapdir/etc/hostname - conf_print_hosts | sudo tee $strapdir/etc/hosts - conf_print_networkifaces | sudo tee $strapdir/etc/network/interfaces - conf_print_resolvconf | sudo tee $strapdir/etc/resolv.conf - conf_print_sourceslist | sudo tee $strapdir/etc/apt/sources.list + 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 - bootstrap_config_thirdstage | sudo tee $strapdir/thirdstage - bootstrap_config_cleanup | sudo tee $strapdir/cleanup + bootstrap_config_thirdstage | sudo tee $strapdir/thirdstage >/dev/null ## chroot into it and configure further ## debootstrap stage 3 @@ -70,7 +70,7 @@ bootstrap_complete_base() { devprocsys mount $strapdir || zerr - chroot-script -d thirdstage cleanup || zerr + chroot-script -d thirdstage || zerr sleep 1 devprocsys umount $strapdir || zerr @@ -79,23 +79,6 @@ bootstrap_complete_base() { bootstrap_tar_unpack $strapdir || zerr } -bootstrap_config_cleanup() { - fn config_cleanup - - cat << EOF -#!/bin/sh -rm -f /debconf.set -rm -f /thirdstage -rm -f /etc/ssh/*_key -rm -f /etc/ssh/*.pub -rm -f /root/.bash_history -#rm -f /usr/bin/qemu-arm-static -## our file for which we check the bootstrap is complete -echo "1" > .done -rm -f /cleanup -EOF -} - bootstrap_config_thirdstage() { fn bootstrap_config_thirdstage req=(core_packages base_packages) @@ -106,7 +89,7 @@ bootstrap_config_thirdstage() { apt-get update debconf-set-selections /debconf.set -echo "root:toor" | chpasswd +echo "${rootcredentials}" | chpasswd sed -i -e 's/KERNEL\!=\"eth\*|/KERNEL\!=\"/' \ /lib/udev/rules.d/75-persistent-net-generator.rules rm -f /etc/udev/rules.d/70-persistent-net.rules @@ -117,6 +100,11 @@ apt-get --yes --force-yes install ${base_packages} apt-get --yes --force-yes purge ${purge_packages} apt-get --yes --force-yes autoremove apt-get clean + +rm -f /debconf.set +rm -f /etc/ssh/ssh_host_* +rm -f /root/.bash_history +echo "1" > .keep EOF } @@ -125,19 +113,6 @@ bootstrap_tar_pack() { req=(bootstrap_tgz) ckreq || return 1 - #for i in $custmodules;do sudo sed -i -e '/'$i'/d' $strapdir/etc/modules;done - #[[ -n $inittab ]] && sudo sed -i -e '/'$inittab'/d' $strapdir/etc/inittab - - cat <<EOF | sudo tee ${strapdir}/prepack -#!/bin/sh -#apt-get --yes --force-yes purge ${extra_packages} -apt-get --yes --force-yes autoremove -apt-get clean -rm -f /prepack -EOF - - chroot-script prepack || zerr - local _dest=$(dirname $bootstrap_tgz) if [[ -f $bootstrap_tgz ]]; then @@ -162,21 +137,24 @@ bootstrap_tar_unpack() { req=(unpath bootstrap_tgz) ckreq || return 1 - [[ -f ${unpath}/.done ]] || { + if [[ -f "${unpath}/.keep" ]]; then mkdir -p ${unpath} silly sudo tar xfp $bootstrap_tgz -C ${unpath} sudo mkdir -p ${unpath}/{boot,dev,sys,proc} - } + else + error "no .keep file found. exiting..." + zerr + exit 1 + fi - cat <<EOF | sudo tee ${strapdir}/postunpack + cat <<EOF | sudo tee ${strapdir}/postunpack >/dev/null #!/bin/sh apt-get update apt-get --yes --force-yes upgrade apt-get --yes --force-yes install ${extra_packages} apt-get --yes --force-yes autoremove apt-get clean -rm -f /postunpack EOF devprocsys mount $strapdir @@ -184,8 +162,8 @@ EOF devprocsys umount $strapdir ## below typically used in arm-sdk - [[ -z $inittab ]] || { print $inittab | sudo tee -a $strapdir/etc/inittab } + [[ -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 - done + print $i | sudo tee -a $strapdir/etc/modules >/dev/null + done || return 0 } diff --git a/zlibs/helpers b/zlibs/helpers @@ -1,5 +1,5 @@ #!/usr/bin/env zsh -# Copyright (c) 2016 Dyne.org Foundation +# Copyright (c) 2016-2017 Dyne.org Foundation # libdevuansdk is maintained by Ivan J. <parazyd@dyne.org> # # This file is part of libdevuansdk @@ -36,11 +36,11 @@ build_image_dist() { ## TODO: add blend_prebuild; blend_midbuild; blend_postbuild bootstrap_complete_base || zerr - [[ $BLEND = 1 ]] && blend_preinst || zerr + blend_preinst || zerr image_prepare_raw || zerr image_partition_raw_${parted_type} || zerr build_kernel_${arch} || zerr - [[ $BLEND = 1 ]] && blend_postinst || zerr + blend_postinst || zerr rsync_to_raw_image || zerr image_pack_dist || zerr } @@ -51,19 +51,44 @@ build_iso_dist() { ckreq || return 1 notice "building complete iso image" + ## XXX: TODO: upstream existing heads code bootstrap_complete_base || zerr - [[ $BLEND = 1 ]] && blend_preinst || zerr + blend_preinst || zerr iso_prepare_strap || zerr build_kernel_${arch} || zerr iso_setup_isolinux || zerr iso_write_isolinux_cfg || zerr - [[ $INSTALLER = 1 ]] && iso_setup_installer - [[ $BLEND = 1 ]] && blend_postinst || zerr + #[[ $INSTALLER = 1 ]] && iso_setup_installer || zerr + blend_postinst || zerr iso_squash_strap || zerr iso_xorriso_build || zerr } +build_vagrant_dist() { + fn build_vagrant_dist + req=(workdir strapdir os arch imageformat) + ckreq || return 1 + + notice "building complete vagrant image" + + image_${imageformat}_as_strapdir || zerr + bootstrap_complete_base || zerr + vm_inject_overrides || zerr + blend_preinst || zerr + vm_setup_grub || zerr + blend_postinst || zerr + vm_umount_${imageformat} || zerr + vm_vbox_setup || zerr + vm_vagrant_package || zerr + vm_pack_dist || zerr +} + +getfield() { + fn getfield $* + print "$1" | grep "^$2=" | sed -e 's:.*=\(.*\)$:\1:g' | sed -e 's:^"\(.*\)"$:\1:g' +} + devprocsys() { fn devprocsys "$@" local watdo="$1" @@ -102,6 +127,19 @@ findloopmapp() { silly sleep 4 } +findfreenbd() { + fn findfreenbd + + notice "looking for a free /dev/nbd" + + for i in $(seq 0 8); do + grep "^/dev/nbd${i}" /proc/mounts >/dev/null || { + print "/dev/nbd${i}" + break + } + done +} + qemu_install_user() { fn qemu_install_user req=(qemu_bin strapdir) @@ -112,14 +150,14 @@ qemu_install_user() { } dpkgdivert() { - fn dpkgdivert $@ + fn dpkgdivert "$@" req=(watdo werdo) local watdo="$1" local werdo="$2" ckreq || return 1 if [[ $watdo = on ]]; then - cat <<EOF | sudo tee ${werdo}/dpkgdivert + cat <<EOF | sudo tee ${werdo}/dpkgdivert >/dev/null #!/bin/sh dpkg-divert --add --local \ --divert /usr/sbin/invoke-rc.d.chroot \ @@ -127,15 +165,13 @@ dpkg-divert --add --local \ cp /bin/true /usr/sbin/invoke-rc.d echo -e "#!/bin/sh\nexit 101" > /usr/sbin/policy-rc.d chmod +x /usr/sbin/policy-rc.d -rm -f /dpkgdivert EOF elif [[ $watdo = off ]]; then - cat <<EOF | sudo tee ${werdo}/dpkgdivert + cat <<EOF | sudo tee ${werdo}/dpkgdivert >/dev/null #!/bin/sh rm -f /usr/sbin/policy-rc.d rm -f /usr/sbin/invoke-rc.d dpkg-divert --remove --rename /usr/sbin/invoke-rc.d -rm -f /dpkgdivert EOF fi @@ -148,7 +184,7 @@ enableserv() { req=(service strapdir) ckreq || return 1 - cat <<EOF | sudo tee -a ${strapdir}/enserv + cat <<EOF | sudo tee -a ${strapdir}/enserv >/dev/null #!/bin/sh update-rc.d ${service} enable EOF @@ -163,7 +199,7 @@ disableserv() { req=(service strapdir) ckreq || return 1 - cat <<EOF | sudo tee -a ${strapdir}/disserv + cat <<EOF | sudo tee -a ${strapdir}/disserv >/dev/null #!/bin/sh update-rc.d ${service} disable EOF @@ -172,68 +208,15 @@ EOF chroot-script disserv } -enablessh() { - fn enablessh - req=(strapdir) - ckreq || return 1 - - cat <<EOF | sudo tee -a ${strapdir}/enssh -#!/bin/sh -sed -i -e 's/PermitRootLogin without-password/PermitRootLogin yes/' /etc/ssh/sshd_config -update-rc.d ssh enable -update-rc.d regensshkeys defaults -update-rc.d regensshkeys enable -rm -f /enssh -EOF - - cat <<EOF | sudo tee ${strapdir}/etc/init.d/regensshkeys -#!/bin/sh -# -### BEGIN INIT INFO -# Provides: something -# Required-Start: \$syslog -# Required-Stop: \$syslog -# Default-Start: 2 3 4 5 -# Default-Stop: 0 1 6 -# Short-Description: Regenerate openssh-server keys -# Description: Regenerate openssh-server keys -### END INIT INFO -# -set -e -set -u - -genkeys() { - /usr/sbin/service ssh stop - /usr/sbin/dpkg-reconfigure openssh-server - /usr/sbin/service ssh start - /usr/sbin/update-rc.d regensshkeys disable -} - -case "\$1" in - start) - genkeys;; - stop) - ;; - *) - echo "usage: \$(basename \$0) {start}" - ;; -esac -EOF - - sudo chmod +x $strapdir/etc/init.d/regensshkeys - - chroot-script -d enssh -} - install-custdebs() { fn install-custdebs req=(R strapdir) ckreq || return 1 sudo mkdir -p $strapdir/debs - sudo cp $CPVERBOSE -f $R/extra/custom-packages/*.deb $strapdir/debs/ + sudo cp $R/extra/custom-packages/*.deb $strapdir/debs/ - cat <<EOF | sudo tee ${strapdir}/install-debs + cat <<EOF | sudo tee ${strapdir}/install-debs >/dev/null #!/bin/sh for deb in /debs/*.deb; do dpkg -i \$deb @@ -241,7 +224,7 @@ for deb in /debs/*.deb; do done apt-get autoremove apt-get clean -rm -rf /debs install-debs +rm -rf /debs EOF chroot-script install-debs } @@ -251,27 +234,34 @@ chroot-script() { case "x$1" in x-d) - shift 1 - local scripts="$@" - - dpkgdivert on $strapdir - for i in $scripts; do - notice "chrooting to execute $i..." - sudo chmod +x $strapdir/$i - sudo -E chroot $strapdir /$i - done - dpkgdivert off $strapdir + local script="$2" + dpkgdivert on "$strapdir" + notice "chrooting to execute $script..." + sudo chmod +x "$strapdir/$script" || zerr + sudo -E chroot "$strapdir" "/$script" || zerr + dpkgdivert off "$strapdir" ;; *) - local scripts="$@" - - for i in $scripts; do - notice "chrooting to execute $i..." - sudo chmod +x $strapdir/$i - sudo -E chroot $strapdir /$i - done + local script="$1" + notice "chrooting to execute $script..." + sudo chmod +x "$strapdir/$script" || zerr + sudo -E chroot "$strapdir" "/$script" || zerr ;; esac + + sudo rm -f $strapdir/$script +} + +blend_preinst() { + fn blend_preinst + func "not overriden" + return 0 +} + +blend_postinst() { + fn blend_postinst + func "not overriden" + return 0 } silly() { @@ -310,6 +300,6 @@ silly() { "god is porco" "A million hamsters are spinning their wheels right now" ) - local rnd=$(shuf -i1-30 -n 1) + local rnd=$(shuf -i1-$#funneh -n 1) act "${funneh[$rnd]}" ; [[ $arg1 = sleep ]] && sleep $arg2 } diff --git a/zlibs/imaging b/zlibs/imaging @@ -1,5 +1,5 @@ #!/usr/bin/env zsh -# Copyright (c) 2016 Dyne.org Foundation +# Copyright (c) 2016-2017 Dyne.org Foundation # libdevuansdk is maintained by Ivan J. <parazyd@dyne.org> # # This file is part of libdevuansdk @@ -19,7 +19,7 @@ ## imagine images -vars+=(image_name bootpart rootpart) +vars+=(image_name bootpart rootpart loopdevice) image_prepare_raw() { fn image_prepare_raw @@ -132,11 +132,10 @@ image_raw_mount() { req=(workdir bootpart rootpart) ckreq || return 1 - mkdir -p $workdir/boot $workdir/root - if [[ $parted_type = dos ]]; then - sudo mount $bootpart $workdir/boot && act "mounted boot partition" || zerr - fi - sudo mount $rootpart $workdir/root && act "mounted root partition" || zerr + 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 } image_raw_umount() { @@ -144,8 +143,56 @@ image_raw_umount() { req=(workdir bootpart rootpart) ckreq || return 1 - if [[ $parted_type = dos ]]; then - sudo umount $workdir/boot && act "unmounted boot partition" || zerr - fi - sudo umount $workdir/root && act "unmounted root partition" || zerr + sudo umount $workdir/mnt/boot && act "unmounted boot partition" || zerr + sleep 1 + sudo umount $workdir/mnt && act "unmounted root partition" || zerr +} + +image_raw_as_strapdir() { + fn image_raw_as_strapdir + req=(workdir strapdir size) + ckreq || return 1 + + pushd "$workdir" + + notice "creating raw image of $size MB" + sudo rm -f base.raw + sudo qemu-img create -f raw base.raw ${size}M || zerr + notice "partitioning" + sudo parted base.raw mktable msdos || zerr + sudo parted base.raw mkpart primary '0%' '100%' || zerr + loopdevice=$(losetup --find) + sudo losetup -P $loopdevice base.raw || zerr + sudo mkfs.ext4 ${loopdevice}p1 || zerr + + 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 + popd +} + +image_qcow2_as_strapdir() { + fn image_qcow2_as_strapdir + req=(workdir strapdir size) + ckreq || return 1 + + pushd "$workdir" + + notice "creating qcow2 image of $size MB" + rm -f base.qcow2 + qemu-img create -f qcow2 base.qcow2 ${size}M || zerr + sudo modprobe nbd max_part=8 || zerr + loopdevice="$(findfreenbd)" + [ -n "$loopdevice" ] || zerr + act "$loopdevice" + sudo qemu-nbd --connect=${loopdevice} base.qcow2 || zerr + notice "partitioning" + sudo parted ${loopdevice} mktable msdos || zerr + sudo parted ${loopdevice} mkpart primary '0%' '100%' || zerr + sudo mkfs.ext4 ${loopdevice}p1 || zerr + + 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 + popd } diff --git a/zlibs/iso b/zlibs/iso @@ -1,5 +1,5 @@ #!/usr/bin/env zsh -# Copyright (c) 2016 Dyne.org Foundation +# Copyright (c) 2016-2017 Dyne.org Foundation # libdevuansdk is maintained by Ivan J. <parazyd@dyne.org> # # This file is part of libdevuansdk @@ -19,7 +19,7 @@ ## burn baby -[[ $INSTALLER = 1 ]] && base_packages+=(grub-pc) +#[[ $INSTALLER = 1 ]] && base_packages+=(grub-pc) iso_prepare_strap() { fn iso_prepare_strap @@ -28,13 +28,12 @@ iso_prepare_strap() { notice "preparing strapdir for livecd" - cat <<EOF | sudo tee ${strapdir}/isoprep + 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 autoremove apt-get clean -rm -f /isoprep EOF chroot-script -d isoprep || zerr @@ -50,12 +49,12 @@ iso_setup_isolinux() { pushd $workdir sudo mkdir -p binary/{live,isolinux} act "copying kernel and initrd" - sudo cp $CPVERBOSE $strapdir/boot/vmlinuz* binary/live/vmlinuz - sudo cp $CPVERBOSE $strapdir/boot/initrd* binary/live/initrd + sudo cp $strapdir/boot/vmlinuz* binary/live/vmlinuz + sudo cp $strapdir/boot/initrd* binary/live/initrd - sudo cp $CPVERBOSE /usr/share/live/build/bootloaders/isolinux/isolinux.bin \ + sudo cp /usr/share/live/build/bootloaders/isolinux/isolinux.bin \ binary/isolinux - sudo cp $CPVERBOSE /usr/share/live/build/bootloaders/isolinux/*.c32 \ + sudo cp /usr/share/live/build/bootloaders/isolinux/*.c32 \ binary/isolinux popd } @@ -66,7 +65,7 @@ iso_write_isolinux_cfg() { ckreq || return 1 notice "writing isolinux configuration" - cat <<EOF | sudo tee ${workdir}/binary/isolinux/isolinux.cfg + cat <<EOF | sudo tee ${workdir}/binary/isolinux/isolinux.cfg >/dev/null ui vesamenu.c32 prompt 0 menu title ${os} boot menu @@ -90,7 +89,7 @@ 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 -comp xz -e boot popd } @@ -121,7 +120,7 @@ iso_setup_installer() { fn iso_setup_installer notice "setting up devuan-installer" - sudo cp $CPVERBOSE $R/extra/installer/* $strapdir/ + sudo cp $R/extra/installer/* $strapdir/ ## TODO: init to script } diff --git a/zlibs/kernel b/zlibs/kernel @@ -1,5 +1,5 @@ #!/usr/bin/env zsh -# Copyright (c) 2016 Dyne.org Foundation +# Copyright (c) 2016-2017 Dyne.org Foundation # libdevuansdk is maintained by Ivan J. <parazyd@dyne.org> # # This file is part of libdevuansdk @@ -22,7 +22,7 @@ build_kernel_amd64() { fn build_kernel_amd64 req=(strapdir arch) - #freq=($strapdir/.done) + #freq=($strapdir/.keep) ckreq || return 1 local kernel_base="linux-image" @@ -43,7 +43,7 @@ build_kernel_amd64() { build_kernel_i386() { fn build_kernel_i386 req=(strapdir arch) - #freq=($strapdir/.done) + #freq=($strapdir/.keep) ckreq || return 1 local kernel_base="linux-image" diff --git a/zlibs/rsync b/zlibs/rsync @@ -1,5 +1,5 @@ #!/usr/bin/env zsh -# Copyright (c) 2016 Dyne.org Foundation +# Copyright (c) 2016-2017 Dyne.org Foundation # libdevuansdk is maintained by Ivan J. <parazyd@dyne.org> # # This file is part of libdevuansdk @@ -26,23 +26,17 @@ rsync_to_raw_image() { notice "rsyncing strapdir to raw image..." image_raw_mount + sleep 1 silly pushd $strapdir - sudo rm -f .done - sudo rsync -HPavz -q --exclude={./boot} ./* $workdir/root || { + #sudo rm -f .done + + sudo rsync -HPavz -q ./* $workdir/mnt || { image_raw_umount - die "not enough space. report a bug please" + die "not enough space, please report a bug" zerr } - - if [[ $parted_type = dos ]]; then - sudo rsync -HPavz -q ./boot/* $workdir/boot || { - image_raw_umount - die "not enough space. report a bug please" - zerr - } - fi popd image_raw_umount diff --git a/zlibs/sysconf b/zlibs/sysconf @@ -1,5 +1,5 @@ #!/usr/bin/env zsh -# Copyright (c) 2016 Dyne.org Foundation +# Copyright (c) 2016-2017 Dyne.org Foundation # libdevuansdk is maintained by Ivan J. <parazyd@dyne.org> # # This file is part of libdevuansdk @@ -66,8 +66,8 @@ fe02::1 ip6-allrouters EOF } -conf_print_networkifaces() { - fn conf_print_networkifaces +conf_print_netifaces() { + fn conf_print_netifaces cat <<EOF # interfaces(5) file used by ifup(8) and ifdown(8) @@ -84,6 +84,9 @@ iface lo inet loopback auto eth0 iface eth0 inet dhcp +#auto eth1 +#iface eth1 inet dhcp + # auto eth0 # iface eth0 inet static # address 10.0.1.10 @@ -119,10 +122,21 @@ conf_print_sourceslist() { deb ${mirror} ${release} ${section} deb ${mirror} ${release}-updates ${section} deb ${mirror} ${release}-security ${section} +#deb ${mirror} ${release}-backports ${section} ## source repositories #deb-src ${mirror} ${release} ${section} #deb-src ${mirror} ${release}-updates ${section} #deb-src ${mirror} ${release}-security ${section} +#deb-src ${mirror} ${release}-backports ${section} +EOF +} + +conf_print_locales() { + fn conf_print_locales + + cat <<EOF +export LANG=C +export LC_ALL=C EOF } diff --git a/zlibs/vm b/zlibs/vm @@ -0,0 +1,186 @@ +#!/usr/bin/env zsh +# Copyright (c) 2016-2017 Dyne.org Foundation +# libdevuansdk is maintained by Ivan J. <parazyd@dyne.org> +# +# 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/>. + +## ma baker + +vars+=(vmname) + +vm_inject_overrides() { + fn vm_inject_overrides + req=(strapdir) + ckreq || return 1 + + notice "injecting rootfs overrides" + cat <<EOF | sudo -E tee ${strapdir}/etc/rc.local >/dev/null +#!/bin/sh +# rc.local for base images + +[ -f /etc/ssh/ssh_host_rsa_key.pub ] || dpkg-reconfigure openssh-server + +exit 0 +EOF + sudo chmod +x $strapdir/etc/rc.local + + 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 +} + +vm_setup_grub() { + fn vm_setup_grub + req=(strapdir loopdevice) + ckreq || return 1 + + notice "setting up grub" + cat <<EOF | sudo tee ${strapdir}/setupgrub >/dev/null +#!/bin/sh +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} +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}() { + fn vm_umount_${imageformat} + req=(strapdir loopdevice imageformat) + ckreq || return 1 + + 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 + notice "unmounting ${imageformat} image from strapdir" + sudo umount $strapdir || zerr + silly sleep 1 + sudo rmdir $strapdir || zerr + + notice "cleaning up" + case "$imageformat" in + raw) + sudo losetup -d ${loopdevice} || zerr + ;; + qcow2) + sudo qemu-nbd --disconnect ${loopdevice} || zerr + ;; + *) + zerr + ;; + esac + silly sleep 1 +} + +vm_vbox_setup() { + fn vm_vbox_setup + req=(workdir imageformat) + ckreq || return 1 + + 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 + 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 + + vminfo="$(VBoxManage showvminfo "$vmname" --machinereadable)" + diskuuid="$(getfield "$vminfo" '"IDE Controller-ImageUUID-0-0"')" + + act "autoreset off on storage" + VBoxManage modifyhd "$diskuuid" --autoreset off || zerr + + act "setting up nat network" + VBoxManage modifyvm "$vmname" --nic1 nat || zerr + popd +} + +vm_vagrant_package() { + fn vm_vagrant_package + req=(workdir vmname) + ckreq || return 1 + + notice "packaging a vagrant box" + + pushd $workdir + act "creating vagrantfile" + cat <<EOF > Vagrantfile +Vagrant.configure("2") do |config| + config.vm.box = "devuanbox.box" + config.ssh.username = "root" + config.ssh.password = "toor" + config.vm.guest = :debian + config.vm.synced_folder ".", "/vagrant", disabled: true + # https://github.com/dotless-de/vagrant-vbguest +end +EOF + act "creating metadata.json" + cat <<EOF > metadata.json +{ + "provider": "virtualbox" +} +EOF + notice "actually packaging..." + vagrant package --base "$vmname" --output ${vm_name}.box --include metadata.json --vagrantfile Vagrantfile || zerr + popd +} + +vm_pack_dist() { + fn vm_pack_dist + req=(workdir imageformat) + ckreq || return 1 + + notice "packing up 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 + notice "cleaning up virtualbox leftovers" + pushd "$workdir" + VBoxManage unregistervm "$vmname" --delete + rm -f metadata.json Vagrantfile + rm -rf .vagrant + popd + rm -rf "$workdir" + rm -rf "$HOME/VirtualBox VMs/vmsdk" + + notice "done!" + ls -1 $R/dist +}