cleanup tmp file structure

This commit is contained in:
toby 2018-09-25 16:18:46 +00:00
parent 56ca407ad9
commit 8b68c136b8
1 changed files with 16 additions and 11 deletions

View File

@ -5,9 +5,15 @@ SIZE=10000
HOSTNAME=localhost
RELEASE=unstable
TMP_DIR=$PWD
TMP_DIR=${TMP_DIR:=$PWD}
MNT_DIR=$TMP_DIR/newroot
RESULT_DIR=${RESULT_DIR:=$TMP_DIR/files}
INITRD_DIR=$TMP_DIR/initramfs
RESULT_DIR=$TMP_DIR/files
[[ -d $MNT_DIR ]] || mkdir -p $MNT_DIR
[[ -d $INITRD_DIR ]] || mkdir -p $INITRD_DIR
[[ -d $RESULT_DIR ]] || mkdir -p $RESULT_DIR
# Configs overwritable via environment variables
@ -29,7 +35,6 @@ cancel() {
trap cancel INT
mkdir $MNT_DIR
if [ $FLAVOUR == "debian" ]; then
@ -156,11 +161,11 @@ chroot $MNT_DIR systemctl enable start-me-up || fail "failed to enable start-me-
##################
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
mkdir -p $INITRD_DIR/bin
wget -O $INITRD_DIR/bin/busybox https://www.busybox.net/downloads/binaries/1.26.1-defconfig-multiarch/busybox-x86_64
chmod +x $INITRD_DIR/bin/busybox
cat <<-"EOF" >$TMP_DIR/initramfs/init
cat <<-"EOF" >$INITRD_DIR/init
#!/bin/busybox sh
# Dump to sh if something fails
@ -202,12 +207,12 @@ cat <<-"EOF" >$TMP_DIR/initramfs/init
exec switch_root /newroot /sbin/init || error
EOF
chmod +x $TMP_DIR/initramfs/init
chmod +x $INITRD_DIR/init
tar -cJf $TMP_DIR/initramfs/rootfs.tar.xz -C $TMP_DIR/newroot .
tar -cJf $INITRD_DIR/rootfs.tar.xz -C $MNT_DIR .
cp $TMP_DIR/newroot/boot/vmlinuz-* $RESULT_DIR/vmlinuz
cd $TMP_DIR/initramfs
cp $MNT_DIR/boot/vmlinuz-* $RESULT_DIR/vmlinuz
cd $INITRD_DIR
find . -print0 | cpio --null -ov --format=newc | gzip -9 > $RESULT_DIR/initramfs.gz