Files
zolliker bedc498a32 move hostkeys directory to /home/l_samenv/.config
else it would be overwritten each time
+ remove boot_tiny after use
2026-10-29 09:05:50 +01:00

102 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
cd "$(dirname "$0")"
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/
KEYDIR=/home/l_samenv/.config/hostkeys
bash build_core.sh $stickname $KEYDIR
if [ ! -f tmp/core.gz ]; then
echo "no core.gz created -> build_core.sh failed"
exit
fi
sudo --user l_samenv cp tmp/core.gz scripts/
rm -rf tmp
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=mbr.bin of=${DEVICE}
parted ${DEVICE} set 1 boot on
mkdir -p /mnt/apusb
mount ${DEVICE}1 /mnt/apusb
echo "copy files ..."
cp -r 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 "an IP address starting with 129.129 indicates the box is already"
echo "registered -> you can login as tc@$stickname"
echo " "
echo "an IP adresss starting with 10 indicates the box has first to be"
echo "registered to PacketFence"
else
echo "/dev/$DEVICE is not a removeable disk"
fi