Several scripts to mount local or remote network storages (SSH, SMB...)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

76 lines
2.1 KiB

#!/bin/bash
## VARIABLES TO BE CHANGED
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