libdevuansdk

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

commit 406ad450042f2910f3d08c104da59903003c54fe
parent a52e018a44d669fd65a9ee5f3d5cc740a5b4ee27
Author: parazyd <parazyd@dyne.org>
Date:   Thu, 29 Sep 2016 21:22:00 +0200

add bootstrap functions

Diffstat:
Aconfig | 59+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Alibdevuansdk | 34++++++++++++++++++++++++++++++++++
Azlibs/bootstrap | 181+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Azlibs/helpers | 83+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Azlibs/sysconf | 131+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
5 files changed, 488 insertions(+), 0 deletions(-)

diff --git a/config b/config @@ -0,0 +1,59 @@ +#!/usr/bin/env zsh +# +# Copyright (c) 2016 Dyne.org Foundation +# libdevuansdk is written and maintained by Ivan J. <parazyd@dyne.org> +# with code contributions from KatolaZ <katolaz@freaknet.org> +# and Jaromil <jaromil@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/>. + +## libdevuansdk configuration + +vars+=(release version mirror section) +arrs+=(core_packages base_packages system_packages) + +os="devuan" +release="jessie" +version="1.0.0-beta" +mirror="http://packages.devuan.org/merged" +section="main" + +core_packages=( + devuan_keyring + debian_keyring + initramfs-tools + binutils + ca-certificates + curl + console-common + less + nano + vi +) + +base_packages=( + bzip2 + dialog + apt-utils + fakeroot + e2fsprogs + parted +) + +system_packages=( + sysvinit + ssh +) diff --git a/libdevuansdk b/libdevuansdk @@ -0,0 +1,34 @@ +#!/usr/bin/env zsh +# +# Copyright (c) 2016 Dyne.org Foundation +# libdevuansdk is written and maintained by Ivan J. <parazyd@dyne.org> +# with code contributions from KatolaZ <katolaz@freaknet.org> +# and Jaromil <jaromil@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/>. + +libdevuansdk_version="0.2-dev" +LIBPATH=${LIBPATH:-`dirname $0`} + +source $LIBPATH/config +source $LIBPATH/zlibs/bootstrap +source $LIBPATH/zlibs/helpers +source $LIBPATH/zlibs/sysconf + +vars+=(libdevuansdk_version) +vars+=(LIBPATH) + +notice "libdevuansdk-v$libdevuansdk_version loaded" diff --git a/zlibs/bootstrap b/zlibs/bootstrap @@ -0,0 +1,181 @@ +#!/usr/bin/env zsh +# +# Copyright (c) 2016 Dyne.org Foundation +# libdevuansdk is written and maintained by Ivan J. <parazyd@dyne.org> +# with code contributions from KatolaZ <katolaz@freaknet.org> +# and Jaromil <jaromil@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/>. + +vars+=(bootstrap_tgz) + +bootstrap() { + fn bootstrap "$@" + req=(arch) + ckreq || return 1 + + notice "bootstrapping $os $arch base" + + bootstrap_tgz="$R/tmp/bootstrap-${os}-${arch}.tgz" + + [[ -f $bootstrap_tgz ]] && { + notice "using the existing bootstrap tarball found in $R/tmp" + bootstrap_tar_unpack $strapdir || { die "failed to extract"; zerr } + return 0 + } + notice "running debootstrap stage 1" + ## deboostrap stage 1 + sudo debootstrap \ + --foreign \ + --arch $arch $release $strapdir $mirror || zerr + + [[ $arch =~ "^arm.." ]] && qemu_install_user + + ## debootstrap stage 2 + notice "running debootstrap stage 2" + sudo chroot $strapdir \ + /debootstrap/debootstrap --second-stage || zerr + + ## 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 + + ## write third-stage for chroot + bootstrap_config_thirdstage | sudo tee $strapdir/thirdstage + bootstrap_config_cleanup | sudo tee $strapdir/cleanup + sudo chmod +x $strapdir/thirdstage + sudo chmod +x $strapdir/cleanup + + ## chroot into it and configure further + ## debootstrap stage 3 + notice "running debootstrap stage 3" + export LANG=C + export LC_ALL=C + export DEBIAN_FRONTEND=noninteractive + + devprocsys mount $strapdir || zerr + + sudo chroot $strapdir /thirdstage || zerr + sudo chroot $strapdir /cleanup || zerr + + sleep 1 && devprocsys umount $strapdir || zerr + + bootstrap_tar_pack || 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 +## our file for which we check the bootstrap is complete +echo "1" > .done +EOF +} + +bootstrap_config_thirdstage() { + fn bootstrap_config_thirdstage + req=(core_packages base_packages system_packages) + ckreq || return 1 + + cat << EOF +#!/bin/sh +dpkg-divert --add --local \ + --divert /usr/sbin/invoke-rc.d.chroot --rename /usr/sbin/invoke-rc.d +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 + +apt-get update +apt-get --yes --force-yes install locales-all +debconf-set-selections /debconf.set + +apt-get update +apt-get -y install ${core_packages} + +echo "root:${os}" | 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 +export DEBIAN_FRONTEND=noninteractive + +apt-get --yes --force-yes install \ + ${base_packages} \ + ${system_packages} \ + ${extra_packages} +apt-get --yes --force-yes dist-upgrade +apt-get --yes --force-yes autoremove + +apt-get clean + +rm -f /usr/sbin/policy-rc.d +rm -f /usr/sbin/invoke-rc.d +dpkg-divert --remove --rename /usr/sbin/invoke-rc.d +EOF +} + +bootstrap_tar_pack() { + fn bootstrap_tar_pack + req=(bootstrap_tgz) + ckreq || return 1 + + local _dest=`dirname $bootstrap_tgz` + + if [[ -f $bootstrap_tgz ]]; then + act "tarball found already in $_dest" + else + notice "Creating boostrap tarball in $bootstrap_tgz" + silly + + pushd ${strapdir} + + mkdir -p ${_dest} + silly + sudo tar czf $bootstrap_tgz \ + --exclude={./boot,./dev,./sys,./proc} \ + ./ + + popd + fi +} + +bootstrap_tar_unpack() { + fn bootstrap_tar_unpack $@ + local unpath="$1" + req=(unpath bootstrap_tgz) + ckreq || return 1 + + [[ -f ${unpath}/.done ]] && { + warning "bootstrap already unpacked in $unpath" + return 1 + } + + mkdir -p ${unpath} + silly + sudo tar xf $bootstrap_tgz -C ${unpath} + sudo mkdir -p ${unpath}/{boot,dev,sys,proc} +} diff --git a/zlibs/helpers b/zlibs/helpers @@ -0,0 +1,83 @@ +#!/usr/bin/env zsh +# +# Copyright (c) 2016 Dyne.org Foundation +# libdevuansdk is written and maintained by Ivan J. <parazyd@dyne.org> +# with code contributions from KatolaZ <katolaz@freaknet.org> +# and Jaromil <jaromil@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/>. + +## helper functions that make your life easier + +devprocsys() { + fn devprocsys "$@" + local watdo="$1" + local werdo="$2" + req=(watdo werdo) + ckreq || return 1 + + if [[ $watdo = mount ]]; then + sudo mount -o bind /sys $werdo/sys && act "mounted sys" + sudo mount -t proc proc $werdo/proc && act "mounted proc" + sudo mount -o bind /dev $werdo/dev && act "mounted dev" + sudo mount -o bind /dev/pts $werdo/dev/pts && act "mounted dev/pts" + elif [[ $watdo = umount ]]; then + sudo umount $werdo/dev/pts && act "umounted dev/pts" && sleep 2 + sudo umount $werdo/dev && act "umounted dev" && sleep 2 + sudo umount $werdo/proc && act "umounted proc" && sleep 2 + sudo umount $werdo/sys && act "umounted sys" && sleep 2 + fi +} + +silly() { + fn silly "$@" + local arg1="$1" + local arg2="$2" + ## cheers mailpile! + funneh=("do not think of purple hippos" + "increasing entropy & scrambling bits" + "indexing kittens..." + "patching bugs..." + "spinning violently around the y-axis" + "warming up particle accelerator" + "this server is powered by a lemon and two electrodes" + "becoming self-aware" + "BCC-ing ALL THE SPIES!" + "all of your config settings & passwords are encrypted with AES256" + "the most common password is 123456, hopefully yours is different" + "good things come to those who wait" + "Make Free Software and be happy" + "We like volcanos, do you like volcanos?" + "Crossing out swear words..." + "Informing David Cameron of suspicious ac^H^H^H ... naaah :)" + "Abandon all hope, ye who enter here" + "Compiling bullshit bingo grid..." + "Estimating chance of asteroid hitting Earth" + "Applying coupons..." + "Backing up the entire Internet..." + "Making you wait for no reason" + "Doing nothing" + "Pay no attention to the man behind the curtain" + "You are great just the way you are" + "Supplying monkeys with typewriters" + "Swapping time and space" + "Self potato" + "it's all lies" + "A million hamsters are spinning their wheels right now" + ) + local rnd=$(shuf -i1-30 -n 1) + act "${funneh[$rnd]}" ; [[ $arg1 = sleep ]] && sleep $arg2 +} diff --git a/zlibs/sysconf b/zlibs/sysconf @@ -0,0 +1,131 @@ +#!/usr/bin/env zsh +# +# Copyright (c) 2016 Dyne.org Foundation +# libdevuansdk is written and maintained by Ivan J. <parazyd@dyne.org> +# with code contributions from KatolaZ <katolaz@freaknet.org> +# and Jaromil <jaromil@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/>. + +## default system configurations + +conf_print_debconf() { + fn conf_print_debconf + + cat << EOF +console-common console-data/keymap/policy select Select keymap from full list +console-common console-data/keymap/full select en-latin1-nodeadkeys +EOF +} + +conf_print_fstab() { + fn conf_print_fstab + + cat << EOF +#<file system> <mount point> <type> <options> <dump> <pass> +proc /proc proc nodev,noexec,nosuid 0 0 + +# rootfs +/dev/sda2 / ext4 errors=remount-ro 0 1 + +# boot +/dev/sda1 /boot ext2 noauto 0 0 +EOF +} + +conf_print_hostname() { + fn conf_print_hostname + req=(os) + ckreq || return 1 + + print $os +} + +conf_print_hosts() { + fn conf_print_hosts + req=(os) + ckreq || return 1 + + cat << EOF +127.0.0.1 ${os} localhost +::1 localhost ip6-localhost ip6-loopback +fe00::0 ip6-localnet +fe00::0 ip6-mcastprefix +fe02::1 ip6-allnodes +fe02::1 ip6-allrouters +EOF +} + +conf_print_networkifaces() { + fn conf_print_networkifaces + + cat << EOF +# interfaces(5) file used by ifup(8) and ifdown(8) + +# Please note that this file is written to be used with dhcpcd +# For static IP, consult /etc/dhcpcd.conf and 'man dhcpcd.conf' + +# Include files from /etc/network/interfaces.d: +source-directory /etc/network/interfaces.d + +auto lo +iface lo inet loopback + +auto eth0 +iface eth0 inet dhcp + +# auto eth0 +# iface eth0 inet static +# address 10.0.1.10 +# netmask 255.255.255.0 + +# allow-hotplug wlan0 +# iface wlan0 inet manual +# wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf + +# allow-hotplug wlan1 +# iface wlan1 inet manual +# wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf +EOF +} + +conf_print_resolvconf() { + fn conf_print_resolvconf + + cat << EOF +## google's nameservers +nameserver 8.8.8.8 +nameserver 8.8.4.4 +EOF +} + +conf_print_sourceslist() { + fn conf_print_sourceslist + req=(mirror release section) + ckreq || return 1 + + cat << EOF +## package repositories +deb ${mirror} ${release} ${section} +deb ${mirror} ${release}-updates ${section} +deb ${mirror} ${release}-security ${section} + +## source repositories +# deb-src ${mirror} ${release} ${section} +# deb-src ${mirror} ${release}-updates ${section} +# deb-src ${mirror} ${release}-security ${section} +EOF +}