Add support for variations of distro images with different files & packages pre-insta...
authorDaniel Abrecht <public@danielabrecht.ch>
Sun, 7 Jul 2019 20:39:40 +0000 (22:39 +0200)
committerDaniel Abrecht <public@danielabrecht.ch>
Sun, 7 Jul 2019 20:39:40 +0000 (22:39 +0200)
21 files changed:
chroot-build-helper/makefile
config/defaults.mk
makefile
packages/default/download [new file with mode: 0644]
packages/default/install_debootstrap [new file with mode: 0644]
packages/default/install_early [new file with mode: 0644]
packages/default/install_target [new file with mode: 0644]
packages/devuan::maemo-leste/install_debootstrap [new file with mode: 0644]
packages/devuan::maemo-leste/install_early [new file with mode: 0644]
packages/devuan::maemo-leste/post_debootstrap [new file with mode: 0755]
packages_download_only [deleted file]
packages_install_debootstrap [deleted file]
packages_install_early [deleted file]
packages_install_target [deleted file]
rootfs_custom_files/etc/apt/sources.list.d/maemo-leste.list::devuan::maemo-leste [new file with mode: 0644]
script/assemble_image.sh
script/chroot_qemu_static.sh
script/debootstrap.sh
script/getrfsfile.sh
script/rootfs_setup.sh
src/make-helper-functions.mk

index d48737b130cda7492e634ef4de7687d0f4b870a8..f086301f40db31e565f013d7500c6453c2c56ed0 100644 (file)
@@ -47,7 +47,7 @@ build-env/$(DISTRO)/$(RELEASE): build-env/.dir $(CHROOT_DUMMY_PACKAGES_FILES)
        chmod 666 "$@.tmp/dev/null"
        chmod +x "$@.tmp/root/helper/mknod" "$@.tmp/root/helper/mount"
        $(SETUPBUILDENV) uexec --allow-setgroups chroot_qemu_static.sh "$(CURDIR)/$@.tmp" /debootstrap/debootstrap --second-stage
-       CHROOT_REPO="$$REPO" ../script/getrfsfile.sh "etc/apt/sources.list" >"$@.tmp/etc/apt/sources.list"
+       CHROOT_REPO="$$REPO" ../script/getrfsfile.sh "rootfs_custom_files/etc/apt/sources.list" >"$@.tmp/etc/apt/sources.list"
        $(SETUPBUILDENV) uexec --allow-setgroups chroot_qemu_static.sh "$(CURDIR)/$@.tmp" apt-get update
        $(SETUPBUILDENV) uexec --allow-setgroups chroot_qemu_static.sh "$(CURDIR)/$@.tmp" sh -c "dpkg -i /root/dummy-debs/*.deb"
        $(SETUPBUILDENV) uexec --allow-setgroups chroot_qemu_static.sh "$(CURDIR)/$@.tmp" apt-get -y install --no-install-recommends build-essential dh-make debhelper devscripts fakeroot
index 0433a9f9bdb917814c5cd07d8d2a49c82525ade0..42237f68fbe38e199b6e07f9632e8ae35057b111 100644 (file)
@@ -1,7 +1,8 @@
 BOARD = devkit
-IMGSIZE = 4GiB # Note: 1GB = 1000MB, 1GiB=1024MiB 
+IMGSIZE = 3GiB # Note: 1GB = 1000MB, 1GiB=1024MiB 
 DISTRO = devuan
 RELEASE = $(DEFAULT_RELEASE-$(DISTRO))
+VARIANT = base
 REPO = http://pkgmaster.devuan.org/merged/
 CHROOT_REPO = $(REPO)
 
@@ -13,7 +14,7 @@ DEFAULT_RELEASE-devuan = beowulf
 DEFAULT_RELEASE-debian = buster
 DEFAULT_RELEASE-ubuntu = disco
 
-IMAGE_NAME = $(DISTRO)-$(RELEASE)-librem5-$(BOARD)-base.img
+IMAGE_NAME = $(DISTRO)-$(RELEASE)-librem5-$(BOARD)-$(VARIANT).img
 
 CROSS_COMPILER = aarch64-linux-gnu-
 
index cfb64bce0b655b6966792d4d7f33105847670341..54d64693833d04ece1f8cce3b7911ff212683058 100644 (file)
--- a/makefile
+++ b/makefile
@@ -15,8 +15,8 @@ clean-fs-all:
        rm -rf build/
 
 clean-fs:
-       rm -rf "build/$(DISTRO)/$(RELEASE)/bootfs.tar"
-       rm -rf "build/$(DISTRO)/$(RELEASE)/rootfs.tar"
+       rm -rf "build/$(IMAGE_NAME)/bootfs.tar"
+       rm -rf "build/$(IMAGE_NAME)/rootfs.tar"
 
 clean-image-all:
        rm -f bin/*.img
@@ -50,13 +50,10 @@ build/bin/writeTar2Ext: repo/tar2ext/.repo build/bin/.dir
        $(MAKE) -C repo/tar2ext/
        cp repo/tar2ext/bin/writeTar2Ext build/bin/
 
-build/$(DISTRO)/$(RELEASE)/rootfs.tar: \
+build/$(IMAGE_NAME)/rootfs.tar: \
   kernel/bin/linux-image.deb \
   uboot/bin/uboot_firmware_and_dtb.bin \
   build/bin/usernsexec \
-  packages_install_debootstrap \
-  packages_install_target \
-  packages_download_only \
   rootfs_custom_files/ \
   bin/.dir
        $(MAKE) extra_packages
@@ -65,7 +62,7 @@ build/$(DISTRO)/$(RELEASE)/rootfs.tar: \
 bin/$(IMAGE_NAME): \
   build/bin/fuseloop \
   build/bin/writeTar2Ext \
-  build/$(DISTRO)/$(RELEASE)/rootfs.tar \
+  build/$(IMAGE_NAME)/rootfs.tar \
   uboot/bin/uboot_firmware_and_dtb.bin \
   kernel/bin/linux-image.deb
        ./script/assemble_image.sh
diff --git a/packages/default/download b/packages/default/download
new file mode 100644 (file)
index 0000000..ccab943
--- /dev/null
@@ -0,0 +1,3 @@
+ssh
+nano
+
diff --git a/packages/default/install_debootstrap b/packages/default/install_debootstrap
new file mode 100644 (file)
index 0000000..5f1825f
--- /dev/null
@@ -0,0 +1,7 @@
+# Needed to install the kernel & bootloader
+u-boot-tools
+# flash-kernel # Uncomment once librem 5 support is in the official repos
+
+# Required by rootfs_setup.sh and first_boot_setup.sh
+dpkg-dev
+initramfs-tools
diff --git a/packages/default/install_early b/packages/default/install_early
new file mode 100644 (file)
index 0000000..6e97365
--- /dev/null
@@ -0,0 +1,15 @@
+locales # Has to be installed before console keyboard, because it needs locale C.UTF-8
+
+# Do make the text readable
+console-setup
+
+# For getting dialogs when we install or reconfigure stuff later on the device
+dialog
+
+# Other useful stuff which is needed before first boot
+ifupdown
+
+# Other useful stuff
+net-tools
+file
+less
diff --git a/packages/default/install_target b/packages/default/install_target
new file mode 100644 (file)
index 0000000..3968fc0
--- /dev/null
@@ -0,0 +1,2 @@
+keyboard-configuration
+console-common
diff --git a/packages/devuan::maemo-leste/install_debootstrap b/packages/devuan::maemo-leste/install_debootstrap
new file mode 100644 (file)
index 0000000..8ceb9b2
--- /dev/null
@@ -0,0 +1,4 @@
+apt-transport-https
+gnupg
+ca-certificates
+wget
diff --git a/packages/devuan::maemo-leste/install_early b/packages/devuan::maemo-leste/install_early
new file mode 100644 (file)
index 0000000..9968962
--- /dev/null
@@ -0,0 +1,6 @@
+openrc
+strace
+hildon-meta
+hildon-connectivity-meta
+hildon-input-meta
+status-area-applet-battery
diff --git a/packages/devuan::maemo-leste/post_debootstrap b/packages/devuan::maemo-leste/post_debootstrap
new file mode 100755 (executable)
index 0000000..da69dae
--- /dev/null
@@ -0,0 +1,4 @@
+#!/bin/sh -ex
+
+# Add maemo leste repo key
+wget -O- https://maedevu.maemo.org/testing-key.asc | apt-key add -
diff --git a/packages_download_only b/packages_download_only
deleted file mode 100644 (file)
index ccab943..0000000
+++ /dev/null
@@ -1,3 +0,0 @@
-ssh
-nano
-
diff --git a/packages_install_debootstrap b/packages_install_debootstrap
deleted file mode 100644 (file)
index 5f1825f..0000000
+++ /dev/null
@@ -1,7 +0,0 @@
-# Needed to install the kernel & bootloader
-u-boot-tools
-# flash-kernel # Uncomment once librem 5 support is in the official repos
-
-# Required by rootfs_setup.sh and first_boot_setup.sh
-dpkg-dev
-initramfs-tools
diff --git a/packages_install_early b/packages_install_early
deleted file mode 100644 (file)
index 6e97365..0000000
+++ /dev/null
@@ -1,15 +0,0 @@
-locales # Has to be installed before console keyboard, because it needs locale C.UTF-8
-
-# Do make the text readable
-console-setup
-
-# For getting dialogs when we install or reconfigure stuff later on the device
-dialog
-
-# Other useful stuff which is needed before first boot
-ifupdown
-
-# Other useful stuff
-net-tools
-file
-less
diff --git a/packages_install_target b/packages_install_target
deleted file mode 100644 (file)
index 3968fc0..0000000
+++ /dev/null
@@ -1,2 +0,0 @@
-keyboard-configuration
-console-common
diff --git a/rootfs_custom_files/etc/apt/sources.list.d/maemo-leste.list::devuan::maemo-leste b/rootfs_custom_files/etc/apt/sources.list.d/maemo-leste.list::devuan::maemo-leste
new file mode 100644 (file)
index 0000000..ceeb23f
--- /dev/null
@@ -0,0 +1 @@
+deb https://maedevu.maemo.org/leste/ leste main
index 8e39d90ee661f38ae6530aa552721f149c25ad12..762d69a12a53ce7e9df8f60941ee7b46eacb5a56 100755 (executable)
@@ -9,7 +9,8 @@ tmp="$(mktemp -d -p build)"
 
 if [ -z "$DISTRO" ]; then DISTRO="devuan"; fi
 if [ -z "$RELEASE" ]; then RELEASE="ascii"; fi
-if [ -z "$IMAGE_NAME" ]; then IMAGE_NAME="$DISTRO-$RELEASE-librem5-devkit-base.img"; fi
+if [ -z "$VARIANT" ]; then VARIANT="base"; fi
+if [ -z "$IMAGE_NAME" ]; then IMAGE_NAME="$DISTRO-$RELEASE-librem5-devkit-$(VARIANT).img"; fi
 
 # Some programs like sfdisk are in /sbin/, but they work just fine as non-root on an image
 PATH="$base/build/bin/:$base/script/:/sbin/:/usr/sbin/:$PATH"
@@ -100,8 +101,8 @@ mkfs.ext2 -L boot "$bootdev"
 mkfs.ext4 -L root -E discard "$rootdev"
 
 # Write rootfs to partitions
-writeTar2Ext "$bootdev" < build/$DISTRO/$RELEASE/bootfs.tar
-writeTar2Ext "$rootdev" < build/$DISTRO/$RELEASE/rootfs.tar
+writeTar2Ext "$bootdev" < "build/$IMAGE_NAME/bootfs.tar"
+writeTar2Ext "$rootdev" < "build/$IMAGE_NAME/rootfs.tar"
 
 # Unmount & remove fuse loop devices
 umount_wait
index 342860ee06f5d4bcb58b56d94b25263bfac72149..2bb46dc5b22c8c42268e0b1b489cc31b6cb9756c 100755 (executable)
@@ -20,6 +20,7 @@ cleanup(){
     true <"$rootfs/dev/zero"
     rm "$rootfs/dev/zero"
   fi
+  rm -f "$rootfs"/usr/sbin/policy-rc.d
 }
 trap cleanup EXIT TERM INT
 
@@ -67,6 +68,11 @@ then
   ) & zero_PID=$!
 fi
 
+cat >"$rootfs"/usr/sbin/policy-rc.d <<EOF
+#!/bin/sh
+exit 101
+EOF
+chmod +x "$rootfs"/usr/sbin/policy-rc.d
 
 # Enter the chroot
 if [ "$AARCH64_EXECUTABLE" = yes ]
@@ -78,5 +84,6 @@ else
 fi
 
 rm -f "$rootfs$qemu_aarch64_static_binary"
+rm -f "$rootfs"/usr/sbin/policy-rc.d
 
 ) 9>"$rootfs/chroot_access_lock"
index 0d5fb0bc372615b82d21eb716154f7263f2d8dc5..cc975a834e5e105ae947fa6eafcbaa5da03d977b 100755 (executable)
@@ -22,11 +22,13 @@ fi
 # Set release repo if not already defined
 if [ -z "$DISTRO" ]; then DISTRO=devuan; fi
 if [ -z "$RELEASE" ]; then RELEASE=ascii; fi
+if [ -z "$VARIANT" ]; then VARIANT=base; fi
+if [ -z "$IMAGE_NAME" ]; then IMAGE_NAME="$DISTRO-$RELEASE-librem5-devkit-$(VARIANT).img"; fi
 if [ -z "$REPO" ]; then REPO=https://pkgmaster.devuan.org/merged/; fi
 if [ -z "$CHROOT_REPO" ]; then CHROOT_REPO="$REPO"; fi
 if [ -z "$KERNEL_DTB" ]; then echo "Pleas set KERNEL_DTB" >2; exit 1; fi
 
-tmp="$base/build/$DISTRO/$RELEASE/"
+tmp="$base/build/$IMAGE_NAME/"
 
 # Cleanup if any of the remaining steps fails
 cleanup(){
@@ -46,10 +48,34 @@ sanitize_pkg_list(){
   sed 's/#.*//' | tr '\n' ',' | sed 's/\(,\|\s\)\+/,/g' | sed 's/^,\+\|,\+$//g'
 }
 
-packages_download_only="$(sanitize_pkg_list < packages_download_only)"
-packages_second_stage="$(sanitize_pkg_list < packages_install_target)"
-packages_early="$(sanitize_pkg_list < packages_install_early)"
-packages="$(sanitize_pkg_list < packages_install_debootstrap)"
+packages=
+packages_early=
+packages_second_stage=
+packages_download_only=
+
+mkdir -p "$tmp/rootfs/root/post_debootstrap/"
+
+i=0
+for spec in "default" "default::$VARIANT" "$DISTRO-$RELEASE::$VARIANT" "$DISTRO-$RELEASE" "$DISTRO::$VARIANT" "$DISTRO"
+do
+  i="$(expr "$i" + 1)"
+  packages_base="packages/$spec/"
+  if [ -f "$packages_base/install_debootstrap" ]
+    then packages="$packages $(sanitize_pkg_list < "$packages_base/install_debootstrap")"
+  fi
+  if [ -f "$packages_base/download" ]
+    then packages_download_only="$packages_download_only $(sanitize_pkg_list < "$packages_base/download")"
+  fi
+  if [ -f "$packages_base/install_early" ]
+    then packages_early="$packages_early $(sanitize_pkg_list < "$packages_base/install_early")"
+  fi
+  if [ -f "$packages_base/install_second_stage" ]
+    then packages_second_stage="$packages_second_stage $(sanitize_pkg_list < "$packages_base/install_second_stage")"
+  fi
+  if [ -x "$packages_base/post_debootstrap" ]
+    then cp "$packages_base/post_debootstrap" "$tmp/rootfs/root/post_debootstrap/$i-$spec.sh"
+  fi
+done
 
 if [ "$AARCH64_EXECUTABLE" != yes ]
   then packages="$packages,fakechroot"
@@ -85,16 +111,22 @@ cp chroot-build-helper/bin/"$DISTRO"/"$RELEASE"/deb-*/*.deb "$tmp/rootfs/root/te
   find | while IFS= read -r file
   do
     file="$(printf "%s" "$file" | sed 's|::[^/]*$||')"
-    source="$file"
-    if   [ -e "$file::$DISTRO-$RELEASE" ]
+    if   [ -e "$file::$DISTRO-$RELEASE::$VARIANT" ]
+      then source="$file::$DISTRO-$RELEASE::$VARIANT"
+    elif [ -e "$file::$DISTRO-$RELEASE" ]
       then source="$file::$DISTRO-$RELEASE"
+    elif [ -e "$file::$DISTRO::$VARIANT" ]
+      then source="$file::$DISTRO::$VARIANT"
     elif [ -e "$file::$DISTRO" ]
       then source="$file::$DISTRO"
+    elif [ -e "$file::$VARIANT" ]
+      then source="$file::$VARIANT"
+    elif [ -e "$file" ]
+      then source="$file"
+      else continue
     fi
     if [ -d "$source" ]
-    then
-      mkdir -p "$tmp/rootfs/$source"
-      continue
+      then continue
     fi
     dir="$tmp/rootfs/$(dirname "$source")"
     mkdir -p "$dir"
@@ -118,7 +150,11 @@ echo "$packages_second_stage" | tr ',' '\n' > "$tmp/rootfs/root/packages_to_inst
 
 # Temporary source list
 (
-  CHROOT_REPO="$REPO" ./script/getrfsfile.sh "etc/apt/sources.list"
+  export CHROOT_REPO="$REPO" 
+  ./script/getrfsfile.sh "rootfs_custom_files/etc/apt/sources.list"
+  for file in "rootfs_custom_files/etc/apt/sources.list.d/"*
+    do ./script/getrfsfile.sh "$(printf "%s" "$file" | sed 's|::[^/]*$||')" || true
+  done
   echo
   echo 'deb file:///root/temp-repo/ ./'
 ) >"$tmp/rootfs/root/temporary-local-repo.list"
index 5153562701e2ac45ecaecb3e16e7bd2cff2f37cf..f4d92b93dc670470520928f385f43f16520a8278 100755 (executable)
@@ -9,19 +9,31 @@ then
 fi
 
 # Make sure the current working directory is correct
-cd "$(dirname "$0")/../rootfs_custom_files/"
+cd "$(dirname "$0")/../"
 
 file="$1"
-if   [ -f "$file.in::$DISTRO-$RELEASE" ]
+if   [ -f "$file.in::$DISTRO-$RELEASE::$VARIANT" ]
+  then source="$file.in::$DISTRO-$RELEASE::$VARIANT"
+elif [ -f "$file.in::$DISTRO-$RELEASE" ]
   then source="$file.in::$DISTRO-$RELEASE"
+elif [ -f "$file::$DISTRO-$RELEASE::$VARIANT" ]
+  then source="$file::$DISTRO-$RELEASE::$VARIANT"
 elif [ -f "$file::$DISTRO-$RELEASE" ]
   then source="$file::$DISTRO-$RELEASE"
+elif [ -f "$file.in::$DISTRO::$VARIANT" ]
+  then source="$file.in::$DISTRO::$VARIANT"
 elif [ -f "$file.in::$DISTRO" ]
   then source="$file.in::$DISTRO"
+elif [ -f "$file::$DISTRO::$VARIANT" ]
+  then source="$file::$DISTRO::$VARIANT"
 elif [ -f "$file::$DISTRO" ]
   then source="$file::$DISTRO"
+elif [ -f "$file.in::$VARIANT" ]
+  then source="$file.in::$VARIANT"
 elif [ -f "$file.in" ]
   then source="$file.in"
+elif [ -f "$file::$VARIANT" ]
+  then source="$file::$VARIANT"
 elif [ -f "$file" ]
   then source="$file"
   else exit 1
index d0cdc530b1af96d97095c37c2c0f8192eba5d7f9..ef6d9e4353d223df9352068fcfba48c0d532577e 100755 (executable)
@@ -27,6 +27,14 @@ export APT_CONFIG=/root/apt-tmp.conf
 
 export DEBIAN_FRONTEND=noninteractive
 
+# run post_debootstrap scripts
+for pdscript in /root/post_debootstrap/*
+do
+  if [ -x "$pdscript" ]
+    then "$pdscript"
+  fi
+done
+
 # Update package list, update everything, install kernel & other custom packages and clean apt cache (remove no longer needed packages)
 apt-get update
 apt-get -y dist-upgrade
@@ -43,6 +51,7 @@ dpkg-reconfigure $(dpkg-query -f '${db:Status-Abbrev} ${binary:Package}\n' -W li
 (
   IFS=", "
   apt-get -y install $install_packages
+  apt-get clean
   for package in $packages
   do
     apt-get -d -y install "$package"
index 60b373484486a83bf8e74b2c45475ba552b44bef..08e9132f9a5ed3a434b871c929dafab0dff1b8a3 100644 (file)
@@ -35,6 +35,10 @@ ifdef REPO-$(DISTRO)-$(RELEASE)
   REPO = $(REPO-$(DISTRO)-$(RELEASE))
 endif
 
+ifdef REPO-$(DISTRO)-$(RELEASE)-$(VARIANT)
+  REPO = $(REPO-$(DISTRO)-$(RELEASE)-$(VARIANT))
+endif
+
 ifdef CHROOT_REPO-$(DISTRO)
   CHROOT_REPO = $(CHROOT_REPO-$(DISTRO))
 endif
@@ -43,6 +47,10 @@ ifdef CHROOT_REPO-$(DISTRO)-$(RELEASE)
   CHROOT_REPO = $(CHROOT_REPO-$(DISTRO)-$(RELEASE))
 endif
 
+ifdef CHROOT_REPO-$(DISTRO)-$(RELEASE)-$(VARIANT)
+  CHROOT_REPO = $(CHROOT_REPO-$(DISTRO)-$(RELEASE)-$(VARIANT))
+endif
+
 CONFIG_VARS := $(sort $(filter-out $(VARS_OLD) VARS_OLD,$(subst %,,$(subst *,,$(.VARIABLES)))))
 IMGSIZE := $(shell echo "$(IMGSIZE)" | sed 's/\s*//g')
 export $(CONFIG_VARS)