GUI now functional
This commit is contained in:
parent
cd962275a2
commit
0871e69946
|
@ -1,3 +1,10 @@
|
||||||
# tildemerge
|
# tildemerge
|
||||||
|
|
||||||
(Working title) A basic script to configure sshfs for tilde, not to be used with existing ssh configs.
|
(Working title) A basic script to configure sshfs for tilde, not to be used with existing ssh configs.
|
||||||
|
|
||||||
|
### Dependencies
|
||||||
|
- gtk (gui)
|
||||||
|
- yad (gui)
|
||||||
|
- xdotool (gui)
|
||||||
|
- ssh
|
||||||
|
- sshfs
|
||||||
|
|
|
@ -0,0 +1,142 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
eval "$(xdotool getmouselocation --shell)"
|
||||||
|
mouse_x=$X
|
||||||
|
mouse_y=$Y
|
||||||
|
|
||||||
|
server_address="tilde.town!tilde.team"
|
||||||
|
login=""
|
||||||
|
ssh_port="22"
|
||||||
|
ssh_dir="$HOME/.ssh"
|
||||||
|
priv_key_path=" "
|
||||||
|
|
||||||
|
get_field(){
|
||||||
|
field_num="$1"
|
||||||
|
info="$2"
|
||||||
|
|
||||||
|
echo "$info" | cut -f "$field_num" -d '|'
|
||||||
|
}
|
||||||
|
|
||||||
|
error_box(){
|
||||||
|
error_text="$1"
|
||||||
|
yad \
|
||||||
|
--posx="$mouse_x" \
|
||||||
|
--posy="$mouse_y" \
|
||||||
|
--width "250" \
|
||||||
|
--image "dialog-error" \
|
||||||
|
--title "Error!" \
|
||||||
|
--text "$error_text" \
|
||||||
|
--button="OK":0
|
||||||
|
}
|
||||||
|
|
||||||
|
succ_box(){
|
||||||
|
succ_text="$1"
|
||||||
|
yad \
|
||||||
|
--posx="$mouse_x" \
|
||||||
|
--posy="$mouse_y" \
|
||||||
|
--width "250" \
|
||||||
|
--image "dialog-info" \
|
||||||
|
--title "Success!" \
|
||||||
|
--text "$succ_text" \
|
||||||
|
--button="OK":0
|
||||||
|
}
|
||||||
|
|
||||||
|
info_box(){
|
||||||
|
info_text="$1"
|
||||||
|
yad \
|
||||||
|
--posx="$mouse_x" \
|
||||||
|
--posy="$mouse_y" \
|
||||||
|
--no-buttons \
|
||||||
|
--width "250" \
|
||||||
|
--image "dialog-info" \
|
||||||
|
--title "Info" \
|
||||||
|
--text "$info_text"
|
||||||
|
}
|
||||||
|
|
||||||
|
get_info() {
|
||||||
|
error_num="0"
|
||||||
|
error_msg=""
|
||||||
|
|
||||||
|
info=$(yad \
|
||||||
|
--posx="$mouse_x" \
|
||||||
|
--posy="$mouse_y" \
|
||||||
|
--title="New server setup" \
|
||||||
|
--text="Add a new server" \
|
||||||
|
--form \
|
||||||
|
--field="Server":CB \
|
||||||
|
--field="Login" \
|
||||||
|
--field="Port" \
|
||||||
|
--field="SSH Directory":DIR \
|
||||||
|
--field="Private key":FL \
|
||||||
|
--button="Cancel":1 \
|
||||||
|
--button="Continue":0 \
|
||||||
|
"$server_address" "$login" "$ssh_port" "$ssh_dir" "$priv_key_path")
|
||||||
|
[ $? -eq "1" ] && exit
|
||||||
|
|
||||||
|
server_address=$(get_field "1" "$info")
|
||||||
|
login=$(get_field "2" "$info")
|
||||||
|
ssh_port=$(get_field "3" "$info")
|
||||||
|
ssh_dir=$(get_field "4" "$info")
|
||||||
|
priv_key_path=$(get_field "5" "$info")
|
||||||
|
|
||||||
|
if test -z "$login"
|
||||||
|
then
|
||||||
|
error_msg="No login provided!"
|
||||||
|
error_num=$(( error_num + 1))
|
||||||
|
fi
|
||||||
|
|
||||||
|
if test -d "$(echo "$priv_key_path" | sed 's/\/ *$//')"
|
||||||
|
then
|
||||||
|
error_msg="$error_msg\\nNo private key provided!"
|
||||||
|
error_num=$(( error_num + 1))
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ $error_num -gt '0' ]
|
||||||
|
then
|
||||||
|
error_box "$error_msg" \
|
||||||
|
&& get_info
|
||||||
|
fi
|
||||||
|
|
||||||
|
configure_server
|
||||||
|
}
|
||||||
|
|
||||||
|
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" \
|
||||||
|
| cut -f 2 -d ' ' \
|
||||||
|
| tr '[:upper:]' '[:lower:]')
|
||||||
|
|
||||||
|
mkdir -p "$ssh_host_dir"
|
||||||
|
cp "$priv_key_path" "$ssh_host_dir/id_$key_type"
|
||||||
|
|
||||||
|
test -e "$ssh_current_config" || touch "$ssh_current_config"
|
||||||
|
cp "$ssh_current_config" "$ssh_temp_config"
|
||||||
|
{
|
||||||
|
echo "Host $server_address"
|
||||||
|
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?
|
||||||
|
echo "$ssh_temp_config"
|
||||||
|
echo "$server_address"
|
||||||
|
if ssh -qF "$ssh_temp_config" "$server_address" exit
|
||||||
|
then
|
||||||
|
kill $info_pid
|
||||||
|
succ_box "Login success!\\nAccount for $server_address created!"
|
||||||
|
cp "$ssh_temp_config" "$ssh_current_config"
|
||||||
|
else
|
||||||
|
kill $info_pid
|
||||||
|
error_box "Login failed, please try again"
|
||||||
|
get_info
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
get_info
|
Loading…
Reference in New Issue