Compare commits

...

No commits in common. "master" and "testing" have entirely different histories.

15 changed files with 155 additions and 460 deletions

View File

@ -1,15 +1,7 @@
# tildemerge
Helps users connect and access files on tildes.
Part of TildeLinux.
(Working title) A basic script to configure sshfs for tilde, not to be used with existing ssh configs.
### Tildes Supported
- tilde.town
- tilde.team
- yourtilde.com
- tilde.institute
- cosmic.voyage
### Dependencies
- gtk (gui)
- yad (gui)
@ -19,21 +11,8 @@ Part of TildeLinux.
- ssh-askpass
### TODO
- Support for passwords with private keys (done probably?)
- Code cleanup
- Equal signs before all yad options
- Move shared functions into separate files
- **Initial ssh setup**
- And error when ssh is not configured
- Password login
- An easy way to transfer private keys?
- Error handling for file creation
- Alert user if (local) directory they are trying to link to already contains a link
- **The exit and cancel buttons should do the same thing**
- A way to cleanly unlink directories
### ChangeLog
**0.1**
- initial *very* alpha release
**0.2**
- huge refractor

30
debian/README.source vendored
View File

@ -1,30 +0,0 @@
tildemerge for Debian
---------------------
Helps users connect and access files on tildes.
Part of TildeLinux.
### Tildes Supported
- tilde.town
- tilde.team
- yourtilde.com
- tilde.institute
- cosmic.voyage
### Dependencies
- gtk (gui)
- yad (gui)
- xdotool (gui)
- ssh
- sshfs
- ssh-askpass
### TODO
- Code cleanup
- Equal signs before all yad options
- Move shared functions into separate files
- Error handling for file creation
-- fosslinux <fosslinux@tilde.team> Sat, 29 Dec 2018 11:13:36 +1100

12
debian/changelog vendored
View File

@ -1,12 +0,0 @@
tildemerge (0.2-1) unstable; urgency=medium
* Code cleanup
* Refractor
-- fosslinux <fosslinux@tilde.team> Sun, 20 Jan 2019 16:00:56 +1100
tildemerge (0.1-1) unstable; urgency=medium
* Initial release
-- fosslinux <fosslinux@tilde.team> Sat, 29 Dec 2018 11:13:36 +1100

1
debian/compat vendored
View File

@ -1 +0,0 @@
11

23
debian/control vendored
View File

@ -1,23 +0,0 @@
Source: tildemerge
Section: xfce
Priority: optional
Maintainer: TildeLinux Maintainers <tildelinux@tildeverse.org>
Build-Depends: debhelper (>= 11)
Standards-Version: 4.1.3
Homepage: https://linux.tildeverse.org
Vcs-Browser: https://tildegit.org/tildelinux/tildemerge
Vcs-Git: https://tildegit.org/tildelinux/tildemerge.git
Package: tildemerge
Architecture: all
Depends: ${misc:Depends}, ssh, sshfs, ssh-askpass, gtk, yad, xdotool
Description: Helps users connect and access files on tildes.
Helps users connect and access files on tildes.
Part of TildeLinux.
.
Supports:
- tilde.town
- tilde.team
- yourtilde.com
- tilde.institute
- cosmic.voyage

19
debian/copyright vendored
View File

@ -1,19 +0,0 @@
Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
Upstream-Name: xfce-config
Source: https://tildegit.org/tildelinux/xfce-config
Files: *
Copyright: 2018 TildeLinux Maintainers <tildelinux@tildeverse.org>
License: GPL-3+
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 <https://www.gnu.org/licenses/>.

25
debian/rules vendored
View File

@ -1,25 +0,0 @@
#!/usr/bin/make -f
# See debhelper(7) (uncomment to enable)
# output every command that modifies files on the build system.
#export DH_VERBOSE = 1
# see FEATURE AREAS in dpkg-buildflags(1)
#export DEB_BUILD_MAINT_OPTIONS = hardening=+all
# see ENVIRONMENT in dpkg-buildflags(1)
# package maintainers to append CFLAGS
#export DEB_CFLAGS_MAINT_APPEND = -Wall -pedantic
# package maintainers to append LDFLAGS
#export DEB_LDFLAGS_MAINT_APPEND = -Wl,--as-needed
%:
dh $@
# dh_make generated override targets
# This is example for Cmake (See https://bugs.debian.org/641051 )
#override_dh_auto_configure:
# dh_auto_configure -- # -DCMAKE_LIBRARY_PATH=$(DEB_HOST_MULTIARCH)

View File

@ -1 +0,0 @@
3.0 (quilt)

View File

@ -1 +0,0 @@
README.source

View File

@ -1,48 +0,0 @@
#!/bin/sh
# Copyright (c) 2018-2019 TildeLinux Maintainers
#
# 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 2 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, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
# Email: tildelinux@tildeverse.org
if test -z "$1"
then
install_dir="$HOME/.local/bin"
else
install_dir="$1"
fi
install_scripts() {
for f in *.sh
do
if ! printf "%s" "$f" | grep -q "install.sh"
then
full_path="${install_dir}/${f}"
cp "$f" "$install_dir"
printf "Copied %s to %s.\\n" "$f" "$full_path"
chmod +x "$full_path"
printf "Made %s executable.\\n\\n" "$full_path"
fi
done
}
if test -f "$install_dir"
then
install_scripts
else
printf "%s not found, creating...\\n" "$install_dir"
mkdir -p "$install_dir"
install_scripts
fi

View File

@ -1,62 +0,0 @@
#!/bin/sh
# Copyright (c) 2018-2019 TildeLinux Maintainers
#
# 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 2 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, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
# Email: tildelinux@tildeverse.org
mounts_file="$HOME/.ssh/mounts"
get_locations() {
if ! grep -q "SSHFS Mount " "$mounts_file"
then
printf "<item label=\"Configure Locations...\">\\n"
printf " <action name=\"Execute\">\\n"
printf " <command>%s/.local/bin/sshfs_gui.sh</command>\\n" "$HOME"
printf " </action>\\n"
printf "</item>\\n"
else
while read -r line
do
location_path=""
if printf "%s" "$line" | grep -q "SSHFS Mount "
then
location_path=$(printf "%s" "$line" | rev | cut -f 2 -d ' ' | rev)
location_name=$(printf "%s" "$line" | rev | cut -f 1-2 -d ' ' | rev)
printf "<item label=\"%s\">\\n" "$location_name"
printf " <action name=\"Execute\">\\n"
printf " <command>thunar %s</command>\\n" "$location_path"
printf " </action>\\n"
printf "</item>\\n"
fi
done < "$mounts_file"
printf "<separator/>\\n"
printf "<item label=\"Configure More Locations...\">\\n"
printf " <action name=\"Execute\">\\n"
printf " <command>%s/.local/bin/sshfs_gui.sh</command>\\n" "$HOME"
printf " </action>\\n"
printf "</item>\\n"
fi
}
printf "<openbox_pipe_menu>\\n"
printf "<item label=\"File Manager\">\\n"
printf " <action name=\"Execute\">\\n"
printf " <command>thunar</command>\\n"
printf " </action>\\n"
printf "</item>\\n"
printf "<separator label=\"Locations\" />\\n"
get_locations
printf "</openbox_pipe_menu>\\n"

135
setup.sh Executable file → Normal file
View File

@ -1,6 +1,6 @@
#!/bin/sh
# Copyright (c) 2018-2019 TildeLinux Maintainers
# Copyright (C) 2018 oneseveneight
#
# 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
@ -15,16 +15,16 @@
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
# Email: tildelinux@tildeverse.org
#
# Email: oneseveneight@airmail.cc
is_substring() {
is_substring(){
case $2 in
*$1*)
return 0
*$1*)
return 0
;;
*)
return 1
*)
return 1
;;
esac
}
@ -33,18 +33,18 @@ configure_directories() {
server_name="$1"
local_dir=""
remote_dir=""
printf "What would you like to call the local directory? (~/Remote/...)?\\n"
echo "What would you like to call the local directory? (~/Remote/...)?"
read -r answer
local_dir="${HOME}/Remote/${answer}"
local_dir="$HOME/Remote/$answer"
mkdir -p "$local_dir"
printf "Created directory %s.\\n" "$local_dir"
printf "What directory on \"%s\" would you like to link it to? (absolute path)\\n" "$server_name"
echo "Created directory $local_dir."
echo "What directory on \"$server_name\" would you like to link it to? (absolute path)"
read -r answer
remote_dir="$answer"
printf "Linking directory %s to %s on \"%s\".\\n" "$local_dir" "$remote_dir" "$server_name"
sshfs "${server_name}:${remote_dir}" "$local_dir"
printf "Done, enjoy!\\n"
echo "Linking directory $local_dir to $remote_dir on \"$server_name\"."
sshfs "$server_name:$remote_dir" "$local_dir"
echo "Done, enjoy!"
}
attempt_login() {
@ -52,27 +52,28 @@ attempt_login() {
ssh_temp_config="$2"
ssh_config="$3"
printf "Attempting to log in with configuration for \"%s\".\\n" "$server_name"
if ssh -qF "$ssh_temp_config" "$server_name" exit ; then
printf "Login successful! Writing ssh config...\\n"
echo "Attempting to log in with configuration for \"$server_name\"."
if ssh -qF "$ssh_temp_config" "$server_name" exit
then
echo "Login successful! Writing ssh config..."
cp "$ssh_temp_config" "$ssh_config"
printf "Would you like to configure sshfs for this server? (y/n)\\n"
echo "Would you like to configure sshfs for this server? (y/n)"
read -r answer
case "$answer" in
"y")
configure_directories "$server_name"
;;
"n")
printf "All right, you're all done!\\n"
printf "Exiting...\\n"
echo "All right, you're all done!"
echo "Exiting..."
;;
"*")
printf "\"%s\" was not recognized as an answer, please enter 'y' or 'n'\\n" "$answer"
echo "\"$answer\" was not recognized as an answer, please enter 'y' or 'n'"
esac
else
printf "Login failed, what would you like to do?\\n"
printf " 1) Try logging in again.\\n"
printf " 2) Re-configure my credentials.\\n"
echo "Login failed, what would you like to do?"
echo " 1) Try logging in again."
echo " 2) Re-configure my credentials."
read -r answer
case "$answer" in
"1")
@ -93,58 +94,57 @@ setup_keys() {
ssh_dir=""
key_type=""
printf "Configuring \"%s\" as \"%s\".\\n" "$server_address" "$server_name"
printf "What is your login name for this server?\\n"
echo "Configuring \"$server_address\" as \"$server_name\"."
echo "What is your login name for this server?"
read -r login
printf "Where is the private key you use for this account? (absolute path)\\n"
echo "Where is the private key you use for this account (absolute path)"
read -r key_path
if test -r "$key_path" ; then
printf "File found, configuring ssh...\\n"
ssh_dir="${HOME}/.ssh"
ssh_host_dir="${HOME}/.ssh/${server_name}"
if test -r "$key_path"
then
echo "File found, configuring ssh..."
ssh_dir="$HOME/.ssh"
ssh_host_dir="$HOME/.ssh/$server_name"
key_type=$(head -n 1 "$key_path" \
| cut -f 2 -d ' ' \
| tr '[:upper:]' '[:lower:]')
test -d "$ssh_dir" || mkdir -p "$ssh_dir"
test -d "$ssh_host_dir" || mkdir -p "$ssh_host_dir"
printf "Key appears to be of type \"%s\".\\n" "$key_type"
printf "Generating public key...\\n"
ssh-keygen -y -f "$key_path" > "${ssh_host_dir}/id_${key_type}.pub"
printf "Copying private key...\\n"
cp "$key_path" "${ssh_host_dir}/id_${key_type}"
printf "Saving configuration...\\n"
test -e "${ssh_dir}/config" || touch "${ssh_dir}/config"
test -d "$ssh_dir" || mkdir "$ssh_dir"
test -d "$ssh_host_dir" || mkdir "$ssh_host_dir"
echo "Key appears to be of type \"$key_type\""
echo "Generating public key..."
ssh-keygen -y -f "$key_path" > "$ssh_host_dir/id_$key_type.pub"
echo "Copying private key..."
cp "$key_path" "$ssh_host_dir/id_$key_type"
echo "Saving configuration..."
test -e "$ssh_dir/config" || touch "$ssh_dir/config"
cp "${ssh_dir}/config" "${ssh_dir}/config.tmp"
{
printf "Host %s\\n" "$server_name"
printf " HostName %s\\n" "$server_address"
printf " port 22\\n"
printf " User %s\\n" "$login"
printf " IdentityFile %s/id_%s\\n" "$ssh_host_dir" "$key_type"
} >> "${ssh_dir}/config.tmp"
printf "Right now your configuration looks like this:\\n"
cat "${ssh_dir}/config.tmp"
cp "$ssh_dir/config" "$ssh_dir/config.tmp"
{
echo "Host $server_name"
echo " HostName $server_address"
echo " port 22"
echo " User $login"
echo " IdentityFile $ssh_host_dir/id_$key_type"
} >> "$ssh_dir/config.tmp"
echo "Right now your configuration looks like this:"
cat "$ssh_dir/config.tmp"
attempt_login "$server_name" "${ssh_dir}/config.tmp" "${ssh_dir}/config"
attempt_login "$server_name" "$ssh_dir/config.tmp" "$ssh_dir/config"
else
printf "%s could not be read.\\n" "$key_path"
printf "Either it doesn't exist, or you dont have the correct permissions, please try again.\\n"
echo "$key_path could not be read."
echo "Either it doesn't exist, or you dont have the correct permissions, please try again."
setup_keys "$server_address" "$server_name"
fi
}
pick_account() {
answers="1 2 3 4"
answers="1 2 3"
answer=""
printf "What account would you like to configure?\\n"
printf " 1) tilde.town\\n"
printf " 2) tilde.team\\n"
printf " 3) yourtilde.com\\n"
printf " 4) cosmic.voyage\\n"
printf " 5) tilde.institute\\n"
echo "What account would you like to configure?"
echo " 1) tilde.town"
echo " 2) tilde.team"
echo " 3) yourtilde.com"
read -r answer
if is_substring "$answer" "$answers"
then
case "$answer" in
@ -156,16 +156,9 @@ pick_account() {
;;
"3")
setup_keys "yourtilde.com" "your"
;;
"4")
setup_keys "cosmic.voyage" "cosmic"
;;
"5")
setup_keys "tilde.institute" "institute"
;;
esac
else
printf "\"%s\" is not a valid option.\\n" "$answer"
echo "\"$answer\" is not a valid option."
pick_account
fi
}

123
setup_gui.sh Executable file → Normal file
View File

@ -1,90 +1,71 @@
#!/bin/sh
# Copyright (c) 2018-2019 TildeLinux Maintainers
#
# 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 2 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, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
# Email: tildelinux@tildeverse.org
export SSH_ASKPASS="/usr/lib/ssh/x11-ssh-askpass"
set -e
eval "$(xdotool getmouselocation --shell)"
mouse_x=$X
mouse_y=$Y
server_address="tilde.town!tilde.team!yourtilde.com!cosmic.voyage!tilde.institute"
server_name="MyTilde"
server_address="tilde.town!tilde.team!yourtilde.com"
server_name="My Tilde"
login=""
ssh_port="22"
ssh_dir="$HOME/.ssh"
priv_key_path=" "
get_field() {
get_field(){
field_num="$1"
info="$2"
printf "%s" "$info" | cut -f "$field_num" -d '|'
echo "$info" | cut -f "$field_num" -d '|'
}
error_box() {
error_box(){
error_text="$1"
yad \
--posx="$mouse_x" \
--posy="$mouse_y" \
--width=250 \
--image="dialog-error" \
--title="Error!" \
--text="$error_text" \
--width 250 \
--image "dialog-error" \
--title "Error!" \
--text "$error_text" \
--button="OK":0
}
succ_box() {
succ_box(){
succ_text="$1"
yad \
--posx="$mouse_x" \
--posy="$mouse_y" \
--width=250 \
--image="dialog-info" \
--title="Success!" \
--text="$succ_text" \
--width 250 \
--image "dialog-info" \
--title "Success!" \
--text "$succ_text" \
--button="OK":0
}
dec_box() {
dec_box(){
error_text="$1"
yad \
--posx="$mouse_x" \
--posy="$mouse_y" \
--width=250 \
--image="dialog-error" \
--title="Error!" \
--text="$error_text" \
--width 250 \
--image "dialog-error" \
--title "Error!" \
--text "$error_text" \
--button="No":1 \
--button="Yes":0
return $?
}
info_box() {
info_box(){
info_text="$1"
yad \
--posx="$mouse_x" \
--posy="$mouse_y" \
--no-buttons \
--width=250 \
--image="dialog-info" \
--title="Info" \
--text="$info_text"
--width 250 \
--image "dialog-info" \
--title "Info" \
--text "$info_text"
}
get_info() {
@ -106,25 +87,25 @@ get_info() {
--button="Cancel":1 \
--button="Continue":0 \
"$server_address" "$server_name" "$login" "$ssh_port" "$ssh_dir" "$priv_key_path")
[ $? -eq 1 ] && exit 1
[ $? -ne 0 ] && exit # Shellcheck will yell at me for this, perhaps find a better way?
server_address=$(get_field 1 "$info")
server_name=$(get_field 2 "$info")
login=$(get_field 3 "$info")
ssh_port=$(get_field 4 "$info")
ssh_dir=$(get_field 5 "$info")
priv_key_path=$(get_field 6 "$info")
if test -z "$login"
then
error_msg="No login provided!"
error_num=$((error_num + 1))
error_num=$(( error_num + 1))
fi
if test -d "$(printf "%s" "$priv_key_path" | sed 's/\/ *$//')"
if test -d "$(echo "$priv_key_path" | sed 's/\/ *$//')"
then
error_msg="${error_msg}\\nNo private key provided!"
error_num=$((error_num + 1))
error_msg="$error_msg\\nNo private key provided!"
error_num=$(( error_num + 1))
fi
if [ $error_num -gt 0 ]
@ -137,10 +118,10 @@ get_info() {
}
configure_server() {
ssh_current_config="${ssh_dir}/config"
ssh_temp_config="${ssh_dir}/config.tmp"
ssh_host_dir="${ssh_dir}/${server_address}"
key_type=$(head -n 1 "${priv_key_path}" \
ssh_current_config="$ssh_dir/config"
ssh_temp_config="$ssh_dir/config.tmp"
ssh_host_dir="$ssh_dir/$server_address"
key_type=$(head -n 1 "$priv_key_path" \
| cut -f 2 -d ' ' \
| tr '[:upper:]' '[:lower:]')
@ -148,9 +129,9 @@ configure_server() {
|| touch "$ssh_current_config"
cp "$ssh_current_config" "$ssh_temp_config"
if grep -qi "Host ${server_name}" "$ssh_current_config"
if grep -qi "Host $server_name" "$ssh_current_config"
then
dec_box "Host named ${server_name} already exists, overwrite?" \
dec_box "Host named $server_name already exists, overwrite?" \
|| get_info
if ! dec_box "Keep old config in file? (ssh will use the new one)"
@ -159,40 +140,40 @@ configure_server() {
in_old_host_block=0
while read -r line
do
if printf "%s" "$line" | grep -q "Host ${server_name}"
if echo "$line" | grep -q "Host $server_name"
then
in_old_host_block=0
elif printf "%s" "$line" | grep -q "Host "
elif echo "$line" | grep -q "Host "
then
in_old_host_block=1
fi
[ $in_old_host_block -eq 1 ] \
&& printf "%s" "$line"
&& echo "$line"
done < "$ssh_current_config" > "$ssh_temp_config"
fi
fi
mkdir -p "$ssh_host_dir"
cp "$priv_key_path" "${ssh_host_dir}/id_${key_type}"
cp "$priv_key_path" "$ssh_host_dir/id_$key_type"
{
printf "Host %s\\n" "$server_name"
printf " HostName %s\\n" "$server_address"
printf " Port %s\\n" "$ssh_port"
printf " User %s\\n" "$login"
printf " IdentityFile %s/id_%s\\n" "$ssh_host_dir" "$key_type"
{
echo "Host $server_name"
echo " HostName $server_address"
echo " Port $ssh_port"
echo " User $login"
echo " IdentityFile $ssh_host_dir/id_$key_type"
} >> "$ssh_temp_config"
info_box "Attempting to log in with the provided credentials..." &
info_pid=$(( $! + 2 )) # yikes, is this safe?
printf "%s\\n" "$ssh_temp_config"
printf "%s\\n" "$server_address"
if setsid -w ssh -qF "$ssh_temp_config" "$server_name" exit
echo "$ssh_temp_config"
echo "$server_address"
if ssh -qF "$ssh_temp_config" "$server_name" exit
then
kill $info_pid
succ_box "Login success!\\nAccount for ${server_address} created!"
succ_box "Login success!\\nAccount for $server_address created!"
cp "$ssh_temp_config" "$ssh_current_config"
rm "$ssh_temp_config"
exit # Without this the "Host already exists" box appears, investigate.

108
sshfs_gui.sh Executable file → Normal file
View File

@ -1,94 +1,72 @@
#!/bin/sh
# Copyright (c) 2018-2019 TildeLinux Maintainers
#
# 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 2 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, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
# Email: tildelinux@tildeverse.org
export SSH_ASKPASS="/usr/lib/ssh/x11-ssh-askpass"
setup_script_path="$HOME/.local/bin/setup_gui.sh"
eval "$(xdotool getmouselocation --shell)"
mouse_x=$X
mouse_y=$Y
mounts_file="$HOME/.ssh/mounts"
ssh_config_file="$HOME/.ssh/config"
server_name=$(grep -E "[H,h]ost " "$ssh_config_file" \
| cut -f 2 -d ' ' \
| tr '\n' '!' \
| sed 's/!$//') # This only works in posix sh
sshfs_local_path="${HOME}/Remote/myfolder"
sshfs_local_path="$HOME/Remote/myfolder"
sshfs_remote_path="$HOME"
get_field() {
get_field(){
field_num="$1"
info="$2"
printf "%s" "$info" | cut -f "$field_num" -d '|'
echo "$info" | cut -f "$field_num" -d '|'
}
error_box() {
error_box(){
error_text="$1"
yad \
--posx="$mouse_x" \
--posy="$mouse_y" \
--width=250 \
--image="dialog-error" \
--title="Error!" \
--text="$error_text" \
--width 250 \
--image "dialog-error" \
--title "Error!" \
--text "$error_text" \
--button="OK":0
}
succ_box() {
succ_box(){
succ_text="$1"
yad \
--posx="$mouse_x" \
--posy="$mouse_y" \
--width=250 \
--image="dialog-info" \
--title="Success!" \
--text="$succ_text" \
--width 250 \
--image "dialog-info" \
--title "Success!" \
--text "$succ_text" \
--button="OK":0
}
dec_box() {
dec_box(){
error_text="$1"
yad \
--posx="$mouse_x" \
--posy="$mouse_y" \
--width=250 \
--image="dialog-error" \
--title="Error!" \
--text="$error_text" \
--width 250 \
--image "dialog-error" \
--title "Error!" \
--text "$error_text" \
--button="No":1 \
--button="Yes":0
return $?
}
info_box() {
info_box(){
info_text="$1"
yad \
--posx="$mouse_x" \
--posy="$mouse_y" \
--no-buttons \
--width=250 \
--image="dialog-info" \
--title="Info" \
--text="$info_text"
--width 250 \
--image "dialog-info" \
--title "Info" \
--text "$info_text"
}
get_info() {
@ -106,22 +84,10 @@ get_info() {
--field="Server Shortname":CB \
--field="Local Directory" \
--field="Remote Directory" \
--button="Configure Servers...":2 \
--button="Cancel":1 \
--button="Continue":0 \
"$ssh_config_file" "$server_name" "$sshfs_local_path" "$sshfs_remote_path")
info_return="$?"
if [ $info_return -eq 1 ]
then
exit
elif [ $info_return -eq 2 ]
then
if ! "$setup_script_path"
then
error_box "${setup_script_path} did not finish successfully!"
get_info
fi
fi
[ $? -ne 0 ] && exit # Shellcheck will yell at me for this, perhaps find a better way?
server_name=$(get_field 2 "$info")
sshfs_local_path=$(get_field 3 "$info")
@ -130,13 +96,13 @@ get_info() {
if test -z "$sshfs_local_path"
then
error_msg="No local path provided!"
error_num=$((error_num + 1))
error_num=$(( error_num + 1))
fi
if test -z "$sshfs_remote_path"
then
error_msg="${error_msg}\\nNo remote path provided!"
error_num=$((error_num + 1))
error_msg="$error_msg\\nNo remote path provided"
error_num=$(( error_num + 1))
fi
if [ $error_num -gt 0 ]
@ -149,35 +115,33 @@ get_info() {
}
configure_mount() {
info_box "Attempting to link directories..." &
info_pid=$(( $! + 2 )) # yikes, is this safe?
test -e "$sshfs_local_path" \
|| mkdir -p "$sshfs_local_path"
if ! setsid -w ssh "$server_name" "test -d \${sshfs_remote_path}"
if ! ssh "$server_name" "test -d $sshfs_remote_path"
then
if dec_box "Directory $sshfs_remote_path does not exist on remote host, create?"
if dec_box "Directory does not exist on remote host, create?"
then
if ! error_msg=$(setsid -w ssh "$server_name" "mkdir \${sshfs_remote_path}" 2>&1)
if ! error_msg=$(ssh "$server_name" "mkdir $sshfs_remote_path" 2>&1)
then
error_box "Failed to create remote directory. ${error_msg}"
error_box "Failed to create remote directory $error_msg"
fi
fi
fi
if error_msg=$(setsid -w sshfs \
"${server_name}:${sshfs_remote_path}" \
"$sshfs_local_path" \
-oauto_cache,reconnect,Compression=no 2>&1)
if error_msg=$(sshfs "$server_name:$sshfs_remote_path" "$sshfs_local_path" 2>&1)
then
kill $info_pid
succ_box "Successfuly linked ${sshfs_local_path} to ${sshfs_remote_path} on ${server_name}"
printf "SSHFS Mount %s (%s)\\n" "${sshfs_local_path}" "${server_name}" >> "$mounts_file"
succ_box "Successfuly linked $sshfs_local_path to $sshfs_remote_path on $server_name"
else
kill $info_pid
error_box "Failed to link ${sshfs_local_path} to ${sshfs_remote_path} on ${server_name}\\n${error_msg}"
error_box "Failed to link $sshfs_local_path to $sshfs_remote_path on $server_name\\n$error_msg"
fi
}
get_info