-
Notifications
You must be signed in to change notification settings - Fork 1
/
MenuStates.sh
executable file
·259 lines (187 loc) · 5.14 KB
/
MenuStates.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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
#!/bin/bash
#Global Variables
GNAME="NULL";
GTMP="/tmp";
function IPeUser()
{
#funcao que recebe uma variavel para preencher nome do minionn
local minionpadrao="minion1"
local listminions=/tmp/listminions.txt
dialog --cr-wrap --sleep 1 --infobox "Procurando Minions Disponíveis..." 0 0
echo -e "$(sudo salt '*' test.ping -s --out=txt | sed "s/\://g" )" > $listminions
local minions=$(cat $listminions)
minionpadrao=$(dialog --stdout --menu 'Escolha o Minion:' 0 0 0 \
`
for x in $minions; do
echo " $x ";
done;
`);
#Valida se houve uma selecao de usuario ou nao
if [ $? -eq 1 ]; then
dialog --cr-wrap --sleep 2 --title 'Tente Novamente' --infobox "Nenhum escolhido" 5 17
Menu;
# else
# dialog --cr-wrap --sleep 1 --infobox "Escolhido $minionpadrao" 0 0
fi
#retorna valores
eval "$1=$minionpadrao"
}
function SelectViewDoTest()
{
clear;
local todialog=$GTMP/RespToDialog.txt
DEFAULT="minion1";
mymini=${1-$DEFAULT}
DEFAULT="top.sls";
mycomm=${2-$DEFAULT}
myselect=$(dialog --stdout --radiolist 'Opcoes' 0 0 0 \
run 'Run / Executar ' off \
testonly 'Test / Testar ' on \
viewonly 'View / Vizualizar ' off);
case $myselect in
"run")
#echo "tree-only"
echo -e "$(sudo salt $mymini state.sls $mycomm)" > $todialog
;;
"testonly")
#echo "all-files"
echo -e "$(sudo salt $mymini state.sls $mycomm test=true)" > $todialog
;;
"viewonly")
#echo "all"
echo -e "$(sudo salt $mymini state.show_sls $mycomm)" > $todialog
;;
*)
echo "Menu Inválido!"
;;
esac
}
function SelectFunction()
{
clear;
local todialog=$GTMP/RespToDialog.txt
#DEFAULT="sys.list_functions";
#mycomm=${1-$DEFAULT}
#dialog --msgbox "Selecione na lista de $mycomm ." 0 0
#echo -e "$($mycomm)" > $todialog
dialog --msgbox "Lista criada tecle enter." 0 0
local modules=$(cat $todialog )
myescolha=$(dialog --stdout --menu 'Escolha.' 0 0 0 \
`
for x in $modules; do
echo " "$x" Escolha-me ";
done;
`);
#Valida se houve uma selecao de usuario ou nao
if [ $? -eq 1 ]; then
dialog --cr-wrap --sleep 2 --title 'Tente Novamente' --infobox "Nenhum escolhido" 5 17
eval "$1=test.ping"
Menu;
else
#dialog --cr-wrap --sleep 2 --infobox "Escolhido: $myescolha" 0 0
eval "$1=$myescolha"
fi
}
function ListStatesTree()
{
clear;
local todialog=$GTMP/RespToDialog.txt
IPeUser myminion
#local mycommand="tree /srv/salt -L 1 | grep -v sls | grep -v directories"
#SelectTree $mycommand mychoice
#dialog --cr-wrap --sleep 2 --infobox "Escolhi: $mychoice" 0 0
#SelectViewDoTest $mychoice commandtorun
#dialog --cr-wrap --sleep 2 --infobox "Recebi: $commandtorun" 0 0
#
#echo -e "$(sudo salt $myminion state.show_highstate --out=json | grep __sls__ | sed 's/, *$//' | sort -u | awk '{print $2}')" > $todialog
#comando mais simples
echo -e "$(sudo salt $myminion cp.list_states | sed 1d | sed "s/\-//g" | tr -s [:space:] )" > $todialog
dialog --title "States off minion: $myminion " --textbox $todialog 45 50
Menu
}
function RunState()
{
clear;
local todialog=$GTMP/RespToDialog.txt
IPeUser myminion
echo -e "$(sudo salt $myminion cp.list_states | sed 1d | sed "s/\- //g" | tr -s [:space:] )" > $todialog
#local mycommand=$(cat $todialog)
SelectFunction mychoice
#dialog --cr-wrap --sleep 2 --infobox "Escolhi: $mychoice" 0 0
SelectViewDoTest $myminion $mychoice
dialog --title 'Documentation' --textbox $todialog 0 0
Menu
}
function RunTopState()
{
clear;
local todialog=$GTMP/RespToDialog.txt
IPeUser myminion
echo -e "$(sudo salt $myminion state.show_top | grep " - " | tr -s [:space:] | sed "s/ \- //g")" > $todialog
#local mycommand=$(cat $todialog)
SelectFunction mychoice
#dialog --cr-wrap --sleep 2 --infobox "Escolhi: $mychoice" 0 0
SelectViewDoTest $myminion $mychoice
dialog --title 'Documentation' --textbox $todialog 0 0
Menu
}
function RunHighState()
{
clear;
local todialog=$GTMP/RespToDialog.txt
IPeUser mymini
myselect=$(dialog --stdout --radiolist 'Opcoes' 0 0 0 \
run 'Run / Executar ' off \
testonly 'Test / Testar ' on \
viewonly 'View / Vizualizar ' off);
case $myselect in
"run")
#echo "tree-only"
echo -e "$(sudo salt $mymini state.highstate)" > $todialog
;;
"testonly")
#echo "all-files"
echo -e "$(sudo salt $mymini state.highstate test=true)" > $todialog
;;
"viewonly")
#echo "all"
echo -e "$(sudo salt $mymini state.show_highstate )" > $todialog
;;
*)
echo "Menu Inválido!"
;;
esac
dialog --title 'Documentation' --textbox $todialog 0 0
Menu
}
function Menu()
{
clear
menuopt=$(dialog --menu "Menu" 20 35 15 \
1 "List State Tree" \
2 "Run States" \
3 "Run HighState" \
4 "Run TopStates" \
9 "Exit" --stdout)
case $menuopt in
1)
ListStatesTree
;;
2)
RunState
;;
3)
RunHighState
;;
4)
RunTopState
;;
9) ./Main.sh
;;
*) echo "Menu Inválido!" ;;
esac
}
function Iniciar(){
Menu
}
Iniciar