mountscript.sh - works in El Capitan but not in High Sierra - can you help me please

spar
New Contributor II

Hello! I'm new at Jamf and also new in scripting. We have the caspersuite 9.82.
Specialists have implemented a mount script named mountscript.sh. That's two years ago.
In El Capitan 10.11.6 it works fine. But since Sierra 10.12 it doesn't work any more. Has anyone a solution for me. Thanks a lot.

#!/bin/bash
#

SCRIPTNAME_USER=".mountscript.sh"
USERNAME="${3}"

if [ -z "${USERNAME}" ] ; then
    echo "error: no username over parameter 3 given - end"
    exit 1
fi

USERHOME="/Users/$USERNAME"

if [ ! -e "${USERHOME}" ] ; then
    echo "error: Userhome ${USERHOME} not useable - End"
    exit 1
fi

MOUNTSCRIPT="/usr/local/bin/mountvolumes.sh"
MOUNTSCRIPT_USER="${USERHOME}/${SCRIPTNAME_USER}"

echo "USERNAME: $USERNAME"
echo "USERHOME: $USERHOME"
echo "MOUNTSCRIPT: $MOUNTSCRIPT"
echo "MOUNTSCRIPT_USER: $MOUNTSCRIPT_USER"

[ ! -e "${MOUNTSCRIPT_USER}" ] && cat "${0}"  | sed -e '/MOUNTSCRIPT BLOCK START/,/MOUNTSCRIPT BLOCK END/!d' > "${MOUNTSCRIPT_USER}"

for i in 4 5 6 7 8 9 10
do
    if [ -n "${!i}" ]; then
        echo "${!i}" >> "${MOUNTSCRIPT_USER}.inc"
    fi
done

chown "${USERNAME}:staff" "${MOUNTSCRIPT_USER}" "${MOUNTSCRIPT_USER}.inc"
chmod 700 "${MOUNTSCRIPT_USER}" "${MOUNTSCRIPT_USER}.inc"

exit 0

### MOUNTSCRIPT BLOCK START
#!/bin/bash

log() {

    logger -t mountvolumes "${1}"
    echo "${1}"

}

log "USERNAME: $USER"
log "USERID: $(id -u)"

    PARAMETER_LIST=$(cat "${0}.inc" | sed -e 's/ /;;;SPACE;;;/g' | tr "*" " ")

    if [ -n "${PARAMETER_LIST}" ] ; then

        for n in ${PARAMETER_LIST}
        do
            PARAMETER=$(echo "${n}" | sed -e 's/;;;SPACE;;;/ /g')

            PARAMETER_PROTOCOL=$(echo "${PARAMETER}" | cut -d "^" -f1)
            PARAMETER_NETWORKSHARE=$(echo "${PARAMETER}" | cut -d "^" -f2)
            PARAMETER_MOUNTPOINT=$(echo "${PARAMETER}" | cut -d "^" -f3)
            PARAMETER_SERVER=$(echo "${PARAMETER_NETWORKSHARE}" | sed -e 's_/.*$__g' -e 's_^.*@__g')
            MOUNTOPTIONS=$(echo "${PARAMETER}" | cut -d "^" -f4)
            PROTOCOL="" ; MOUNTPOINT="" ; NETWORKSHARE=""

            case "$(echo "${PARAMETER_PROTOCOL}" | tr "[:upper:]" "[:lower:]")" in
                afp)
                    PROTOCOL="afp"
                    NETWORKSHARE="afp://${PARAMETER_NETWORKSHARE}"
                    ;;
                smb)
                    PROTOCOL="smbfs"
                    NETWORKSHARE="//${PARAMETER_NETWORKSHARE}"
                    ;;
                http|https)
                    PROTOCOL="webdav"
                    NETWORKSHARE="${PARAMETER_PROTOCOL}://${PARAMETER_NETWORKSHARE}"
                    ;;
            esac    
            MOUNTPOINT="${PARAMETER_MOUNTPOINT}"

            LOOP=1
            while [ -e "${MOUNTPOINT}" ]  && [ ${LOOP} -lt 20 ]
            do
                MOUNTPOINT="${PARAMETER_MOUNTPOINT}-${LOOP}"
                LOOP=$((LOOP +1))
            done

            if [ -n "${PROTOCOL}" ] && [ -n "${NETWORKSHARE}" ] && [ -n "${MOUNTPOINT}" ]; then

                SERVEROK=true
                [ -n "${PARAMETER_SERVER}" ] && [ -n "$(ping -c 1 -t 1 "${PARAMETER_SERVER}" | grep "0 packets received")" ] && SERVEROK=false

                if ${SERVEROK}; then

                    log "bind server ${NETWORKSHARE} and Mountpoint ${MOUNTPOINT} an (Options: ${MOUNTOPTIONS})"
                    log "mount -t ${PROTOCOL} ${MOUNTOPTIONS} ${NETWORKSHARE} ${MOUNTPOINT}"
                    mkdir "${MOUNTPOINT}"
                    mount -t ${PROTOCOL} ${MOUNTOPTIONS} "${NETWORKSHARE}" "${MOUNTPOINT}"
                    ERRL=$?

                    if [ ${ERRL} -gt 0 ]; then

                        rmdir "${MOUNTPOINT}"
                        log "error: Fehler beim Anbinden von ${NETWORKSHARE} and Mountpoint ${MOUNTPOINT}"    
                    fi
                else
                    log "error: Server ${PARAMETER_SERVER} nicht erreichbar."

                fi
            else
                log "error: Parameter ${PARAMETER} fehlerhaft."
            fi  
        done
    fi
exit 0
### MOUNTSCRIPT BLOCK END
3 REPLIES 3

spar
New Contributor II

Hy! Can anyone help me please? Thank's.

ICTMuttenz
Contributor

Is there any error in policy?

spar
New Contributor II

Policy runs at log on - Scipt runs "after" - Parameter for scipt ist afp^;AUTH=Client%20Krb%20v2@axx-hqezipxx/Transfer_Intern^/Volumes/Transfer_Intern
b1482b6c0b0d4f779d6cd314384adb6f

Script result from HS Client is the same as El Capitan:
Executing Policy at.spar.Mount Volume - Transfer_Intern
Running script l_create_mountvolumes_script.sh...
Script exit code: 0
Script result: USERNAME: u124xxx
USERHOME: /Users/u124xxx
MOUNTSCRIPT: /usr/local/bin/mountvolumes.sh
MOUNTSCRIPT_USER: /Users/u124xxx/.mountscript.sh

Maybe Apple have changed permissions in the macOS?