From b1e3929f5cfdcc668e1a4c93f28909a30ed5beab Mon Sep 17 00:00:00 2001 From: Markus Zolliker Date: Wed, 28 Oct 2026 11:39:18 +0100 Subject: [PATCH] no password, stick label upper case, reorganize file structure + 'write_to_ssd' and 'clone' are now commands --- bootlocal.sh | 5 ++--- build_core.sh | 17 +++++++++++++++-- makeusb | 46 +++++++++++++++++++++++++++++----------------- 3 files changed, 46 insertions(+), 22 deletions(-) diff --git a/bootlocal.sh b/bootlocal.sh index 53fe27e..261eee0 100644 --- a/bootlocal.sh +++ b/bootlocal.sh @@ -8,9 +8,8 @@ for f in /usr/local/tce.installed/*; do [ -x "$f" ] && "$f" done -# passwords (delete these two lines if only key login is wanted) -echo "tc:tc" | chpasswd -echo "root:root" | chpasswd +# passwords (add this line if only key login is not working) +# echo "tc:tc" | chpasswd # ssh files for user tc, staged in /opt/ssh by build_core.sh if [ -d /opt/ssh ]; then diff --git a/build_core.sh b/build_core.sh index aa05cae..c70e9cf 100644 --- a/build_core.sh +++ b/build_core.sh @@ -40,6 +40,9 @@ if [ -z "$1" ]; then else stickname=$1 fi +label=${stickname//-/_} +label=${label^^} + # the name ends up in a directory name and in a script: allow only safe characters case "$stickname" in *[!A-Za-z0-9-]*|.*) echo "invalid hostname '$stickname' (use letters, digits and dash only)"; exit 1 ;; @@ -48,7 +51,7 @@ esac # ssh host keys: use hostkeys_ if present, create missing keys otherwise STICKDIR=$PWD/sticks/$stickname KEYDIR=$STICKDIR/hostkeys -SSHDIR=$STICKDIR/ssh +SSHDIR=$PWD/tmp/ssh_for_boxes if [ -d "$KEYDIR" ]; then echo "using ssh host keys from $KEYDIR" else @@ -86,7 +89,7 @@ for t in tcz/*.tcz; do cp -a "$TMP/x/." "$WORK/" done -echo "add ssh host keys from $KEYDIR" +echo "add ssh files from $SSHDIR for user tc host" if [ -d "$SSHDIR" ]; then echo "stage $SSHDIR in /opt/ssh" @@ -94,6 +97,8 @@ if [ -d "$SSHDIR" ]; then cp -a "$SSHDIR"/. "$WORK/opt/ssh/" fi +echo "add ssh host keys from $KEYDIR" + mkdir -p "$WORK/usr/local/etc/ssh" for k in "$KEYDIR"/ssh_host_*_key; do install -m 600 -o root -g root "$k" "$WORK/usr/local/etc/ssh/" @@ -103,6 +108,14 @@ done install -m 755 -o root -g root bootlocal.sh "$WORK/opt/bootlocal.sh" install -m 755 -o root -g root $STICKDIR/bootsync.sh "$WORK/opt/bootsync.sh" +# commands whose scripts live on the stick: small wrappers in /usr/local/bin +STICKCMDS="clone write_to_ssd" +mkdir -p "$WORK/usr/local/bin" +for c in $STICKCMDS; do + printf '#!/bin/sh\ncd %s && exec bash ./%s "$@"\n' "/media/$label" "$c" > "$WORK/usr/local/bin/$c" + chmod 755 "$WORK/usr/local/bin/$c" +done + OUT=core.gz echo "pack $STICKDIR/$OUT" (cd "$WORK" && find . | cpio -o -H newc --quiet) | gzip -9 > "${OUT}.new" diff --git a/makeusb b/makeusb index 746f81a..50f17e6 100755 --- a/makeusb +++ b/makeusb @@ -1,7 +1,8 @@ #!/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 +# 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; } @@ -34,53 +35,64 @@ if [[ " ${DISKS[@]} " =~ " $DEVICE " ]]; then fi if [ -z "$1" ]; then - read -p "name for stick [apu-boot]: " stickname - stickname=${stickname:-apu-boot} + read -p "name for stick name [apu-boot]: " name + name=${name:-apu-boot} else - stickname=$1 + 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 $stickname" + echo "create TinyLinux stick $label (host name $stickname)" - if [ ! -d boot_tiny ] ; then - sudo --user l_samenv scp -r l_samenv@linse-c:boxes/boot_tiny ./ - fi + 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 - bash build_core.sh $stickname - if [ ! -f $STICKDIR/core.gz ]; then - echo "no core.gz created -> build_core.sh failed" - exit - fi + echo "no core.gz created -> build_core.sh failed" + exit fi - sudo --user l_samenv cp $STICKDIR/core.gz boot_tiny/core.gz + sudo --user l_samenv cp $STICKDIR/core.gz 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 $stickname -I ${DEVICE}1 + mkfs.vfat -n $label -I ${DEVICE}1 syslinux -i ${DEVICE}1 - dd conv=notrunc bs=440 count=1 if=boot_tiny/mbr.bin of=${DEVICE} + 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 boot_tiny/* /mnt/apusb/ + 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 "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