2018-09-24 08:54:24 -05:00
|
|
|
#!/bin/bash
|
|
|
|
set -Eeuxo pipefail
|
|
|
|
|
2018-09-25 11:18:46 -05:00
|
|
|
TMP_DIR=${TMP_DIR:=$PWD}
|
2018-09-24 08:54:24 -05:00
|
|
|
MNT_DIR=$TMP_DIR/newroot
|
2018-09-25 11:18:46 -05:00
|
|
|
INITRD_DIR=$TMP_DIR/initramfs
|
|
|
|
RESULT_DIR=$TMP_DIR/files
|
2019-01-08 15:39:49 -06:00
|
|
|
KERNEL_DIR=$RESULT_DIR/kernel
|
2018-09-25 11:18:46 -05:00
|
|
|
|
|
|
|
[[ -d $MNT_DIR ]] || mkdir -p $MNT_DIR
|
|
|
|
[[ -d $INITRD_DIR ]] || mkdir -p $INITRD_DIR
|
|
|
|
[[ -d $RESULT_DIR ]] || mkdir -p $RESULT_DIR
|
2019-01-08 15:39:49 -06:00
|
|
|
[[ -d $KERNEL_DIR ]] || mkdir -p $KERNEL_DIR
|
2018-09-24 08:54:24 -05:00
|
|
|
|
|
|
|
# Configs overwritable via environment variables
|
2019-02-25 12:43:55 -06:00
|
|
|
ROOTPASSWD=${ROOTPASSWD:='$6$LmI1TuCG$YRTAdn/Ht7v1kNdkb8HFXV4S7Sau571DD3kaBWltX72OSo21P7ON9JRw4XepjsBQ0FzzBebfsdQ4YfH9M2CaN0'} ## wit
|
2018-09-27 07:54:05 -05:00
|
|
|
RELEASE=${RELEASE:=unstable}
|
2018-09-24 08:54:24 -05:00
|
|
|
FLAVOUR=${FLAVOUR:=debian} # Either 'debian' or 'ubuntu'
|
2019-02-08 15:25:56 -06:00
|
|
|
INCLUDES=${INCLUDES:="openssh-server,init,curl,parted,xz-utils,vim,locales-all,less,dmidecode,iputils-ping,fping,tcpdump,rsync,ethtool,lldpd,iproute2,net-tools,sudo,gnupg,tcpdump,mtr-tiny,ifupdown,ipmitool,iptables,telnet,netcat,bridge-utils,vlan,ifstat,ncurses-term,wget,pciutils,dhcpcd5,python,efibootmgr,busybox-static,firmware-qlogic"}
|
2018-09-24 08:54:24 -05:00
|
|
|
MIRROR=${MIRROR:="https://mirrors.wit.com/debian"}
|
2019-02-24 18:23:30 -06:00
|
|
|
DEBCORE_INCLUDES=${DEBCORE_INCLUDES:="wit-start-me-up"}
|
2018-09-24 08:54:24 -05:00
|
|
|
|
|
|
|
|
|
|
|
fail() {
|
|
|
|
echo ""
|
|
|
|
echo "FAILED: $1"
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
|
|
|
cancel() {
|
|
|
|
fail "CTRL-C detected"
|
|
|
|
}
|
|
|
|
|
|
|
|
trap cancel INT
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if [ $FLAVOUR == "debian" ]; then
|
|
|
|
BOOT_PKG="linux-image-$ARCH"
|
|
|
|
elif [ $FLAVOUR == "ubuntu" ]; then
|
|
|
|
BOOT_PKG="linux-image-generic"
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
###################
|
|
|
|
## build root fs ##
|
|
|
|
###################
|
|
|
|
|
|
|
|
|
|
|
|
echo "Installing Debian $RELEASE..."
|
2019-02-08 15:39:04 -06:00
|
|
|
debootstrap --variant=minbase --components=main,contrib,non-free --include=$INCLUDES,$BOOT_PKG $RELEASE $MNT_DIR $MIRROR || fail "cannot install $RELEASE"
|
2018-09-24 08:54:24 -05:00
|
|
|
|
2019-01-09 13:04:09 -06:00
|
|
|
echo localhost > $MNT_DIR/etc/hostname
|
2018-09-24 08:54:24 -05:00
|
|
|
|
|
|
|
cat <<EOF > $MNT_DIR/etc/hosts
|
|
|
|
127.0.0.1 localhost
|
|
|
|
# The following lines are desirable for IPv6 capable hosts
|
|
|
|
::1 localhost ip6-localhost ip6-loopback
|
|
|
|
ff02::1 ip6-allnodes
|
|
|
|
ff02::2 ip6-allrouters
|
|
|
|
EOF
|
|
|
|
|
2019-01-09 13:04:09 -06:00
|
|
|
echo "ipv4: \4 ipv6: \6" >>$MNT_DIR/etc/issue
|
2018-09-24 08:54:24 -05:00
|
|
|
|
|
|
|
rm -f $MNT_DIR/etc/apt/sources.list
|
|
|
|
echo 'deb https://mirrors.wit.com/debian sid main contrib non-free' > $MNT_DIR/etc/apt/sources.list
|
2019-01-24 17:16:47 -06:00
|
|
|
echo 'deb https://mirrors.wit.com/debcore sid main experimental' >> $MNT_DIR/etc/apt/sources.list
|
2018-09-24 08:54:24 -05:00
|
|
|
curl https://mirrors.wit.com/debcore/public.key | LANG=C DEBIAN_FRONTEND=noninteractive chroot $MNT_DIR apt-key add -
|
|
|
|
|
2018-09-25 03:32:34 -05:00
|
|
|
LANG=C DEBIAN_FRONTEND=noninteractive chroot $MNT_DIR apt-get update
|
2019-02-24 18:23:30 -06:00
|
|
|
LANG=C DEBIAN_FRONTEND=noninteractive chroot $MNT_DIR apt-get install $DEBCORE_INCLUDES
|
2018-09-25 03:32:34 -05:00
|
|
|
LANG=C DEBIAN_FRONTEND=noninteractive chroot $MNT_DIR apt-get clean
|
2018-09-24 08:54:24 -05:00
|
|
|
|
|
|
|
cat /dev/null > $MNT_DIR/etc/machine-id
|
|
|
|
|
|
|
|
mkdir -p $MNT_DIR/root/.ssh
|
|
|
|
echo ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDd7rLlS1NmTpBr5KP5ryuA/euGD8I6uc2RCg4sCIlvH0FhEPb123QuMVImHi23ftVP61cKZXm8MlTtAoLHduYtGMHCkJWAAkiIpPetAP2KPIpuadtgIS8xuD/TCYjl0xNXLh0M1C7i7HOnTd8yr+3QNjUppyDdKjLvMQbPWZZTU5rt7CYoGlrxHjieCkq9jj8kRjRARUaAJ4DHEgMFUDIcq3JYluzzkgPK/JFwoq/IokVQCr5qfQRwr3SCkD4sIuGTj+J67uzabIr/xDBqlrMW3T+7YfY12ciHpijob+l7xESkJ+6Gxh56z8llBkGiVyh3UqnmW4MvfuAA/D3Dzhwr afrank@adams-mbp.lan > $MNT_DIR/root/.ssh/authorized_keys
|
|
|
|
|
|
|
|
|
|
|
|
cat <<EOF >$MNT_DIR/etc/dhcpcd.conf
|
|
|
|
hostname
|
|
|
|
duid
|
|
|
|
slaac hwaddr
|
|
|
|
noipv4ll
|
|
|
|
option domain_name_servers, domain_name, domain_search, host_name
|
|
|
|
option classless_static_routes, ntp_servers, interface_mtu
|
|
|
|
require dhcp_server_identifier
|
|
|
|
EOF
|
|
|
|
|
|
|
|
|
2019-02-25 12:43:55 -06:00
|
|
|
chroot $MNT_DIR usermod -p "${ROOTPASSWD}" root
|
2018-11-07 15:55:03 -06:00
|
|
|
chroot $MNT_DIR ssh-keygen -q -f /root/.ssh/id_rsa -C root@pxeboot -N ""
|
2018-09-24 08:54:24 -05:00
|
|
|
|
2018-11-07 15:55:03 -06:00
|
|
|
echo "### public ssh key for root of this install"
|
|
|
|
cat $MNT_DIR/root/.ssh/id_rsa.pub
|
2018-09-24 08:54:24 -05:00
|
|
|
|
|
|
|
|
|
|
|
##################
|
|
|
|
## build initrd ##
|
|
|
|
##################
|
|
|
|
|
|
|
|
|
2018-09-25 11:18:46 -05:00
|
|
|
mkdir -p $INITRD_DIR/bin
|
2019-01-07 13:22:40 -06:00
|
|
|
cp $MNT_DIR/bin/busybox $INITRD_DIR/bin/busybox
|
2018-09-24 08:54:24 -05:00
|
|
|
|
2018-09-25 17:24:49 -05:00
|
|
|
cat <<-"EOF" >$INITRD_DIR/init
|
2018-09-24 16:02:44 -05:00
|
|
|
#!/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
|
|
|
|
mdev -s
|
|
|
|
|
|
|
|
mkdir -p /newroot
|
2018-09-25 17:24:49 -05:00
|
|
|
mount -t tmpfs -o size=${size:=10000}m tmpfs /newroot || error
|
2018-09-24 16:02:44 -05:00
|
|
|
|
|
|
|
echo "Extracting rootfs... "
|
2019-02-25 02:21:19 -06:00
|
|
|
xz -d -c -f rootfs.tar.xz | tar -x -f - -C /newroot || error
|
2018-09-24 16:02:44 -05:00
|
|
|
|
|
|
|
mount --move /sys /newroot/sys
|
|
|
|
mount --move /proc /newroot/proc
|
|
|
|
mount --move /dev /newroot/dev
|
|
|
|
|
|
|
|
exec switch_root /newroot /sbin/init || error
|
2018-09-24 08:54:24 -05:00
|
|
|
EOF
|
|
|
|
|
2018-09-25 11:18:46 -05:00
|
|
|
chmod +x $INITRD_DIR/init
|
2018-09-24 08:54:24 -05:00
|
|
|
|
2019-02-20 22:12:54 -06:00
|
|
|
XZ_OPT=-T0 tar -cJf $INITRD_DIR/rootfs.tar.xz -C $MNT_DIR .
|
|
|
|
|
2018-09-24 08:54:24 -05:00
|
|
|
|
2019-01-08 15:39:49 -06:00
|
|
|
#[ -d /usr/lib/linux-image-* ] && cp -r $MNT_DIR/usr/lib/linux-image-* $RESULT_DIR/dtbs
|
2019-01-07 13:22:40 -06:00
|
|
|
rm $MNT_DIR/boot/initrd.img-*
|
|
|
|
|
2019-01-08 15:39:49 -06:00
|
|
|
mv $MNT_DIR/boot/vmlinuz-* $KERNEL_DIR/vmlinuz-$ARCH
|
2018-09-24 08:54:24 -05:00
|
|
|
|
2019-01-08 15:39:49 -06:00
|
|
|
cd $INITRD_DIR
|
|
|
|
find . -print0 | cpio --null -ov --format=newc | gzip -9 > $KERNEL_DIR/initramfs-$ARCH.gz
|
|
|
|
cd -
|
|
|
|
|
|
|
|
apt-get update
|
|
|
|
if [[ $ARCH = amd64 ]]
|
|
|
|
then
|
|
|
|
apt-get -y install grub-common grub-efi-$ARCH-bin grub-pc-bin
|
|
|
|
grub-mknetdir --directory=/usr/lib/grub/i386-pc/ --net-directory=$RESULT_DIR/
|
|
|
|
grub-mknetdir --directory=/usr/lib/grub/x86_64-efi/ --net-directory=$RESULT_DIR/
|
|
|
|
else
|
|
|
|
apt-get -y install grub-common grub-efi-$ARCH-bin
|
|
|
|
grub-mknetdir --net-directory=$RESULT_DIR/
|
|
|
|
fi
|
2018-09-24 08:54:24 -05:00
|
|
|
|
2019-01-10 05:47:36 -06:00
|
|
|
rm -rf $RESULT_DIR/boot/grub/locale/ $RESULT_DIR/boot/grub/fonts/
|
|
|
|
|
2018-09-24 08:54:24 -05:00
|
|
|
ls -la $RESULT_DIR/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
exit 0
|
|
|
|
|
|
|
|
|