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.
70 lines
1.8 KiB
70 lines
1.8 KiB
#!/usr/bin/env bash
|
|
|
|
# Title: SSHFS Manager
|
|
# Description: bash script for connect remote server via sshfs and standard ssh config
|
|
# Author: Michael Berner
|
|
# Made: Secven Security
|
|
# Project URL: https://github.com/bernermic/sshfsconnect
|
|
# Project URL: https://git.disroot.org/bullet/sshmanager
|
|
# Version 1.0.0
|
|
# Licence: GNU General Public License v3.0
|
|
|
|
CONFIG_DIR=~/.config/sshfsconnect
|
|
SSHFS_OPTIONS="auto_cache,kernel_cache,reconnect,transform_symlinks,follow_symlinks,default_permissions,allow_other"
|
|
|
|
# check preconditions
|
|
check() {
|
|
test $(grep "^user_allow_other" /etc/fuse.conf) || { echo >&2 "I require user_allow_other in /etc/fuse.conf. Aborting."; exit 1;}
|
|
test $(grep "^Host " ~/.ssh/config | wc -l) -gt 0 || { echo >&2 "I require a configured Host in ~/.ssh/config. Please see https://git.disroot.org/bullet/sshmanager."; exit 1;}
|
|
}
|
|
|
|
# adding default config
|
|
configure() {
|
|
local sshfsconfig="$CONFIG_DIR/$1"
|
|
|
|
test -f "$sshfsconfig" && return
|
|
|
|
test -d "$config" || mkdir -p "$config" &> /dev/null
|
|
echo "DIR=/" > "$sshfsconfig"
|
|
echo "OPTIONS=$SSHFS_OPTIONS" >> "$sshfsconfig"
|
|
|
|
echo "You can modify the default config here: $sshfsconfig"
|
|
}
|
|
|
|
toggleMount() {
|
|
host=$1
|
|
mount=~/mount/$host
|
|
|
|
if test -z "$(mount | grep "$mount")"
|
|
then
|
|
mnt "$host" "$mount" || unmount "$mount"
|
|
fi
|
|
}
|
|
|
|
unmount() {
|
|
mount=$1
|
|
|
|
fusermount -u "$mount"
|
|
|
|
test $? = 0 && echo "$mount is unmounted" || echo "Error occured while unmount"
|
|
}
|
|
|
|
mnt() {
|
|
host=$1
|
|
mount=$2
|
|
|
|
sshfsconfig="$CONFIG_DIR/$1"
|
|
dir="$(grep "^DIR=" "$sshfsconfig" | awk -F '=' '{print $2}')"
|
|
options="$(grep "^OPTIONS=" "$sshfsconfig" | awk -F '=' '{print $2}')"
|
|
|
|
test -d "$mount" || mkdir -p "$mount"
|
|
sshfs "$host":"$dir" "$mount" -o "$options"
|
|
|
|
test $? = 0 && echo "$mount is mounted" || echo "Error occured while mount"
|
|
}
|
|
|
|
|
|
check
|
|
configure "$1" # configure the chosen host
|
|
toggleMount "$1" # mount or unmount filesystem
|