From 1a7e628dedd16e275edaf0c3e117301471a1383a Mon Sep 17 00:00:00 2001 From: Daniel James Date: Thu, 9 May 2019 17:47:16 +0100 Subject: [PATCH] Fixes #12 - Install custom packages from additional repositories --- README.md | 11 +++++++---- bootstrap/0002_minimal.sh | 37 +++++++++++++++++++++++++++++++++++-- default-config | 3 ++- tasks/raspberry-pi-3.sh | 3 +++ 4 files changed, 47 insertions(+), 7 deletions(-) create mode 100644 tasks/raspberry-pi-3.sh diff --git a/README.md b/README.md index a19fdd7..9b1e6f2 100644 --- a/README.md +++ b/README.md @@ -37,7 +37,7 @@ The `dibby` script has three command line arguments, corresponding in turn to th 1. The _workspace_ is a directory on your local system which will contain your dibby project. This directory needs to be created before you run `dibby` for the first time. The workspace directory is kept separate from dibby itself, so your workspace can be public or private, depending on your project requirements. A dibby workspace can be developed collaboratively using your own git repository, if you wish. -2. The _config_ file is where you set the options for the target systems which will boot your dibby project image. This includes the CPU architecture for your dibby project, as well as the initial hostname and root password of the target devices. This file also enables you to specify a Debian preseed file and post-installation script, a custom package selection and custom tasks, using the following format: +2. The _config_ file is where you set the options for the target systems which will boot your dibby project image. This includes the CPU architecture for your dibby project, as well as the initial hostname and root password of the target devices. This file also enables you to specify a Debian preseed file and post-installation script, a custom package selection, custom tasks and a custom package mirror, using the following format: ``` CONFIG_ARCH="armhf" CONFIG_HOSTNAME="myhostname" @@ -45,7 +45,8 @@ CONFIG_ROOT_PASSWORD="myrootpassword" CONFIG_PRESEED="preseed.conf" CONFIG_POSTINST="postinst.sh" CONFIG_CUSTOM_PACKAGES="jackd2" -CONFIG_CUSTOM_TASKS="openssh-server" +CONFIG_CUSTOM_TASKS="raspberry-pi-3" +CONFIG_CUSTOM_MIRROR="https://apt.64studio.net/" ``` You can also pass options to `debootstrap` from the dibby project config file, including the mirror to obtain the Debian packages from, the base Debian suite for your project, and any Debian packages to exclude from the build: @@ -69,7 +70,7 @@ nano ~/myproject/myconfig sudo ./dibby ~/myproject myconfig mydebian.img ``` -Please be aware that the step _Unpacking the base system..._ can take a long time, depending on the speed of your build host. +Please be aware that the step _Unpacking the base system..._ can take a long time, depending on the speed of your build host. ### Creating unique images @@ -79,7 +80,9 @@ For example, you might wish to create a series of up-to-date Debian images which ### The tasks directory -The purpose of tasks in dibby is to set up modular components containing Debian packages and configurations for them that work well together, without having to specify each package and configuration option every time you create a new dibby project. Inside the _tasks_ directory (installed to `/usr/share/dibby/tasks/` when using the Debian package of dibby) you will find scripts which are run from the main `dibby` script. You can use these ready-made task scripts as they are, modify them, or create as many new tasks as you need. +The purpose of tasks in dibby is to set up modular components containing Debian packages and configurations for them that work well together, without having to specify each package and configuration option every time you create a new dibby project. These tasks can be generic, for any system, or they can target specific hardware such as the Raspberry Pi 3. + +Inside the _tasks_ directory (installed to `/usr/share/dibby/tasks/` when using the Debian package of dibby) you will find scripts which are run from the main `dibby` script. You can use these ready-made task scripts as they are, modify them, or create as many new tasks as you need. For example, during the development phase of your dibby project, you might wish to include an OpenSSH server in your build with remote root access by password to the target device. A script called `openssh-server.sh` is included in the _tasks_ directory for this purpose. (This approach is a more modular alternative to using `d-i preseed/late_command` in the preseed file, one which enables you to put your hacks for a particular package in the same task script which selects that package). diff --git a/bootstrap/0002_minimal.sh b/bootstrap/0002_minimal.sh index bac179d..a552977 100644 --- a/bootstrap/0002_minimal.sh +++ b/bootstrap/0002_minimal.sh @@ -1,4 +1,5 @@ # hostname +info "Setting hostname to $CONFIG_HOSTNAME" echo "$CONFIG_HOSTNAME" > $ROOTFS/etc/hostname # hosts file @@ -29,11 +30,21 @@ iface eth0 inet dhcp" >> $ROOTFS/etc/network/interfaces mkdir -p "$ROOTFS/mnt/workspace" mount --bind "$WORKSPACE" "$ROOTFS/mnt/workspace" -# setup main apt repository +# setup main apt and dibby repositories info "Setting up APT for $CONFIG_DEBOOTSTRAP_MIRROR" cat << EOF > $ROOTFS/etc/apt/sources.list deb $CONFIG_DEBOOTSTRAP_MIRROR $CONFIG_DEBOOTSTRAP_SUITE main contrib non-free deb-src $CONFIG_DEBOOTSTRAP_MIRROR $CONFIG_DEBOOTSTRAP_SUITE main contrib non-free + +deb https://apt.64studio.net/dibby $CONFIG_DEBOOTSTRAP_SUITE main +deb-src https://apt.64studio.net/dibby $CONFIG_DEBOOTSTRAP_SUITE main +EOF + +cat << EOF > $ROOTFS/etc/apt/preferences + + Package: * + Pin: origin "apt.64studio.net" + Pin-Priority: 1001 EOF if [ $CONFIG_DEBOOTSTRAP_SUITE = "buster" ] || @@ -41,9 +52,10 @@ if [ $CONFIG_DEBOOTSTRAP_SUITE = "buster" ] || [ $CONFIG_DEBOOTSTRAP_SUITE = "testing" ] || [ $CONFIG_DEBOOTSTRAP_SUITE = "stable" ] then - # setup additional apt repositories + # setup additional Debian apt repositories info "Adding update and debian-security repositories" cat << EOF >> $ROOTFS/etc/apt/sources.list + deb $CONFIG_DEBOOTSTRAP_MIRROR $CONFIG_DEBOOTSTRAP_SUITE-updates main contrib non-free deb-src $CONFIG_DEBOOTSTRAP_MIRROR $CONFIG_DEBOOTSTRAP_SUITE-updates main contrib non-free @@ -52,6 +64,27 @@ deb-src http://deb.debian.org/debian-security $CONFIG_DEBOOTSTRAP_SUITE/updates EOF fi +# setup custom apt repository and pin it to high priority +if [ -n "$CONFIG_CUSTOM_MIRROR" ]; then + +info "Setting up APT for $CONFIG_CUSTOM_MIRROR" +cat << EOF >> $ROOTFS/etc/apt/sources.list + +deb $CONFIG_CUSTOM_MIRROR $CONFIG_DEBOOTSTRAP_SUITE main +deb-src $CONFIG_CUSTOM_MIRROR $CONFIG_DEBOOTSTRAP_SUITE main +EOF + +CONFIG_CUSTOM_ORIGIN=$(echo $CONFIG_CUSTOM_MIRROR | sed 's;https://;;' | sed 's;http://;;' | sed 's;ftp://;;') + +cat << EOF >> $ROOTFS/etc/apt/preferences + + Package: * + Pin: origin "$CONFIG_CUSTOM_ORIGIN" + Pin-Priority: 1002 +EOF + +fi + # do not install recommended packages # TODO remove after? echo "APT::Install-Recommends \"0\"; diff --git a/default-config b/default-config index aa9fd79..7382e20 100644 --- a/default-config +++ b/default-config @@ -12,4 +12,5 @@ CONFIG_ROOT_PASSWORD="" CONFIG_PRESEED="" CONFIG_POSTINST="" CONFIG_CUSTOM_PACKAGES="" -CONFIG_CUSTOM_TASKS="" +CONFIG_CUSTOM_TASKS="raspberry-pi-3" +CONFIG_CUSTOM_MIRROR="" diff --git a/tasks/raspberry-pi-3.sh b/tasks/raspberry-pi-3.sh new file mode 100644 index 0000000..ca551a9 --- /dev/null +++ b/tasks/raspberry-pi-3.sh @@ -0,0 +1,3 @@ +# install raspberry pi 3 support packages from apt.64studio.net/dibby +chroot_exec apt-get install libraspberrypi0 libraspberrypi-bin linux-image-4.19.25-v7-raspberrypi-default raspberrypi-bootloader-nokernel --yes +