From 5c619086a172aea5438c1e3a76fde1f5d56df3b1 Mon Sep 17 00:00:00 2001 From: Didier Roche Date: Wed, 22 Apr 2015 09:34:26 +0100 Subject: [PATCH] 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