#!/bin/sh
MACHINE=$1
IP=$2
SHARE=$3
MOUNTPOINT=$4
USERNAME=$5
PASSWORD=$6
USECIFS=$7
echo "func mount called: with
MACHINE=$1
IP=$2
SHARE=$3
MOUNTPOINT=$4
USERNAME=$5
PASSWORD=?
USECIFS=$7" >> ${TMP}log
#escape dollars, spaces are substituted with \040
MOUNTED="$(mount | grep $(echo "$MOUNTPOINT" | sed 's/\$/\\$/g;s/ /\\\\040/g'))$(mount | grep "$MOUNTPOINT")"
if [ "$MOUNTED" ]; then
echo "$MACHINE $SHARE は既に接続済みです" >> ${TMP}log
else
mkdir -p "$MOUNTPOINT"

#check to see if cifs is enabled
if [ "$USECIFS" = "true" -a "$(lsmod | grep cifs)" ]; then
mount-FULL -t cifs "//${IP}/${SHARE}" "${MOUNTPOINT}" -o username="${USERNAME}",password=${PASSWORD},iocharset=utf8 2>>${TMP}log
else # default to mounting with smbmount if no cifs
if [ "$USECIFS" = "true" ]; then
export MAIN_DIALOG="<window title=\"Pnethood Error\" icon-name=\"gtk-network\"><vbox><text wrap=\"true\"><label>Unable to connect to share using Common Internet Filesystem (CIFS). You probably don't have the cifs module installed. Share will be mounted using the smb protocol. Untick the box on the main window to avoid seeing this message again.</label></text><hbox homogeneous=\"true\"><pixmap icon_size=\"5\"><input file stock=\"gtk-dialog-error\"></input></pixmap><button ok></button></hbox></vbox></window>"
gtkdialog3 --program=MAIN_DIALOG --center
fi
smbfs "//${IP}/${SHARE}" "${MOUNTPOINT}" -o "username=${USERNAME},password=${PASSWORD}" 2>>${TMP}log >>/dev/null # redirecting stdout needed to lose init_iconv encoding conversion error messages
fi

MOUNTED="$(mount | grep $(echo "$MOUNTPOINT" | sed 's/\$/\\$/g;s/ /\\\\040/g'))$(mount | grep "$MOUNTPOINT")"
if [ "$MOUNTED" ];then
echo "$MACHINE" "$SHARE" の接続に成功>> ${TMP}log
else
rmdir "$MOUNTPOINT" #I think this is safe, it will only rm if empty, this prevents use of empty mountpoint
echo "$MACHINE" "$SHARE" の接続に失敗 >> ${TMP}log
export MAIN_DIALOG="<window title=\"Pnethood Error\" icon-name=\"gtk-network\"><vbox><text wrap=\"true\"><label>Mount: $MACHINE $SHARE failed. The server may be refusing you access to this share or your password may be incorrect. Please hit the $SHARE disconnect button to reset the display.</label></text><hbox homogeneous=\"true\"><pixmap icon_size=\"5\"><input file stock=\"gtk-dialog-error\"></input></pixmap><button ok></button></hbox></vbox></window>"
gtkdialog3 --program=MAIN_DIALOG --center
fi
fi
