Browse Source

Start reworking things for systemd-based 16.04

tags/nilmbuntu-5
Jim Paris 7 years ago
parent
commit
884e045cce
12 changed files with 137 additions and 111 deletions
  1. +1
    -1
      buildiso.sh
  2. +8
    -4
      config
  3. +0
    -17
      config-12.10
  4. +0
    -17
      config-13.04
  5. +0
    -17
      config-13.10
  6. +19
    -0
      config-16.04
  7. +13
    -12
      customize.sh
  8. +91
    -37
      enter.sh
  9. +1
    -1
      extractiso.sh
  10. +4
    -5
      full-rebuild.sh
  11. BIN
      nilmbuntu.png
  12. BIN
      splash.png

+ 1
- 1
buildiso.sh View File

@@ -37,7 +37,7 @@ sudo find ${ISO} -type f -print0 \
| grep -v md5sum.txt \
| sudo tee ${ISO}/md5sum.txt >/dev/null

sudo chown -R ${USER} ${ISO}
sudo chown -R ${NONPRIV_UID} ${ISO}

# build CD
xorriso -as mkisofs \


+ 8
- 4
config View File

@@ -2,8 +2,12 @@

if [ -z "$BUILD_CONFIG" ] ; then
echo "Set BUILD_CONFIG first"
exit 1
false
else
echo "Loading config file: config-$BUILD_CONFIG"
. config-$BUILD_CONFIG
# echo " Ubuntu version: ${VERSION}"
# echo " Input ISO: ${ISONAME}"
# echo " from: ${ORIGURL}"
# echo " Output ISO: ${OUTPUT}"
fi

echo "Loading config file: config-$BUILD_CONFIG"
. config-$BUILD_CONFIG

+ 0
- 17
config-12.10 View File

@@ -1,17 +0,0 @@
# output image
VERSION="12.10.2"
OUTPUT="nilmdbuntu-${VERSION}.iso"

# original ISOs
ISONAME="xubuntu-12.10-desktop-amd64.iso"
ORIG="tmp-12.10/$ISONAME"
ORIGURL="http://cdimage.ubuntu.com/xubuntu/releases/12.10/release/$ISONAME"

# work directories, temporary qemu HD image
FS="tmp-12.10/fs"
ISO="tmp-12.10/iso"
MNT="tmp-12.10/mnt"
DISK="tmp-12.10/disk.img"

# local user
USER=jim:jim

+ 0
- 17
config-13.04 View File

@@ -1,17 +0,0 @@
# output image
VERSION="13.04.2"
OUTPUT="nilmdbuntu-${VERSION}.iso"

# original ISOs
ISONAME="xubuntu-13.04-desktop-amd64.iso"
ORIG="tmp-13.04/$ISONAME"
ORIGURL="http://cdimage.ubuntu.com/xubuntu/releases/13.04/release/$ISONAME"

# work directories, temporary qemu HD image
FS="tmp-13.04/fs"
ISO="tmp-13.04/iso"
MNT="tmp-13.04/mnt"
DISK="tmp-13.04/disk.img"

# local user
USER=jim:jim

+ 0
- 17
config-13.10 View File

@@ -1,17 +0,0 @@
# output image
VERSION="13.10.2"
OUTPUT="nilmdbuntu-${VERSION}.iso"

# original ISOs
ISONAME="xubuntu-13.10-desktop-amd64.iso"
ORIG="tmp-13.10/$ISONAME"
ORIGURL="http://hex1a4.net/xubuntu-13.10-desktop-amd64.iso"

# work directories, temporary qemu HD image
FS="tmp-13.10/fs"
ISO="tmp-13.10/iso"
MNT="tmp-13.10/mnt"
DISK="tmp-13.10/disk.img"

# local user
USER=jim:jim

+ 19
- 0
config-16.04 View File

@@ -0,0 +1,19 @@
# -*- sh -*-

# output image
VERSION="16.04"
OUTPUT="nilmbuntu-${VERSION}.iso"

# original ISO
ISONAME="xubuntu-${VERSION}-desktop-amd64.iso"
ORIGURL="http://cdimage.ubuntu.com/xubuntu/releases/${VERSION}/release/${ISONAME}"

# work directories, temporary qemu HD image, etc. Shouldn't need to change these.
ORIG="tmp-${VERSION}/$ISONAME"
FS="tmp-${VERSION}/fs"
ISO="tmp-${VERSION}/iso"
MNT="tmp-${VERSION}/mnt"
DISK="tmp-${VERSION}/disk.img"

# non-privileged user, so we don't need to do everything as root
NONPRIV_UID=${SUDO_UID:-$UID}

+ 13
- 12
customize.sh View File

@@ -6,16 +6,16 @@ set -x

# Customize the outer ISO image
sed -i -s -e \
"s/DISKNAME.*/DISKNAME NilmDBuntu $VERSION by Jim Paris/" \
"s/DISKNAME.*/DISKNAME NILMbuntu $VERSION/" \
${ISO}/README.diskdefines

# The .disk/info file is important -- it's used by ubiquity to extract
# out the distro name in dialogs, and I think casper might use it too
echo "NilmDBuntu $VERSION by Jim Paris" > ${ISO}/.disk/info
echo "NILMbuntu $VERSION" > ${ISO}/.disk/info

# Set up preseed file
cp ${ISO}/preseed/xubuntu.seed ${ISO}/preseed/nilmdbuntu.seed
cat >> ${ISO}/preseed/nilmdbuntu.seed <<"EOF"
cp ${ISO}/preseed/xubuntu.seed ${ISO}/preseed/nilmbuntu.seed
cat >> ${ISO}/preseed/nilmbuntu.seed <<"EOF"
# Commands to run on successful install:
# - Regenerate SSH host keys
# - Remove "quiet splash" from grub command line
@@ -35,7 +35,8 @@ ubiquity ubiquity/success_command string \
umount /target/$i; done; \
echo "success_command done" >>/target/var/log/installer/postinst.log

# Default user. Ubiquity should let them change this
# Default user. Ubiquity should let them change this.
# (To skip the dialog completely, maybe set a password?)
d-i passwd/user-fullname string NILM User
d-i passwd/username string nilm
#d-i passwd/user-password password nilm
@@ -45,24 +46,24 @@ d-i passwd/auto-login boolean true
EOF

# Set up isolinux how we want by editing its config
TRY="Boot ^NilmDBuntu ${VERSION}"
TRY="Boot ^NILMbuntu ${VERSION}"
cp splash.png ${ISO}/isolinux/splash.png
perl -n -i \
-e '$n=1 if /^label/; $n=2 if /^label live-install/; next if $n==2;' \
-e "s/menu label.*(Try|NilmDBuntu).*/menu label $TRY/g;" \
-e "s,preseed/.*[.]seed,preseed/nilmdbuntu.seed,g;" \
-e "s/menu label.*(Try|NILM).*/menu label $TRY/g;" \
-e "s,preseed/.*[.]seed,preseed/nilmbuntu.seed,g;" \
-e "s/ quiet splash//g;" \
-e "print;" \
${ISO}/isolinux/txt.cfg
sed -i -s -e "s/^ui gfxboot/# ui gfxboot/g;" ${ISO}/isolinux/isolinux.cfg

# Set up grub similarly
TRY="Boot NilmDBuntu ${VERSION}"
TRY="Boot NILMbuntu ${VERSION}"
perl -n -i \
-e "next if /menuentry \"Install/../^}$/;" \
-e "next if /menuentry \"OEM install/../^}$/;" \
-e "s/menuentry \"(Try|NilmDBuntu).*\" {/menuentry \"${TRY}\" {/g;" \
-e "s,preseed/.*[.]seed,preseed/nilmdbuntu.seed,g;" \
-e "s/menuentry \"(Try|NILM).*\" \{/menuentry \"${TRY}\" {/g;" \
-e "s,preseed/.*[.]seed,preseed/nilmbuntu.seed,g;" \
-e "s/ quiet splash//g;" \
-e "print;" \
${ISO}/boot/grub/{grub,loopback}.cfg
@@ -70,7 +71,7 @@ perl -n -i \
if ! [ "$1" == "skip" ] ; then

# Run the customize-inner.sh script inside the chroot
sudo cp nilmdbuntu.png ${FS}/usr/share/xfce4/backdrops/nilmdbuntu.png
sudo cp nilmbuntu.png ${FS}/usr/share/xfce4/backdrops/nilmbuntu.png
sudo cp customize-inner.sh ${FS}/root/customize-inner.sh
sudo chmod +x ${FS}/root/customize-inner.sh
./enter.sh "cd /root ; ./customize-inner.sh"


+ 91
- 37
enter.sh View File

@@ -5,20 +5,75 @@ if [ $UID -ne 0 ] ; then
echo "Need to be root; trying sudo"
exec sudo env BUILD_CONFIG=$BUILD_CONFIG $0 "$@"
fi

# enter the chroot and run the command (if supplied) or a shell
. config || exit 0

# Spawn a systemd container that boots the machine, then run the given
# command. We can't execute systemd-nspawn directly, because that
# only allows us to either boot the machine, or run a command (not
# both). Instead let's execute systemd-nspawn in a transient systemd
# unit, then enter it using machinectl.

UNIT=nilmbuntu-run-$VERSION
MACH=nilmbuntu-$VERSION

kill_container() {
# Kill any running container
if systemctl --quiet is-active $UNIT ; then
echo "Stopping container..."
# We could use "machinectl terminate", but that will wait
# for a clean shutdown or timeout; we don't need a clean
# shutdown, so send a SIGTERM twice to get systemd-nspawn
# to terminate pretty quickly
systemctl kill $UNIT
sleep 2
systemctl kill $UNIT

# Then wait for it to really stop
systemctl stop $UNIT
fi

# If systemd-nspawn returned with a failure code,
# the transient service unit file will stick around,
# so make sure we clear that.
if systemctl --quiet is-failed $UNIT ; then
systemctl reset-failed $UNIT
fi
}

start_container() {
# Start the container
kill_container
echo "Starting container..."
systemd-run --unit=$UNIT systemd-nspawn \
--quiet \
--keep-unit \
--boot \
--directory $(realpath $FS) \
--machine $MACH
echo "Waiting..."
while ! machinectl status $MACH >/dev/null 2>&1 ; do
sleep 0.1
done
}

FAILED=0
run() {
# Run a command inside the container
echo "+" "$1"
chroot ${FS} env -i \
HOME=/root \
PATH=/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin \
TERM=$TERM \
IN_CHROOT=1 \
bash -c "$1"
RET=$?

# machinectl doesn't propagate return codes, so append something
# to the command that saves the result of what we ran.
echo "99" > $FS/jim-cmd-result
CMD="$1 ; echo \$? > /jim-cmd-result"

# Run it
env SYSTEMD_LOG_LEVEL=notice machinectl \
shell $MACH /usr/bin/env IN_CHROOT=1 \
bash -c "$CMD"

# Check result
RET=$(cat $FS/jim-cmd-result)
rm -f $FS/jim-cmd-result
if [ $RET -ne 0 ] && [ "$1" != "exec bash" ] ; then
printf "%s\n" "----------- WARNING: failed with exit code $RET"
FAILED=$RET
@@ -27,20 +82,19 @@ run() {
}

set -e
umount ${FS}/dev/pts || true
umount ${FS}/sys/kernel/security || true
umount ${FS}/sys || true
umount ${FS}/proc || true
mount -t proc none ${FS}/proc
mount -t sysfs none ${FS}/sys
mount -t devpts none ${FS}/dev/pts

run "echo 'nameserver 8.8.8.8' > /etc/resolv.conf"
run "dbus-uuidgen > /var/lib/dbus/machine-id"
run "dpkg-divert --local --rename --add /sbin/initctl"
run "ln -sf /bin/true /sbin/initctl"
run "dpkg-divert --local --rename --add /usr/sbin/update-grub"
run "ln -sf /bin/true /usr/sbin/update-grub"

start_container

run "resolvconf --disable-updates"
run "echo 'nameserver 8.8.8.8' > /run/resolvconf/resolv.conf"

#run "dbus-uuidgen > /var/lib/dbus/machine-id"
#run "dpkg-divert --local --rename --add /sbin/initctl"
#run "ln -sf /bin/true /sbin/initctl"
#run "dpkg-divert --local --rename --add /usr/sbin/update-grub"
#run "ln -sf /bin/true /usr/sbin/update-grub"

run "ping -c 5 google.com"

set +e
if [ -z "$1" ] ; then
@@ -48,21 +102,21 @@ if [ -z "$1" ] ; then
else
run "$1"
fi

echo "Cleaning up..."

run "apt-get clean"
run "rm /sbin/initctl"
run "dpkg-divert --rename --remove /sbin/initctl"
run "rm /usr/sbin/update-grub"
run "dpkg-divert --rename --remove /usr/sbin/update-grub"
run "rm /var/lib/dbus/machine-id"
run "> /etc/resolv.conf"
run "rm -rf /tmp/* /tmp/.??* /root/.bash_history"

umount ${FS}/dev/pts
umount ${FS}/sys/kernel/security || true
umount ${FS}/sys
umount ${FS}/proc

echo "cleaned up"
#run "rm /sbin/initctl"
#run "dpkg-divert --rename --remove /sbin/initctl"
#run "rm /usr/sbin/update-grub"
#run "dpkg-divert --rename --remove /usr/sbin/update-grub"
#run "rm /var/lib/dbus/machine-id"
#run "> /etc/resolv.conf"
run "rm -f /root/.bash_history"

kill_container

echo "Done"
if [ $FAILED -ne 0 ] ; then
exit $FAILED
fi


+ 1
- 1
extractiso.sh View File

@@ -29,7 +29,7 @@ sudo mount -o loop,ro "$ORIG" ${MNT}
# copy data
sudo mkdir ${ISO}
sudo rsync --exclude=/casper/filesystem.squashfs -a ${MNT}/ ${ISO}
sudo chown -R ${USER} ${ISO}
sudo chown -R ${NONPRIV_UID} ${ISO}
chmod -R u+w ${ISO}

# copy squashfs


+ 4
- 5
full-rebuild.sh View File

@@ -11,13 +11,12 @@ fi

set -e

#rm -f ${OUTPUT}
./cleanup.sh
for d in ${ORIG} ${OUTPUT} ${DISK} ; do
mkdir -p $(dirname $d)
chown ${USER} $(dirname $d)
chown ${NONPRIV_UID} $(dirname $d)
done
./extractiso.sh
./customize.sh
./buildiso.sh
chown ${USER} ${ORIG} ${OUTPUT}
#./customize.sh
#./buildiso.sh
#chown ${NONPRIV_UID} ${ORIG} ${OUTPUT}

BIN
nilmdbuntu.png → nilmbuntu.png View File

Before After
Width: 1920  |  Height: 1200  |  Size: 599 KiB Width: 1920  |  Height: 1200  |  Size: 589 KiB

BIN
splash.png View File

Before After
Width: 640  |  Height: 480  |  Size: 1.4 KiB Width: 640  |  Height: 480  |  Size: 1.1 KiB

Loading…
Cancel
Save