-
Notifications
You must be signed in to change notification settings - Fork 0
/
dcvgui.sh
executable file
·150 lines (137 loc) · 5.03 KB
/
dcvgui.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#!/usr/bin/env bash
: "${CONFIGDIR:=$HOME/.config/dcvgui}"
: "${DCVVIEWER:=dcvviewer}"
DCVVIEWER_OPTIONS=(--fullscreen --certificate-validation-policy=accept-untrusted)
DEFAULT_PORT=8443
check_prereqs () {
command -v yad >/dev/null 2>&1 || {
echo >&2 "Error: yad is not installed; please install it."
exit 1
}
command -v "$DCVVIEWER" >/dev/null 2>&1 || {
echo >&2 "Error: dcvviewer ($DCVVIEWER) is not installed; please install it."
exit 1
}
mkdir -p "$CONFIGDIR"
}
show_error () {
local ERR_OPTIONS=(--text-info
--height 100 --width 300 --window-icon=gtk-dialog-error --centered --title "Error"
--fore=RED --margins=10 --wrap
--button OK:0
)
yad "${ERR_OPTIONS[@]}" <<< "Error: $*"
}
run_gui () {
local GUI_OPTIONS=(--height 300 --window-icon=applications-libraries --centered --borders=10 --title "Choose DCV Connection"
--no-click --ellipsize end
--button "Quit"\!application-exit:1
--button "Manage"\!control-center2:2
--button "Launch"\!gtk-ok:0
)
local done=0
while [[ $done == 0 ]]; do
# List all filenames in config dir, without extension
local NAMES
NAMES=$( (cd "$CONFIGDIR" && /bin/ls -1 -- *.dcv 2>/dev/null) | sed 's/\.dcv$//')
local result
result=$(echo "$NAMES" | yad --list "${GUI_OPTIONS[@]}" --column=Machine --separator "")
local status=$?
case $status in
0 ) # OK
if [[ -z $result ]]; then
show_error "Must choose a connection"
run_gui
else
echo Running "$DCVVIEWER" "${DCVVIEWER_OPTIONS[@]}" "${CONFIGDIR}/${result}.dcv"
("$DCVVIEWER" "${DCVVIEWER_OPTIONS[@]}" "${CONFIGDIR}/${result}.dcv") &
#exit 0
fi
;;
1 ) # Cancel
exit 1
;;
2 ) # Manage (create/delete connections)
run_manage
# after this, loop around and show gui
;;
esac
done
}
run_manage () {
# Manage shows all existing connections, but you can add/delete
local done=0
while [[ $done == 0 ]]; do
local NAMES
NAMES=$( (cd "$CONFIGDIR" && /bin/ls -1 -- *.dcv 2>/dev/null) | sed 's/\.dcv$//')
local result
local MANAGE_OPTIONS=(--height 300 --window-icon=control-center2 --centered --borders=10 --title "Manage DCV Connections"
--text "Select a connection to delete, \nor press <b>Add</b> to create a new one"
--text-align=center
--column="Connection to delete"
--separator=""
--no-click --ellipsize end
--button "Cancel"\!gtk-cancel:1
--button "Add..."\!list-add:0
--button "Delete"\!gtk-delete:2
)
result=$(echo "$NAMES" | yad --list "${MANAGE_OPTIONS[@]}")
local status=$?
case $status in
0 ) # Add
run_create
done=1
;;
1 ) # Cancel
done=1
;;
2 ) # Delete
local fname="${CONFIGDIR}/${result}.dcv"
[[ -e $fname ]] && rm "$fname"
# show dialog again
;;
esac
done
}
run_create () {
local CREATE_OPTIONS=(--height=275 --width=500 --margins=10 --borders=15 --window-icon=list-add --centered --title "Create DCV Connection"
--text "Connection Details:"
--field "Connection Name" ""
--field "Host Name/IP" ""
--field User ""
--field Port:NUM "$DEFAULT_PORT"
)
# Show the Create GUI form
result=$(yad --form "${CREATE_OPTIONS[@]}")
local status=$?
if [[ $status != 0 ]]; then
# Cancel -- go back to main GUI
run_gui
fi
IFS="|" read -r connection_name ip user port <<< "$result"
connection_name="${connection_name//\//_}" # remove slashes
if [[ -z $connection_name || -z $ip || -z $port ]]; then
show_error "Connection name, IP addr and port must all be specified."
run_gui
fi
local fname="${CONFIGDIR}/${connection_name}.dcv"
if [[ -e "$fname" ]]; then
show_error "Connection $fname already exists; please remove it or use a different name"
exit 1
fi
# Create the file
{
echo "[connect]"
echo "host=$ip"
echo "port=$port"
echo "user=$user"
echo
echo "[version]"
echo "format=1.0"
} > "$fname"
# Now pop up the GUI again so they can use it
run_gui
}
# Do it
check_prereqs
run_gui