2014-11-28 17:02:20 +01:00
|
|
|
#!/bin/bash
|
2015-07-07 15:04:28 +02:00
|
|
|
########################################################################
|
|
|
|
# Copyright (C) 2014 Max Mehl <mail@mehl.mx>
|
|
|
|
########################################################################
|
|
|
|
#
|
|
|
|
# This program is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
#
|
|
|
|
########################################################################
|
|
|
|
#
|
|
|
|
# This is a script to mount Windows/SMB shared drives via a dialogue
|
|
|
|
# It is very basic and was used for a special environment, however it's
|
|
|
|
# more clever than mnt-share.sh
|
|
|
|
# It requires smbfs/cifs-utils to be installed.
|
|
|
|
#
|
|
|
|
########################################################################
|
2014-11-28 17:02:20 +01:00
|
|
|
|
|
|
|
|
|
|
|
cd "$(dirname "$(readlink -f "$0")")"
|
|
|
|
# Test if config.cfg exists and set needed variables
|
|
|
|
if [ ! -e config.cfg ]; then echo "Missing config.cfg file. Edit and rename config.cfg.sample"; exit 1; fi
|
|
|
|
source config.cfg
|
|
|
|
|
|
|
|
# Choose preconfigured SHARE to mount
|
|
|
|
function mount {
|
|
|
|
if ! SHARE=$(zenity --list \
|
|
|
|
--height=300 \
|
|
|
|
--text="Please choose. Cancel to unmount shares." \
|
|
|
|
--title="Choose Network Share" \
|
|
|
|
--column "Preconfigured Network Shares" \
|
|
|
|
${SHAREPATH[*]}); then
|
|
|
|
unmountquestion # If you press cancel, it should ask you to unmount all drives
|
|
|
|
fi
|
|
|
|
|
|
|
|
# If you double click on an entry, it gives 'server1|server1' as result instead of 'server1'
|
|
|
|
# This command cuts of everything after |
|
|
|
|
NUM=$(echo $SHARE | awk -F: '{ print $1 }') # Which Array?
|
|
|
|
SHARE=$(echo $SHARE | awk -F\| '{ print $1 }' | awk -F: '{ print $2 }')
|
|
|
|
SHAREDIR=$(echo $SHARE | awk -F/ '{ print $2 }') # Directory to use
|
|
|
|
|
|
|
|
# Make a local directory if not available
|
|
|
|
if [ ! -e "$LOCALMOUNTDIR"/"$SHAREDIR" ]; then
|
|
|
|
mkdir -p "$LOCALMOUNTDIR"/"$SHAREDIR"
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Command to mount actually
|
|
|
|
OPT="-o user="${SHAREUSER[$NUM]}",password="${SHAREPASS[$NUM]}""
|
|
|
|
echo "mount -t cifs //$SHARE $LOCALMOUNTDIR/$SHAREDIR $OPT"
|
|
|
|
|
|
|
|
quitquestion # one more share or quit?
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Ask if all preconfigured shares should be unmounted
|
|
|
|
function unmountquestion {
|
|
|
|
zenity --question --text="Unmount all preconfigured\nnetwork shares now?"
|
|
|
|
if [ "$?" = "0" ]; then
|
|
|
|
unmount # unmount function
|
|
|
|
else
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
# Procedure to unmount all preconfigured shares and exit program afterwards
|
|
|
|
function unmount {
|
|
|
|
for ((i = 0; i < ${#SHAREPATH[*]}; i++))
|
|
|
|
do
|
|
|
|
SHAREDIR=$(echo "${SHAREPATH[$i]}" | awk -F/ '{ print $2 }')
|
|
|
|
unmount "$LOCALMOUNTDIR"/$SHAREDIR
|
|
|
|
echo ""${SHAREPATH[$i]}" unmounted."
|
|
|
|
done
|
|
|
|
exit 0
|
|
|
|
}
|
|
|
|
|
|
|
|
# Should another network share storage be mounted?
|
|
|
|
function quitquestion {
|
|
|
|
zenity --question \
|
|
|
|
--text="Mount another network share storage?"
|
|
|
|
if [ "$?" = "1" ]; then
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
# Loop for endless mounts until stopped by unmount or unmountquestion
|
|
|
|
while :
|
|
|
|
do
|
|
|
|
mount # mount function
|
|
|
|
done
|