Files
zolliker f8155b0928 tinylinux improvements
- move this stuff to the tinylinux subdirectory
- convert name to uppercase with optional underscore for label
- convert to lowercase with optional dash for host name
- remove ssh things from repo(s), now on linse-c:boxes/ssh_for_boxes
2026-10-26 11:07:20 +01:00

99 lines
2.6 KiB
Bash
Executable File

#!/bin/bash
# create an USB stick with TinyLinux on it
# name of the USB stick to be created
BOOT_TINY_SRC=l_samenv@linse-c:boxes/boot_tiny
SSH_BOXES_SRC=l_samenv@linse-c:boxes/ssh_for_boxes
[ "$EUID" -eq 0 ] || { echo "Please run as root"; exit 1; }
# list removeable disks
DISKS=()
while read LINE
do
ARR=($LINE)
if [[ ${ARR[@]:0:2} == "1 disk" ]]; then
DISKS+=(${ARR[@]:2:1})
printf "%-7s %7s " ${ARR[@]:2:2}
echo ${ARR[@]:4}
elif [[ ${ARR[@]:0:2} == "1 part" ]]; then
printf " %7s " ${ARR[@]:3:1}
echo ${ARR[@]:4}
fi
done < <(lsblk -l --output RM,TYPE,NAME,SIZE,LABEL,VENDOR,MODEL)
echo "which device? should be one of: ${DISKS[@]}"
read DEVICE
if [ -z $DEVICE ] ; then
exit
fi
if [[ " ${DISKS[@]} " =~ " $DEVICE " ]]; then
if [[ $(cat /sys/block/$DEVICE/removable) != "1" ]]; then
echo "/dev/$DEVICE is not a removable disk"
exit
fi
if [ -z "$1" ]; then
read -p "name for stick name [apu-boot]: " name
name=${name:-apu-boot}
else
name=$1
fi
stickname=${name//_/-}
stickname=${stickname,,}
label=${name//-/_}
label=${label^^}
# allow only letters and digits
case "$stickname" in
*[!A-Za-z0-9-]*|.*) echo "invalid hostname '$stickname' (use letters, digits and dash only)"; exit 1 ;;
esac
echo "create TinyLinux stick $label (host name $stickname)"
rm -rf tmp
sudo --user l_samenv mkdir tmp
sudo --user l_samenv scp -r $BOOT_TINY_SRC tmp/
sudo --user l_samenv scp -r $SSH_BOXES_SRC tmp/
STICKDIR=sticks/$stickname
if [ ! -d $STICKDIR ]; then
mkdir -p $STICKDIR
fi
bash build_core.sh $stickname
if [ ! -f $STICKDIR/core.gz ]; then
echo "no core.gz created -> build_core.sh failed"
exit
fi
sudo --user l_samenv cp $STICKDIR/core.gz tmp/boot_tiny/scripts/
DEVICE=/dev/$DEVICE
umount ${DEVICE}1
dd if=/dev/zero of=${DEVICE} count=1 conv=notrunc
echo -e "o\nn\np\n1\n\n\nw" | fdisk ${DEVICE}
mkfs.vfat -n $label -I ${DEVICE}1
syslinux -i ${DEVICE}1
dd conv=notrunc bs=440 count=1 if=tmp/boot_tiny/mbr.bin of=${DEVICE}
parted ${DEVICE} set 1 boot on
mkdir -p /mnt/apusb
mount ${DEVICE}1 /mnt/apusb
echo "copy files ..."
cp -r tmp/boot_tiny/scripts/* /mnt/apusb/
umount /mnt/apusb
echo "done."
echo "--------------------------------------------------------------------"
echo "stick into a box, reboot and wait 2 minutes, then:"
echo ""
echo "nslookup $stickname"
echo ""
echo "if found ip start with 129.129., you can login as tc@$stickname"
echo "ip start with 10., the box has first to be registered to PacketFence"
else
echo "/dev/$DEVICE is not a removeable disk"
fi