commit 70568c2357bf4324c870422b9c21a0e7f72a7717
parent afa49d23cea1f8536e73eee0189c62da36face6f
Author: parazyd <parazyd@dyne.org>
Date: Wed, 8 Jun 2016 15:33:54 +0200
base system bootstrap
Diffstat:
7 files changed, 438 insertions(+), 17 deletions(-)
diff --git a/config b/config
@@ -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/>.
+
+## Distro-specific settings
+
+# os name
+os="devuan"
+
+# release name
+release="jessie"
+
+# release version
+version="1.0.0-beta2"
+
+# mirror url
+mirror="http://packages.devuan.org/merged"
+
+# mirror repo section
+section="main"
+
+# core packages for the system
+core_packages=(devuan-keyring debian-keyring)
+core_packages+=(git-core binutils ca-certificates curl)
+core_packages+=(locales console-common less nano vim)
+
+# base packages for the system
+base_packages=(bzip2 dialog apt-utils fakeroot e2fsprogs parted)
+
+# other system packages
+system_packages=(sysvinit ssh)
+
+## libdevuansdk-specific settings
+workdir="$R/workdir"
+strapdir="${workdir}/strapdir"
diff --git a/doc/README-configuration.md b/doc/README-configuration.md
@@ -0,0 +1,7 @@
+libdevuansdk configuration
+--------------------------
+
+## Variables
+
+### `strapdir`
+Path to your bootstrap directory (rootfs)
diff --git a/doc/README-functions.md b/doc/README-functions.md
@@ -1,6 +1,23 @@
libdevuansdk functions
----------------------
+# zlibs/debootstrap
+
+## bootstrap()
+Stages 1, 2, and 3 of debootstrap.
+
+## config_cleanup()
+Final cleanup of the rootfs.
+
+## config_thirdstage()
+Shell script for the system's third debootstrap stage.
+
+## tar_bootstrap()
+Make a tarball of a base working system, ready to be worked on later.
+
+## tar_unpack()
+Unpack the tarball of a base working system to the strapdir.
+
# zlibs/helpers
## escalate()
@@ -41,6 +58,9 @@ Prints default `/etc/hosts`
## conf_print_networkifaces()
Prints the `/etc/network/interfaces` file
+## conf_print_resolvconf()
+Prints the `/etc/resolv.conf` file.
+
## conf_print_sourceslist()
Prints default `/etc/apt/sources.list`
diff --git a/libdevuansdk b/libdevuansdk
@@ -1,32 +1,34 @@
#!/usr/bin/env zsh
#
-# Copyright (C) 2012-2016 Dyne.org Foundation
+# 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 Public License
-# as published by the Free Software Foundation; either
-# version 3 of the License, or (at your option) any later
-# version.
+# 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 source code 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. Please refer to the GNU Public License for more
-# details.
+# 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 Public License
-# along with this source code; if not, write to: Free
-# Software Foundation, Inc., 675 Mass Ave, Cambridge, MA
-# 02139, USA.
+# 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/>.
devuan_sdk_version=0.1
-# export DOWSE_PREFIX and DOWSE_HOME to override
R=${SDK_PREFIX:-/usr/local/devuan-sdk}
H=${SDK_HOME:-$HOME/.devuan-sdk}
E=${SDK_CONF:-/etc/devuan-sdk}
+R=`pwd` # NOTE: for development
+
[[ -r $R ]] || {
print "Devuan SDK is not installed in: $R"
print "export SDK_PREFIX if installed on a different path"
@@ -48,13 +50,17 @@ LOG=${LOG:-""}
vars+=(R H E)
# source $R/zlibs/library
+source $R/config
+source $R/zlibs/debootstrap
+source $R/zlibs/helpers
+source $R/zlibs/sysconf
# conclude initialization
if [[ -r $R/zuper/zuper.init ]]; then
source $R/zuper/zuper.init
else source ./zuper/zuper.init; fi
-# add all other dowse binaries to the path
+# add all other binaries to the path
path+=($R/bin)
rehash
diff --git a/zlibs/debootstrap b/zlibs/debootstrap
@@ -0,0 +1,145 @@
+#!/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/>.
+
+## Debootstrap things
+
+bootstrap() {
+ fn bootstrap $@
+ arch="$1"
+ req=(os strapdir workdir arch release mirror)
+ ckreq || return 1
+
+ notice "Bootstrapping ${os} base"
+
+ mkdir -p ${strapdir}
+
+ if [[ -f $R/tmp/${os}-${arch}.tgz ]]; then
+ tar_unpack ${strapdir}
+ else
+ # Debootstrap stage 1
+ escalate "root" "debootstrap --foreign --arch ${arch} ${release} ${strapdir} ${mirror}"
+
+ # Debootstrap stage 2
+ escalate "root" "chroot ${strapdir} /debootstrap/debootstrap --second-stage"
+
+ # write all system configuration
+ conf_print_debconf | escalate "root" "tee ${strapdir}/debconf.set"
+ conf_print_fstab | escalate "root" "tee ${strapdir}/etc/fstab"
+ conf_print_hostname | escalate "root" "tee ${strapdir}/etc/hostname"
+ conf_print_hosts | escalate "root" "tee ${strapdir}/etc/hosts"
+ conf_print_networkifaces | escalate "root" "tee ${strapdir}/etc/network/interfaces"
+ conf_print_resolvconf | escalate "root" "tee ${strapdir}/etc/resolv.conf"
+ conf_print_sourceslist | escalate "root" "tee ${strapdir}/etc/apt/sources.list"
+
+ # write third-stage for chroot
+ config_thirdstage | escalate "root" "tee ${strapdir}/thirdstage.sh"
+ config_cleanup | escalate "root" "tee ${strapdir}/cleanup.sh"
+ escalate "root" "chmod +x ${strapdir}/thirdstage.sh"
+ escalate "root" "chmod +x ${strapdir}/cleanup.sh"
+
+ # chroot into it and configure further
+ # Debootstrap stage 3
+ export LC_ALL=C
+ export DEBIAN_FRONTEND=noninteractive
+
+ mountdevproc ${strapdir}
+
+ escalate "root" "chroot ${strapdir} /thirdstage.sh"
+
+ umountdevproc ${strapdir}
+
+ tar_bootstrap
+ fi
+}
+
+config_cleanup() {
+ fn config_cleanup
+
+ cat << EOF
+#!/bin/sh
+
+rm -f /debconf.set
+rm -f /thirdstage.sh
+EOF
+}
+
+config_thirdstage() {
+ fn 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:devuan" | 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}
+apt-get --yes --force-yes install ${system_packages}
+
+apt-get --yes --force-yes dist-upgrade
+
+apt-get --yes --force-yes autoremove
+
+rm -f /usr/sbin/policy-rc.d
+rm -f /usr/sbin/invoke-rc.d
+dpkg-divert --remove --rename /usr/sbin/invoke-rc.d
+EOF
+}
+
+tar_bootstrap() {
+ fn tar_bootstrap
+
+ if [[ -f $R/tmp/${os}-${arch}.tgz ]]; then
+ return 0
+ else
+ pushd ${strapdir}
+ tar czf ${os}-${arch}.tgz ./*
+ mkdir -p $R/tmp
+ mv ${os}-${arch}.tgz $R/tmp/
+ popd
+ fi
+}
+
+tar_unpack() {
+ fn tar_unpack $@
+ local unpath="$1"
+ req=(unpath)
+ ckreq || return 1
+
+ tar xf $R/tmp/${os}-${arch}.tgz -C ${unpath}
+}
diff --git a/zlibs/helpers b/zlibs/helpers
@@ -0,0 +1,60 @@
+#!/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/>.
+
+## Helper functions that make your life easier
+
+escalate() {
+ fn escalate $@
+ local user="$1"
+ local cmnd="$2"
+ req=(user cmnd)
+ ckreq || return 1
+
+ if [[ `command -v sudo` ]]; then
+ sudo -E -u ${user} ${cmnd}
+ else
+ su -c ${cmnd} ${user}
+ fi
+}
+
+mountdevproc() {
+ fn mountdevproc $@
+ strapdir="$1"
+ req=(strapdir)
+ ckreq || return 1
+
+ escalate "root" "mount -t proc proc ${strapdir}/proc" && act "mounted /proc"
+ escalate "root" "mount -o bind /dev ${strapdir}/dev" && act "mounted /dev"
+ escalate "root" "mount -o bind /dev/pts ${strapdir}/dev/pts" && act "mounted /dev/pts"
+}
+
+umountdevproc() {
+ fn umountdevproc $@
+ strapdir="$1"
+ req=(strapdir)
+ ckreq || return 1
+
+ escalate "root" "umount ${strapdir}/dev/pts" && act "unmounted /dev/pts" && sleep 2
+ escalate "root" "umount ${strapdir}/dev" && act "unmounted /dev" && sleep 2
+ escalate "root" "umount ${strapdir}/proc" && act "unmounted /proc" && sleep 2
+}
diff --git a/zlibs/sysconf b/zlibs/sysconf
@@ -0,0 +1,129 @@
+#!/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/>.
+
+## Default system configuration
+
+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
+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
+deb ${mirror} ${release} ${section}
+deb ${mirror} ${release}-updates ${section}
+deb ${mirror} ${release}-security ${section}
+
+deb-src ${mirror} ${release} ${section}
+deb-src ${mirror} ${release}-updates ${section}
+deb-src ${mirror} ${release}-security ${section}
+EOF
+}