[X2Go-Commits] [live-build-x2go] 22/108: fixed error related to chmod, changed *LABEL* mechanism to the one used by 2260-getsshhostkeysfrommedia, added various comments to make code more readable/understandable
git-admin at x2go.org
git-admin at x2go.org
Wed Mar 20 22:13:08 CET 2019
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 a8afba5d2899685682f5757f29d1bf73bf1e9cf6
Author: Stefan Baur (BAUR-ITCS) <kontakt at baur-itcs.de>
Date: Tue Feb 6 12:19:15 2018 +0100
fixed error related to chmod, changed *LABEL* mechanism to the one used by 2260-getsshhostkeysfrommedia,added various comments to make code more readable/understandable
---
.../lib/live/config/2270-getsshclientkeysfrommedia | 32 ++++++++++++++++++----
1 file changed, 27 insertions(+), 5 deletions(-)
diff --git a/config/includes.chroot/lib/live/config/2270-getsshclientkeysfrommedia b/config/includes.chroot/lib/live/config/2270-getsshclientkeysfrommedia
index 8090eee..a04800d 100755
--- a/config/includes.chroot/lib/live/config/2270-getsshclientkeysfrommedia
+++ b/config/includes.chroot/lib/live/config/2270-getsshclientkeysfrommedia
@@ -23,7 +23,7 @@ GetSSHClientKeysFromMedia ()
mkdir -p $(readlink -m "$USERHOME/.ssh")
chown $TARGETUSERNAME: \
$(readlink -m "$USERHOME/.ssh")
- chmod 700 $KEYDESTPATH
+ chmod 700 \
$(readlink -m "$USERHOME/.ssh")
# any keyfile in the config dir will be copied over to live system
@@ -74,46 +74,68 @@ GetSSHClientKeysFromMedia ()
TARGETUSERNAME="x2gothinclient"
fi
- # search for our magic label
- X2GOTCELIVELABELS=$(awk '$3~/^[^\/]/ && $3="" ; $1=="X2GO-TCE-LIVE" { print $2 " " $3 " " $4 }' /var/lib/live/config/opensshkeys)
+ # list devices (and mountpoints, if present)
+ 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 " " $4}')
# support for second label value (for dual-mode media where keys are stored on the windows-readable partition)
- PORTABLEAPPLABELS=$(awk '$3~/^[^\/]/ && $3="" ; $1=="PORTABLEAPP" { print $2 " " $3 " " $4 }' /var/lib/live/config/opensshkeys)
+ PORTABLEAPPLABELS=$(echo -e "$LABELMPLIST" | awk '$3~/^[^\/]/ && $3="" ; $1=="PORTABLEAPP" { print $2 " " $3 " " $4}')
# block device list, removable first (we want USB media to be able to override keys on fixed disks)
BLOCKDEVS="$(echo "$X2GOTCELIVELABELS\n$PORTABLEAPPLABELS" | awk '$3 == "1" {print $2}') $(echo "$X2GOTCELIVELABELS\n$PORTABLEAPPLABELS" | awk '$3 == "0" {print $2}')"
+ # 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\n$PORTABLEAPPLABELS" | 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}')
echo -n "\n$(date +'%F | %T | ')'$0' Checking status of Device '$NEXTDEVICE' for BLOCKDEV '$BLOCKDEV'." | tee -a /dev/tty8
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 ...
touch /var/lib/live/config/opensshclientkeys
+ # 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.
mount -o ro /dev/$NEXTDEVICE /media/fixeddisks/$NEXTDEVICE
if check_for_config /media/fixeddisks/$NEXTDEVICE ; then
+ # we umount, then make a note that we succeeded ...
umount /media/fixeddisks/$NEXTDEVICE
touch /var/lib/live/config/opensshclientkeys
+ # 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 "BLOCKDEVS: '$BLOCKDEVS'" > /var/lib/live/config/opensshclientkeys
echo "X2GOTCELIVELABELS: '$X2GOTCELIVELABELS'" >> /var/lib/live/config/opensshclientkeys
echo "PORTABLEAPPLABELS: '$PORTABLEAPPLABELS'" >> /var/lib/live/config/opensshclientkeys
--
Alioth's /home/x2go-admin/maintenancescripts/git/hooks/post-receive-email on /srv/git/code.x2go.org/live-build-x2go.git
More information about the x2go-commits
mailing list