qmnt - Added UUID mount labeling option

This commit is contained in:
Logan G 2024-09-25 12:52:57 -06:00
parent 44cad425a4
commit dbecee4919
Signed by: logan
GPG key ID: E328528C921E7A7A

View file

@ -19,6 +19,7 @@ MOUNT_FOLDER="/run/media/${CURRENT_USER}"
ALLOW_UUID="0" ALLOW_UUID="0"
ALLOW_LABEL="0" ALLOW_LABEL="0"
LABEL_BY="LABEL"
print_help () { print_help () {
cat /dev/stdin << EOF cat /dev/stdin << EOF
@ -32,6 +33,7 @@ Options:
-u --uuid Allow UUIDs as the target -u --uuid Allow UUIDs as the target
-l --label Allow labels as the target -l --label Allow labels as the target
-d --dry-run Does nothing -d --dry-run Does nothing
-U --label-uuid Use UUID instead of drive label for mountpoint name
-ro --read-only Mounts target as read only -ro --read-only Mounts target as read only
EOF EOF
@ -123,7 +125,7 @@ get_mapped () {
trap "cryptsetup close ${TARGET}" EXIT trap "cryptsetup close ${TARGET}" EXIT
[[ ! -z $(blkid -o value -s LABEL "${TARGET}") ]] && LABEL=$(blkid -o value -s LABEL "${TARGET}") [[ ! -z $(blkid -o value -s "${LABEL_BY}" "${TARGET}") ]] && LABEL=$(blkid -o value -s "${LABEL_BY}" "${TARGET}")
TYPE=$(blkid -o value -s TYPE "${TARGET}" || true) # Fuck you bash TYPE=$(blkid -o value -s TYPE "${TARGET}" || true) # Fuck you bash
fi fi
@ -150,6 +152,9 @@ for arg in "$@"; do
"-d" | "--dry-run") "-d" | "--dry-run")
DRY_RUN="1" DRY_RUN="1"
;; ;;
"-U" | "--label-uuid")
LABEL_BY="UUID"
;;
"-ro" | "--read-only") "-ro" | "--read-only")
MOUNT_OPTS+=",ro" MOUNT_OPTS+=",ro"
;; ;;
@ -166,7 +171,7 @@ fi
MAPPED_NAME="" MAPPED_NAME=""
LABEL=$(blkid -o value -s LABEL "${TARGET}") LABEL=$(blkid -o value -s "${LABEL_BY}" "${TARGET}")
[[ -z $LABEL ]] && LABEL=$(basename "${TARGET}") [[ -z $LABEL ]] && LABEL=$(basename "${TARGET}")
TYPE=$(blkid -o value -s TYPE "${TARGET}") TYPE=$(blkid -o value -s TYPE "${TARGET}")