From adf29d7dd6a551f086085c659ce87a2140a12bcf Mon Sep 17 00:00:00 2001 From: Jonathan Bauer Date: Mon, 10 Nov 2014 15:35:55 +0100 Subject: [pam-common-share] use last directory in the path as the name of the directory to mount the share to --- .../openslx/scripts/pam_script_mount_common_share | 27 ++++++++++++++++------ 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/remote/modules/pam-common-share/data/opt/openslx/scripts/pam_script_mount_common_share b/remote/modules/pam-common-share/data/opt/openslx/scripts/pam_script_mount_common_share index 5c034824..5416842f 100644 --- a/remote/modules/pam-common-share/data/opt/openslx/scripts/pam_script_mount_common_share +++ b/remote/modules/pam-common-share/data/opt/openslx/scripts/pam_script_mount_common_share @@ -74,11 +74,18 @@ mount_share() { return; fi - # now create the subdir within $COMMON_SHARE_MOUNT_POINT - mkdir -p "${COMMON_SHARE_MOUNT_POINT}/${SHARE_NUM}" || \ - { slxlog "pam-share-mkdirfail" "Share${SHARE_NUM}: Could not create directory '${COMMON_SHARE_MOUNT_POINT}/${SHARE_NUM}'."; return; } + # we just mount it to the directory with the same name as the + # last directory in the path name of the share + # e.g. //windows.net/lehrpool -> ${COMMON_SHARE_MOUNT_POINT}/lehrpool + local TARGET_DIR="${COMMON_SHARE_MOUNT_POINT}/$(basename ${SHARE_PATH})" + # it exists, so let's create ${COMMON_SHARE_MOUNT_POINT}/lehrpool_${SHARE_NUM} + [ -d "${TARGET_DIR}" ] && TARGET_DIR="${TARGET_DIR}_${SHARE_NUM}" + + # at this point is TARGET_DIR pointing to the right directory. + mkdir -p "${TARGET_DIR}" || \ + { slxlog "pam-share-mkdirfail" "Share${SHARE_NUM}: Could not create directory '${TARGET_DIR}'. Skipping share."; return; } # now try to mount it - ( mount ${MOUNT_OPTS} "${SHARE_PATH}" "${COMMON_SHARE_MOUNT_POINT}/${SHARE_NUM}" > "${MOUNT_OUTPUT}" 2>&1 || touch "${SIGNAL}" ) & + ( mount ${MOUNT_OPTS} "${SHARE_PATH}" "${TARGET_DIR}" > "${MOUNT_OUTPUT}" 2>&1 || touch "${SIGNAL}" ) & MOUNT_PID=$! for COUNTER in 1 1 2 4; do kill -0 "${MOUNT_PID}" 2>/dev/null || break @@ -87,10 +94,10 @@ mount_share() { # check for failures if [ -e "${SIGNAL}" ]; then - slxlog "pam-share-mount" "Mount of '${SHARE_PATH}' to '${COMMON_SHARE_MOUNT_POINT}/${SHARE_NUM}' failed. (Args: ${MOUNT_OPTS}" "${MOUNT_OUTPUT}" + slxlog "pam-share-mount" "Mount of '${SHARE_PATH}' to '${TARGET_DIR}' failed. (Args: ${MOUNT_OPTS}" "${MOUNT_OUTPUT}" rm -f -- "${SIGNAL}" elif kill -9 "${MOUNT_PID}" 2>/dev/null; then - slxlog "pam-share-mount" "Mount of '${SHARE_PATH}' to '${COMMON_SHARE_MOUNT_POINT}/${SHARE_NUM}' timed out. (Args: ${MOUNT_OPTS}" "${MOUNT_OUTPUT}" + slxlog "pam-share-mount" "Mount of '${SHARE_PATH}' to '${TARGET_DIR}' timed out. (Args: ${MOUNT_OPTS}" "${MOUNT_OUTPUT}" fi ( sleep 2; rm -f -- "${MOUNT_OUTPUT}" ) & @@ -114,7 +121,13 @@ mount_share() { for SHARE in ${!SLX_SHARE_*}; do # skip if the variable doesn't end in _PATH [[ "$SHARE" =~ .*_PATH$ ]] || continue - # ok so we have a path in S, let's extract the number of the share + # first let's check if we have already mounted it, since we don't have to + # do anything is it already is. + if mount | grep -q "${SHARE}"; then + # already mounted, just skip. + continue + fi + # ok so we have a path in $SHARE, let's extract the number of the share # i.e. SLX_SHARE_0_PATH -> share number 0 # first strip the leading SLX_SHARE_ SHARE=${SHARE#SLX_SHARE_} -- cgit v1.2.3-55-g7522