re-structuring everything to make it look more like a package that one can build, also adding syslinux pxe configs and cleanup

This commit is contained in:
toby 2018-09-24 21:02:44 +00:00
parent d02b2eba2c
commit d2083c622d
9 changed files with 119 additions and 130 deletions

View File

@ -3,9 +3,8 @@ pipeline:
image: registry.v1.cloud.wit.com/toby/packager:1.3
commands:
- export DEBNAME=wit-pxeboot
- export RESULT_DIR=/tmp/result
- echo "$DEBNAME (1.0.$(date +%Y.%m.%d.%H.%M)) unstable; urgency=low\n\n$(git log --format=" * %s")\n\n -- wit <netops@wit.com> $(date -R)" >debian/changelog
- ./create_pxeinitrd.sh
- cd $RESULT_DIR
- dpkg-buildpackage --no-sign
- ls -lha ../$DEBNAME_*_all.deb
- echo "$SSH_KEY" >/tmp/id_rsa

View File

@ -1,15 +1,13 @@
#!/bin/bash
set -Eeuxo pipefail
DEBNAME=${DEBNAME:=wit-pxeboot}
SIZE=10000
HOSTNAME=localhost
RELEASE=unstable
TMP_DIR=$(mktemp -d)
TMP_DIR=$PWD
MNT_DIR=$TMP_DIR/newroot
RESULT_DIR=${RESULT_DIR:=/tmp/result}
RESULT_DIR=${RESULT_DIR:=$TMP_DIR/files}
# Configs overwritable via environment variables
@ -19,12 +17,7 @@ MIRROR=${MIRROR:="https://mirrors.wit.com/debian"}
ARCH=${ARCH:=amd64}
clean_debian() {
[ "$TMP_DIR" != "" ] && rm -r $TMP_DIR
}
fail() {
clean_debian
echo ""
echo "FAILED: $1"
exit 1
@ -167,73 +160,6 @@ chroot $MNT_DIR systemctl enable start-me-up || fail "failed to enable start-me-
###############
## deb build ##
###############
mkdir -p $RESULT_DIR/debian
echo -e "$DEBNAME (1.0.$(date +%Y.%m.%d.%H.%M)) unstable; urgency=low\n\n$(git log --format=" * %s")\n\n -- wit <netops@wit.com> $(date -R)" >$RESULT_DIR/debian/changelog
echo "11" >$RESULT_DIR/debian/compat
cat <<EOF >$RESULT_DIR/debian/$DEBNAME.install
./vmlinuz /srv/tftp/wit-pxeboot/
./initramfs.gz /srv/tftp/wit-pxeboot/
EOF
cat <<EOF >$RESULT_DIR/debian/control
Source: $DEBNAME
Section: unknown
Priority: optional
Maintainer: wit <netops@wit.com>
Build-Depends: debhelper (>= 11)
Standards-Version: 4.1.3
Homepage: http://www.wit.com
Package: $DEBNAME
Architecture: all
Depends: \${misc:Depends}, tftpd-hpa
Description: kernel and initrd to pxeboot debcore
kernel and initrd to boot a pxe image easily
it also includes a rootfs to quickly kickstart
a local install
EOF
cat <<"EOF" >$RESULT_DIR/debian/rules
#!/usr/bin/make -f
# See debhelper(7) (uncomment to enable)
# output every command that modifies files on the build system.
#export DH_VERBOSE = 1
# see FEATURE AREAS in dpkg-buildflags(1)
#export DEB_BUILD_MAINT_OPTIONS = hardening=+all
# see ENVIRONMENT in dpkg-buildflags(1)
# package maintainers to append CFLAGS
#export DEB_CFLAGS_MAINT_APPEND = -Wall -pedantic
# package maintainers to append LDFLAGS
#export DEB_LDFLAGS_MAINT_APPEND = -Wl,--as-needed
%:
dh $@
# dh_make generated override targets
# This is example for Cmake (See https://bugs.debian.org/641051 )
#override_dh_auto_configure:
# dh_auto_configure -- # -DCMAKE_LIBRARY_PATH=$(DEB_HOST_MULTIARCH)
EOF
##################
## build initrd ##
@ -244,69 +170,61 @@ mkdir -p $TMP_DIR/initramfs/bin
wget -O $TMP_DIR/initramfs/bin/busybox https://www.busybox.net/downloads/binaries/1.26.1-defconfig-multiarch/busybox-x86_64
chmod +x $TMP_DIR/initramfs/bin/busybox
cat > $TMP_DIR/initramfs/init << EOF
#!/bin/busybox sh
# Dump to sh if something fails
error() {
echo "Jumping into the shell..."
setsid cttyhack sh
}
# Populate /bin with binaries from busybox
/bin/busybox --install /bin
mkdir -p /proc
mount -t proc proc /proc
mkdir -p /sys
mount -t sysfs sysfs /sys
mkdir -p /sys/dev
mkdir -p /var/run
mkdir -p /dev
mkdir -p /dev/pts
mount -t devpts devpts /dev/pts
# Populate /dev
echo /bin/mdev > /proc/sys/kernel/hotplug
mdev -s
mkdir -p /newroot
mount -t tmpfs -o size=${SIZE}m tmpfs /newroot || error
echo "Extracting rootfs... "
xz -d -c -f rootfs.tar.xz | tar -x -f - -C /newroot || error
mount --move /sys /newroot/sys
mount --move /proc /newroot/proc
mount --move /dev /newroot/dev
exec switch_root /newroot /sbin/init || error
cat <<-"EOF" >$TMP_DIR/initramfs/init
#!/bin/busybox sh
# Dump to sh if something fails
error() {
echo "Jumping into the shell..."
setsid cttyhack sh
}
# Populate /bin with binaries from busybox
/bin/busybox --install /bin
mkdir -p /proc
mount -t proc proc /proc
mkdir -p /sys
mount -t sysfs sysfs /sys
mkdir -p /sys/dev
mkdir -p /var/run
mkdir -p /dev
mkdir -p /dev/pts
mount -t devpts devpts /dev/pts
# Populate /dev
echo /bin/mdev > /proc/sys/kernel/hotplug
mdev -s
mkdir -p /newroot
mount -t tmpfs -o size=${SIZE}m tmpfs /newroot || error
echo "Extracting rootfs... "
xz -d -c -f rootfs.tar.xz | tar -x -f - -C /newroot || error
mount --move /sys /newroot/sys
mount --move /proc /newroot/proc
mount --move /dev /newroot/dev
exec switch_root /newroot /sbin/init || error
EOF
chmod +x $TMP_DIR/initramfs/init
cd $TMP_DIR/newroot
tar cJf $TMP_DIR/initramfs/rootfs.tar.xz .
cd $TMP_DIR/initramfs
mkdir -p $RESULT_DIR
find . -print0 | cpio --null -ov --format=newc | gzip -9 > $RESULT_DIR/initramfs.gz
tar -cJf $TMP_DIR/initramfs/rootfs.tar.xz -C $TMP_DIR/newroot .
cp $TMP_DIR/newroot/boot/vmlinuz-* $RESULT_DIR/vmlinuz
cd $TMP_DIR/initramfs
find . -print0 | cpio --null -ov --format=newc | gzip -9 > $RESULT_DIR/initramfs.gz
ls -la $RESULT_DIR/
#############
## cleanup ##
#############
clean_debian
exit 0

1
debian/compat vendored Normal file
View File

@ -0,0 +1 @@
11

15
debian/control vendored Normal file
View File

@ -0,0 +1,15 @@
Source: wit-pxeboot
Section: unknown
Priority: optional
Maintainer: wit <netops@wit.com>
Build-Depends: debhelper (>= 11)
Standards-Version: 4.1.3
Homepage: http://www.wit.com
Package: wit-pxeboot
Architecture: all
Depends: ${misc:Depends}, tftpd-hpa
Description: kernel and initrd to pxeboot debcore
kernel and initrd to boot a pxe image easily
it also includes a rootfs to quickly kickstart
a local install

25
debian/rules vendored Executable file
View File

@ -0,0 +1,25 @@
#!/usr/bin/make -f
# See debhelper(7) (uncomment to enable)
# output every command that modifies files on the build system.
#export DH_VERBOSE = 1
# see FEATURE AREAS in dpkg-buildflags(1)
#export DEB_BUILD_MAINT_OPTIONS = hardening=+all
# see ENVIRONMENT in dpkg-buildflags(1)
# package maintainers to append CFLAGS
#export DEB_CFLAGS_MAINT_APPEND = -Wall -pedantic
# package maintainers to append LDFLAGS
#export DEB_LDFLAGS_MAINT_APPEND = -Wl,--as-needed
%:
dh $@
# dh_make generated override targets
# This is example for Cmake (See https://bugs.debian.org/641051 )
#override_dh_auto_configure:
# dh_auto_configure -- # -DCMAKE_LIBRARY_PATH=$(DEB_HOST_MULTIARCH)

5
debian/wit-pxeboot.install vendored Normal file
View File

@ -0,0 +1,5 @@
files/vmlinuz /srv/tftp/wit-pxeboot/
files/initramfs.gz /srv/tftp/wit-pxeboot/
files/debcore /srv/tftp/wit-pxeconfig/
files/install /srv/tftp/wit-pxeconfig/
files/localboot /srv/tftp/wit-pxeconfig/

9
files/debcore Normal file
View File

@ -0,0 +1,9 @@
serial 1 115200
prompt 1
timeout 100
default debcore
label debcore
kernel wit-pxeboot/vmlinuz
append initrd=wit-pxeboot/initramfs.gz acpi=off console=tty0 console=ttyS1,115200n8 ---

9
files/install Normal file
View File

@ -0,0 +1,9 @@
serial 1 115200
prompt 1
timeout 100
default install
label install
kernel wit-pxeboot/vmlinuz
append initrd=wit-pxeboot/initramfs.gz acpi=off console=tty0 console=ttyS1,115200n8 execstartup='sleep 60; /root/install.sh wit-network-config && echo -e "======\nSUCCESS\n======" || exit 1' ---

8
files/localboot Normal file
View File

@ -0,0 +1,8 @@
serial 1 115200
prompt 1
timeout 100
default local
label local
LOCALBOOT -1