Added gui

This commit is contained in:
fosslinux 2018-11-14 18:49:12 -08:00 committed by Samuel Tyler
parent 8d8338c7e6
commit cd962275a2
1 changed files with 82 additions and 0 deletions

82
yad.sh Normal file
View File

@ -0,0 +1,82 @@
#!/bin/sh
server_address="tilde.town!tilde.team"
login=""
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"
echo "Error: $error_text"
yad \
--width "250" \
--image "dialog-error" \
--title "Error!" \
--text "$error_text"
}
info_box(){
info_text="$1"
echo "$info_text"
yad \
--no-buttons \
--width "250" \
--image "dialog-info" \
--title "Info" \
--text "$info_text"
}
get_info() {
error_num="0"
error_msg=""
info=$(yad \
--title="New server setup" \
--text="Add a new server" \
--form \
--field="Server":CB \
--field="Login" \
--field="SSH Directory":DIR \
--field="Private key":FL \
"$server_address" "$login" "$ssh_dir" "$priv_key_path")
server_address=$(get_field "1" "$info")
login=$(get_field "2" "$info")
ssh_dir=$(get_field "3" "$info")
priv_key_path=$(get_field "4" "$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
}
test_info() {
info_box "Attempting to log in with the provided credentials"
if ssh -qF "$ssh_temp_config" "$server_name" exit
then
info_box "Login success! writing config..."
fi
}
get_info
test_info