qmnt - Added dry run mode for testing
This commit is contained in:
parent
d9e58a5c3b
commit
d4736bc591
1 changed files with 42 additions and 33 deletions
21
tools/qmnt
21
tools/qmnt
|
@ -31,6 +31,7 @@ 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
|
||||
-ro --read-only Mounts target as read only
|
||||
EOF
|
||||
|
||||
|
@ -111,6 +112,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
|
||||
|
@ -124,6 +126,7 @@ get_mapped () {
|
|||
[[ ! -z $(blkid -o value -s LABEL "${TARGET}") ]] && LABEL=$(blkid -o value -s LABEL "${TARGET}")
|
||||
|
||||
TYPE=$(blkid -o value -s TYPE "${TARGET}" || true) # Fuck you bash
|
||||
fi
|
||||
}
|
||||
|
||||
if [[ "$#" -eq 0 ]]; then
|
||||
|
@ -144,6 +147,9 @@ for arg in "$@"; do
|
|||
"-l" | "--label")
|
||||
ALLOW_LABEL="1"
|
||||
;;
|
||||
"-d" | "--dry-run")
|
||||
DRY_RUN="1"
|
||||
;;
|
||||
"-ro" | "--read-only")
|
||||
MOUNT_OPTS+=",ro"
|
||||
;;
|
||||
|
@ -178,15 +184,17 @@ 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 ! 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 +208,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