diff options
-rwxr-xr-x | scripts/mount-store | 81 |
1 files changed, 49 insertions, 32 deletions
diff --git a/scripts/mount-store b/scripts/mount-store index 8ba2a42..d4311a1 100755 --- a/scripts/mount-store +++ b/scripts/mount-store @@ -34,49 +34,66 @@ images) esac FLAG="${DEST}/.notmounted" -SUBDIR="${DEST}/bwlehrpool_store" -DNBDDIR="${DEST}/stage4" -storage_test () { - rm -f -- "${FLAG}" - if [ -e "${FLAG}" ]; then - echo "Error: File '.notmounted' exists on remote storage and could not be deleted." >&2 - echo "Error: Make sure the share is writable." >&2 - return 5 - fi - chgrp images "${DEST}" 2>/dev/null - mkdir -p "${SUBDIR}" - if [ ! -d "${SUBDIR}" ]; then - echo "Error: Could not create directory $(basename "${SUBDIR}")! Storage not writable!" >&2 +prepare_dir () { + local owner="$1" + local testuser="$2" + local dir="$3" + echo "Preparing ${dir}..." + mkdir -p "${dir}" + if ! [ -d "${dir}" ]; then + echo "Error: Could not create directory! Storage not writable!" >&2 return 6 fi - echo "Applying group..." - find "${SUBDIR}" -type d -exec chgrp images {} \; 2>/dev/null + echo "Applying owner/group..." + find "${dir}" -type d -exec chown "$owner" {} \; 2>/dev/null echo "Applying permissions..." - find "${SUBDIR}" -type d -exec chmod ug+rwx {} \; 2>/dev/null + find "${dir}" -type d -exec chmod ug+rwx {} \; 2>/dev/null echo "Creating test file..." - local TEST="${SUBDIR}/.deleteme-$RANDOM-$RANDOM" - sudo -n -u dmsd touch "$TEST" + local TEST="${dir}/.deleteme-$RANDOM-$RANDOM-$$" + sudo -n -u "${testuser}" touch "$TEST" local RET=$? if [ -e "$TEST" ]; then - sudo -n -u dmsd rm -f -- "$TEST" + sudo -n -u "${testuser}" rm -f -- "$TEST" else [ "$RET" = "0" ] && RET=127 - echo "Error: Mounted share is not writable." >&2 - ls -al "${DEST}" "${SUBDIR}" >&2 + echo "Error: Storage is not writable." >&2 + ls -al "${DEST}" "${dir}" >&2 fi - echo "Applying permissions for stage4 directory..." - mkdir -p "${DNBDDIR}" - if [ ! -d "${DNBDDIR}" ]; then - echo "Error: Could not create directory $(basename "${DNBDDIR}")! Storage not writable!" >&2 - return 6 - fi - find "${DNBDDIR}" -type d -exec chown dnbd3:dnbd3 {} \; 2>/dev/null - find "${DNBDDIR}" -type d -exec chmod ug+rwx {} \; 2>/dev/null - # TODO: touch and rm like above... return $RET } +prepare_storage () { + local cifs=false + local type dnbd3_owner + case "$1" in + nfs*) type="remote" ;; + cifs) type="remote" ; cifs=true ;; + local) type="local" ;; + *) echo "Invalid storage type '$1'" ; return 1 ;; + esac + rm -f -- "${FLAG}" + if [ -e "${FLAG}" ]; then + echo "Error: File '.notmounted' exists on $type storage and could not be deleted." >&2 + echo "Error: Make sure it is writable." >&2 + return 5 + fi + if ! prepare_dir "root:images" "dmsd" "${DEST}/bwlehrpool_store"; then + return 8 + fi + if $cifs; then + adduser dnbd3 images 2> /dev/null + dnbd3_owner="root:images" + else + deluser dnbd3 images 2> /dev/null + dnbd3_owner="dnbd3:dnbd3" + fi + if ! prepare_dir "${dnbd3_owner}" "dnbd3" "${DEST}/stage4"; then + return 9 + fi + return 0 +} + enable_nfs_export () { if [ -n "$TM_NOLOCALNFS" ]; then disable_nfs_export @@ -174,7 +191,7 @@ fi # Unmount and not requested to mount (local mode) if [[ "${SOURCE}" == "null" ]]; then - rm -f -- "${FLAG}" + prepare_storage "local" systemctl --no-block start dnbd3-server.service enable_nfs_export echo "Success. Now using internal storage." @@ -205,7 +222,7 @@ exec_mount () { RET=$? [ "$RET" -ne "0" ] && return "$RET" echo "Mount succeeded, checking write permissions...." - storage_test + prepare_storage "$fstype" RET=$? [ "$RET" -eq "0" ] && return 0 umount -v "$DEST" || umount -v -f -l "$DEST" |