Added host names, config overwriting
This commit is contained in:
parent
0871e69946
commit
e53826911b
78
setup_gui.sh
78
setup_gui.sh
|
@ -5,6 +5,7 @@ mouse_x=$X
|
||||||
mouse_y=$Y
|
mouse_y=$Y
|
||||||
|
|
||||||
server_address="tilde.town!tilde.team"
|
server_address="tilde.town!tilde.team"
|
||||||
|
server_name="My Tilde"
|
||||||
login=""
|
login=""
|
||||||
ssh_port="22"
|
ssh_port="22"
|
||||||
ssh_dir="$HOME/.ssh"
|
ssh_dir="$HOME/.ssh"
|
||||||
|
@ -22,7 +23,7 @@ error_box(){
|
||||||
yad \
|
yad \
|
||||||
--posx="$mouse_x" \
|
--posx="$mouse_x" \
|
||||||
--posy="$mouse_y" \
|
--posy="$mouse_y" \
|
||||||
--width "250" \
|
--width 250 \
|
||||||
--image "dialog-error" \
|
--image "dialog-error" \
|
||||||
--title "Error!" \
|
--title "Error!" \
|
||||||
--text "$error_text" \
|
--text "$error_text" \
|
||||||
|
@ -34,27 +35,41 @@ succ_box(){
|
||||||
yad \
|
yad \
|
||||||
--posx="$mouse_x" \
|
--posx="$mouse_x" \
|
||||||
--posy="$mouse_y" \
|
--posy="$mouse_y" \
|
||||||
--width "250" \
|
--width 250 \
|
||||||
--image "dialog-info" \
|
--image "dialog-info" \
|
||||||
--title "Success!" \
|
--title "Success!" \
|
||||||
--text "$succ_text" \
|
--text "$succ_text" \
|
||||||
--button="OK":0
|
--button="OK":0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dec_box(){
|
||||||
|
error_text="$1"
|
||||||
|
yad \
|
||||||
|
--posx="$mouse_x" \
|
||||||
|
--posy="$mouse_y" \
|
||||||
|
--width 250 \
|
||||||
|
--image "dialog-error" \
|
||||||
|
--title "Error!" \
|
||||||
|
--text "$error_text" \
|
||||||
|
--button="No":1 \
|
||||||
|
--button="Yes":0
|
||||||
|
return $?
|
||||||
|
}
|
||||||
|
|
||||||
info_box(){
|
info_box(){
|
||||||
info_text="$1"
|
info_text="$1"
|
||||||
yad \
|
yad \
|
||||||
--posx="$mouse_x" \
|
--posx="$mouse_x" \
|
||||||
--posy="$mouse_y" \
|
--posy="$mouse_y" \
|
||||||
--no-buttons \
|
--no-buttons \
|
||||||
--width "250" \
|
--width 250 \
|
||||||
--image "dialog-info" \
|
--image "dialog-info" \
|
||||||
--title "Info" \
|
--title "Info" \
|
||||||
--text "$info_text"
|
--text "$info_text"
|
||||||
}
|
}
|
||||||
|
|
||||||
get_info() {
|
get_info() {
|
||||||
error_num="0"
|
error_num=0
|
||||||
error_msg=""
|
error_msg=""
|
||||||
|
|
||||||
info=$(yad \
|
info=$(yad \
|
||||||
|
@ -64,20 +79,22 @@ get_info() {
|
||||||
--text="Add a new server" \
|
--text="Add a new server" \
|
||||||
--form \
|
--form \
|
||||||
--field="Server":CB \
|
--field="Server":CB \
|
||||||
|
--field="Short Name" \
|
||||||
--field="Login" \
|
--field="Login" \
|
||||||
--field="Port" \
|
--field="Port" \
|
||||||
--field="SSH Directory":DIR \
|
--field="SSH Directory":DIR \
|
||||||
--field="Private key":FL \
|
--field="Private key":FL \
|
||||||
--button="Cancel":1 \
|
--button="Cancel":1 \
|
||||||
--button="Continue":0 \
|
--button="Continue":0 \
|
||||||
"$server_address" "$login" "$ssh_port" "$ssh_dir" "$priv_key_path")
|
"$server_address" "$server_name" "$login" "$ssh_port" "$ssh_dir" "$priv_key_path")
|
||||||
[ $? -eq "1" ] && exit
|
[ $? -ne 0 ] && exit # Shellcheck will yell at me for this, perhaps find a better way?
|
||||||
|
|
||||||
server_address=$(get_field "1" "$info")
|
server_address=$(get_field 1 "$info")
|
||||||
login=$(get_field "2" "$info")
|
server_name=$(get_field 2 "$info")
|
||||||
ssh_port=$(get_field "3" "$info")
|
login=$(get_field 3 "$info")
|
||||||
ssh_dir=$(get_field "4" "$info")
|
ssh_port=$(get_field 4 "$info")
|
||||||
priv_key_path=$(get_field "5" "$info")
|
ssh_dir=$(get_field 5 "$info")
|
||||||
|
priv_key_path=$(get_field 6 "$info")
|
||||||
|
|
||||||
if test -z "$login"
|
if test -z "$login"
|
||||||
then
|
then
|
||||||
|
@ -91,7 +108,7 @@ get_info() {
|
||||||
error_num=$(( error_num + 1))
|
error_num=$(( error_num + 1))
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ $error_num -gt '0' ]
|
if [ $error_num -gt 0 ]
|
||||||
then
|
then
|
||||||
error_box "$error_msg" \
|
error_box "$error_msg" \
|
||||||
&& get_info
|
&& get_info
|
||||||
|
@ -109,13 +126,40 @@ configure_server() {
|
||||||
| cut -f 2 -d ' ' \
|
| cut -f 2 -d ' ' \
|
||||||
| tr '[:upper:]' '[:lower:]')
|
| tr '[:upper:]' '[:lower:]')
|
||||||
|
|
||||||
|
test -e "$ssh_current_config" \
|
||||||
|
|| touch "$ssh_current_config"
|
||||||
|
cp "$ssh_current_config" "$ssh_temp_config"
|
||||||
|
|
||||||
|
if grep -qi "Host $server_name" "$ssh_current_config"
|
||||||
|
then
|
||||||
|
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)"
|
||||||
|
then
|
||||||
|
IFS=""
|
||||||
|
in_old_host_block=0
|
||||||
|
while read -r line
|
||||||
|
do
|
||||||
|
if echo "$line" | grep -q "Host $server_name"
|
||||||
|
then
|
||||||
|
in_old_host_block=0
|
||||||
|
elif echo "$line" | grep -q "Host "
|
||||||
|
then
|
||||||
|
in_old_host_block=1
|
||||||
|
fi
|
||||||
|
|
||||||
|
[ $in_old_host_block -eq 1 ] \
|
||||||
|
&& echo "$line"
|
||||||
|
done < "$ssh_current_config" > "$ssh_temp_config"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
mkdir -p "$ssh_host_dir"
|
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"
|
||||||
|
|
||||||
test -e "$ssh_current_config" || touch "$ssh_current_config"
|
|
||||||
cp "$ssh_current_config" "$ssh_temp_config"
|
|
||||||
{
|
{
|
||||||
echo "Host $server_address"
|
echo "Host $server_name"
|
||||||
echo " HostName $server_address"
|
echo " HostName $server_address"
|
||||||
echo " Port $ssh_port"
|
echo " Port $ssh_port"
|
||||||
echo " User $login"
|
echo " User $login"
|
||||||
|
@ -127,11 +171,13 @@ configure_server() {
|
||||||
info_pid=$(( $! + 2 )) # yikes, is this safe?
|
info_pid=$(( $! + 2 )) # yikes, is this safe?
|
||||||
echo "$ssh_temp_config"
|
echo "$ssh_temp_config"
|
||||||
echo "$server_address"
|
echo "$server_address"
|
||||||
if ssh -qF "$ssh_temp_config" "$server_address" exit
|
if ssh -qF "$ssh_temp_config" "$server_name" exit
|
||||||
then
|
then
|
||||||
kill $info_pid
|
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"
|
cp "$ssh_temp_config" "$ssh_current_config"
|
||||||
|
rm "$ssh_temp_config"
|
||||||
|
exit # Without this the "Host already exists" box appears, investigate.
|
||||||
else
|
else
|
||||||
kill $info_pid
|
kill $info_pid
|
||||||
error_box "Login failed, please try again"
|
error_box "Login failed, please try again"
|
||||||
|
|
Loading…
Reference in New Issue