diff --git a/config b/config index 9948b25..eeec0ba 100644 --- a/config +++ b/config @@ -28,6 +28,8 @@ version="1.0.0-beta2" mirror="http://auto.mirror.devuan.org/merged" section="main" +isomirror="http://files.devuan.org/devuan_jessie_beta" + image_name="${os}_${release}_${version}_${arch}" [[ -n $blend_name ]] && image_name="${image_name}_${blend_name}" [[ -n $device_name ]] && image_name="${image_name}_${device_name}" @@ -72,4 +74,8 @@ base_packages=( purge_packages+=( dbus nano + exim4 + exim4-base + exim4-config + reportbug ) diff --git a/libdevuansdk b/libdevuansdk index 3dc9a17..73d9a10 100644 --- a/libdevuansdk +++ b/libdevuansdk @@ -28,6 +28,7 @@ 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) diff --git a/zlibs/bootstrap b/zlibs/bootstrap index 538f8e7..2c21c3b 100644 --- a/zlibs/bootstrap +++ b/zlibs/bootstrap @@ -88,8 +88,7 @@ bootstrap_config_cleanup() { #!/bin/sh rm -f /debconf.set rm -f /thirdstage -rm -f /etc/ssh/*_key -rm -f /etc/ssh/*.pub +rm -f /etc/ssh/ssh_host_* rm -f /root/.bash_history #rm -f /usr/bin/qemu-arm-static ## our file for which we check the bootstrap is complete @@ -186,7 +185,7 @@ EOF devprocsys umount $strapdir ## below typically used in arm-sdk - [[ -z $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 diff --git a/zlibs/helpers b/zlibs/helpers index a585fe7..8dbf885 100644 --- 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. # # This file is part of libdevuansdk @@ -58,12 +58,39 @@ build_iso_dist() { build_kernel_${arch} || zerr iso_setup_isolinux || zerr iso_write_isolinux_cfg || zerr - [[ $INSTALLER = 1 ]] && iso_setup_installer + [[ $INSTALLER = 1 ]] && iso_setup_installer || zerr [[ $BLEND = 1 ]] && blend_postinst || zerr iso_squash_strap || zerr iso_xorriso_build || zerr } +build_vagrant_dist() { + fn build_vagrant_dist + req=(workdir strapdir os arch) + ckreq || return 1 + + notice "building complete vagrant image" + + image_raw_as_strapdir || zerr + bootstrap_complete_base || zerr + vm_inject_overrides || zerr + [[ $BLEND = 1 ]] && blend_preinst || zerr + vm_setup_grub || zerr + [[ $BLEND = 1 ]] && blend_postinst || zerr + vm_umount_raw || zerr + vm_vbox_setup || zerr + vm_vagrant_package || zerr + vm_pack_dist || zerr +} + +getfield() { + fn getfield $* + + echo "$1" | grep "^$2=" | \ + sed -e 's:.*=\(.*\)$:\1:g' | \ + sed -e 's:^"\(.*\)"$:\1:g' +} + devprocsys() { fn devprocsys "$@" local watdo="$1" diff --git a/zlibs/imaging b/zlibs/imaging index 7c776b8..4306380 100644 --- a/zlibs/imaging +++ b/zlibs/imaging @@ -19,7 +19,7 @@ ## imagine images -vars+=(image_name bootpart rootpart) +vars+=(image_name bootpart rootpart loopdevice) image_prepare_raw() { fn image_prepare_raw @@ -151,3 +151,26 @@ image_raw_umount() { sleep 1 sudo umount $workdir/mnt && act "unmounted root partition" || zerr } + +image_raw_as_strapdir() { + fn image_raw_as_strapdir + req=(workdir strapdir) + ckreq || return 1 + + pushd "$workdir" + + notice "creating raw image of $size MB" + sudo -E rm -f base.raw + sudo -E qemu-img create -f raw base.raw + notice "partitioning" + sudo -E parted base.raw mktable msdos + sudo -E parted base.raw mkpart primary '0%' '100%' + loopdevice=$(losetup --find) + sudo -E losetup -P $loopdevice base.raw + sudo -E mkfs.ext4 ${loopdevice}p1 + + notice "mounting raw image to strapdir" + sudo mount ${loopdevice}p1 $strapdir + + popd +} diff --git a/zlibs/sysconf b/zlibs/sysconf index e2af917..a49c216 100644 --- a/zlibs/sysconf +++ b/zlibs/sysconf @@ -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 diff --git a/zlibs/vm b/zlibs/vm new file mode 100644 index 0000000..3ebd7ea --- /dev/null +++ b/zlibs/vm @@ -0,0 +1,171 @@ +#!/usr/bin/env zsh +# Copyright (c) 2016-2017 Dyne.org Foundation +# libdevuansdk is maintained by Ivan J. +# +# 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 . + +## ma baker +# +# deps: +# virtualbox +# qemu-kvm + +vars+=(vmname) + +vm_inject_overrides() { + fn vm_inject_overrides + req=(strapdir) + ckreq || return 1 + + notice "injecting rootfs overrides" + cat </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 -E chmod +x $strapdir/etc/rc.local + + print "rootfs / rootfs rw 0 0" | sudo -E 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 </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_raw() { + fn vm_umount_raw + req=(strapdir loopdevice) + ckreq || return 1 + + notice "remounting raw image" + sudo -E 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 raw image from strapdir" + silly sleep 1 + sudo umount $strapdir || zerr + sudo rmdir $strapdir || zerr + + sync + silly sleep 1 + notice "cleaning up" + sudo losetup -d ${loopdevice} || zerr + silly sleep 1 +} + +vm_vbox_setup() { + fn vm_vbox_setup + req=(workdir) + ckreq || return 1 + + notice "converting raw image to vdi" + pushd $workdir + sudo -E qemu-img convert -f raw -O vdi base.raw base.vdi || zerr + sudo -E 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 /personalcloud || 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 < Vagrantfile +Vagrant.configure("2") do |config| + config.vm.box = "devuanbox.box" + config.ssh.username = "root" + config.ssh.password = "toor" + config.vm.guest = :debian +end +EOF + act "creating metadata.json" + cat < metadata.json +{ + "provider": "virtualbox" +} +EOF + notice "actually packaging..." + vagrant package --base "$vmname" --outbut devuanbox.box --include metadata.json --vagrantfile Vagrantfile || zerr + popd +} + +vm_pack_dist() { + fn vm_pack_dist + req=(workdir) + ckreq || return 1 + + notice "packing up dist" + mkdir -p $R/dist + mv $workdir/devuanbox.box $R/dist/ + act "calculating sha256sum..." + silly + sha256sum $R/dist/devuanbox.box > $R/dist/devuanbox.box.sha + notice "done!" + ls -1 $R/dist +}