This is an automated email from the git hooks/post-receive script. x2go pushed a commit to branch feature/openbox in repository live-build-x2go. commit 6db8f4b105a0e8dd2f45ade2bad28b782ade6830 Author: Stefan Baur (BAUR-ITCS) <kontakt@baur-itcs.de> Date: Tue Feb 6 11:41:58 2018 +0100 changed how BLOCKDEVS list is created, added various comments to make code more readable/understandable --- .../lib/live/config/2260-getsshhostkeysfrommedia | 38 +++++++++++++++++++--- 1 file changed, 34 insertions(+), 4 deletions(-) diff --git a/config/includes.chroot/lib/live/config/2260-getsshhostkeysfrommedia b/config/includes.chroot/lib/live/config/2260-getsshhostkeysfrommedia index 965bdad..81d9af3 100755 --- a/config/includes.chroot/lib/live/config/2260-getsshhostkeysfrommedia +++ b/config/includes.chroot/lib/live/config/2260-getsshhostkeysfrommedia @@ -11,15 +11,23 @@ GetSSHHostKeysFromMedia () echo -n "\n$(date +'%F | %T | ')'$0' is waiting for tty8 to become available." sleep 2 done + while ! service udev status >/dev/null; do + echo -n "\n$(date +'%F | %T | ')'$0' Waiting for udev to start ..." | tee -a /dev/tty8 + sleep 1; + done + while ! udevadm settle; do + echo -n "\n$(date +'%F | %T | ')'$0' Waiting for udev to process all events ..." | tee -a /dev/tty8 + sleep 1; + done # list devices (and mountpoints, if present) - LABELMPLIST=$(lsblk -oLABEL,NAME,MOUNTPOINT -l) + LABELMPLIST=$(lsblk -oLABEL,NAME,MOUNTPOINT,HOTPLUG -ln) # search for our magic label - X2GOTCELIVELABELS=$(echo -e "$LABELMPLIST" | awk '$3~/^[^\/]/ && $3="" ; $1=="X2GO-TCE-LIVE" { print $2 " " $3}') + X2GOTCELIVELABELS=$(echo -e "$LABELMPLIST" | awk '$3~/^[^\/]/ && $3="" ; $1=="X2GO-TCE-LIVE" { print $2 " " $3 " " $4}') # block device list, non-removable first (for security - we don't want USB media to be able to override keys on fixed disks) - BLOCKDEVS=$(grep -H '' /sys/block/*/removable | awk -F':' '{ print $2 ":" $1}' | sort | awk -F'/' '{print $4}') + BLOCKDEVS="$(echo $X2GOTCELIVELABELS | awk '$3 == "0" {print $2}') $(echo $X2GOTCELIVELABELS | awk '$3 == "1" {print $2}')" check_for_config (){ if [ -d $1/config/sshdkeys ] ; then @@ -77,37 +85,59 @@ GetSSHHostKeysFromMedia () fi } + # for every block device in our list, do ... for BLOCKDEV in $BLOCKDEVS; do + # check if it also appears in the list of devices carrying our magic label + # this should always be the case since we changed how BLOCKDEVS is assembled NEXTDEVICE=$(echo "$X2GOTCELIVELABELS" | grep "$BLOCKDEV") if [ -n "$NEXTDEVICE" ] ; then + # now figure out the mountpoint MNTPT=$(echo $NEXTDEVICE | awk '{print $2}') + # and the device name? Wait, this is the magic label instead. NEXTDEVICE=$(echo $NEXTDEVICE | awk '{print $1}') if [ -n "$MNTPT" ] ; then + # If the mountpoint variable isn't empty, it means the device is already mounted. echo -n "\n$(date +'%F | %T | ')'$0' Device '$NEXTDEVICE' is mounted at: '$MNTPT'" | tee -a /dev/tty8 + # so let's check if we have a config directory at that mountpoint. if check_for_config $MNTPT ; then + # if we managed to pull a config off of it (or save one on it), we make a note of this ... echo -e "$LABELMPLIST" >/var/lib/live/config/opensshkeys + # and quit right here. exit 0 fi else + # So there's no active mount for the device with our magic label ... echo -n "\n$(date +'%F | %T | ')'$0' Device '$NEXTDEVICE' is not mounted." | tee -a /dev/tty8 + # let's see if this is a fixed disk. if grep -q "^0$" /sys/block/$BLOCKDEV/removable ; then + # yes, it is, so let's go ahead and try to mount it ... echo -n "\n$(date +'%F | %T | ')'$0' Device '$NEXTDEVICE' is a fixed disk, mounting ..." | tee -a /dev/tty8 + # obviously, we need a mountpoint for it ... mkdir -p /media/fixeddisks/$NEXTDEVICE + # and now we can try to mount it. Let's do it in readonly mode, just to play it safe. + # a read-write remount is only attempted within check_for_config if it finds an empty + # sshd keys directory. mount -o ro /dev/$NEXTDEVICE /media/fixeddisks/$NEXTDEVICE + # If we managed to pull a config off of it (or save one on it), ... if check_for_config /media/fixeddisks/$NEXTDEVICE ; then + # we umount, then make a note that we succeeded ... umount /media/fixeddisks/$NEXTDEVICE echo -e "$LABELMPLIST" >/var/lib/live/config/opensshkeys + # and quit right here. exit 0 fi + # If we didn't succeed in pulling a config, we still need to umount what we mounted. umount /media/fixeddisks/$NEXTDEVICE else + # If a removable disk hasn't been mounted by the automounter, something's amiss and we shouldn't try to meddle with it. + # So let's make a note of this and move on. echo -n "\n$(date +'%F | %T | ')'$0' Device '$NEXTDEVICE' is a removable disk, not mounted by automounter, skipping." | tee -a /dev/tty8 - : fi fi fi done + # Now let's leave a mark saying that we're done, so the next script can pick up on it. echo -e "$LABELMPLIST" >/var/lib/live/config/opensshkeys ) & } -- Alioth's /home/x2go-admin/maintenancescripts/git/hooks/post-receive-email on /srv/git/code.x2go.org/live-build-x2go.git