enable configuration of where predefined mountpoints are mounted to
This commit is contained in:
@@ -6,9 +6,9 @@ LOCALMOUNTDIR=/home/user/remote
|
|||||||
SSHCONFIG=$HOME/.ssh/config
|
SSHCONFIG=$HOME/.ssh/config
|
||||||
|
|
||||||
# If you don't want to use your .ssh/config file or need to define the passwords manually, you can add predefined entries here.
|
# If you don't want to use your .ssh/config file or need to define the passwords manually, you can add predefined entries here.
|
||||||
# Format: user;;host;;port;;pass;;path
|
# Format: user;host;port;pass;path;localpath
|
||||||
#PRESSH[0]='user1;;domain1.org;;22;;secretpassword1;;/'
|
#PRESSH[0]='user1;domain1.org;22;secretpassword1;/;/home/mypc/remote'
|
||||||
#PRESSH[1]='user2;;domain2.org;;23;;secretpassword2;;/home/user2/'
|
#PRESSH[1]='user2;domain2.org;23;secretpassword2;/home/user2/;/media/mylocalspace'
|
||||||
|
|
||||||
|
|
||||||
## mnt-share.sh
|
## mnt-share.sh
|
||||||
|
|||||||
53
mnt-sftp.sh
53
mnt-sftp.sh
@@ -41,13 +41,14 @@ function sshadd {
|
|||||||
|
|
||||||
for ((i = 0; i < ${#PRESSH[*]}; i++))
|
for ((i = 0; i < ${#PRESSH[*]}; i++))
|
||||||
do
|
do
|
||||||
PREUSER[$i]=$(echo ${PRESSH[$i]} | awk -F";;" '{ print $1 }')
|
PREUSER[$i]=$(echo ${PRESSH[$i]} | awk -F";" '{ print $1 }')
|
||||||
PREHOST[$i]=$(echo ${PRESSH[$i]} | awk -F";;" '{ print $2 }')
|
PREHOST[$i]=$(echo ${PRESSH[$i]} | awk -F";" '{ print $2 }')
|
||||||
PREPORT[$i]=$(echo ${PRESSH[$i]} | awk -F";;" '{ print $3 }')
|
PREPORT[$i]=$(echo ${PRESSH[$i]} | awk -F";" '{ print $3 }')
|
||||||
PREPASS[$i]=$(echo ${PRESSH[$i]} | awk -F";;" '{ print $4 }')
|
PREPASS[$i]=$(echo ${PRESSH[$i]} | awk -F";" '{ print $4 }')
|
||||||
PREPATH[$i]=$(echo ${PRESSH[$i]} | awk -F";;" '{ print $5 }')
|
PREPATH[$i]=$(echo ${PRESSH[$i]} | awk -F";" '{ print $5 }')
|
||||||
|
PRELOCAL[$i]=$(echo ${PRESSH[$i]} | awk -F";" '{ print $6 }')
|
||||||
|
|
||||||
PRESSHLIST[$i]=${PREUSER[$i]}"@"${PREHOST[$i]}
|
PRESSHLIST[$i]=${PREUSER[$i]}"@"${PREHOST[$i]}":"${PREPATH[$i]}
|
||||||
done
|
done
|
||||||
|
|
||||||
# Read all hosts from ~/.ssh/config
|
# Read all hosts from ~/.ssh/config
|
||||||
@@ -57,6 +58,7 @@ SSHLIST=$(grep -E "Host\s[[:alnum:]]" $SSHCONFIG | awk -F' ' '{ print $2 }')
|
|||||||
function mount {
|
function mount {
|
||||||
if ! SSH=$(zenity --list \
|
if ! SSH=$(zenity --list \
|
||||||
--height=400 \
|
--height=400 \
|
||||||
|
--width=350 \
|
||||||
--text="Please choose. Cancel to unmount drives." \
|
--text="Please choose. Cancel to unmount drives." \
|
||||||
--title="Choose SSH server" \
|
--title="Choose SSH server" \
|
||||||
--column "Available SSH servers" \
|
--column "Available SSH servers" \
|
||||||
@@ -75,10 +77,15 @@ function mount {
|
|||||||
if [ "$SSH" == "<manual input>" ]; then
|
if [ "$SSH" == "<manual input>" ]; then
|
||||||
MAN="1"
|
MAN="1"
|
||||||
SSHUSER=$(zenity --entry --text "SSH user" --title "Enter SSH user")
|
SSHUSER=$(zenity --entry --text "SSH user" --title "Enter SSH user")
|
||||||
|
checkexit $?
|
||||||
SSHHOST=$(zenity --entry --text "SSH host" --title "Enter SSH host")
|
SSHHOST=$(zenity --entry --text "SSH host" --title "Enter SSH host")
|
||||||
|
checkexit $?
|
||||||
SSHPORT=$(zenity --entry --text "SSH port (default 22)" --title "Enter SSH port")
|
SSHPORT=$(zenity --entry --text "SSH port (default 22)" --title "Enter SSH port")
|
||||||
|
checkexit $?
|
||||||
SSHPASS=$(zenity --entry --hide-text --text "SSH password" --title "Enter SSH password")
|
SSHPASS=$(zenity --entry --hide-text --text "SSH password" --title "Enter SSH password")
|
||||||
|
checkexit $?
|
||||||
SSHPATH=$(zenity --entry --text "Desired root directory on server (default /)" --title "Enter SSH root directory")
|
SSHPATH=$(zenity --entry --text "Desired root directory on server (default /)" --title "Enter SSH root directory")
|
||||||
|
checkexit $?
|
||||||
if [ "$SSHPORT" == "" ]; then
|
if [ "$SSHPORT" == "" ]; then
|
||||||
SSHPORT=22
|
SSHPORT=22
|
||||||
fi
|
fi
|
||||||
@@ -99,6 +106,7 @@ function mount {
|
|||||||
SSHPORT=${PREPORT[$i]}
|
SSHPORT=${PREPORT[$i]}
|
||||||
SSHPASS=${PREPASS[$i]}
|
SSHPASS=${PREPASS[$i]}
|
||||||
SSHPATH=${PREPATH[$i]}
|
SSHPATH=${PREPATH[$i]}
|
||||||
|
SSHLOCAL=${PRELOCAL[$i]}
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
@@ -107,16 +115,22 @@ function mount {
|
|||||||
MAN="0"
|
MAN="0"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [ "$SSHLOCAL" != "" ]; then
|
||||||
|
MOUNTDIR="$SSHLOCAL"
|
||||||
|
else
|
||||||
|
MOUNTDIR="$LOCALMOUNTDIR"/"$SSH"
|
||||||
|
fi
|
||||||
|
|
||||||
# Make a local directory if not available
|
# Make a local directory if not available
|
||||||
if [ ! -e "$LOCALMOUNTDIR"/"$SSH" ]; then
|
if [ ! -e "$MOUNTDIR" ]; then
|
||||||
mkdir -p "$LOCALMOUNTDIR"/"$SSH"
|
mkdir -p "$MOUNTDIR"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Command to mount actually
|
# Command to mount actually
|
||||||
if [ "$MAN" = "0" ]; then
|
if [ "$MAN" = "0" ]; then
|
||||||
sshfs -C "$SSH": "$LOCALMOUNTDIR"/"$SSH"/ -o follow_symlinks &
|
sshfs -C "$SSH": "$MOUNTDIR"/ -o follow_symlinks &
|
||||||
else
|
else
|
||||||
echo "$SSHPASS" | sshfs -C -o password_stdin -p "$SSHPORT" "$SSHUSER"@"$SSHHOST":"$SSHPATH" "$LOCALMOUNTDIR"/"$SSH"/ -o follow_symlinks &
|
echo "$SSHPASS" | sshfs -C -o password_stdin -p "$SSHPORT" "$SSHUSER"@"$SSHHOST":"$SSHPATH" "$MOUNTDIR"/ -o follow_symlinks &
|
||||||
fi
|
fi
|
||||||
|
|
||||||
quitquestion # one more ssh server or quit?
|
quitquestion # one more ssh server or quit?
|
||||||
@@ -144,6 +158,20 @@ function unmount {
|
|||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
|
# Go through predefined mounts and unmount them if they're mounted
|
||||||
|
for ((i = 0; i < ${#PRESSHLIST[*]}; i++))
|
||||||
|
do
|
||||||
|
PREUSER[$i]=$(echo ${PRESSH[$i]} | awk -F";" '{ print $1 }')
|
||||||
|
PREHOST[$i]=$(echo ${PRESSH[$i]} | awk -F";" '{ print $2 }')
|
||||||
|
PREPATH[$i]=$(echo ${PRESSH[$i]} | awk -F";" '{ print $5 }')
|
||||||
|
PRELOCAL[$i]=$(echo ${PRESSH[$i]} | awk -F";" '{ print $6 }')
|
||||||
|
SSH[$i]=${PREUSER[$i]}"@"${PREHOST[$i]}":"${PREPATH[$i]}
|
||||||
|
if [ "$(cat /etc/mtab | grep -q "${SSH[$i]}"; echo $?)" == "0" ]; then
|
||||||
|
fusermount -u ${PRELOCAL[$i]}
|
||||||
|
echo "${PRELOCAL[$i]} unmounted."
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
# Remove all empty directories which have been created by the manual/predefined mount process (m-XYZ-$RANDOM)
|
# Remove all empty directories which have been created by the manual/predefined mount process (m-XYZ-$RANDOM)
|
||||||
find "$LOCALMOUNTDIR"/ -maxdepth 1 -type d -empty -regextype sed -regex ".*/[pm]-.\+\?-[0-9]\{2,6\}" -delete
|
find "$LOCALMOUNTDIR"/ -maxdepth 1 -type d -empty -regextype sed -regex ".*/[pm]-.\+\?-[0-9]\{2,6\}" -delete
|
||||||
|
|
||||||
@@ -159,6 +187,11 @@ function quitquestion {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Check whether one clicked "cancel" in zenity question
|
||||||
|
function checkexit {
|
||||||
|
if [ $1 = 1 ]; then exit 1; fi
|
||||||
|
}
|
||||||
|
|
||||||
sshadd # sshadd function
|
sshadd # sshadd function
|
||||||
|
|
||||||
# Loop for endless mounts until stopped by unmount or unmountquestion
|
# Loop for endless mounts until stopped by unmount or unmountquestion
|
||||||
|
|||||||
Reference in New Issue
Block a user