libdevuansdk

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

commit e3c0e5595be96a45d2e5861d37c77e5af4c611a2
parent aa56b84ad9130ce71a65fae049e3d3835d3726e2
Author: Jaromil <jaromil@dyne.org>
Date:   Mon, 13 Jun 2016 16:57:54 +0200

renaming of zlibs

now organized as name of file -> first prefix on functions
to reflect also the tools/actions of reference

bootstrap, isolinux, kernel, qemu, sysconf

eliminated generic "customize" name, obsoleted imaging

Diffstat:
Mlibdevuansdk | 10++++++----
Rzlibs/debootstrap -> zlibs/bootstrap | 0
Dzlibs/customise | 182-------------------------------------------------------------------------------
Azlibs/grub | 54++++++++++++++++++++++++++++++++++++++++++++++++++++++
Azlibs/kernel | 56++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Azlibs/qemu | 115+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mzlibs/sysconf | 38+-------------------------------------
7 files changed, 232 insertions(+), 223 deletions(-)

diff --git a/libdevuansdk b/libdevuansdk @@ -56,12 +56,14 @@ vars+=(R H E) vars+=(name_default) # source $R/zlibs/library source $E/config -source $R/zlibs/debootstrap +source $R/zlibs/bootstrap source $R/zlibs/helpers -source $R/zlibs/imaging -source $R/zlibs/iso +# source $R/zlibs/imaging +source $R/zlibs/isolinux +source $R/zlibs/kernel +source $R/zlibs/qemu source $R/zlibs/sysconf -source $R/zlibs/customise + # conclude initialization diff --git a/zlibs/debootstrap b/zlibs/bootstrap diff --git a/zlibs/customise b/zlibs/customise @@ -1,182 +0,0 @@ -#!/usr/bin/env zsh -# -# Copyright (c) 2016 Dyne.org Foundation -# libdevuansdk is written and maintained by -# Jaromil <jaromil@dyne.org> -# KatolaZ <katolaz@freaknet.org> -# parazyd <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/>. - -### customise - -kernel_x86_install_default(){ - fn kernel_x86_install_default $@ - req=(strapdir os release version arch) - root=$strapdir - freq=($root/.done) - reqck || return 1 - - local kernel_base=linux-image - local kernel="" - - case $arch in - amd64) - kernel=${kernel_base}-amd64 - ;; - i386) - kernel=${kernel_base}-586 - ;; - *) - error "Architecture ::1 arch:: is not supported!!!" ${arch} - zerr; zshexit - ;; - esac - - notice "Installing stock kernel for ::1 arch:: (::2 kernel::)" $arch $kernel - - mountdevprocsys ${root} - - sudo chroot ${root} apt-get --yes --force-yes --no-install-recommends install $kernel - - umountdevprocsys ${root} - notice "default kernel installed" -} - -grub_install_target_dev(){ - fn grub_install_target_dev $@ - root=$1 - install_dev=$2 - req=(root install_dev) - freq=($root/.done $root/dev/pts/0) - ckreq || return 1 - - # TODO: should we use qemu-chroot here for $arch = arm (parazyd?) - sudo chroot ${root} apt-get install --assume-yes --no-install-recommends grub-common - if [[ ! -d ${root}/boot/grub ]]; then - sudo mkdir ${root}/boot/grub - fi - - ztmp - devicemap=$ztmpfile - - - cat > ${devicemap} <<EOF -(hd0) /dev/loop0 -EOF - sudo cp ${devicemap} ${root}/boot/grub/device.map - sudo chroot ${root} grub-mkconfig -o /boot/grub/grub.cfg - ## we now tamper with grub.cfg, to remove all references to - ## loopback devices... - ## FIXME!!! This is a hack... - sudo -- sed -r -i -e 's/.*loop.*//g' ${root}/boot/grub/grub.cfg - - sudo grub-install --root-directory=${root} --no-floppy \ - --modules="ext2 part_msdos" ${install_dev} -} - - -qemu_make_img(){ - - fn qemu_make_img $@ - local imgfile=${1:-"$H/builds/${name_default}_${arch}.img"} - local imgsize=${2:-4G} - local imgformat=${3:-raw} - req=(strapdir os release version arch imgfile imgsize) - root=$strapdir - freq=($root/.done) - reqck || return 1 - - local blockskip=2050 - - ## create the qemu image - notice "Creating qemu image: $imgfile" - - qemu-img create -f ${imgformat} ${imgfile} ${imgsize} - [[ $? = 0 ]] || { - error "failed: qemu-img create -f ${imgformat} ${imgfile} ${imgsize}" - zsherr; zshexit } - - sudo parted ${imgfile} --script -- mklabel msdos && - sudo parted ${imgfile} --script -- mkpart primary ${blockskip}s -1s && - sudo parted ${imgfile} --script -- set 1 boot on - [[ $? = 0 ]] || { - error "failed: parted $imgfile scripts (mklabel, mkpart and setboot)" - zsherr; zshexit } - - ## setup the loop device - loop1=`sudo losetup -f` - sudo losetup ${loop1} ${imgfile} - [[ $? = 0 ]] || { - error "failed: losetup $loop2 $imgfile" - zsherr; zshexit } - - loop2=`sudo losetup -f` - sudo losetup -o $((${blockskip} * 512)) ${loop2} ${loop1} - [[ $? = 0 ]] || { - sudo losetup -d ${loop1} - error "failed: losetup -o $((${blockskip} * 512)) ${loop2} ${loop1}" - zsherr; zshexit } - - ## now we create the fs - act "creating filesystem" - sudo mkfs.ext4 ${loop2} - [[ $? = 0 ]] || { - sudo losetup -d ${loop2} - sudo losetup -d ${loop1} - error "failed: mkfs.ext4 $loop2" - zsherr; zshexit } - - ## and we loop-mount it - - ztmpd - mntdir=$ztmpdir - sudo mount -o loop ${loop2} ${mntdir} - [[ $? = 0 ]] || { - sudo losetup -d ${loop2} - sudo losetup -d ${loop1} - error "failed: mount -o loop ${loop2} ${mntdir}" - zsherr; zshexit } - - func "mntdir: $mntdir" - func "strapdir: $strapdir" - - # now we rsync everything - sudo rsync -raX ${strapdir}/ ${mntdir} - [[ $? = 0 ]] || { - umount $mntdir - sudo losetup -d ${loop2} - sudo losetup -d ${loop1} - error "failed: rsync -raX ${strapdir}/ ${mntdir}" - zsherr; zshexit } - - # we now install the grub bootloader - mountdevprocsys ${mntdir} - grub_install_target_dev ${mntdir} ${loop1} - umountdevprocsys ${mntdir} - - sync - sudo umount ${mntdir} - - sudo losetup -d ${loop2} - sudo losetup -d ${loop1} - - if [[ ! -z ${imgfile} ]]; then - notice "QEMU image created in ::1 imgfile::" ${imgfile} - else - warning "Unable to create QEMU image file in ::1 imgfile::" ${imgfile} - fi -} diff --git a/zlibs/grub b/zlibs/grub @@ -0,0 +1,54 @@ +#!/usr/bin/env zsh +# +# Copyright (c) 2016 Dyne.org Foundation +# libdevuansdk is written and maintained by +# Jaromil <jaromil@dyne.org> +# KatolaZ <katolaz@freaknet.org> +# parazyd <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/>. + + +grub_install_target_dev(){ + fn grub_install_target_dev $@ + root=$1 + install_dev=$2 + req=(root install_dev) + freq=($root/.done $root/dev/pts/0) + ckreq || return 1 + + # TODO: should we use qemu-chroot here for $arch = arm (parazyd?) + sudo chroot ${root} apt-get install --assume-yes --no-install-recommends grub-common + if [[ ! -d ${root}/boot/grub ]]; then + sudo mkdir ${root}/boot/grub + fi + + ztmp + devicemap=$ztmpfile + + cat > ${devicemap} <<EOF +(hd0) /dev/loop0 +EOF + sudo cp ${devicemap} ${root}/boot/grub/device.map + sudo chroot ${root} grub-mkconfig -o /boot/grub/grub.cfg + ## we now tamper with grub.cfg, to remove all references to + ## loopback devices... + ## FIXME!!! This is a hack... + sudo -- sed -r -i -e 's/.*loop.*//g' ${root}/boot/grub/grub.cfg + + sudo grub-install --root-directory=${root} --no-floppy \ + --modules="ext2 part_msdos" ${install_dev} +} diff --git a/zlibs/kernel b/zlibs/kernel @@ -0,0 +1,56 @@ +#!/usr/bin/env zsh +# +# Copyright (c) 2016 Dyne.org Foundation +# libdevuansdk is written and maintained by +# Jaromil <jaromil@dyne.org> +# KatolaZ <katolaz@freaknet.org> +# parazyd <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/>. + + +kernel_x86_install_default(){ + fn kernel_x86_install_default $@ + req=(strapdir os release version arch) + root=$strapdir + freq=($root/.done) + reqck || return 1 + + local kernel_base=linux-image + local kernel="" + + case $arch in + amd64) + kernel=${kernel_base}-amd64 + ;; + i386) + kernel=${kernel_base}-586 + ;; + *) + error "Architecture ::1 arch:: is not supported!!!" ${arch} + zerr; zshexit + ;; + esac + + notice "Installing stock kernel for ::1 arch:: (::2 kernel::)" $arch $kernel + + mountdevprocsys ${root} + + sudo chroot ${root} apt-get --yes --force-yes --no-install-recommends install $kernel + + umountdevprocsys ${root} + notice "default kernel installed" +} diff --git a/zlibs/qemu b/zlibs/qemu @@ -0,0 +1,115 @@ +#!/usr/bin/env zsh +# +# Copyright (c) 2016 Dyne.org Foundation +# libdevuansdk is written and maintained by +# Jaromil <jaromil@dyne.org> +# KatolaZ <katolaz@freaknet.org> +# parazyd <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/>. + + +qemu_make_img(){ + + fn qemu_make_img $@ + local imgfile=${1:-"$H/builds/${name_default}_${arch}.img"} + local imgsize=${2:-4G} + local imgformat=${3:-raw} + req=(strapdir os release version arch imgfile imgsize) + root=$strapdir + freq=($root/.done) + reqck || return 1 + + local blockskip=2050 + + ## create the qemu image + notice "Creating qemu image: $imgfile" + + qemu-img create -f ${imgformat} ${imgfile} ${imgsize} + [[ $? = 0 ]] || { + error "failed: qemu-img create -f ${imgformat} ${imgfile} ${imgsize}" + zsherr; zshexit } + + sudo parted ${imgfile} --script -- mklabel msdos && + sudo parted ${imgfile} --script -- mkpart primary ${blockskip}s -1s && + sudo parted ${imgfile} --script -- set 1 boot on + [[ $? = 0 ]] || { + error "failed: parted $imgfile scripts (mklabel, mkpart and setboot)" + zsherr; zshexit } + + ## setup the loop device + loop1=`sudo losetup -f` + sudo losetup ${loop1} ${imgfile} + [[ $? = 0 ]] || { + error "failed: losetup $loop2 $imgfile" + zsherr; zshexit } + + loop2=`sudo losetup -f` + sudo losetup -o $((${blockskip} * 512)) ${loop2} ${loop1} + [[ $? = 0 ]] || { + sudo losetup -d ${loop1} + error "failed: losetup -o $((${blockskip} * 512)) ${loop2} ${loop1}" + zsherr; zshexit } + + ## now we create the fs + act "creating filesystem" + sudo mkfs.ext4 ${loop2} + [[ $? = 0 ]] || { + sudo losetup -d ${loop2} + sudo losetup -d ${loop1} + error "failed: mkfs.ext4 $loop2" + zsherr; zshexit } + + ## and we loop-mount it + + ztmpd + mntdir=$ztmpdir + sudo mount -o loop ${loop2} ${mntdir} + [[ $? = 0 ]] || { + sudo losetup -d ${loop2} + sudo losetup -d ${loop1} + error "failed: mount -o loop ${loop2} ${mntdir}" + zsherr; zshexit } + + func "mntdir: $mntdir" + func "strapdir: $strapdir" + + # now we rsync everything + sudo rsync -raX ${strapdir}/ ${mntdir} + [[ $? = 0 ]] || { + umount $mntdir + sudo losetup -d ${loop2} + sudo losetup -d ${loop1} + error "failed: rsync -raX ${strapdir}/ ${mntdir}" + zsherr; zshexit } + + # we now install the grub bootloader + mountdevprocsys ${mntdir} + grub_install_target_dev ${mntdir} ${loop1} + umountdevprocsys ${mntdir} + + sync + sudo umount ${mntdir} + + sudo losetup -d ${loop2} + sudo losetup -d ${loop1} + + if [[ ! -z ${imgfile} ]]; then + notice "QEMU image created in ::1 imgfile::" ${imgfile} + else + warning "Unable to create QEMU image file in ::1 imgfile::" ${imgfile} + fi +} diff --git a/zlibs/sysconf b/zlibs/sysconf @@ -21,43 +21,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/>. -## Default system configuration - -conf_install_grub() { - fn conf_install_grub $@ - chrootpath="$1" - req=(chrootpath) - ckreq || return 1 - - notice "Installing grub-pc" - sudo chroot ${chrootpath} apt-get --yes --force-yes install grub-pc -} - -conf_install_kernel() { - fn conf_install_kernel $@ - chrootpath="$1" - req=(arch chrootpath) - ckreq || return 1 - - local kernel_base=linux-image - local kernel="" - - case $arch in - amd64) - kernel=${kernel_base}-amd64 - ;; - i386) - kernel=${kernel_base}-586 - ;; - *) - error "Architecture ::1 arch:: is not supported!!!" ${arch} - zerr; zshexit - ;; - esac - - notice "Installing stock kernel for ::1 arch:: (::2 kernel::)" $arch $kernel - sudo chroot ${chrootpath} apt-get --yes --force-yes install $kernel -} +## base system configurations conf_print_debconf() { fn conf_print_debconf