forked from lbdyck/prompters
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathzotinstall
executable file
·128 lines (109 loc) · 4.76 KB
/
zotinstall
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
#!/bin/env bash
VER='0.03'
clear
#---------------------------------------------------#
# Name: zotinstall #
# #
# Purpose: prompt user for zopen packages that are #
# not installed but available to be. #
# #
# Dependencies: gum and zopen and bash #
# #
# Syntax: zotinstall #
# #
# Author/Contributors: #
# Lionel B. Dyck ([email protected]) #
# #
# Change History (current on top): #
# 2024/02/04 LBD - 0.03 Enable filtering and more #
# 2024/02/04 LBD - 0.02 Refine #
# 2024/02/03 LBD - 0.01 Creation #
#---------------------------------------------------#
# Repository: github.com/lbdyck/prompters #
#---------------------------------------------------#
# Copyleft by Lionel B. Dyck 2024 #
#---------------------------------------------------#
#----------------------------------------------------------------#
# Define the color for the banner #
# 5 - purple #
# 12 - blue shade #
# 33 - darker blue #
# 46 - green #
# 51 - turq shade #
#----------------------------------------------------------------#
COLOR=51
#----------------------------------------------------------------#
# Define the spinner #
# line, dot, minidot, jump, pulse, points, globe, moon, #
# monkey, meter, hamburger #
#----------------------------------------------------------------#
SPIN="line"
#SPIN="dot"
#SPIN="minidot"
#SPIN="jump"
#SPIN="pulse"
#SPIN="points"
#SPIN="globe"
#SPIN="moon"
#SPIN="monkey"
#SPIN="meter"
#SPIN="hamburger"
#----------------------------------------------------------#
# Define out temp and tempw variables #
#----------------------------------------------------------#
TEMP="/tmp/zopen_list"
TEMPW="/tmp/zopen_listw"
#----------------------------------------------------------#
# Define the MANDB variable - null to not run #
#----------------------------------------------------------#
MANDB="mandb"
#MANDB=""
#----------------------------------------------------------#
# Define the gum environment variables #
#----------------------------------------------------------#
export GUM_INPUT_PROMPT_FOREGROUND="#$COLOR"
export GUM_INPUT_PLACEHOLDER=". . ."
export GUM_IMPORT_PROMPT="* "
export TERM=xterm-256color
#----------------------------------------------------------------#
# Define the TAG REDIR for our needs #
#----------------------------------------------------------------#
export _TAG_REDIR_IN=txt
export _TAG_REDIR_OUT=txt
export _TAG_REDIR_ERR=txt
# Display our banner
gum style \
--foreground $COLOR --border-foreground $COLOR --border double \
--align center --width 50 --margin "1 2" --padding "2 4" \
'z/OS Open Tools Installation Selector' $VER
# spinning something while we collect the list of all available packages
gum spin --title "Generating list of available packages" -s "$SPIN" \
--show-output --spinner.foreground="$COLOR" --title.foreground="$COLOR" \
-- zopen query --list > "$TEMP"
# Ask the user if they want to filter the packages
FILTER=$(gum input --prompt "Enter text to filter the available packages or blank:" \
--placeholder="e.g. ssh" --value=" " --header.foreground="$COLOR")
# Test if there is a filter and if so then clean up working file
if [ ! -z $FILTER ]; then
grep -i $FILTER $TEMP > $TEMPW
mv -f "$TEMPW" "$TEMP"
fi
# Prompt for package selections - any number allowed
# but first remove all installed packages and only use
# the package name
SELECTED=$(cat "$TEMP"| grep Not | cut -d " " -f1 | \
gum choose --no-limit \
--header "Select packages to install" --header.foreground="$COLOR")
# Test if any packages selected - must have at least one
if [ -z "$SELECTED" ]; then
echo "No selections - exiting...."
exit 0
fi
# Remove the work files
rm $TEMP
# Generate the zopen install command
INSTALL="zopen install -y $SELECTED"
# report what we have generated for the user
echo -e "Generated command: \n$INSTALL"
# If gum confirm Yes then process the next command
gum confirm "Execute Generated zopen install:" && $INSTALL && $MANDB