From 5c619086a172aea5438c1e3a76fde1f5d56df3b1 Mon Sep 17 00:00:00 2001 From: Didier Roche Date: Wed, 22 Apr 2015 09:34:26 +0100 Subject: [PATCH 1/6] Create hooks for the ubuntu-desktop-next new based on snappy image. --- debian/changelog | 6 + .../hooks/00-uid-gid-fix.chroot_early | 241 ++++++++++++++++++ .../hooks/01-setup_user.chroot | 37 +++ .../hooks/02-add_user_to_groups.chroot | 8 + .../hooks/03-boot_with_systemd.chroot | 11 + .../hooks/04-configure_network.chroot | 9 + .../hooks/05-create_minimal_fstab.chroot | 6 + .../07-configure-system-image-client.chroot | 7 + .../hooks/08-etc-writable.chroot | 15 ++ .../hooks/10-remove-documentation.binary | 22 ++ .../hooks/14-set-motd.chroot | 14 + .../hooks/15-remove-grub-common.chroot | 4 + .../hooks/400-create-apt-get-warning.binary | 19 ++ .../500-move-kernel-to-device-tar.binary | 108 ++++++++ .../hooks/99zz-check-uid-gid.chroot | 52 ++++ 15 files changed, 559 insertions(+) create mode 100755 live-build/ubuntu-desktop-next/hooks/00-uid-gid-fix.chroot_early create mode 100755 live-build/ubuntu-desktop-next/hooks/01-setup_user.chroot create mode 100755 live-build/ubuntu-desktop-next/hooks/02-add_user_to_groups.chroot create mode 100755 live-build/ubuntu-desktop-next/hooks/03-boot_with_systemd.chroot create mode 100755 live-build/ubuntu-desktop-next/hooks/04-configure_network.chroot create mode 100755 live-build/ubuntu-desktop-next/hooks/05-create_minimal_fstab.chroot create mode 100755 live-build/ubuntu-desktop-next/hooks/07-configure-system-image-client.chroot create mode 100644 live-build/ubuntu-desktop-next/hooks/08-etc-writable.chroot create mode 100644 live-build/ubuntu-desktop-next/hooks/10-remove-documentation.binary create mode 100644 live-build/ubuntu-desktop-next/hooks/14-set-motd.chroot create mode 100644 live-build/ubuntu-desktop-next/hooks/15-remove-grub-common.chroot create mode 100644 live-build/ubuntu-desktop-next/hooks/400-create-apt-get-warning.binary create mode 100644 live-build/ubuntu-desktop-next/hooks/500-move-kernel-to-device-tar.binary create mode 100755 live-build/ubuntu-desktop-next/hooks/99zz-check-uid-gid.chroot diff --git a/debian/changelog b/debian/changelog index eb3798e2..2efd1adc 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,9 @@ +livecd-rootfs (2.299+desktopnext1) vivid; urgency=medium + + * Create hooks for the ubuntu-desktop-next new based on snappy image. + + -- Didier Roche Wed, 22 Apr 2015 09:32:15 +0100 + livecd-rootfs (2.299) vivid; urgency=medium * Fix snappy motd to not reference 'development', which isn't always true. diff --git a/live-build/ubuntu-desktop-next/hooks/00-uid-gid-fix.chroot_early b/live-build/ubuntu-desktop-next/hooks/00-uid-gid-fix.chroot_early new file mode 100755 index 00000000..00ff4e3f --- /dev/null +++ b/live-build/ubuntu-desktop-next/hooks/00-uid-gid-fix.chroot_early @@ -0,0 +1,241 @@ +#!/bin/sh -eu + +ERRCNT="" + +# Known good post-debootstrap values +passwd_bootstrap="af34a24499223f08ab713138bec7ff54" +shadow_bootstrap="1fd73103260cbe5a13a4a38320de4129" +group_bootstrap="9edf30f181a6fd1d860cc7f4a71aa640" +gshadow_bootstrap="b9db51ef767ab98db963db69844635dd" + +# Current post-debootstrap values +passwd_hash=$(set -- $(md5sum /etc/passwd) && echo $1) +shadow_hash=$(set -- $(cat /etc/shadow | sed "s/:.*:0:99999:/:0:99999:/g" | md5sum) && echo $1) +group_hash=$(set -- $(md5sum /etc/group) && echo $1) +gshadow_hash=$(set -- $(md5sum /etc/gshadow) && echo $1) + +# /etc/passwd +if [ "$passwd_bootstrap" = "$passwd_hash" ]; then + cat > /etc/passwd <&2 + echo "The output below might help to resolve the issue" >&2 + cat /etc/passwd + echo "passwd md5sum: $passwd_hash" >&2 + ERRCNT=1 +fi + +# /etc/shadow +if [ "$shadow_bootstrap" = "$shadow_hash" ]; then + cat > /etc/shadow <&2 + echo "The output below might help to resolve the issue" >&2 + cat /etc/shadow + echo "shadow md5sum: $shadow_hash" >&2 + ERRCNT=1 +fi + +# /etc/group +if [ "$group_bootstrap" = "$group_hash" ]; then + cat > /etc/group <&2 + echo "The output below might help to resolve the issue" >&2 + cat /etc/group + echo "group md5sum: $group_hash" >&2 + ERRCNT=1 +fi + +# /etc/gshadow +if [ "$gshadow_bootstrap" = "$gshadow_hash" ]; then + cat > /etc/gshadow <&2 + echo "The output below might help to resolve the issue" >&2 + cat /etc/gshadow + echo "gshadow md5sum: $gshadow_hash" >&2 + ERRCNT=1 +fi + +if [ -n "$ERRCNT" ]; then + echo "There were changes to the password database," >&2 + echo "please adjust the values in the livecd-rootfs source in the file:" >&2 + echo "live-build/ubuntu-core/hooks/00-uid-gid-fix.chroot_early" >&2 + echo >&2 + echo "Please check also if a maintainer script of the package" >&2 + echo "that added these entries perhaps created a home directory and," >&2 + echo "if needed, add code for creation of it to the above hook" >&2 + exit 1 +fi + + +# Record the current state for later comparison +for file in /etc/passwd /etc/shadow /etc/group /etc/gshadow; do + rm -f ${file}- + cp ${file} ${file}.orig +done diff --git a/live-build/ubuntu-desktop-next/hooks/01-setup_user.chroot b/live-build/ubuntu-desktop-next/hooks/01-setup_user.chroot new file mode 100755 index 00000000..967c6a1b --- /dev/null +++ b/live-build/ubuntu-desktop-next/hooks/01-setup_user.chroot @@ -0,0 +1,37 @@ +#!/bin/sh -x + +set -e + +USER=ubuntu +UGID=1000 + +echo "I: creating default user $USER" +adduser --gecos $USER --disabled-login $USER --uid $UGID + +chown -R $UGID:$UGID /home/$USER + +# Enable libnss-extrusers +sed -i 's/^group:.*compat/\0 extrausers/' /etc/nsswitch.conf +sed -i 's/^passwd:.*compat/\0 extrausers/' /etc/nsswitch.conf +sed -i 's/^shadow:.*compat/\0 extrausers/' /etc/nsswitch.conf + +# Move user from /etc to extrausers location +grep "^$USER" /etc/group >> /var/lib/extrausers/group +grep "^$USER" /etc/passwd >> /var/lib/extrausers/passwd +grep "^$USER" /etc/shadow >> /var/lib/extrausers/shadow +grep "^$USER" /etc/gshadow >> /var/lib/extrausers/gshadow +chmod 0644 /var/lib/extrausers/group +chmod 0644 /var/lib/extrausers/passwd +chmod 0640 /var/lib/extrausers/shadow +chmod 0640 /var/lib/extrausers/gshadow +chown root:shadow /var/lib/extrausers/shadow +chown root:shadow /var/lib/extrausers/gshadow +sed -i "/^$USER/d" /etc/group +sed -i "/^$USER/d" /etc/passwd +sed -i "/^$USER/d" /etc/shadow +sed -i "/^$USER/d" /etc/gshadow + +# needs to run *after* the user was moved out to /var/lib/extrausers +echo "I: set user $USER password to $USER" +echo "$USER:$USER" | chpasswd + diff --git a/live-build/ubuntu-desktop-next/hooks/02-add_user_to_groups.chroot b/live-build/ubuntu-desktop-next/hooks/02-add_user_to_groups.chroot new file mode 100755 index 00000000..104cd44c --- /dev/null +++ b/live-build/ubuntu-desktop-next/hooks/02-add_user_to_groups.chroot @@ -0,0 +1,8 @@ +#!/bin/sh -x + +USER=ubuntu + +DEFGROUPS="docker,sudo" + +echo "I: add $USER to ($DEFGROUPS) group(s)" +usermod -a -G ${DEFGROUPS} ${USER} diff --git a/live-build/ubuntu-desktop-next/hooks/03-boot_with_systemd.chroot b/live-build/ubuntu-desktop-next/hooks/03-boot_with_systemd.chroot new file mode 100755 index 00000000..f19164f0 --- /dev/null +++ b/live-build/ubuntu-desktop-next/hooks/03-boot_with_systemd.chroot @@ -0,0 +1,11 @@ +#!/bin/sh -x + +# Boot using systemd and disable quiet boot +# to see what is happening. +systemd=/lib/systemd/systemd +if [ -f /etc/default/grub ]; then + sed -i \ + -e "s,^\\([ ]*GRUB_CMDLINE_LINUX\\)=\"\"$,\\1=\"init=$systemd\",g" \ + -e 's,^\([ ]*GRUB_CMDLINE_LINUX_DEFAULT\)="quiet splash",\1="",g' \ + /etc/default/grub +fi diff --git a/live-build/ubuntu-desktop-next/hooks/04-configure_network.chroot b/live-build/ubuntu-desktop-next/hooks/04-configure_network.chroot new file mode 100755 index 00000000..d96d9aa8 --- /dev/null +++ b/live-build/ubuntu-desktop-next/hooks/04-configure_network.chroot @@ -0,0 +1,9 @@ +#!/bin/sh -x + +if=eth0 + +# Manually configure the first ethernet device +cat >/etc/network/interfaces.d/"$if"<>/etc/fstab</etc/motd<$PREFIX/usr/local/bin/no-apt < $TMPDIR/hardware.yaml << EOF +kernel: assets/vmlinuz +initrd: assets/initrd.img +partiton-layout: system-AB +EOF + +# arch specific ones +if [ "$ARCH" = "armhf" ]; then + cat >> $TMPDIR/hardware.yaml << EOF +dtbs: assets/dtbs +bootloader: u-boot +EOF +else + cat >> $TMPDIR/hardware.yaml << EOF +bootloader: grub +EOF +fi +) + +# and tar it up +( + cd $TMPDIR + tar -c -z -f $HERE/device.tar.gz system assets hardware.yaml +) + +# now build the azure device tarball by adding walinuxagent +if [ -e binary/boot/filesystem.dir/var/lib/dpkg/info/walinuxagent.list ]; +then +( + cd binary/boot/filesystem.dir + while read line; do + line=$(echo $line |cut -d/ -f2-) + if [ -e "$line" ] && [ ! -d "$line" ]; then + cp -ar --parent $line $TMPDIR/system + fi + done < var/lib/dpkg/info/walinuxagent.list + # created by walinuxagent postinst/dh-systemd + cp -ar --parent var/lib/systemd/deb-systemd-helper-enabled/walinuxagent* $TMPDIR/system + cp -ar --parent etc/systemd/system/multi-user.target.wants/walinuxagent* $TMPDIR/system + mkdir -p $TMPDIR/system/var/lib/waagent +) +# and tar it up +( + cd $TMPDIR + tar -c -z -f $HERE/device-azure.tar.gz system assets hardware.yaml +) +fi +rm -rf $TMPDIR + +# remove files from the root filesystem +(cd binary/boot/filesystem.dir + rm -f boot/vmlinu?-* + rm -f boot/initrd.img-* + rm -f boot/abi-* + rm -f boot/System.map-* + rm -f initrd.img + rm -f vmlinu? + rm -rf lib/modules + rm -rf lib/firmware + # remove walinuxagent + if [ -e var/lib/dpkg/info/walinuxagent.list ]; then + chroot . dpkg --purge walinuxagent || true + fi +) diff --git a/live-build/ubuntu-desktop-next/hooks/99zz-check-uid-gid.chroot b/live-build/ubuntu-desktop-next/hooks/99zz-check-uid-gid.chroot new file mode 100755 index 00000000..4d7b807d --- /dev/null +++ b/live-build/ubuntu-desktop-next/hooks/99zz-check-uid-gid.chroot @@ -0,0 +1,52 @@ +#!/bin/sh -eu + +ERRCNT="" + +passwd_hash=$(set -- $(md5sum /etc/passwd) && echo $1) +shadow_hash=$(set -- $(cat /etc/shadow | sed "s/:.*:0:99999:/:0:99999:/g" | md5sum) && echo $1) +group_length=$(cat /etc/group | wc -l) +gshadow_length=$(cat /etc/gshadow | wc -l) + +passwd_orig_hash=$(set -- $(md5sum /etc/passwd.orig) && echo $1) +shadow_orig_hash=$(set -- $(cat /etc/shadow.orig | sed "s/:.*:0:99999:/:0:99999:/g" | md5sum) && echo $1) +group_orig_length=$(cat /etc/group.orig | wc -l) +gshadow_orig_length=$(cat /etc/gshadow.orig | wc -l) + +if [ "$passwd_hash" != "$passwd_orig_hash" ]; then + echo "/etc/passwd has changed during setup." >&2 + echo "The new /etc/passwd md5sum is: $passwd_hash" >&2 + diff -Nrup /etc/passwd.orig /etc/passwd >&2 || true + ERRCNT=1 +fi + +if [ "$shadow_hash" != "$shadow_orig_hash" ]; then + echo "/etc/shadow has changed during setup." >&2 + echo "The new /etc/shadow md5sum is: $shadow_hash" >&2 + diff -Nrup /etc/shadow.orig /etc/shadow >&2 || true + ERRCNT=1 +fi + +if [ "$group_length" != "$group_orig_length" ]; then + echo "/etc/group has changed during setup." >&2 + diff -Nrup /etc/group.orig /etc/group >&2 || true + ERRCNT=1 +fi + +if [ "$gshadow_length" != "$gshadow_orig_length" ]; then + echo "/etc/gshadow has changed during setup." >&2 + diff -Nrup /etc/gshadow.orig /etc/gshadow >&2 || true + ERRCNT=1 +fi + +if [ -n "$ERRCNT" ]; then + echo "There were changes to the password database," >&2 + echo "please adjust the values in the livecd-rootfs source in the file:" >&2 + echo "live-build/ubuntu-core/hooks/00-uid-gid-fix.chroot_early" >&2 + echo >&2 + echo "Please check also if a maintainer script of the package" >&2 + echo "that added these entries perhaps created a home directory and," >&2 + echo "if needed, add code for creation of it to the above hook" >&2 + exit 1 +fi + +rm /etc/passwd.orig /etc/shadow.orig /etc/group.orig /etc/gshadow.orig From b35e94e457a919d5182c883abe036f08471eb1c2 Mon Sep 17 00:00:00 2001 From: Didier Roche Date: Wed, 22 Apr 2015 10:57:51 +0100 Subject: [PATCH 2/6] add build main configs --- live-build/auto/build | 11 +++++++++-- live-build/auto/config | 17 +++++++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/live-build/auto/build b/live-build/auto/build index 539ac7c2..f9e13169 100755 --- a/live-build/auto/build +++ b/live-build/auto/build @@ -329,8 +329,8 @@ if [ -e "binary/$INITFS/filesystem.packages-remove" ]; then fi fi -# ubuntu-core splits kernel stuff into a "device" tarball so at this point -# we reset it to "none" as all the work to extract it was done already +# ubuntu-core and ubuntu-desktop-next splits kernel stuff into a "device" tarball so +# at this point we reset it to "none" as all the work to extract it was done already # in a binary hook if [ "$PROJECT" = "ubuntu-core" ] && [ "$SUBPROJECT" = "system-image" ]; then LB_LINUX_FLAVOURS=none @@ -343,6 +343,13 @@ if [ "$PROJECT" = "ubuntu-core" ] && [ "$SUBPROJECT" = "system-image" ]; then mv device-azure.tar.gz "$PREFIX.azure.device.tar.gz" fi fi +if [ "$PROJECT" = "ubuntu-desktop-next" ] && [ "$SUBPROJECT" = "system-image" ]; then + LB_LINUX_FLAVOURS=none + + # rename to have the right prefix etc + mv device.tar.gz "$PREFIX.device.tar.gz" + +fi for FLAVOUR in $LB_LINUX_FLAVOURS; do if [ -z "$LB_LINUX_FLAVOURS" ] || [ "$LB_LINUX_FLAVOURS" = "none" ]; then diff --git a/live-build/auto/config b/live-build/auto/config index c11ea361..62639e7d 100755 --- a/live-build/auto/config +++ b/live-build/auto/config @@ -210,6 +210,23 @@ case $PROJECT in case $ARCH in amd64) add_package live linux-signed-generic ;; esac + + # system image snappy desktop next image + # mvo: This is for cron.daily-preinstalled + # CDIMAGE_PREINSTALLED is not passed from build.py + # and PREINSTALLED means something different. So + # we use SUBPROJECT to pass on the information + if [ "$SUBPROJECT" = "system-image" ]; then + add_task install ubuntu-core + + OPTS="${OPTS:+$OPTS }--linux-packages=linux-image" + + # contains the framework definition + add_package install ubuntu-core-libs + + # universe needed for 'system-image-cli' + COMPONENTS='main restricted universe' + fi ;; kubuntu|kubuntu-dvd) From 8a2102ae9822fe32e2644eb4c8c247ee43028b1d Mon Sep 17 00:00:00 2001 From: Didier Roche Date: Wed, 22 Apr 2015 10:58:28 +0100 Subject: [PATCH 3/6] update changelog --- debian/changelog | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/debian/changelog b/debian/changelog index 2efd1adc..07b56554 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,6 +1,7 @@ -livecd-rootfs (2.299+desktopnext1) vivid; urgency=medium +livecd-rootfs (2.299+desktopnext2) vivid; urgency=medium - * Create hooks for the ubuntu-desktop-next new based on snappy image. + * Create hooks and image build config for the ubuntu-desktop-next + new based on snappy image. -- Didier Roche Wed, 22 Apr 2015 09:32:15 +0100 From c59f8ebacd9e9c9d3cb12572b96d446199dd6227 Mon Sep 17 00:00:00 2001 From: Didier Roche Date: Wed, 22 Apr 2015 11:37:43 +0100 Subject: [PATCH 4/6] removed the part that is in the seed and ubiquity --- live-build/auto/config | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/live-build/auto/config b/live-build/auto/config index 62639e7d..b24e0178 100755 --- a/live-build/auto/config +++ b/live-build/auto/config @@ -162,7 +162,7 @@ if [ "$PREINSTALLED" = "true" ] && [ "$SUBPROJECT" != "wubi" ]; then ubuntu-server) add_package live oem-config-debconf ubiquity-frontend-debconf ;; - ubuntu-core|base|ubuntu-touch|ubuntu-cpc) + ubuntu-core|base|ubuntu-touch|ubuntu-cpc|ubuntu-deskop-next) ;; *) add_package live oem-config-gtk ubiquity-frontend-gtk @@ -217,13 +217,8 @@ case $PROJECT in # and PREINSTALLED means something different. So # we use SUBPROJECT to pass on the information if [ "$SUBPROJECT" = "system-image" ]; then - add_task install ubuntu-core - OPTS="${OPTS:+$OPTS }--linux-packages=linux-image" - # contains the framework definition - add_package install ubuntu-core-libs - # universe needed for 'system-image-cli' COMPONENTS='main restricted universe' fi From 7af419aa630231da735dd325015099c212ca94c9 Mon Sep 17 00:00:00 2001 From: Didier Roche Date: Wed, 22 Apr 2015 11:38:46 +0100 Subject: [PATCH 5/6] update changelog --- debian/changelog | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/debian/changelog b/debian/changelog index 07b56554..783f3e2a 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,4 +1,4 @@ -livecd-rootfs (2.299+desktopnext2) vivid; urgency=medium +livecd-rootfs (2.299+desktopnext3) vivid; urgency=medium * Create hooks and image build config for the ubuntu-desktop-next new based on snappy image. From db631a4d2fd8b22bcb3e9ac5b6a1b23ed4fdc2a5 Mon Sep 17 00:00:00 2001 From: Didier Roche Date: Wed, 22 Apr 2015 14:13:37 +0100 Subject: [PATCH 6/6] fix some typo and take colin's feedback into account --- live-build/auto/build | 7 +++++-- live-build/auto/config | 5 +---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/live-build/auto/build b/live-build/auto/build index f9e13169..ba39f171 100755 --- a/live-build/auto/build +++ b/live-build/auto/build @@ -332,7 +332,8 @@ fi # ubuntu-core and ubuntu-desktop-next splits kernel stuff into a "device" tarball so # at this point we reset it to "none" as all the work to extract it was done already # in a binary hook -if [ "$PROJECT" = "ubuntu-core" ] && [ "$SUBPROJECT" = "system-image" ]; then +case $PROJECT:$SUBPROJECT in + ubuntu-core:system-image|ubuntu-desktop-next:system-image) LB_LINUX_FLAVOURS=none # rename to have the right prefix etc @@ -342,7 +343,9 @@ if [ "$PROJECT" = "ubuntu-core" ] && [ "$SUBPROJECT" = "system-image" ]; then if [ -e device-azure.tar.gz ]; then mv device-azure.tar.gz "$PREFIX.azure.device.tar.gz" fi -fi + ;; +esac + if [ "$PROJECT" = "ubuntu-desktop-next" ] && [ "$SUBPROJECT" = "system-image" ]; then LB_LINUX_FLAVOURS=none diff --git a/live-build/auto/config b/live-build/auto/config index b24e0178..05de8695 100755 --- a/live-build/auto/config +++ b/live-build/auto/config @@ -162,7 +162,7 @@ if [ "$PREINSTALLED" = "true" ] && [ "$SUBPROJECT" != "wubi" ]; then ubuntu-server) add_package live oem-config-debconf ubiquity-frontend-debconf ;; - ubuntu-core|base|ubuntu-touch|ubuntu-cpc|ubuntu-deskop-next) + ubuntu-core|base|ubuntu-touch|ubuntu-cpc|ubuntu-desktop-next) ;; *) add_package live oem-config-gtk ubiquity-frontend-gtk @@ -218,9 +218,6 @@ case $PROJECT in # we use SUBPROJECT to pass on the information if [ "$SUBPROJECT" = "system-image" ]; then OPTS="${OPTS:+$OPTS }--linux-packages=linux-image" - - # universe needed for 'system-image-cli' - COMPONENTS='main restricted universe' fi ;;