mirror of
https://github.com/iiab/iiab.git
synced 2025-03-09 15:40:17 +00:00
Add lockfile removal before exit in usbmount script per Jerry's recommendation.
Add lockfile removal before exit in usbmount script per Jerry's recommendation. Also adjusted spacing! Read up on file locking a bit: - https://www.baeldung.com/linux/file-locking - https://linux.die.net/man/1/lockfile-create
This commit is contained in:
parent
a96b46c223
commit
fe6516b2e9
1 changed files with 88 additions and 87 deletions
|
@ -96,8 +96,9 @@ if [ "$1" = add ]; then
|
||||||
USAGE=$(echo "$DEVINFO" | sed 's/.*[[:blank:]]USAGE="\([^"]*\)".*/\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 | egrep -q "(filesystem|disklabel)"; then
|
||||||
log debug "/$DEVNAME does not contain a filesystem or disklabel"
|
log debug "/$DEVNAME does not contain a filesystem or disklabel"
|
||||||
exit
|
lockfile-remove /var/run/usbmount/.mount
|
||||||
|
exit
|
||||||
fi
|
fi
|
||||||
|
|
||||||
log debug "/$DEVNAME contains filesystem type $FSTYPE"
|
log debug "/$DEVNAME contains filesystem type $FSTYPE"
|
||||||
|
@ -109,7 +110,7 @@ if [ "$1" = add ]; then
|
||||||
log debug "BOOT_DEV $BOOT_DEV"
|
log debug "BOOT_DEV $BOOT_DEV"
|
||||||
|
|
||||||
if [ $BOOTFW_DEV = /$DEVNAME ]; then
|
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
|
lockfile-remove /var/run/usbmount/.mount
|
||||||
exit
|
exit
|
||||||
elif [ $ROOT_DEV = /$DEVNAME ]; then
|
elif [ $ROOT_DEV = /$DEVNAME ]; then
|
||||||
|
@ -124,107 +125,107 @@ if [ "$1" = add ]; then
|
||||||
|
|
||||||
# Try to use specifications in /etc/fstab to skip.
|
# Try to use specifications in /etc/fstab to skip.
|
||||||
if egrep -q "^[[:blank:]]*$DEVNAME" /etc/fstab; then
|
if egrep -q "^[[:blank:]]*$DEVNAME" /etc/fstab; then
|
||||||
log debug "skipping /$DEVNAME exit"
|
log debug "skipping /$DEVNAME exit"
|
||||||
lockfile-remove /var/run/usbmount/.mount
|
lockfile-remove /var/run/usbmount/.mount
|
||||||
exit
|
exit
|
||||||
elif grep -q "^[[:blank:]]*UUID=$UUID" /etc/fstab; then
|
elif grep -q "^[[:blank:]]*UUID=$UUID" /etc/fstab; then
|
||||||
log debug "skipping $UUID"
|
log debug "skipping $UUID"
|
||||||
lockfile-remove /var/run/usbmount/.mount
|
lockfile-remove /var/run/usbmount/.mount
|
||||||
exit
|
exit
|
||||||
else
|
else
|
||||||
log debug "/$DEVNAME contains filesystem type $FSTYPE"
|
log debug "/$DEVNAME contains filesystem type $FSTYPE"
|
||||||
fstype=$FSTYPE
|
fstype=$FSTYPE
|
||||||
# Test if the filesystem type is in the list of filesystem
|
# Test if the filesystem type is in the list of filesystem
|
||||||
# types to mount.
|
# types to mount.
|
||||||
if in_list "$fstype" "$FILESYSTEMS"; then
|
if in_list "$fstype" "$FILESYSTEMS"; then
|
||||||
# Search an available mountpoint.
|
# Search an available mountpoint.
|
||||||
for v in $MOUNTPOINTS; do
|
for v in $MOUNTPOINTS; do
|
||||||
if [ -d "$v" ] && ! grep -q "^[^ ][^ ]* *$v " /proc/mounts; then
|
if [ -d "$v" ] && ! grep -q "^[^ ][^ ]* *$v " /proc/mounts; then
|
||||||
mountpoint="$v"
|
mountpoint="$v"
|
||||||
log debug "mountpoint $mountpoint is available for /$DEVNAME"
|
log debug "mountpoint $mountpoint is available for /$DEVNAME"
|
||||||
break
|
break
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
if [ -n "$mountpoint" ]; then
|
if [ -n "$mountpoint" ]; then
|
||||||
# Determine mount options.
|
# Determine mount options.
|
||||||
options=
|
options=
|
||||||
for v in $FS_MOUNTOPTIONS; do
|
for v in $FS_MOUNTOPTIONS; do
|
||||||
if expr "$v" : "-fstype=$fstype,."; then
|
if expr "$v" : "-fstype=$fstype,."; then
|
||||||
options="$(echo "$v" | sed 's/^[^,]*,//')"
|
options="$(echo "$v" | sed 's/^[^,]*,//')"
|
||||||
break
|
break
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
if [ -n "$MOUNTOPTIONS" ]; then
|
if [ -n "$MOUNTOPTIONS" ]; then
|
||||||
options="$MOUNTOPTIONS${options:+,$options}"
|
options="$MOUNTOPTIONS${options:+,$options}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Mount the filesystem.
|
# 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"
|
mount "-t$fstype" "${options:+-o$options}" "$DEVNAME" "$mountpoint"
|
||||||
|
|
||||||
# Determine vendor and model.
|
# Determine vendor and model.
|
||||||
vendor=
|
vendor=
|
||||||
if [ -r "/sys$DEVPATH/device/vendor" ]; then
|
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
|
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
|
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
|
elif [ -r "/sys$DEVPATH/../device/../manufacturer" ]; then
|
||||||
vendor="`cat \"/sys$DEVPATH/../device/../manufacturer\"`"
|
vendor="`cat \"/sys$DEVPATH/../device/../manufacturer\"`"
|
||||||
fi
|
fi
|
||||||
vendor="$(echo "$vendor" | sed 's/^[[:blank:]]\+//; s/[[:blank:]]\+$//')"
|
vendor="$(echo "$vendor" | sed 's/^[[:blank:]]\+//; s/[[:blank:]]\+$//')"
|
||||||
|
|
||||||
model=
|
model=
|
||||||
if [ -r "/sys$DEVPATH/device/model" ]; then
|
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
|
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
|
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
|
elif [ -r "/sys$DEVPATH/../device/../product" ]; then
|
||||||
model="`cat \"/sys$DEVPATH/../device/../product\"`"
|
model="`cat \"/sys$DEVPATH/../device/../product\"`"
|
||||||
fi
|
fi
|
||||||
model="$(echo "$model" | sed 's/^[[:blank:]]\+//; s/[[:blank:]]\+$//')"
|
model="$(echo "$model" | sed 's/^[[:blank:]]\+//; s/[[:blank:]]\+$//')"
|
||||||
|
|
||||||
# Run hook scripts; ignore errors.
|
# Run hook scripts; ignore errors.
|
||||||
export UM_DEVICE="$DEVNAME"
|
export UM_DEVICE="$DEVNAME"
|
||||||
export UM_MOUNTPOINT="$mountpoint"
|
export UM_MOUNTPOINT="$mountpoint"
|
||||||
export UM_FILESYSTEM="$fstype"
|
export UM_FILESYSTEM="$fstype"
|
||||||
export UM_MOUNTOPTIONS="$options"
|
export UM_MOUNTOPTIONS="$options"
|
||||||
export UM_VENDOR="$vendor"
|
export UM_VENDOR="$vendor"
|
||||||
export UM_MODEL="$model"
|
export UM_MODEL="$model"
|
||||||
log info "executing command: run-parts /etc/usbmount/mount.d"
|
log info "executing command: run-parts /etc/usbmount/mount.d"
|
||||||
run-parts /etc/usbmount/mount.d || :
|
run-parts /etc/usbmount/mount.d || :
|
||||||
else
|
else
|
||||||
# No suitable mount point found.
|
# No suitable mount point found.
|
||||||
log warning "no mountpoint found for $DEVNAME"
|
log warning "no mountpoint found for $DEVNAME"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
elif [ "$1" = remove ]; then
|
elif [ "$1" = remove ]; then
|
||||||
|
|
||||||
# A block or partition device has been removed.
|
# A block or partition device has been removed.
|
||||||
# Test if it is mounted.
|
# Test if it is mounted.
|
||||||
while read device mountpoint fstype remainder; do
|
while read device mountpoint fstype remainder; do
|
||||||
if [ "$DEVNAME" = "$device" ]; then
|
if [ "$DEVNAME" = "$device" ]; then
|
||||||
# If the mountpoint and filesystem type are maintained by
|
# If the mountpoint and filesystem type are maintained by
|
||||||
# this script, unmount the filesystem.
|
# this script, unmount the filesystem.
|
||||||
if in_list "$mountpoint" "$MOUNTPOINTS" &&
|
if in_list "$mountpoint" "$MOUNTPOINTS" &&
|
||||||
in_list "$fstype" "$FILESYSTEMS"; then
|
in_list "$fstype" "$FILESYSTEMS"; then
|
||||||
log info "executing command: umount -l $mountpoint"
|
log info "executing command: umount -l $mountpoint"
|
||||||
umount -l "$mountpoint"
|
umount -l "$mountpoint"
|
||||||
|
|
||||||
# Run hook scripts; ignore errors.
|
# Run hook scripts; ignore errors.
|
||||||
export UM_DEVICE="$DEVNAME"
|
export UM_DEVICE="$DEVNAME"
|
||||||
export UM_MOUNTPOINT="$mountpoint"
|
export UM_MOUNTPOINT="$mountpoint"
|
||||||
export UM_FILESYSTEM="$fstype"
|
export UM_FILESYSTEM="$fstype"
|
||||||
log info "executing command: run-parts /etc/usbmount/umount.d"
|
log info "executing command: run-parts /etc/usbmount/umount.d"
|
||||||
run-parts /etc/usbmount/umount.d || :
|
run-parts /etc/usbmount/umount.d || :
|
||||||
fi
|
fi
|
||||||
break
|
break
|
||||||
fi
|
fi
|
||||||
done < /proc/mounts
|
done < /proc/mounts
|
||||||
else
|
else
|
||||||
log err "unexpected: action '$1'"
|
log err "unexpected: action '$1'"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue