Compare commits
3 commits
d9e58a5c3b
...
dbecee4919
Author | SHA1 | Date | |
---|---|---|---|
dbecee4919 | |||
44cad425a4 | |||
d4736bc591 |
1 changed files with 51 additions and 34 deletions
33
tools/qmnt
33
tools/qmnt
|
@ -19,6 +19,7 @@ MOUNT_FOLDER="/run/media/${CURRENT_USER}"
|
|||
|
||||
ALLOW_UUID="0"
|
||||
ALLOW_LABEL="0"
|
||||
LABEL_BY="LABEL"
|
||||
|
||||
print_help () {
|
||||
cat /dev/stdin << EOF
|
||||
|
@ -31,6 +32,8 @@ Options:
|
|||
-p --permissions Force mount permissions to current user
|
||||
-u --uuid Allow UUIDs as the target
|
||||
-l --label Allow labels as the target
|
||||
-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
|
||||
EOF
|
||||
|
||||
|
@ -111,6 +114,7 @@ get_mapped () {
|
|||
|
||||
echo "Target \"${TARGET}\" is not unlocked"
|
||||
|
||||
if [[ -z $DRY_RUN ]]; then
|
||||
MAPPED_NAME=$(blkid -o value -s UUID "${TARGET}")
|
||||
if ! cryptsetup open "${TARGET}" "${MAPPED_NAME}"; then
|
||||
echo -e "\e[1;31mCould not unlock target \"${TARGET}\"!""\e[0m" 1>&2
|
||||
|
@ -121,9 +125,10 @@ get_mapped () {
|
|||
|
||||
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
|
||||
fi
|
||||
}
|
||||
|
||||
if [[ "$#" -eq 0 ]]; then
|
||||
|
@ -144,6 +149,12 @@ for arg in "$@"; do
|
|||
"-l" | "--label")
|
||||
ALLOW_LABEL="1"
|
||||
;;
|
||||
"-d" | "--dry-run")
|
||||
DRY_RUN="1"
|
||||
;;
|
||||
"-U" | "--label-uuid")
|
||||
LABEL_BY="UUID"
|
||||
;;
|
||||
"-ro" | "--read-only")
|
||||
MOUNT_OPTS+=",ro"
|
||||
;;
|
||||
|
@ -160,7 +171,7 @@ fi
|
|||
|
||||
MAPPED_NAME=""
|
||||
|
||||
LABEL=$(blkid -o value -s LABEL "${TARGET}")
|
||||
LABEL=$(blkid -o value -s "${LABEL_BY}" "${TARGET}")
|
||||
[[ -z $LABEL ]] && LABEL=$(basename "${TARGET}")
|
||||
|
||||
TYPE=$(blkid -o value -s TYPE "${TARGET}")
|
||||
|
@ -178,15 +189,20 @@ else
|
|||
MOUNT_OPTS="${DEFAULT_MOUNT_OPTS["$TYPE"]}""${MOUNT_OPTS}"
|
||||
fi
|
||||
|
||||
[[ ! -d "${MOUNT_FOLDER}" ]] && mkdir "${MOUNT_FOLDER}"
|
||||
[[ ! -d "${MOUNT_FOLDER}/${LABEL}" ]] && mkdir "${MOUNT_FOLDER}/${LABEL}"
|
||||
[[ ! -d "${MOUNT_FOLDER}" && -z $DRY_RUN ]] && mkdir "${MOUNT_FOLDER}"
|
||||
[[ ! -d "${MOUNT_FOLDER}/${LABEL}" && -z $DRY_RUN ]] && mkdir "${MOUNT_FOLDER}/${LABEL}"
|
||||
|
||||
if ! mount -o "${MOUNT_OPTS}" --source "${TARGET}" --target "${MOUNT_FOLDER}/${LABEL}"; then
|
||||
|
||||
if [[ -z $DRY_RUN ]]; then
|
||||
if \
|
||||
mountpoint "${MOUNT_FOLDER}/${LABEL}" 2>&1 &>/dev/null || \
|
||||
findmnt -n -o SOURCE "${TARGET}" 2>&1 &>/dev/null || \
|
||||
! mount -o "${MOUNT_OPTS}" --source "${TARGET}" --target "${MOUNT_FOLDER}/${LABEL}"; then
|
||||
echo -e "\e[1;31mFailed to mount \"${TARGET}\"!""\e[0m" 1>&2
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
(
|
||||
(
|
||||
set +e
|
||||
|
||||
trap '' SIGHUP SIGTERM
|
||||
|
@ -200,6 +216,7 @@ fi
|
|||
|
||||
[ -b /dev/mapper/"${2}" ] && cryptsetup close /dev/mapper/"${2}"
|
||||
' -- "${MOUNT_FOLDER}/${LABEL}" "${MAPPED_NAME}" >/dev/null 2>&1 &
|
||||
) &
|
||||
) &
|
||||
fi
|
||||
|
||||
echo -e "\e[1;32mDevice \"${TARGET}\" successfully mounted at \"${MOUNT_FOLDER}/${LABEL}\"""\e[0m"
|
||||
|
|
Loading…
Reference in a new issue