2025-01-25 20:30:36 +00:00
|
|
|
#!/bin/bash
|
|
|
|
# Create symlink in DocumentRoot/content to automounted usb drive
|
|
|
|
#
|
|
|
|
# based on a similar script in the xs-rsync package
|
|
|
|
# by Martin Langhoff <martin@laptop.org>
|
|
|
|
#
|
|
|
|
# and the adaptation for xs-activity-server by Douglas Bagnall
|
|
|
|
# <douglas@paradise.net.nz>
|
|
|
|
#
|
|
|
|
# by Tim Moody tim@timmoody.com
|
|
|
|
|
2025-01-26 01:55:13 +00:00
|
|
|
# Better to set this in /etc/usbmount/usbmount.conf
|
|
|
|
# VERBOSE=yes
|
2025-01-25 20:30:36 +00:00
|
|
|
|
2025-01-26 03:41:10 +00:00
|
|
|
# UM_MOUNTPOINT is documented at: https://github.com/rbrito/usbmount#hook-scripts
|
|
|
|
UM_DEV=$(findmnt -no source $UM_MOUNTPOINT)
|
2025-01-25 20:30:36 +00:00
|
|
|
|
2025-01-25 22:30:14 +00:00
|
|
|
# 2022-06-16 better security thanks to @tim-moody and @jvonau:
|
|
|
|
# https://github.com/iiab/iiab/pull/3254
|
2025-01-25 22:04:46 +00:00
|
|
|
LIB_DEV=$(findmnt -no source /library | cut -d '[' -f 1)
|
|
|
|
ROOT_DEV=$(findmnt -no source /)
|
|
|
|
BOOT_DEV=$(findmnt -no source /boot)
|
|
|
|
BOOTFW_DEV=$(findmnt -no source /boot/firmware)
|
2025-01-26 03:41:10 +00:00
|
|
|
|
2025-01-26 01:49:12 +00:00
|
|
|
# Verbose logging to illuminate occasional boot bugginess:
|
2025-01-26 03:41:10 +00:00
|
|
|
logger -t "usb_lib (70-usb-library)" "UM_DEV is: $UM_DEV"
|
2025-01-26 01:49:12 +00:00
|
|
|
logger -t "usb_lib (70-usb-library)" "LIB_DEV is: $LIB_DEV"
|
|
|
|
logger -t "usb_lib (70-usb-library)" "ROOT_DEV is: $ROOT_DEV"
|
|
|
|
logger -t "usb_lib (70-usb-library)" "BOOT_DEV is: $BOOT_DEV"
|
|
|
|
logger -t "usb_lib (70-usb-library)" "BOOTFW_DEV is: $BOOTFW_DEV"
|
2025-01-26 03:41:10 +00:00
|
|
|
|
|
|
|
if [ "$UM_DEV" == "$LIB_DEV" ]; then
|
2025-01-31 06:41:23 +00:00
|
|
|
logger -t "usb_lib (70-usb-library)" "Skipping $UM_MOUNTPOINT containing /library"
|
2025-02-11 08:45:52 +00:00
|
|
|
exit 1
|
2025-01-26 03:41:10 +00:00
|
|
|
elif [ "$UM_DEV" == "$ROOT_DEV" ]; then
|
2025-01-31 06:41:23 +00:00
|
|
|
logger -t "usb_lib (70-usb-library)" "Skipping $UM_MOUNTPOINT containing rootfs"
|
2025-02-11 08:45:52 +00:00
|
|
|
exit 1
|
2025-01-26 03:41:10 +00:00
|
|
|
elif [ "$UM_DEV" == "$BOOT_DEV" ]; then
|
2025-01-31 06:41:23 +00:00
|
|
|
logger -t "usb_lib (70-usb-library)" "Skipping $UM_MOUNTPOINT containing /boot"
|
2025-02-11 08:45:52 +00:00
|
|
|
exit 1
|
2025-01-26 03:41:10 +00:00
|
|
|
elif [ "$UM_DEV" == "$BOOTFW_DEV" ]; then
|
2025-01-31 06:41:23 +00:00
|
|
|
logger -t "usb_lib (70-usb-library)" "Skipping $UM_MOUNTPOINT containing /boot/firmware"
|
2025-02-11 08:45:52 +00:00
|
|
|
exit 1
|
2025-01-25 20:30:36 +00:00
|
|
|
fi
|
|
|
|
|
2025-01-26 04:57:27 +00:00
|
|
|
# 2025-01-25: Check for existence of folder PUBLIC on USB stick: if found, the stick will not be completely browsable.
|
|
|
|
# Teachers can set their stick for 1 of 2 two "personalities" — students can either upload "confidential homework" or
|
|
|
|
# "public artwork" — as summarized here: https://github.com/iiab/iiab/blob/master/roles/usb_lib/README.rst
|
2025-01-25 22:04:46 +00:00
|
|
|
if [ -d $UM_MOUNTPOINT/PUBLIC ]; then
|
|
|
|
SHARE_DIR=$UM_MOUNTPOINT/PUBLIC
|
2025-01-31 06:41:23 +00:00
|
|
|
logger -t "usb_lib (70-usb-library)" "Found /PUBLIC on $UM_MOUNTPOINT"
|
2025-01-25 22:04:46 +00:00
|
|
|
else
|
|
|
|
SHARE_DIR=$UM_MOUNTPOINT
|
2025-01-31 06:41:23 +00:00
|
|
|
logger -t "usb_lib (70-usb-library)" "Did not find /PUBLIC on $UM_MOUNTPOINT"
|
2025-01-25 22:04:46 +00:00
|
|
|
fi
|
|
|
|
|
2025-01-26 01:52:04 +00:00
|
|
|
CONTENT_LINK_USB=$(basename $UM_MOUNTPOINT | awk '{print toupper($0)}')
|
2025-02-11 08:45:52 +00:00
|
|
|
if [ -z "$CONTENT_LINK_USB" ]; then
|
2025-02-11 15:42:05 +00:00
|
|
|
logger -t "usb_lib (70-usb-library)" 'ERROR: Var CONTENT_LINK_USB is empty ("rm -rf /library/www/html/local_content/" would be dangerous!)'
|
2025-02-11 08:45:52 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
2025-01-25 20:30:36 +00:00
|
|
|
CONTENT_LINK="{{ doc_root }}/local_content/$CONTENT_LINK_USB"
|
2025-02-11 08:13:51 +00:00
|
|
|
# 'rm -rf' even stronger than 'ln -nsf' and 'ln -Tsf'
|
|
|
|
# https://serverfault.com/questions/147787/how-to-update-a-symbolic-link-target-ln-f-s-not-working/522483#522483
|
2025-02-11 08:45:52 +00:00
|
|
|
logger -t "usb_lib (70-usb-library)" "Creating link from $CONTENT_LINK to $SHARE_DIR"
|
2025-02-11 08:13:51 +00:00
|
|
|
rm -rf $CONTENT_LINK
|
|
|
|
ln -s $SHARE_DIR $CONTENT_LINK
|