move hostkeys directory to /home/l_samenv/.config
else it would be overwritten each time + remove boot_tiny after use
This commit is contained in:
1 parent
ee076c10ce
commit
bedc498a32
2 files changed
+34
-32
No files matched your search
+20
-21
@@ -4,20 +4,20 @@
|
||||
# network and no tce-load are needed at boot
|
||||
# - /opt/bootlocal.sh starts sshd and sets up ~/.ssh
|
||||
# - the ssh/ directory (authorized_keys, id_rsa, ...) is staged in /opt/ssh
|
||||
# - the stick gets a hostname and its own, fixed ssh host keys
|
||||
# - the stick gets a hostname and its own, ssh host keys (depending on stick name)
|
||||
#
|
||||
# Needs: root, cpio, gzip, unsquashfs (package squashfs-tools), ssh-keygen
|
||||
#
|
||||
# Put these next to this script:
|
||||
# core.gz.orig the original, unmodified core.gz (keep it, never overwrite)
|
||||
# tcz/*.tcz extensions fetched on the Tiny Core box with
|
||||
# "tce-load -w nano lz4 openssh", copied from tce/optional
|
||||
# ssh/ files for ~/.ssh of user tc (authorized_keys, ...)
|
||||
# core.gz.orig the original, unmodified core.gz (keep it, never overwrite)
|
||||
# tcz/*.tcz extensions fetched on the Tiny Core box with
|
||||
# "tce-load -w nano lz4 openssh", copied from tce/optional
|
||||
# tmp/ssh_for_boxes/ files for ~/.ssh of user tc (authorized_keys, ...)
|
||||
# bootlocal.sh
|
||||
# sticks/<name>/hostkeys/ ssh host keys of the stick called <name>. Used if it
|
||||
# exists, created (and filled with new keys) if it does not.
|
||||
# Keep it, then a rebuilt stick keeps its identity.
|
||||
# Result: sticks/<name>/core.gz (copy it into boot_tiny/ and commit it)
|
||||
# ../hostkeys/<name>/ ssh host keys of the stick called <name>. Used if it
|
||||
# exists, created (and filled with new keys) if it does not.
|
||||
# Keep it, then a rebuilt stick keeps its identity.
|
||||
# Result: tmp/core.gz (to be copied to the stick)
|
||||
set -e
|
||||
cd "$(dirname "$0")"
|
||||
|
||||
@@ -48,10 +48,11 @@ case "$stickname" in
|
||||
*[!A-Za-z0-9-]*|.*) echo "invalid hostname '$stickname' (use letters, digits and dash only)"; exit 1 ;;
|
||||
esac
|
||||
|
||||
# ssh host keys: use hostkeys_<name> if present, create missing keys otherwise
|
||||
STICKDIR=$PWD/sticks/$stickname
|
||||
KEYDIR=$STICKDIR/hostkeys
|
||||
SSHDIR=$PWD/tmp/ssh_for_boxes
|
||||
# ssh host keys: use previous hostkeys if present, create missing keys otherwise
|
||||
KEYDIR=${2:hostkeys}
|
||||
# temporary files: needs ssh_for_boxes here before and puts core.gz as a result
|
||||
TMPDIR=tmp
|
||||
SSHDIR=$TMPDIR/ssh_for_boxes
|
||||
if [ -d "$KEYDIR" ]; then
|
||||
echo "using ssh host keys from $KEYDIR"
|
||||
else
|
||||
@@ -66,7 +67,7 @@ for t in dsa rsa ecdsa ed25519; do
|
||||
fi
|
||||
done
|
||||
|
||||
cat << EOF > $STICKDIR/bootsync.sh
|
||||
cat << EOF > $TMPDIR/bootsync.sh
|
||||
#!/bin/sh
|
||||
# put other system startup commands here, the boot process will wait until they complete.
|
||||
# Use bootlocal.sh for system startup commands that can run in the background
|
||||
@@ -106,7 +107,7 @@ for k in "$KEYDIR"/ssh_host_*_key; do
|
||||
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"
|
||||
install -m 755 -o root -g root $TMPDIR/bootsync.sh "$WORK/opt/bootsync.sh"
|
||||
|
||||
# commands whose scripts live on the stick: small wrappers in /usr/local/bin
|
||||
STICKCMDS="clone write_to_ssd"
|
||||
@@ -117,13 +118,11 @@ for c in $STICKCMDS; do
|
||||
done
|
||||
|
||||
OUT=core.gz
|
||||
echo "pack $STICKDIR/$OUT"
|
||||
(cd "$WORK" && find . | cpio -o -H newc --quiet) | gzip -9 > "${OUT}.new"
|
||||
|
||||
mv "${OUT}.new" $STICKDIR/$OUT
|
||||
echo "pack $TMPDIR/$OUT"
|
||||
(cd "$WORK" && find . | cpio -o -H newc --quiet) | gzip -9 > "$TMPDIR/${OUT}"
|
||||
|
||||
# change ownership of generated files to the owner of the current directory
|
||||
chown -R --reference=. $STICKDIR
|
||||
chown -R --reference=. $KEYDIR $TMPDIR
|
||||
|
||||
ls -l "$STICKDIR/$OUT"
|
||||
ls -l "$TMPDIR/$OUT"
|
||||
echo "done."
|
||||
@@ -1,7 +1,9 @@
|
||||
#!/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
|
||||
|
||||
cd "$(dirname "$0")"
|
||||
|
||||
SSH_BOXES_SRC=l_samenv@linse-c:boxes/ssh_for_boxes
|
||||
|
||||
[ "$EUID" -eq 0 ] || { echo "Please run as root"; exit 1; }
|
||||
@@ -57,17 +59,15 @@ if [[ " ${DISKS[@]} " =~ " $DEVICE " ]]; then
|
||||
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
|
||||
|
||||
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 $KEYDIR
|
||||
if [ ! -f tmp/core.gz ]; then
|
||||
echo "no core.gz created -> build_core.sh failed"
|
||||
exit
|
||||
fi
|
||||
sudo --user l_samenv cp $STICKDIR/core.gz scripts/
|
||||
sudo --user l_samenv cp tmp/core.gz scripts/
|
||||
rm -rf tmp
|
||||
DEVICE=/dev/$DEVICE
|
||||
|
||||
umount ${DEVICE}1
|
||||
@@ -89,10 +89,13 @@ if [[ " ${DISKS[@]} " =~ " $DEVICE " ]]; then
|
||||
echo "--------------------------------------------------------------------"
|
||||
echo "stick into a box, reboot and wait 2 minutes, then:"
|
||||
echo ""
|
||||
echo "nslookup $stickname"
|
||||
echo "> nslookup $stickname"
|
||||
echo ""
|
||||
echo "if found ip start with 129.129., you can login as tc@$stickname"
|
||||
echo "if ip starts with 10., the box has first to be registered to PacketFence"
|
||||
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
|
||||
Reference in new issue
Block a user