From 20cda93f2393c6d110577689c65df34edfdd7828 Mon Sep 17 00:00:00 2001 From: Jerry Vonau Date: Sat, 15 Feb 2025 10:45:44 -0600 Subject: [PATCH 01/17] tweek udev rules & usbmount@.service --- roles/usb_lib/templates/usbmount.rules.j2 | 3 +-- roles/usb_lib/templates/usbmount@.service.j2 | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/roles/usb_lib/templates/usbmount.rules.j2 b/roles/usb_lib/templates/usbmount.rules.j2 index 939a31041..0e64d56e3 100644 --- a/roles/usb_lib/templates/usbmount.rules.j2 +++ b/roles/usb_lib/templates/usbmount.rules.j2 @@ -1,3 +1,2 @@ ACTION=="add", SUBSYSTEMS=="usb", SUBSYSTEM=="block", ENV{ID_FS_USAGE}=="filesystem" PROGRAM="/bin/systemd-escape -p --template=usbmount@.service $env{DEVNAME}", ENV{SYSTEMD_WANTS}+="%c" -ACTION=="remove", SUBSYSTEMS=="usb", SUBSYSTEM=="block", ENV{ID_FS_USAGE}=="filesystem" PROGRAM="/bin/systemd-escape -p /usr/share/usbmount/usbmount remove" - +ACTION=="remove", SUBSYSTEMS=="usb", SUBSYSTEM=="block", ENV{ID_FS_USAGE}=="filesystem" PROGRAM="/bin/systemd-escape -p --template=usbmount@.service $env{DEVNAME}" diff --git a/roles/usb_lib/templates/usbmount@.service.j2 b/roles/usb_lib/templates/usbmount@.service.j2 index 6cf1f990b..9466591a4 100644 --- a/roles/usb_lib/templates/usbmount@.service.j2 +++ b/roles/usb_lib/templates/usbmount@.service.j2 @@ -10,6 +10,6 @@ TimeoutStartSec=0 Environment=DEVNAME=%I ExecStart=/usr/local/sbin/usbmount add ExecStop=/usr/local/sbin/iiab-clean-usb.sh %I -ExecStopPost=/bin/umount /%I +ExecStopPost=/usr/local/sbin/usbmount remove RemainAfterExit=yes RuntimeDirectory=usbmount From c935eb52bc4c67873386e23def03dc6915fc37dd Mon Sep 17 00:00:00 2001 From: Jerry Vonau Date: Sat, 15 Feb 2025 11:12:15 -0600 Subject: [PATCH 02/17] logging --- roles/usb_lib/templates/iiab-clean-usb.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/roles/usb_lib/templates/iiab-clean-usb.sh b/roles/usb_lib/templates/iiab-clean-usb.sh index 360d737f4..cff4ce72d 100644 --- a/roles/usb_lib/templates/iiab-clean-usb.sh +++ b/roles/usb_lib/templates/iiab-clean-usb.sh @@ -6,9 +6,9 @@ MNT_POINT=$(findmnt -no target $DEVICE) CONTENT_LINK_USB=$(basename $MNT_POINT | awk '{print toupper($0)}') CONTENT_LINK="/library/www/html/local_content/$CONTENT_LINK_USB" -logger -t "usb_lib (iiab-clean-usb.sh)" "Attempting to remove symlink $CONTENT_LINK, as auto-created earlier by usbmount." +logger -t "usbmount (iiab-clean-usb.sh)" "Attempting to remove symlink $CONTENT_LINK, as auto-created earlier by usb_lib." if [ -L $CONTENT_LINK ]; then /usr/bin/rm $CONTENT_LINK - logger -t "usb_lib (iiab-clean-usb.sh)" "Symlink $CONTENT_LINK removed, as auto-created earlier by usbmount." + logger -t "usbmount (iiab-clean-usb.sh)" "Symlink $CONTENT_LINK removed, as auto-created earlier by usb_lib." fi From 38494d20c97732670d915f6b5ae697ade652b0cf Mon Sep 17 00:00:00 2001 From: Jerry Vonau Date: Sat, 15 Feb 2025 10:45:44 -0600 Subject: [PATCH 03/17] mounting /dev/ --- roles/usb_lib/files/usbmount/usbmount | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/roles/usb_lib/files/usbmount/usbmount b/roles/usb_lib/files/usbmount/usbmount index 8104564e7..f8984f2e8 100644 --- a/roles/usb_lib/files/usbmount/usbmount +++ b/roles/usb_lib/files/usbmount/usbmount @@ -160,7 +160,7 @@ if [ "$1" = add ]; then fi # Mount the filesystem. - log info "executing command: mount -t$fstype ${options:+-o$options} $DEVNAME $mountpoint" + log info "executing command: mount -t$fstype ${options:+-o$options} /$DEVNAME $mountpoint" mount "-t$fstype" "${options:+-o$options}" "$DEVNAME" "$mountpoint" # Determine vendor and model. From c8682aa9862b025e22ac1ed09969524ec5e5a1db Mon Sep 17 00:00:00 2001 From: Jerry Vonau Date: Sat, 15 Feb 2025 11:02:12 -0600 Subject: [PATCH 04/17] fix remove --- roles/usb_lib/files/usbmount/usbmount | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/roles/usb_lib/files/usbmount/usbmount b/roles/usb_lib/files/usbmount/usbmount index f8984f2e8..bbbc9554f 100644 --- a/roles/usb_lib/files/usbmount/usbmount +++ b/roles/usb_lib/files/usbmount/usbmount @@ -209,10 +209,11 @@ elif [ "$1" = remove ]; then # A block or partition device has been removed. # Test if it is mounted. while read device mountpoint fstype remainder; do - if [ "$DEVNAME" = "$device" ]; then - # If the mountpoint and filesystem type are maintained by - # this script, unmount the filesystem. - if in_list "$mountpoint" "$MOUNTPOINTS" && + if [ "/$DEVNAME" = "$device" ]; then + log debug "umount device is $device" + # If the mountpoint and filesystem type are maintained by + # this script, unmount the filesystem. + if in_list "$mountpoint" "$MOUNTPOINTS" && in_list "$fstype" "$FILESYSTEMS"; then log info "executing command: umount -l $mountpoint" umount -l "$mountpoint" From 06eb5dde45c70d9e01b48a81121d65fe4674db2b Mon Sep 17 00:00:00 2001 From: Jerry Vonau Date: Sat, 15 Feb 2025 10:45:42 -0600 Subject: [PATCH 05/17] finish tab spacing --- roles/usb_lib/files/usbmount/usbmount | 104 +++++++++++++------------- 1 file changed, 52 insertions(+), 52 deletions(-) diff --git a/roles/usb_lib/files/usbmount/usbmount b/roles/usb_lib/files/usbmount/usbmount index bbbc9554f..d280eb354 100644 --- a/roles/usb_lib/files/usbmount/usbmount +++ b/roles/usb_lib/files/usbmount/usbmount @@ -83,7 +83,7 @@ if [ "$1" = add ]; then # Acquire lock. log debug "trying to acquire lock /var/run/usbmount/.mount.lock" lockfile-create --retry 6 /var/run/usbmount/.mount || \ - { log err "cannot acquire lock /var/run/usbmount/.mount.lock"; exit 1; } + { log err "cannot acquire lock /var/run/usbmount/.mount.lock"; exit 1; } trap '( lockfile-remove /var/run/usbmount/.mount )' 0 log debug "acquired lock /var/run/usbmount/.mount.lock" @@ -98,7 +98,7 @@ if [ "$1" = add ]; then if ! echo $USAGE | egrep -q "(filesystem|disklabel)"; then log debug "/$DEVNAME does not contain a filesystem or disklabel" lockfile-remove /var/run/usbmount/.mount - exit + exit fi log debug "/$DEVNAME contains filesystem type $FSTYPE" @@ -110,7 +110,7 @@ if [ "$1" = add ]; then log debug "BOOT_DEV $BOOT_DEV" if [ $BOOTFW_DEV = /$DEVNAME ]; then - log debug "skipping BOOTFS_DEV $BOOTFS_DEV mounted at /boot/firmware" + log debug "skipping BOOTFS_DEV $BOOTFS_DEV mounted at /boot/firmware" lockfile-remove /var/run/usbmount/.mount exit elif [ $ROOT_DEV = /$DEVNAME ]; then @@ -131,7 +131,7 @@ if [ "$1" = add ]; then elif grep -q "^[[:blank:]]*UUID=$UUID" /etc/fstab; then log debug "skipping $UUID" lockfile-remove /var/run/usbmount/.mount - exit + exit else log debug "/$DEVNAME contains filesystem type $FSTYPE" fstype=$FSTYPE @@ -142,7 +142,7 @@ if [ "$1" = add ]; then for v in $MOUNTPOINTS; do if [ -d "$v" ] && ! grep -q "^[^ ][^ ]* *$v " /proc/mounts; then mountpoint="$v" - log debug "mountpoint $mountpoint is available for /$DEVNAME" + log debug "mountpoint $mountpoint is available for /$DEVNAME" break fi done @@ -155,55 +155,55 @@ if [ "$1" = add ]; then break fi done - if [ -n "$MOUNTOPTIONS" ]; then - options="$MOUNTOPTIONS${options:+,$options}" + if [ -n "$MOUNTOPTIONS" ]; then + options="$MOUNTOPTIONS${options:+,$options}" + fi + + # Mount the filesystem. + log info "executing command: mount -t$fstype ${options:+-o$options} /$DEVNAME $mountpoint" + mount "-t$fstype" "${options:+-o$options}" "/$DEVNAME" "$mountpoint" + + # Determine vendor and model. + vendor= + if [ -r "/sys$DEVPATH/device/vendor" ]; then + vendor="`cat \"/sys$DEVPATH/device/vendor\"`" + elif [ -r "/sys$DEVPATH/../device/vendor" ]; then + vendor="`cat \"/sys$DEVPATH/../device/vendor\"`" + elif [ -r "/sys$DEVPATH/device/../manufacturer" ]; then + vendor="`cat \"/sys$DEVPATH/device/../manufacturer\"`" + elif [ -r "/sys$DEVPATH/../device/../manufacturer" ]; then + vendor="`cat \"/sys$DEVPATH/../device/../manufacturer\"`" + fi + vendor="$(echo "$vendor" | sed 's/^[[:blank:]]\+//; s/[[:blank:]]\+$//')" + + model= + if [ -r "/sys$DEVPATH/device/model" ]; then + model="`cat \"/sys$DEVPATH/device/model\"`" + elif [ -r "/sys$DEVPATH/../device/model" ]; then + model="`cat \"/sys$DEVPATH/../device/model\"`" + elif [ -r "/sys$DEVPATH/device/../product" ]; then + model="`cat \"/sys$DEVPATH/device/../product\"`" + elif [ -r "/sys$DEVPATH/../device/../product" ]; then + model="`cat \"/sys$DEVPATH/../device/../product\"`" + fi + model="$(echo "$model" | sed 's/^[[:blank:]]\+//; s/[[:blank:]]\+$//')" + + # Run hook scripts; ignore errors. + export UM_DEVICE="/$DEVNAME" + export UM_MOUNTPOINT="$mountpoint" + export UM_FILESYSTEM="$fstype" + export UM_MOUNTOPTIONS="$options" + export UM_VENDOR="$vendor" + export UM_MODEL="$model" + log info "executing command: run-parts /etc/usbmount/mount.d" + run-parts /etc/usbmount/mount.d || : + else + # No suitable mount point found. + log warning "no mountpoint found for /$DEVNAME" + exit 1 fi - - # Mount the filesystem. - log info "executing command: mount -t$fstype ${options:+-o$options} /$DEVNAME $mountpoint" - mount "-t$fstype" "${options:+-o$options}" "$DEVNAME" "$mountpoint" - - # Determine vendor and model. - vendor= - if [ -r "/sys$DEVPATH/device/vendor" ]; then - vendor="`cat \"/sys$DEVPATH/device/vendor\"`" - elif [ -r "/sys$DEVPATH/../device/vendor" ]; then - vendor="`cat \"/sys$DEVPATH/../device/vendor\"`" - elif [ -r "/sys$DEVPATH/device/../manufacturer" ]; then - vendor="`cat \"/sys$DEVPATH/device/../manufacturer\"`" - elif [ -r "/sys$DEVPATH/../device/../manufacturer" ]; then - vendor="`cat \"/sys$DEVPATH/../device/../manufacturer\"`" - fi - vendor="$(echo "$vendor" | sed 's/^[[:blank:]]\+//; s/[[:blank:]]\+$//')" - - model= - if [ -r "/sys$DEVPATH/device/model" ]; then - model="`cat \"/sys$DEVPATH/device/model\"`" - elif [ -r "/sys$DEVPATH/../device/model" ]; then - model="`cat \"/sys$DEVPATH/../device/model\"`" - elif [ -r "/sys$DEVPATH/device/../product" ]; then - model="`cat \"/sys$DEVPATH/device/../product\"`" - elif [ -r "/sys$DEVPATH/../device/../product" ]; then - model="`cat \"/sys$DEVPATH/../device/../product\"`" - fi - model="$(echo "$model" | sed 's/^[[:blank:]]\+//; s/[[:blank:]]\+$//')" - - # Run hook scripts; ignore errors. - export UM_DEVICE="$DEVNAME" - export UM_MOUNTPOINT="$mountpoint" - export UM_FILESYSTEM="$fstype" - export UM_MOUNTOPTIONS="$options" - export UM_VENDOR="$vendor" - export UM_MODEL="$model" - log info "executing command: run-parts /etc/usbmount/mount.d" - run-parts /etc/usbmount/mount.d || : - else - # No suitable mount point found. - log warning "no mountpoint found for $DEVNAME" - exit 1 fi - fi -fi + fi elif [ "$1" = remove ]; then # A block or partition device has been removed. From 412cbd655cf82c01a85c9af6c3a6a61a3427b109 Mon Sep 17 00:00:00 2001 From: Jerry Vonau Date: Sat, 15 Feb 2025 12:28:56 -0600 Subject: [PATCH 06/17] shellcheck --- roles/usb_lib/files/usbmount/usbmount | 38 +++++++++++++-------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/roles/usb_lib/files/usbmount/usbmount b/roles/usb_lib/files/usbmount/usbmount index d280eb354..b4572acc4 100644 --- a/roles/usb_lib/files/usbmount/usbmount +++ b/roles/usb_lib/files/usbmount/usbmount @@ -24,8 +24,8 @@ exec > /dev/null 2>&1 # Log a string via the syslog facility. log() { - if [ $1 != debug ] || expr "$VERBOSE" : "[yY]" > /dev/null; then - logger -p user.$1 -t "usbmount[$$]" -- "$2" + if [ "$1" != debug ] || expr "$VERBOSE" : "[yY]" > /dev/null; then + logger -p user."$1" -t "usbmount[$$]" -- "$2" fi } @@ -90,12 +90,12 @@ if [ "$1" = add ]; then # Grab device information from device and "divide it" # FIXME: improvement: implement mounting by label (notice that labels # can contain spaces, which makes things a little bit less comfortable). - DEVINFO=$(/sbin/blkid -p $DEVNAME) + DEVINFO=$(/sbin/blkid -p "$DEVNAME") FSTYPE=$(echo "$DEVINFO" | sed 's/.*[[:blank:]]TYPE="\([^"]*\)".*/\1/g; s/[[:blank:]]*//g;') UUID=$(echo "$DEVINFO" | sed 's/.*[[:blank:]]UUID="\([^"]*\)".*/\1/g; s/[[:blank:]]*//g;') USAGE=$(echo "$DEVINFO" | sed 's/.*[[:blank:]]USAGE="\([^"]*\)".*/\1/g; s/[[:blank:]]*//g;') - if ! echo $USAGE | egrep -q "(filesystem|disklabel)"; then + if ! echo "$USAGE" | grep -Eq "(filesystem|disklabel)"; then log debug "/$DEVNAME does not contain a filesystem or disklabel" lockfile-remove /var/run/usbmount/.mount exit @@ -109,26 +109,26 @@ if [ "$1" = add ]; then BOOT_DEV=$(/usr/bin/findmnt -no source /boot) log debug "BOOT_DEV $BOOT_DEV" - if [ $BOOTFW_DEV = /$DEVNAME ]; then - log debug "skipping BOOTFS_DEV $BOOTFS_DEV mounted at /boot/firmware" + if [ "$BOOTFW_DEV" = /"$DEVNAME" ]; then + log debug "skipping BOOTFW_DEV $BOOTFW_DEV mounted at /boot/firmware" lockfile-remove /var/run/usbmount/.mount exit - elif [ $ROOT_DEV = /$DEVNAME ]; then + elif [ "$ROOT_DEV" = /"$DEVNAME" ]; then log debug "skipping ROOT_DEV $ROOT_DEV mounted at /" lockfile-remove /var/run/usbmount/.mount exit - elif [ $BOOT_DEV = /$DEVNAME ]; then + elif [ "$BOOT_DEV" = /"$DEVNAME" ]; then log debug "skipping BOOT_DEV $BOOT_DEV mount as /boot" lockfile-remove /var/run/usbmount/.mount exit fi # Try to use specifications in /etc/fstab to skip. - if egrep -q "^[[:blank:]]*$DEVNAME" /etc/fstab; then + if grep -Eq "^[[:blank:]]*$DEVNAME" /etc/fstab; then log debug "skipping /$DEVNAME exit" lockfile-remove /var/run/usbmount/.mount exit - elif grep -q "^[[:blank:]]*UUID=$UUID" /etc/fstab; then + elif grep -Eq "^[[:blank:]]*UUID=$UUID" /etc/fstab; then log debug "skipping $UUID" lockfile-remove /var/run/usbmount/.mount exit @@ -166,25 +166,25 @@ if [ "$1" = add ]; then # Determine vendor and model. vendor= if [ -r "/sys$DEVPATH/device/vendor" ]; then - vendor="`cat \"/sys$DEVPATH/device/vendor\"`" + vendor="$(cat \"/sys"$DEVPATH"/device/vendor\")" elif [ -r "/sys$DEVPATH/../device/vendor" ]; then - vendor="`cat \"/sys$DEVPATH/../device/vendor\"`" + vendor="$(cat \"/sys"$DEVPATH"/../device/vendor\")" elif [ -r "/sys$DEVPATH/device/../manufacturer" ]; then - vendor="`cat \"/sys$DEVPATH/device/../manufacturer\"`" + vendor="$(cat \"/sys"$DEVPATH"/device/../manufacturer\")" elif [ -r "/sys$DEVPATH/../device/../manufacturer" ]; then - vendor="`cat \"/sys$DEVPATH/../device/../manufacturer\"`" + vendor="$(cat \"/sys"$DEVPATH"/../device/../manufacturer\")" fi vendor="$(echo "$vendor" | sed 's/^[[:blank:]]\+//; s/[[:blank:]]\+$//')" model= if [ -r "/sys$DEVPATH/device/model" ]; then - model="`cat \"/sys$DEVPATH/device/model\"`" + model="$(cat \"/sys"$DEVPATH"/device/model\")" elif [ -r "/sys$DEVPATH/../device/model" ]; then - model="`cat \"/sys$DEVPATH/../device/model\"`" + model="$(cat \"/sys"$DEVPATH"/../device/model\")" elif [ -r "/sys$DEVPATH/device/../product" ]; then - model="`cat \"/sys$DEVPATH/device/../product\"`" + model="$(cat \"/sys"$DEVPATH"/device/../product\")" elif [ -r "/sys$DEVPATH/../device/../product" ]; then - model="`cat \"/sys$DEVPATH/../device/../product\"`" + model="$(cat \"/sys"$DEVPATH"/../device/../product\")" fi model="$(echo "$model" | sed 's/^[[:blank:]]\+//; s/[[:blank:]]\+$//')" @@ -208,7 +208,7 @@ elif [ "$1" = remove ]; then # A block or partition device has been removed. # Test if it is mounted. - while read device mountpoint fstype remainder; do + while read -r device mountpoint fstype; do if [ "/$DEVNAME" = "$device" ]; then log debug "umount device is $device" # If the mountpoint and filesystem type are maintained by From 89a42c5003479641c4e951e72501c495878d6c99 Mon Sep 17 00:00:00 2001 From: Jerry Vonau Date: Sat, 15 Feb 2025 13:08:37 -0600 Subject: [PATCH 07/17] drop fstype for umount --- roles/usb_lib/files/usbmount/usbmount | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/roles/usb_lib/files/usbmount/usbmount b/roles/usb_lib/files/usbmount/usbmount index b4572acc4..74cbc6a3a 100644 --- a/roles/usb_lib/files/usbmount/usbmount +++ b/roles/usb_lib/files/usbmount/usbmount @@ -211,10 +211,10 @@ elif [ "$1" = remove ]; then while read -r device mountpoint fstype; do if [ "/$DEVNAME" = "$device" ]; then log debug "umount device is $device" + log debug "umount mountpoint is $mountpoint" # If the mountpoint and filesystem type are maintained by # this script, unmount the filesystem. - if in_list "$mountpoint" "$MOUNTPOINTS" && - in_list "$fstype" "$FILESYSTEMS"; then + if in_list "$mountpoint" "$MOUNTPOINTS"; then log info "executing command: umount -l $mountpoint" umount -l "$mountpoint" From 5b84cd0b874735379b257fab0d957cf2d41706c0 Mon Sep 17 00:00:00 2001 From: Jerry Vonau Date: Sat, 15 Feb 2025 14:12:37 -0600 Subject: [PATCH 08/17] move to files --- .../{templates => files/usbmount}/iiab-clean-usb.sh | 10 +++++++--- roles/usb_lib/files/usbmount/usbmount | 5 ++--- .../usbmount/usbmount.rules} | 0 .../usbmount/usbmount@.service} | 0 roles/usb_lib/tasks/install.yml | 13 +++---------- 5 files changed, 12 insertions(+), 16 deletions(-) rename roles/usb_lib/{templates => files/usbmount}/iiab-clean-usb.sh (65%) rename roles/usb_lib/{templates/usbmount.rules.j2 => files/usbmount/usbmount.rules} (100%) rename roles/usb_lib/{templates/usbmount@.service.j2 => files/usbmount/usbmount@.service} (100%) diff --git a/roles/usb_lib/templates/iiab-clean-usb.sh b/roles/usb_lib/files/usbmount/iiab-clean-usb.sh similarity index 65% rename from roles/usb_lib/templates/iiab-clean-usb.sh rename to roles/usb_lib/files/usbmount/iiab-clean-usb.sh index cff4ce72d..ee4eee19b 100644 --- a/roles/usb_lib/templates/iiab-clean-usb.sh +++ b/roles/usb_lib/files/usbmount/iiab-clean-usb.sh @@ -1,9 +1,13 @@ #!/bin/bash # Remove symlink in /library/www/html/local_content to automounted USB drive +# exported +#UM_DEVICE="$DEVNAME" +#UM_MOUNTPOINT="$mountpoint" +#UM_FILESYSTEM="$fstype" -DEVICE="/$(echo $1 | sed 's|-|/|')" -MNT_POINT=$(findmnt -no target $DEVICE) -CONTENT_LINK_USB=$(basename $MNT_POINT | awk '{print toupper($0)}') +#DEVICE="/$(echo $1 | sed 's|-|/|')" +#MNT_POINT=$(findmnt -no target $DEVICE) +CONTENT_LINK_USB=$(basename "$UM_MOUNTPOINT" | awk '{print toupper($0)}') CONTENT_LINK="/library/www/html/local_content/$CONTENT_LINK_USB" logger -t "usbmount (iiab-clean-usb.sh)" "Attempting to remove symlink $CONTENT_LINK, as auto-created earlier by usb_lib." diff --git a/roles/usb_lib/files/usbmount/usbmount b/roles/usb_lib/files/usbmount/usbmount index 74cbc6a3a..e1cb60bcc 100644 --- a/roles/usb_lib/files/usbmount/usbmount +++ b/roles/usb_lib/files/usbmount/usbmount @@ -215,15 +215,14 @@ elif [ "$1" = remove ]; then # If the mountpoint and filesystem type are maintained by # this script, unmount the filesystem. if in_list "$mountpoint" "$MOUNTPOINTS"; then - log info "executing command: umount -l $mountpoint" - umount -l "$mountpoint" - # Run hook scripts; ignore errors. export UM_DEVICE="$DEVNAME" export UM_MOUNTPOINT="$mountpoint" export UM_FILESYSTEM="$fstype" log info "executing command: run-parts /etc/usbmount/umount.d" run-parts /etc/usbmount/umount.d || : + log info "executing command: umount -l $mountpoint" + umount -l "$mountpoint" fi break fi diff --git a/roles/usb_lib/templates/usbmount.rules.j2 b/roles/usb_lib/files/usbmount/usbmount.rules similarity index 100% rename from roles/usb_lib/templates/usbmount.rules.j2 rename to roles/usb_lib/files/usbmount/usbmount.rules diff --git a/roles/usb_lib/templates/usbmount@.service.j2 b/roles/usb_lib/files/usbmount/usbmount@.service similarity index 100% rename from roles/usb_lib/templates/usbmount@.service.j2 rename to roles/usb_lib/files/usbmount/usbmount@.service diff --git a/roles/usb_lib/tasks/install.yml b/roles/usb_lib/tasks/install.yml index 660df7eb2..cac0c3d58 100644 --- a/roles/usb_lib/tasks/install.yml +++ b/roles/usb_lib/tasks/install.yml @@ -93,16 +93,9 @@ with_items: - { src: 'usbmount/usbmount.conf', dest: '/etc/usbmount/', mode: '0644' } - { src: 'usbmount/usbmount', dest: '/usr/local/sbin/', mode: '0755' } - -- name: 'Install from template: /etc/udev/rules.d/usbmount.rules, /etc/systemd/system/usbmount@.service, /usr/local/sbin/iiab-clean-usb.sh' - template: - src: "{{ item.src }}" - dest: "{{ item.dest }}" - mode: "{{ item.mode }}" - with_items: - - { src: 'usbmount.rules.j2', dest: '/etc/udev/rules.d/usbmount.rules', mode: '0644' } - - { src: 'usbmount@.service.j2', dest: '/etc/systemd/system/usbmount@.service', mode: '0644' } - - { src: 'iiab-clean-usb.sh', dest: '/usr/local/sbin/', mode: '0755' } + - { src: 'usbmount/usbmount.rules', dest: '/etc/udev/rules.d/usbmount.rules', mode: '0644' } + - { src: 'usbmount/usbmount@.service', dest: '/etc/systemd/system/usbmount@.service', mode: '0644' } + - { src: 'usbmount/iiab-clean-usb.sh', dest: '/etc/usbmount/umount.d/iiab-clean-usb.sh', mode: '0755' } - name: Add dir {{ doc_root }}/upload2usb (0775) owned by {{ apache_user }}:{{ apache_user }} file: From a5be0e19d299c6b88f3504a69974f64513f017c5 Mon Sep 17 00:00:00 2001 From: Jerry Vonau Date: Sat, 15 Feb 2025 14:18:12 -0600 Subject: [PATCH 09/17] unit file --- roles/usb_lib/files/usbmount/usbmount@.service | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/roles/usb_lib/files/usbmount/usbmount@.service b/roles/usb_lib/files/usbmount/usbmount@.service index 9466591a4..dc0025915 100644 --- a/roles/usb_lib/files/usbmount/usbmount@.service +++ b/roles/usb_lib/files/usbmount/usbmount@.service @@ -9,7 +9,6 @@ ConditionPathExists=/var/run TimeoutStartSec=0 Environment=DEVNAME=%I ExecStart=/usr/local/sbin/usbmount add -ExecStop=/usr/local/sbin/iiab-clean-usb.sh %I -ExecStopPost=/usr/local/sbin/usbmount remove +ExecStop=/usr/local/sbin/usbmount remove RemainAfterExit=yes RuntimeDirectory=usbmount From 0286fed85c60a224d7e95a8ee7371e02c07b56ad Mon Sep 17 00:00:00 2001 From: Jerry Vonau Date: Sat, 15 Feb 2025 14:50:45 -0600 Subject: [PATCH 10/17] moved to usbmount --- .../templates/mount.d/70-usb-library.j2 | 42 ++++++++++++------- 1 file changed, 26 insertions(+), 16 deletions(-) diff --git a/roles/usb_lib/templates/mount.d/70-usb-library.j2 b/roles/usb_lib/templates/mount.d/70-usb-library.j2 index 8263bde1f..e77092fce 100644 --- a/roles/usb_lib/templates/mount.d/70-usb-library.j2 +++ b/roles/usb_lib/templates/mount.d/70-usb-library.j2 @@ -8,39 +8,49 @@ # # # by Tim Moody tim@timmoody.com +# Jerry Vonau jvonau3@gmail.com +# +# exported from usbmount +# UM_DEVICE="/$DEVNAME" +# UM_MOUNTPOINT="$mountpoint" +# UM_FILESYSTEM="$fstype" +# UM_MOUNTOPTIONS="$options" +# UM_VENDOR="$vendor" +# UM_MODEL="$model" +# UM_MOUNTPOINT is documented at: https://github.com/rbrito/usbmount#hook-scripts # Better to set this in /etc/usbmount/usbmount.conf # VERBOSE=yes -# UM_MOUNTPOINT is documented at: https://github.com/rbrito/usbmount#hook-scripts UM_DEV=$(findmnt -no source $UM_MOUNTPOINT) # 2022-06-16 better security thanks to @tim-moody and @jvonau: # https://github.com/iiab/iiab/pull/3254 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) +# excluded from mounting in usbmount +#ROOT_DEV=$(findmnt -no source /) +#BOOT_DEV=$(findmnt -no source /boot) +#BOOTFW_DEV=$(findmnt -no source /boot/firmware) # Verbose logging to illuminate occasional boot bugginess: logger -t "usb_lib (70-usb-library)" "UM_DEV is: $UM_DEV" 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" +#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" if [ "$UM_DEV" == "$LIB_DEV" ]; then logger -t "usb_lib (70-usb-library)" "Skipping $UM_MOUNTPOINT containing /library" exit 1 -elif [ "$UM_DEV" == "$ROOT_DEV" ]; then - logger -t "usb_lib (70-usb-library)" "Skipping $UM_MOUNTPOINT containing rootfs" - exit 1 -elif [ "$UM_DEV" == "$BOOT_DEV" ]; then - logger -t "usb_lib (70-usb-library)" "Skipping $UM_MOUNTPOINT containing /boot" - exit 1 -elif [ "$UM_DEV" == "$BOOTFW_DEV" ]; then - logger -t "usb_lib (70-usb-library)" "Skipping $UM_MOUNTPOINT containing /boot/firmware" - exit 1 +#elif [ "$UM_DEV" == "$ROOT_DEV" ]; then +# logger -t "usb_lib (70-usb-library)" "Skipping $UM_MOUNTPOINT containing rootfs" +# exit 1 +#elif [ "$UM_DEV" == "$BOOT_DEV" ]; then +# logger -t "usb_lib (70-usb-library)" "Skipping $UM_MOUNTPOINT containing /boot" +# exit 1 +#elif [ "$UM_DEV" == "$BOOTFW_DEV" ]; then +# logger -t "usb_lib (70-usb-library)" "Skipping $UM_MOUNTPOINT containing /boot/firmware" +# exit 1 fi # 2025-01-25: Check for existence of folder PUBLIC on USB stick: if found, the stick will not be completely browsable. From a2bc696f4d60fc201e784ae2a4a8d999797265a5 Mon Sep 17 00:00:00 2001 From: Jerry Vonau Date: Sat, 15 Feb 2025 14:55:48 -0600 Subject: [PATCH 11/17] logging --- roles/usb_lib/templates/mount.d/70-usb-library.j2 | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/roles/usb_lib/templates/mount.d/70-usb-library.j2 b/roles/usb_lib/templates/mount.d/70-usb-library.j2 index e77092fce..e133b6bb5 100644 --- a/roles/usb_lib/templates/mount.d/70-usb-library.j2 +++ b/roles/usb_lib/templates/mount.d/70-usb-library.j2 @@ -22,6 +22,7 @@ # Better to set this in /etc/usbmount/usbmount.conf # VERBOSE=yes +logger -t "usbmount - usb_lib (70-usb-library)" "UM_MOUNTPOINT is: $UM_MOUNTPOINT" UM_DEV=$(findmnt -no source $UM_MOUNTPOINT) # 2022-06-16 better security thanks to @tim-moody and @jvonau: @@ -33,14 +34,14 @@ LIB_DEV=$(findmnt -no source /library | cut -d '[' -f 1) #BOOTFW_DEV=$(findmnt -no source /boot/firmware) # Verbose logging to illuminate occasional boot bugginess: -logger -t "usb_lib (70-usb-library)" "UM_DEV is: $UM_DEV" -logger -t "usb_lib (70-usb-library)" "LIB_DEV is: $LIB_DEV" +logger -t "usbmount - usb_lib (70-usb-library)" "UM_DEV is: $UM_DEV" +logger -t "usbmount - 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" if [ "$UM_DEV" == "$LIB_DEV" ]; then - logger -t "usb_lib (70-usb-library)" "Skipping $UM_MOUNTPOINT containing /library" + logger -t "usbmount - usb_lib (70-usb-library)" "Skipping $UM_MOUNTPOINT containing /library" exit 1 #elif [ "$UM_DEV" == "$ROOT_DEV" ]; then # logger -t "usb_lib (70-usb-library)" "Skipping $UM_MOUNTPOINT containing rootfs" @@ -58,20 +59,20 @@ fi # "public artwork" — as summarized here: https://github.com/iiab/iiab/blob/master/roles/usb_lib/README.rst if [ -d $UM_MOUNTPOINT/PUBLIC ]; then SHARE_DIR=$UM_MOUNTPOINT/PUBLIC - logger -t "usb_lib (70-usb-library)" "Found /PUBLIC on $UM_MOUNTPOINT" + logger -t "usbmount - usb_lib (70-usb-library)" "Found /PUBLIC on $UM_MOUNTPOINT" else SHARE_DIR=$UM_MOUNTPOINT - logger -t "usb_lib (70-usb-library)" "Did not find /PUBLIC on $UM_MOUNTPOINT" + logger -t "usbmount - usb_lib (70-usb-library)" "Did not find /PUBLIC on $UM_MOUNTPOINT" fi CONTENT_LINK_USB=$(basename $UM_MOUNTPOINT | awk '{print toupper($0)}') if [ -z "$CONTENT_LINK_USB" ]; then - logger -t "usb_lib (70-usb-library)" 'ERROR: Var CONTENT_LINK_USB is empty ("rm -rf /library/www/html/local_content/" would be dangerous!)' + logger -t "usbmount - usb_lib (70-usb-library)" 'ERROR: Var CONTENT_LINK_USB is empty ("rm -rf /library/www/html/local_content/" would be dangerous!)' exit 1 fi CONTENT_LINK="{{ doc_root }}/local_content/$CONTENT_LINK_USB" # '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 -logger -t "usb_lib (70-usb-library)" "Creating link from $CONTENT_LINK to $SHARE_DIR" +logger -t "usbmount - usb_lib (70-usb-library)" "Creating link from $CONTENT_LINK to $SHARE_DIR" rm -rf $CONTENT_LINK ln -s $SHARE_DIR $CONTENT_LINK From 334d80d579d40fc7828eea2df56f64b294d815cd Mon Sep 17 00:00:00 2001 From: Jerry Vonau Date: Sat, 15 Feb 2025 15:19:33 -0600 Subject: [PATCH 12/17] export --- roles/usb_lib/files/usbmount/usbmount | 2 +- roles/usb_lib/templates/mount.d/70-usb-library.j2 | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/roles/usb_lib/files/usbmount/usbmount b/roles/usb_lib/files/usbmount/usbmount index e1cb60bcc..e676f7cd1 100644 --- a/roles/usb_lib/files/usbmount/usbmount +++ b/roles/usb_lib/files/usbmount/usbmount @@ -216,7 +216,7 @@ elif [ "$1" = remove ]; then # this script, unmount the filesystem. if in_list "$mountpoint" "$MOUNTPOINTS"; then # Run hook scripts; ignore errors. - export UM_DEVICE="$DEVNAME" + export UM_DEVICE="/$DEVNAME" export UM_MOUNTPOINT="$mountpoint" export UM_FILESYSTEM="$fstype" log info "executing command: run-parts /etc/usbmount/umount.d" diff --git a/roles/usb_lib/templates/mount.d/70-usb-library.j2 b/roles/usb_lib/templates/mount.d/70-usb-library.j2 index e133b6bb5..7b0ac9c97 100644 --- a/roles/usb_lib/templates/mount.d/70-usb-library.j2 +++ b/roles/usb_lib/templates/mount.d/70-usb-library.j2 @@ -23,7 +23,8 @@ # VERBOSE=yes logger -t "usbmount - usb_lib (70-usb-library)" "UM_MOUNTPOINT is: $UM_MOUNTPOINT" -UM_DEV=$(findmnt -no source $UM_MOUNTPOINT) +logger -t "usbmount - usb_lib (70-usb-library)" "UM_DEVICE is: $UM_DEVICE" +#UM_DEV=$(findmnt -no source $UM_MOUNTPOINT) # 2022-06-16 better security thanks to @tim-moody and @jvonau: # https://github.com/iiab/iiab/pull/3254 @@ -34,13 +35,13 @@ LIB_DEV=$(findmnt -no source /library | cut -d '[' -f 1) #BOOTFW_DEV=$(findmnt -no source /boot/firmware) # Verbose logging to illuminate occasional boot bugginess: -logger -t "usbmount - usb_lib (70-usb-library)" "UM_DEV is: $UM_DEV" logger -t "usbmount - 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" -if [ "$UM_DEV" == "$LIB_DEV" ]; then +#if [ "$UM_DEV" == "$LIB_DEV" ]; then +if [ "$UM_DEVICE" == "$LIB_DEV" ]; then logger -t "usbmount - usb_lib (70-usb-library)" "Skipping $UM_MOUNTPOINT containing /library" exit 1 #elif [ "$UM_DEV" == "$ROOT_DEV" ]; then From aa8ce5841d7e2d82028c5b3af0be33b208dee4d4 Mon Sep 17 00:00:00 2001 From: Jerry Vonau Date: Sat, 15 Feb 2025 15:54:10 -0600 Subject: [PATCH 13/17] touchups --- roles/usb_lib/files/usbmount/usbmount | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/roles/usb_lib/files/usbmount/usbmount b/roles/usb_lib/files/usbmount/usbmount index e676f7cd1..e6a153966 100644 --- a/roles/usb_lib/files/usbmount/usbmount +++ b/roles/usb_lib/files/usbmount/usbmount @@ -90,12 +90,12 @@ if [ "$1" = add ]; then # Grab device information from device and "divide it" # FIXME: improvement: implement mounting by label (notice that labels # can contain spaces, which makes things a little bit less comfortable). - DEVINFO=$(/sbin/blkid -p "$DEVNAME") + DEVINFO=$(/sbin/blkid -p "/$DEVNAME") FSTYPE=$(echo "$DEVINFO" | sed 's/.*[[:blank:]]TYPE="\([^"]*\)".*/\1/g; s/[[:blank:]]*//g;') UUID=$(echo "$DEVINFO" | sed 's/.*[[:blank:]]UUID="\([^"]*\)".*/\1/g; s/[[:blank:]]*//g;') USAGE=$(echo "$DEVINFO" | sed 's/.*[[:blank:]]USAGE="\([^"]*\)".*/\1/g; s/[[:blank:]]*//g;') - if ! echo "$USAGE" | grep -Eq "(filesystem|disklabel)"; then + if ! echo "$USAGE" | grep -E "(filesystem|disklabel)"; then log debug "/$DEVNAME does not contain a filesystem or disklabel" lockfile-remove /var/run/usbmount/.mount exit @@ -206,17 +206,19 @@ if [ "$1" = add ]; then fi elif [ "$1" = remove ]; then + log debug "DEVNAME is /$DEVNAME" # A block or partition device has been removed. # Test if it is mounted. - while read -r device mountpoint fstype; do + while read -r device mountpoint fstype junk; do if [ "/$DEVNAME" = "$device" ]; then log debug "umount device is $device" - log debug "umount mountpoint is $mountpoint" + log debug "umount fstype is $fstype" # If the mountpoint and filesystem type are maintained by # this script, unmount the filesystem. if in_list "$mountpoint" "$MOUNTPOINTS"; then # Run hook scripts; ignore errors. - export UM_DEVICE="/$DEVNAME" + log debug "umount mountpoint is $mountpoint" + export UM_DEVICE="$device" export UM_MOUNTPOINT="$mountpoint" export UM_FILESYSTEM="$fstype" log info "executing command: run-parts /etc/usbmount/umount.d" From 7fb780aea23d621ca40f4b7c1e004bcecf93277e Mon Sep 17 00:00:00 2001 From: Jerry Vonau Date: Sat, 15 Feb 2025 23:51:04 -0600 Subject: [PATCH 14/17] bring back umount.d/70-usb-library.j2 --- .../{iiab-clean-usb.sh => iiab-clean-usb.sh.unused} | 0 roles/usb_lib/tasks/install.yml | 1 - roles/usb_lib/tasks/nginx.yml | 8 ++++++++ .../70-usb-library => umount.d/70-usb-library.j2} | 13 +++++-------- 4 files changed, 13 insertions(+), 9 deletions(-) rename roles/usb_lib/files/usbmount/{iiab-clean-usb.sh => iiab-clean-usb.sh.unused} (100%) rename roles/usb_lib/templates/{umount.d.unused/70-usb-library => umount.d/70-usb-library.j2} (52%) diff --git a/roles/usb_lib/files/usbmount/iiab-clean-usb.sh b/roles/usb_lib/files/usbmount/iiab-clean-usb.sh.unused similarity index 100% rename from roles/usb_lib/files/usbmount/iiab-clean-usb.sh rename to roles/usb_lib/files/usbmount/iiab-clean-usb.sh.unused diff --git a/roles/usb_lib/tasks/install.yml b/roles/usb_lib/tasks/install.yml index cac0c3d58..96ec0eaa2 100644 --- a/roles/usb_lib/tasks/install.yml +++ b/roles/usb_lib/tasks/install.yml @@ -95,7 +95,6 @@ - { src: 'usbmount/usbmount', dest: '/usr/local/sbin/', mode: '0755' } - { src: 'usbmount/usbmount.rules', dest: '/etc/udev/rules.d/usbmount.rules', mode: '0644' } - { src: 'usbmount/usbmount@.service', dest: '/etc/systemd/system/usbmount@.service', mode: '0644' } - - { src: 'usbmount/iiab-clean-usb.sh', dest: '/etc/usbmount/umount.d/iiab-clean-usb.sh', mode: '0755' } - name: Add dir {{ doc_root }}/upload2usb (0775) owned by {{ apache_user }}:{{ apache_user }} file: diff --git a/roles/usb_lib/tasks/nginx.yml b/roles/usb_lib/tasks/nginx.yml index 1e6be6d21..3e47dad8f 100644 --- a/roles/usb_lib/tasks/nginx.yml +++ b/roles/usb_lib/tasks/nginx.yml @@ -1,3 +1,11 @@ +- name: Install /etc/usbmount/umount.d/70-usb-library from template + template: + src: umount.d/70-usb-library.j2 + dest: /etc/usbmount/umount.d/70-usb-library + owner: root + group: root + mode: '0751' + - name: Install /etc/usbmount/mount.d/70-usb-library from template, if usb_lib_enabled template: src: mount.d/70-usb-library.j2 diff --git a/roles/usb_lib/templates/umount.d.unused/70-usb-library b/roles/usb_lib/templates/umount.d/70-usb-library.j2 similarity index 52% rename from roles/usb_lib/templates/umount.d.unused/70-usb-library rename to roles/usb_lib/templates/umount.d/70-usb-library.j2 index d8e095008..4f55d4d6a 100644 --- a/roles/usb_lib/templates/umount.d.unused/70-usb-library +++ b/roles/usb_lib/templates/umount.d/70-usb-library.j2 @@ -8,17 +8,14 @@ # # # by Tim Moody tim@timmoody.com +# Jerry Vonau jvonau3@gmail.com -CONTENT_LINK_USB=`basename $UM_MOUNTPOINT | awk '{print toupper($0)}'` +CONTENT_LINK_USB=$(basename $UM_MOUNTPOINT | awk '{print toupper($0)}') CONTENT_LINK="{{ doc_root }}/local_content/$CONTENT_LINK_USB" -logger -p user.notice -t "usb_lib (70-usb-library)" -- "Attempting to remove link $CONTENT_LINK." +logger -p user.notice -t "usbmount (70-usb-library)" -- "Attempting to remove link $CONTENT_LINK." if [ -L $CONTENT_LINK ]; then -{% if is_debuntu %} - /bin/rm -f $CONTENT_LINK -{% else %} - /usr/bin/rm -f $CONTENT_LINK -{% endif %} - logger -p user.notice -t "usb_lib (70-usb-library)" -- "$CONTENT_LINK removed." + rm -f $CONTENT_LINK + logger -p user.notice -t "usbmount (70-usb-library)" -- "$CONTENT_LINK removed." fi From 896d31cf90c39ffe47bfe4d38c92e64b7a8c25b6 Mon Sep 17 00:00:00 2001 From: Jerry Vonau Date: Sun, 16 Feb 2025 14:41:25 -0600 Subject: [PATCH 15/17] export notes --- roles/usb_lib/templates/mount.d/70-usb-library.j2 | 2 +- roles/usb_lib/templates/umount.d/70-usb-library.j2 | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/roles/usb_lib/templates/mount.d/70-usb-library.j2 b/roles/usb_lib/templates/mount.d/70-usb-library.j2 index 7b0ac9c97..433b697f6 100644 --- a/roles/usb_lib/templates/mount.d/70-usb-library.j2 +++ b/roles/usb_lib/templates/mount.d/70-usb-library.j2 @@ -11,7 +11,7 @@ # Jerry Vonau jvonau3@gmail.com # # exported from usbmount -# UM_DEVICE="/$DEVNAME" +# UM_DEVICE="$device" # UM_MOUNTPOINT="$mountpoint" # UM_FILESYSTEM="$fstype" # UM_MOUNTOPTIONS="$options" diff --git a/roles/usb_lib/templates/umount.d/70-usb-library.j2 b/roles/usb_lib/templates/umount.d/70-usb-library.j2 index 4f55d4d6a..babf8cf2e 100644 --- a/roles/usb_lib/templates/umount.d/70-usb-library.j2 +++ b/roles/usb_lib/templates/umount.d/70-usb-library.j2 @@ -9,6 +9,11 @@ # # by Tim Moody tim@timmoody.com # Jerry Vonau jvonau3@gmail.com +# +# exported from usbmount +# UM_DEVICE="$device" +# UM_MOUNTPOINT="$mountpoint" +# UM_FILESYSTEM="$fstype" CONTENT_LINK_USB=$(basename $UM_MOUNTPOINT | awk '{print toupper($0)}') CONTENT_LINK="{{ doc_root }}/local_content/$CONTENT_LINK_USB" From 3e6f551d5ca1a82501bc85a4a29c027c84943793 Mon Sep 17 00:00:00 2001 From: Jerry Vonau Date: Wed, 19 Feb 2025 00:51:37 -0600 Subject: [PATCH 16/17] logging --- .../templates/mount.d/70-usb-library.j2 | 34 +++++-------------- 1 file changed, 8 insertions(+), 26 deletions(-) diff --git a/roles/usb_lib/templates/mount.d/70-usb-library.j2 b/roles/usb_lib/templates/mount.d/70-usb-library.j2 index 433b697f6..b8df7613f 100644 --- a/roles/usb_lib/templates/mount.d/70-usb-library.j2 +++ b/roles/usb_lib/templates/mount.d/70-usb-library.j2 @@ -22,37 +22,19 @@ # Better to set this in /etc/usbmount/usbmount.conf # VERBOSE=yes -logger -t "usbmount - usb_lib (70-usb-library)" "UM_MOUNTPOINT is: $UM_MOUNTPOINT" -logger -t "usbmount - usb_lib (70-usb-library)" "UM_DEVICE is: $UM_DEVICE" -#UM_DEV=$(findmnt -no source $UM_MOUNTPOINT) +logger -p user.notice -t "usbmount - usb_lib (70-usb-library)" "UM_MOUNTPOINT is: $UM_MOUNTPOINT" +logger -p user.notice -t "usbmount - usb_lib (70-usb-library)" "UM_DEVICE is: $UM_DEVICE" # 2022-06-16 better security thanks to @tim-moody and @jvonau: # https://github.com/iiab/iiab/pull/3254 LIB_DEV=$(findmnt -no source /library | cut -d '[' -f 1) -# excluded from mounting in usbmount -#ROOT_DEV=$(findmnt -no source /) -#BOOT_DEV=$(findmnt -no source /boot) -#BOOTFW_DEV=$(findmnt -no source /boot/firmware) # Verbose logging to illuminate occasional boot bugginess: -logger -t "usbmount - 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" +logger -p user.notice -t "usbmount - usb_lib (70-usb-library)" "LIB_DEV is: $LIB_DEV" -#if [ "$UM_DEV" == "$LIB_DEV" ]; then if [ "$UM_DEVICE" == "$LIB_DEV" ]; then - logger -t "usbmount - usb_lib (70-usb-library)" "Skipping $UM_MOUNTPOINT containing /library" + logger -p user.notice -t "usbmount - usb_lib (70-usb-library)" "Skipping $UM_MOUNTPOINT containing /library" exit 1 -#elif [ "$UM_DEV" == "$ROOT_DEV" ]; then -# logger -t "usb_lib (70-usb-library)" "Skipping $UM_MOUNTPOINT containing rootfs" -# exit 1 -#elif [ "$UM_DEV" == "$BOOT_DEV" ]; then -# logger -t "usb_lib (70-usb-library)" "Skipping $UM_MOUNTPOINT containing /boot" -# exit 1 -#elif [ "$UM_DEV" == "$BOOTFW_DEV" ]; then -# logger -t "usb_lib (70-usb-library)" "Skipping $UM_MOUNTPOINT containing /boot/firmware" -# exit 1 fi # 2025-01-25: Check for existence of folder PUBLIC on USB stick: if found, the stick will not be completely browsable. @@ -60,20 +42,20 @@ fi # "public artwork" — as summarized here: https://github.com/iiab/iiab/blob/master/roles/usb_lib/README.rst if [ -d $UM_MOUNTPOINT/PUBLIC ]; then SHARE_DIR=$UM_MOUNTPOINT/PUBLIC - logger -t "usbmount - usb_lib (70-usb-library)" "Found /PUBLIC on $UM_MOUNTPOINT" + logger -p user.notice -t "usbmount - usb_lib (70-usb-library)" "Found /PUBLIC on $UM_MOUNTPOINT" else SHARE_DIR=$UM_MOUNTPOINT - logger -t "usbmount - usb_lib (70-usb-library)" "Did not find /PUBLIC on $UM_MOUNTPOINT" + logger -p user.notice -t "usbmount - usb_lib (70-usb-library)" "Did not find /PUBLIC on $UM_MOUNTPOINT" fi CONTENT_LINK_USB=$(basename $UM_MOUNTPOINT | awk '{print toupper($0)}') if [ -z "$CONTENT_LINK_USB" ]; then - logger -t "usbmount - usb_lib (70-usb-library)" 'ERROR: Var CONTENT_LINK_USB is empty ("rm -rf /library/www/html/local_content/" would be dangerous!)' + logger -p user.notice -t "usbmount - usb_lib (70-usb-library)" 'ERROR: Var CONTENT_LINK_USB is empty ("rm -rf /library/www/html/local_content/" would be dangerous!)' exit 1 fi CONTENT_LINK="{{ doc_root }}/local_content/$CONTENT_LINK_USB" # '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 -logger -t "usbmount - usb_lib (70-usb-library)" "Creating link from $CONTENT_LINK to $SHARE_DIR" +logger -p user.notice -t "usbmount - usb_lib (70-usb-library)" "Creating link from $CONTENT_LINK to $SHARE_DIR" rm -rf $CONTENT_LINK ln -s $SHARE_DIR $CONTENT_LINK From 419e4d0a0cc43a454fe29ae5cd21e9646dab24bf Mon Sep 17 00:00:00 2001 From: Jerry Vonau Date: Thu, 20 Feb 2025 02:24:23 -0600 Subject: [PATCH 17/17] usb_lib in umount.d/70-usb-library --- roles/usb_lib/templates/umount.d/70-usb-library.j2 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/roles/usb_lib/templates/umount.d/70-usb-library.j2 b/roles/usb_lib/templates/umount.d/70-usb-library.j2 index babf8cf2e..6ee2afc42 100644 --- a/roles/usb_lib/templates/umount.d/70-usb-library.j2 +++ b/roles/usb_lib/templates/umount.d/70-usb-library.j2 @@ -18,9 +18,9 @@ CONTENT_LINK_USB=$(basename $UM_MOUNTPOINT | awk '{print toupper($0)}') CONTENT_LINK="{{ doc_root }}/local_content/$CONTENT_LINK_USB" -logger -p user.notice -t "usbmount (70-usb-library)" -- "Attempting to remove link $CONTENT_LINK." +logger -p user.notice -t "usbmount - usb_lib (70-usb-library)" -- "Attempting to remove link $CONTENT_LINK." if [ -L $CONTENT_LINK ]; then rm -f $CONTENT_LINK - logger -p user.notice -t "usbmount (70-usb-library)" -- "$CONTENT_LINK removed." + logger -p user.notice -t "usbmount - usb_lib (70-usb-library)" -- "$CONTENT_LINK removed." fi