Skip to content

Commit

Permalink
restructure the repo
Browse files Browse the repository at this point in the history
  • Loading branch information
Fuseteam committed Apr 3, 2022
1 parent 149f56d commit 3ba1b11
Show file tree
Hide file tree
Showing 6 changed files with 107 additions and 94 deletions.
18 changes: 0 additions & 18 deletions Makefile

This file was deleted.

77 changes: 77 additions & 0 deletions bin/sshmount
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
#!/bin/bash
prefix="${HOME}/.local/lib"
source "${prefix}"/sshmountlib
if [ ! -f $confile ]; then
echo please setup ${confile} first;
exit 1;
fi

flags=();
fwdflag='';
sshflag='';
sshopts='';
reqArg=false;
while getopts 'r:fsCu:p:o:F:S:d1hiwlV' flag; do
case ${flag} in
u) unmount "$flag" "$2";exit;;
w) fwdflag='true';reqArg='';;
S) sshflag='true';sshopts=${OPTARG};;
r) remountflag='true';reqArg='';;
F|p|o) flags+=(-$flag "${OPTARG}");reqArg='true';;
C|f|1|s|d) flags+=(-"$flag");;
V) sshfs --version;exit;;
l) listMounts;exit;;
*) print_usage;
exit;;
esac
done
if [[ -z "${flags[*]}" && -z "$fwdflag" && -z "$sshflag" && -z "$remountflag" ]]; then
HostArg=$1
elif [[ -z "${reqArg}" ]]; then
HostArg=${BASH_ARGV[0]};
else
echo "missing argument";exit;
fi
if [ -z "$HostArg" ]; then
print_usage;
exit
fi

#trap ctrl-c and call ctrl_c()
trap "set +x;ctrl_c" INT

function ctrl_c() {
unmount u "$HostArg";
exit;
}

Host=$(fetchHost "$HostArg");
[[ -z "$Host" || "$Host" = 2 ]] && { echo host "$Host" not defined in "$confile"; exit 2; }

[[ "$Host" = "1" ]] && { echo no unique match! check in the "$confile" that "$Host" is only used once;exit 1; }
[ ! -z "$remountflag" ] && unmount u "$HostArg";
LD=$(fetchHostAttribute "$Host" '---' 'LocalDirectory');
RD=$(fetchHostAttribute "$Host" '---' 'RemoteDirectory');
PFwd=$(fetchHostAttribute "$Host" "---" "PortForwarding");
LFwd=$(fetchHostAttribute "$Host" "---" "LocalForward" "-L");
RFwd=$(fetchHostAttribute "$Host" "---" "RemoteForward" "-R");
checkMounts $LD;
[[ "$LD" = "1" || "$RD" = "1" ]] && { echo no unique match! check in the "$confile" that "$Host" defined only once as a directory;exit 1; }

if [[ -n "$PFwd" && "$PFwd" = "yes" && -z "$sshopts" ]]; then
{ sshflag='true'; sshopts="-oClearAllForwardings=no"; }
elif [[ -n "$PFwd" && "$PFwd" = "yes" && -n "$sshopts" ]]; then
{ sshflag='true'; sshopts="-oClearAllForwardings=no $sshopts"; }
fi
[[ -n "$LFwd" && "$LFwd" != "2" ]] && { sshopts="$sshopts$LFwd"; }
[[ -n "$RFwd" && "$RFwd" != "2" ]] && { sshopts="$sshopts$RFwd"; }

Hostchk=$(awk /"$Host"/ "$confile"|grep -q Host);
[[ -z $Hostchk ]] && Host=$(fetchHostAttribute "$Host" "---" "Host");
[[ "$LD" = "2" ]] && { echo host "$Host" missing LocalDirectory attribute in "$confile"; exit 2; }
[[ "$RD" = "2" ]] && { echo host "$Host" missing RemoteDirectory attribute in "$confile"; exit 2; }
[ ! -d "$LD" ] && mkdir "$LD";
[ ! -z "$fwdflag" ] && fwd=",ssh_command=ssh -oClearAllForwardings=no";
[ ! -z "$sshflag" ] && ssh=",ssh_command=ssh $sshopts";
set -x
sshfs -o reconnect,ServerAliveInterval=15,sync_readdir,kernel_cache,compression=yes"$fwd""$ssh" "${flags[@]}" "$LD" "$Host":"$RD";
7 changes: 0 additions & 7 deletions config.mk

This file was deleted.

File renamed without changes.
File renamed without changes.
99 changes: 30 additions & 69 deletions sshmount
Original file line number Diff line number Diff line change
@@ -1,77 +1,38 @@
#!/bin/bash
prefix="${HOME}/.local/lib"
source "${prefix}"/sshmountlib
if [ ! -f $confile ]; then
echo please setup ${confile} first;
exit 1;
fi

flags=();
fwdflag='';
sshflag='';
sshopts='';
reqArg=false;
while getopts 'r:fsCu:p:o:F:S:d1hiwlV' flag; do
case ${flag} in
u) unmount "$flag" "$2";exit;;
w) fwdflag='true';reqArg='';;
S) sshflag='true';sshopts=${OPTARG};;
r) remountflag='true';reqArg='';;
F|p|o) flags+=(-$flag "${OPTARG}");reqArg='true';;
C|f|1|s|d) flags+=(-"$flag");;
V) sshfs --version;exit;;
l) listMounts;exit;;
*) print_usage;
exit;;
esac
done
if [[ -z "${flags[*]}" && -z "$fwdflag" && -z "$sshflag" && -z "$remountflag" ]]; then
HostArg=$1
elif [[ -z "${reqArg}" ]]; then
HostArg=${BASH_ARGV[0]};
else
echo "missing argument";exit;
fi
if [ -z "$HostArg" ]; then
print_usage;
exit
fi
SCRP_DIR=$(dirname "${BASH_SOURCE[0]}")
prefix="$HOME/.local";
comprefix="${prefix}/share/bash-completion/completions"
name=sshmount
maintainer=fuseteam

#trap ctrl-c and call ctrl_c()
trap "set +x;ctrl_c" INT
download_sshmount(){
echo "downloading latest version"
wget -q https://github.com/${maintainer}/${name}/releases/latest/download/${name}.zip -O $HOME/Downloads/${name}.zip
}

function ctrl_c() {
unmount u "$HostArg";
exit;
unzip_sshmount() {
say "unpacking..."
unzip -q $HOME/Downloads/${name}.zip -d $HOME/${name}
}

Host=$(fetchHost "$HostArg");
[[ -z "$Host" || "$Host" = 2 ]] && { echo host "$Host" not defined in "$confile"; exit 2; }
install_sshmount(){
mkdir -p ${prefix}/bin
mkdir -p ${prefix}/lib
mkdir -p ${comprefix}
chmod 755 ${prefix}/bin/*
cp -f $SCRP_DIR/bin/* ${prefix}/bin
cp -f $SCRP_DIR/lib/* ${prefix}/lib
cp -rf $SCRP_DIR/share/* ${prefix}/share
}

[[ "$Host" = "1" ]] && { echo no unique match! check in the "$confile" that "$Host" is only used once;exit 1; }
[ ! -z "$remountflag" ] && unmount u "$HostArg";
LD=$(fetchHostAttribute "$Host" '---' 'LocalDirectory');
RD=$(fetchHostAttribute "$Host" '---' 'RemoteDirectory');
PFwd=$(fetchHostAttribute "$Host" "---" "PortForwarding");
LFwd=$(fetchHostAttribute "$Host" "---" "LocalForward" "-L");
RFwd=$(fetchHostAttribute "$Host" "---" "RemoteForward" "-R");
checkMounts $LD;
[[ "$LD" = "1" || "$RD" = "1" ]] && { echo no unique match! check in the "$confile" that "$Host" defined only once as a directory;exit 1; }
remove_sshmount(){
rm -f ${prefix}/bin/sshmount\
${prefix}/lib/sshmountlib\
${comprefix}/sshmount
}

if [[ -n "$PFwd" && "$PFwd" = "yes" && -z "$sshopts" ]]; then
{ sshflag='true'; sshopts="-oClearAllForwardings=no"; }
elif [[ -n "$PFwd" && "$PFwd" = "yes" && -n "$sshopts" ]]; then
{ sshflag='true'; sshopts="-oClearAllForwardings=no $sshopts"; }
if [ "$1" = "setup" ]; then
install_${name};
rm -r $HOME/${name};
rm -r $HOME/Downloads/${name}.zip;
fi
[[ -n "$LFwd" && "$LFwd" != "2" ]] && { sshopts="$sshopts$LFwd"; }
[[ -n "$RFwd" && "$RFwd" != "2" ]] && { sshopts="$sshopts$RFwd"; }

Hostchk=$(awk /"$Host"/ "$confile"|grep -q Host);
[[ -z $Hostchk ]] && Host=$(fetchHostAttribute "$Host" "---" "Host");
[[ "$LD" = "2" ]] && { echo host "$Host" missing LocalDirectory attribute in "$confile"; exit 2; }
[[ "$RD" = "2" ]] && { echo host "$Host" missing RemoteDirectory attribute in "$confile"; exit 2; }
[ ! -d "$LD" ] && mkdir "$LD";
[ ! -z "$fwdflag" ] && fwd=",ssh_command=ssh -oClearAllForwardings=no";
[ ! -z "$sshflag" ] && ssh=",ssh_command=ssh $sshopts";
set -x
sshfs -o reconnect,ServerAliveInterval=15,sync_readdir,kernel_cache,compression=yes"$fwd""$ssh" "${flags[@]}" "$LD" "$Host":"$RD";

0 comments on commit 3ba1b11

Please sign in to comment.