-
Notifications
You must be signed in to change notification settings - Fork 0
/
vut.sh
executable file
·473 lines (423 loc) · 11.7 KB
/
vut.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
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
#!/usr/bin/env bash
# shellcheck disable=SC2162,SC2317
# program name
progname=${0##*/}
version="0.23b"
# enable translation
_enable_translation() {
if [[ -f "$HOME/.config/osowoso/ ${progname}/${LANGUAGE}.cfg" ]]; then
source "$HOME/.config/osowoso/${progname}/${LANGUAGE}.cfg"
elif [[ -f "$HOME/.config/osowoso/${progname}/${LANG:0:5}.cfg" ]]; then
source "$HOME/.config/osowoso/${progname}/${LANG:0:5}.cfg"
elif [[ -f "$HOME/.config/osowoso/${progname}/${LANG:0:2}.cfg" ]]; then
source "$HOME/.config/osowoso/${progname}/${LANG:0:2}.cfg"
else
source "$HOME/.config/osowoso/${progname}/en.cfg"
fi
}
_create_config() {
config_path="$HOME/.config/osowoso/${progname}"
config="$HOME/.config/osowoso/${progname}/${progname}.conf"
mkdir -p "$config_path"
touch "$config"
}
_define_colors() {
cr="\033[0;31m"
cg="\033[0;32m"
green="\033[32m"
cy="\033[0;33m"
cb="\033[0;34m"
cyan="\033[0;36m"
clc="\033[36m"
cw="\033[0;37m"
bold="\033[1m"
cc="\033[0m"
c="\[0;"
}
_print_menu() {
"$clear_yes" >/dev/null 2>&1
echo -e "${bold}${header}${cc}"
echo -e "${bold}${1}${cc}"
shift
for ((i=1; i<=$#; i++)); do
echo -e "${clc}$i.${cc} ${bold}${!i}${cc}"
done
echo -e "${clc}0.${cc} Help${cc}"
echo -e "${cr}${menu_up}${cc}"
}
_print_header() {
HEADER_BUBBLE=$(gum style --height 5 --width 25 --padding '1 3' --border double --border-foreground 57 "Void Ultimate Tool version $version")
HELP_BUBBLE=$(gum style --width 25 --padding '1 3' --border double --border-foreground 212 "current dir $(gum style --foreground "#04B575" "Heeelp")")
gum join --horizontal "$HEADER_BUBBLE" "$HELP_BUBBLE"
}
_print_src_header() {
HEADER_BUBBLE=$(gum style --height 5 --width 25 --padding '1 3' --border double --border-foreground 57 "Tools to work with xbps-src Using:fzf git vpsm xtools xxtools")
HELP_BUBBLE=$(gum style --width 25 --padding '1 3' --border double --border-foreground 212 "XBPS_DISTDIR \n $XBPS_DISTDIR repo: $MY_XBPS_REPO $(git branch | grep '*') PR: $pr_number $(gum style --foreground "#04B575" "Heeelp")")
gum join --horizontal "$HEADER_BUBBLE" "$HELP_BUBBLE"
}
function hlp_main {
"#TODO"
}
function hlp_src {
"#TODO"
}
function hlp_xbps {
"#TODO"
}
function config_edit {
"$EDITOR" "$config"
}
function config_edit_vars {
"$clear_yes" >/dev/null 2>&1
# display a list of variables
echo "List of variables in the configuration file:"
cat "$config"
# offer the user to select variables to edit
read -p "Enter the variable numbers to edit (separated by space), or press ENTER to select all variables: " varnums
# if the user didn't enter any variable number, edit all variables
if [[ -z $varnums ]]; then
varnums=$(awk -F= '/^[^#]/ {print NR}' "$HOME/.config/vut/vut.conf")
fi
# iterate over the selected variables and offer the user the option to edit each one
for varnum in $varnums; do
# get the variable name and current value from the configuration file
var=$(awk -F= '/^[^#]/ {if (NR == '$varnum') print $1}' "$HOME/.config/vut/vut.conf")
varvalue=$(grep "^$var=" "$HOME/.config/vut/vut.conf" | cut -d= -f2)
# if the variable doesn't exist, inform the user and skip it
if [[ -z $varvalue ]]; then
echo "Variable $var does not exist in the configuration file, skipping it."
continue
fi
# display the current value of the variable and offer the user the option to change it
read -p "The current value of $var is \"$varvalue\". Do you want to change it? (y/N) " choice
case "$choice" in
y|Y )
# get the new value of the variable from the user and change it in the configuration file
read -p "Enter the new value for $var: " newvalue
sed -i "s/^$var=.*/$var=$newvalue/" "$HOME/.config/vut/vut.conf"
echo "Variable $var has been changed to \"$newvalue\"."
;;
* )
# the user didn't want to change the value of the variable, skip it
;;
esac
done
}
# listing available templates
function list_templates {
cd "$XBPS_DISTDIR" || exit 2
find ./*/ | sed 's#/##'
}
# list available arguments
function list_arguments {
cat "$config_path/arguments"
}
function list_arguments2 {
# Get the list of functions in the script
functions=($(declare -F | awk '{print $NF}'))
# Print the names of the functions
for f in "${functions[@]}"; do
if [[ $f == function* ]]; then
echo "${f/function /}"
fi
done
}
function src_list_gen {
ls srcpkgs/ > "$config_path/list"
}
# updating templates from git
function src_update {
vpsm upr && read -n 1 -s -r -p "Press any key to continue"
}
# create new template
function src_new {
new="yes"
read -p "Enter the template name: " template
vpsm n "$template"
}
# choose template to work with
function src_choose {
new="no"
template=$(find srcpkgs/ -maxdepth 1 | cut -d'/' -f2 | fzf)
echo "$template"
}
# try to autobump template (xxtools)
function src_bump {
xxautobump "$template"
}
# clean template build directory
function src_clean {
vpsm cl "$template"
}
# open project homepage
# shellcheck disable=SC2154,SC1091
function src_homepage {
source "srcpkgs/$template/template"
xdg-open "$homepage"
}
# check template on repology
function src_repology {
xdg-open https://repology.org/projects/?search="$template"
}
# check for void-packages PRs
function src_pr_check {
if [ -z "$pr_number" ]; then
xdg-open https://github.com/void-linux/void-packages/pulls?q="$template"
else
xdg-open https://github.com/void-linux/void-packages/pulls/"$pr_number"
fi
}
function src_pr_create {
set_branch_name
}
function create_repo_github {
curl -H "$GITHUB_TOKEN" https://api.github.com/user/repos -d '{"name":"REPO"}'
git init
git remote add origin [email protected]:"${USERNAME}/${REPO}.git"
}
# etnter number of guthub PR
function src_pr_number {
read -p "Enter number of your PR: " pr_number
}
function repo_push {
git push -u "$REPO_NAME" "$HEAD"
read -p "Press Enter to continue"
}
function set_branch_name {
# Generate a suggested branch name
template="feature/$(whoami)/$(git rev-parse --abbrev-ref HEAD | sed 's/\//-/g')-"
# Ask the user if they want to use the suggested branch name
read -p "Use the suggested branch name \"$template\"? (y/n) " choice
# If the user doesn't want to use the suggested name, prompt them for a new name
if [[ $choice =~ ^[Nn]$ ]]; then
read -p "Enter a new branch name: " branch_name
else
branch_name="$template"
fi
}
# lint template
function src_lint {
vpsm lint "$template"
}
# checksum template
function src_checksum {
vpsm xgsum "$template"
}
# dit template
function src_edit {
#vpsm et "$template"
"$TERMINAL" -e "$EDITOR srcpkgs/${template}/template" &
}
# downloading and building a template
function src_build {
vpsm pkg "$template"
}
# installing a package
function src_install {
xi "$template"
}
# enter XBPS_DISTDIR
function src_enter {
cd "$XBPS_DISTDIR" && echo "Entered $XBPS_DISTDIR" && export XBPS_DISTDIR="$XBPS_DISTDIR" && export EDITOR="$EDITOR" || echo "XBPS_DISTDIR not set!"
}
function save_arguments {
# Get the list of functions in the script
declare -F | while read line; do
# Extract the function name
func_name=$(echo "$line" | awk '{print $3}')
# Check if the function starts with the word "function"
if [[ $func_name == function* ]]; then
# Write the function name to the "arguments" file
echo "${func_name/function /}" > "${config_path}/arguments"
fi
done
}
# Get the list of functions in the script
declare -F | while read line; do
# Extract the function name
func_name=$(echo "$line" | awk '{print $3}')
# Check if the function starts with the word "function"
if [[ $func_name == function* ]]; then
# Add a case branch for the function to the switch statement
case "$1" in
"${func_name/function /}")
# Execute the function
$func_name
exit 0
;;
esac
fi
done
install_essentials() {
echo "#TODO"
}
# Main script
_define_colors
#_enable_translation
_create_config
# shellcheck source=./vut.conf
source "$config"
while true; do
header_box="Void Ultimate Tool"
help_box="$hlp_main"
menu_up="00. Quit"
menu_name="main"
_print_header
_print_menu "main menu:" \
"${cg} menu XBPS-SRC" \
"${cg} menu PACKAGES" \
"${cy} Update xbps" \
"${cy} Update all" \
"${cyan} List possible arguments" \
"${cyan} Edit config file" \
"${cc} Install essential programs"
read -p "Select an operation (00 0-7): " main_choice
case "$main_choice" in
1)
while true; do
help_box="hello"
menu_up="00. Back"
menu_name="src"
src_enter
_print_src_header
_print_menu "~" \
"${cr} Create template" \
"${cr} Choose template" \
"${cy}${template}${cc} on repology" \
"autobump ${cg}${template}${clc}" \
"edit ${cg}${template}${cc}" \
"checksum ${cg}${template}${clc}" \
"lint ${cg}${template}${clc}" \
"build ${cg}${template}${clc}" \
"install ${cg}${template}${clc}" \
"${cc} Update${clc}" \
"${cc} Clean ${cg}${template}${clc}" \
"${cg}${template}${cc} PR check" \
"${cg}${template}${cc} create PR" \
"${cg}${template}${cc} push" \
"generate list of current templates" \
"${cc} open template${cc} homepage"
read -p "Select an operation (00 0-16): " template_choice
case "$template_choice" in
1)
src_new
;;
2)
src_choose
;;
3)
src_repology
;;
4)
src_bump
;;
5)
src_edit
;;
6)
src_checksum
;;
7)
src_lint
;;
8)
src_build
;;
9)
src_install
;;
10)
src_update
;;
11)
src_clean
;;
12)
src_pr_check
;;
13)
src_pr_create
;;
14)
REPO="$MY_XBPS_REPO"
HEAD="$template"
repo_push
;;
15)
src_list_gen
;;
16)
src_homepage
;;
0)
hlp_src
;;
00)
break
;;
*)
echo "Invalid choice: $choice"
;;
esac
done
;;
2)
while true; do
# second sub-menu
header="Tools for working with packages"
menu_up="00. Back"
menu_name="xbps"
_print_menu "PACKAGES:" \
"Install Package" \
"Remove Package"
read -p "Select an operation (00 0-2): " package_choice
case "$package_choice" in
1)
install_package
;;
2)
remove_package
;;
0)
hlp_xbps
;;
00)
break
;;
*)
echo "Invalid selection, please try again."
;;
esac
done
;;
3)
sudo xbps-install -Suv
read -p "Press Enter to continue"
;;
4)
topgrade
read -p "Press Enter to continue"
;;
5)
list_arguments
read -p "Press Enter to continue"
;;
6)
config_edit
read -p "Press Enter to continue"
;;
7)
install_essentials
;;
0)
hlp_main
;;
00)
exit 0
;;
*)
echo "Invalid selection, please try again."
read -p "Press Enter to continue"
;;
esac
done