Skip to content

Commit f2aeb7a

Browse files
authored
Create pecu_release_selector.sh
1 parent 8bb74cc commit f2aeb7a

File tree

1 file changed

+266
-0
lines changed

1 file changed

+266
-0
lines changed

pecu_release_selector.sh

Lines changed: 266 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,266 @@
1+
#!/bin/bash
2+
# -----------------------------------------------------------------------------
3+
# PECU Release Selector
4+
# By Daniel Puente García (Danielop95/DVNILXP)
5+
# Version: 0.0 - 14/4/2025
6+
#
7+
# This script fetches PECU releases from GitHub and lets you pick one to run.
8+
# Stable releases are shown in green (with the first stable marked as [RECOMMENDED])
9+
# and pre-releases in yellow.
10+
#
11+
# Before starting, it checks that curl and jq are installed and verifies network
12+
# connectivity, letting you know what's happening along the way.
13+
#
14+
# Usage: Run as root on your Proxmox server.
15+
# -----------------------------------------------------------------------------
16+
17+
# Color definitions
18+
RED='\e[0;31m'
19+
GREEN='\e[0;32m'
20+
BLUE='\e[0;34m'
21+
YELLOW='\e[0;33m'
22+
NC='\e[0m' # No color
23+
24+
# GitHub repository information
25+
GITHUB_REPO="Danilop95/Proxmox-Enhanced-Configuration-Utility"
26+
API_URL="https://api.github.com/repos/${GITHUB_REPO}/releases"
27+
28+
# -----------------------------------------------------------------------------
29+
# Function: Check network connectivity
30+
# -----------------------------------------------------------------------------
31+
check_network() {
32+
echo -ne "${YELLOW}Checking network connectivity...${NC} "
33+
if ping -c 1 -W 2 google.com &> /dev/null; then
34+
echo -e "${GREEN}OK${NC}"
35+
else
36+
echo -e "${RED}FAILED${NC}"
37+
echo -e "${RED}Network connectivity appears to be unavailable or DNS resolution is failing."
38+
echo -e "Please check your network and DNS settings before running this script.${NC}"
39+
exit 1
40+
fi
41+
}
42+
43+
# -----------------------------------------------------------------------------
44+
# Function: Check and install dependencies interactively
45+
# -----------------------------------------------------------------------------
46+
check_dependencies() {
47+
check_network
48+
49+
local deps=(curl jq)
50+
for dep in "${deps[@]}"; do
51+
if ! command -v "$dep" >/dev/null 2>&1; then
52+
echo -e "${RED}Dependency '$dep' is not installed.${NC}"
53+
read -rp "Would you like to install '$dep'? (y/N): " answer
54+
case "$answer" in
55+
[yY]|[yY][eE][sS])
56+
echo -e "${YELLOW}Updating package lists...${NC}"
57+
if ! apt-get update; then
58+
echo -e "${RED}Failed to update package lists. This may be due to a temporary "
59+
echo -e "failure in DNS resolution or network issues. Please try running:"
60+
echo -e " apt-get update --fix-missing"
61+
echo -e "or check your network settings before continuing.${NC}"
62+
exit 1
63+
fi
64+
echo -e "${YELLOW}Installing $dep...${NC}"
65+
if ! apt-get install -y "$dep"; then
66+
echo -e "${RED}Error: Failed to install $dep. Exiting.${NC}"
67+
exit 1
68+
fi
69+
;;
70+
*)
71+
echo -e "${RED}Cannot proceed without $dep. Exiting.${NC}"
72+
exit 1
73+
;;
74+
esac
75+
else
76+
echo -e "${GREEN}Dependency '$dep' is already installed.${NC}"
77+
fi
78+
done
79+
}
80+
81+
# -----------------------------------------------------------------------------
82+
# Loading Screen (Banner and Spinner)
83+
# -----------------------------------------------------------------------------
84+
show_loading_banner() {
85+
clear
86+
echo -e "${BLUE}=================================================${NC}"
87+
echo -e "${BLUE} PROXMOX ENHANCED CONFIG UTILITY (PECU) ${NC}"
88+
echo -e "${BLUE}=================================================${NC}"
89+
echo -e "${GREEN} By Daniel Puente García (Danielop95/DVNILXP)${NC}"
90+
echo
91+
92+
local banner_lines=(
93+
" ____ ______________ __"
94+
" / __ \\/ ____/ ____/ / / /"
95+
" / /_/ / __/ / / / / / / "
96+
" / ____/ /___/ /___/ /_/ / "
97+
"/_/ /_____/\____/\____/ "
98+
" "
99+
)
100+
101+
echo -e "${YELLOW}"
102+
for line in "${banner_lines[@]}"; do
103+
echo "$line"
104+
sleep 0.07
105+
done
106+
echo -e "${NC}"
107+
sleep 0.5
108+
}
109+
110+
show_release_spinner() {
111+
local messages=(
112+
"Fetching Stable Releases..."
113+
"Fetching Pre-release Versions..."
114+
"Preparing Version Selector..."
115+
"Recommended: Use Stable Release!"
116+
"Proxmox Enhanced Utility"
117+
)
118+
119+
echo -ne "${YELLOW}Initializing Release Selector: ${NC}"
120+
for msg in "${messages[@]}"; do
121+
printf "\r${YELLOW}%-50s${NC}" "$msg"
122+
sleep 0.7
123+
done
124+
echo
125+
sleep 1
126+
}
127+
128+
print_banner() {
129+
clear
130+
cat << 'EOF'
131+
===========================================
132+
Proxmox Enhanced Configuration Utility
133+
Version Selector
134+
===========================================
135+
EOF
136+
}
137+
138+
# -----------------------------------------------------------------------------
139+
# Fetch releases from GitHub API
140+
# -----------------------------------------------------------------------------
141+
fetch_releases() {
142+
local json
143+
echo -e "${BLUE}Fetching release information from GitHub...${NC}"
144+
json=$(curl -sL "$API_URL")
145+
if [[ -z "$json" ]]; then
146+
echo -e "${RED}Error: Failed to fetch release information from GitHub.${NC}"
147+
exit 1
148+
fi
149+
150+
# Format: tag_name | prerelease | published_at
151+
echo "$json" | jq -r '.[] | "\(.tag_name) | \(.prerelease) | \(.published_at)"'
152+
}
153+
154+
# -----------------------------------------------------------------------------
155+
# Display the release selection menu with color differentiation
156+
# -----------------------------------------------------------------------------
157+
display_menu() {
158+
local releases=("$@")
159+
local recommended_index=-1
160+
161+
# First pass: determine the recommended (first stable release) index
162+
for i in "${!releases[@]}"; do
163+
local pre
164+
pre=$(echo "${releases[$i]}" | cut -d'|' -f2 | xargs)
165+
if [[ "$pre" == "false" ]] && [[ $recommended_index -eq -1 ]]; then
166+
recommended_index=$i
167+
break
168+
fi
169+
done
170+
171+
echo -e "\nSelect a PECU version to execute:"
172+
echo "-----------------------------------"
173+
local index=1
174+
for rel in "${releases[@]}"; do
175+
local tag pre published
176+
tag=$(echo "$rel" | cut -d'|' -f1 | xargs)
177+
pre=$(echo "$rel" | cut -d'|' -f2 | xargs)
178+
published=$(echo "$rel" | cut -d'|' -f3 | xargs)
179+
180+
if [[ "$pre" == "true" ]]; then
181+
# Pre-release: show in yellow
182+
echo -e " ${index}) ${YELLOW}${tag} (Pre-release)${NC} - Published: ${published}"
183+
else
184+
# Stable release: show in green; mark as RECOMMENDED if first stable
185+
if [[ $((index-1)) -eq $recommended_index ]]; then
186+
echo -e " ${index}) ${GREEN}${tag} (Stable) [RECOMMENDED]${NC} - Published: ${published}"
187+
else
188+
echo -e " ${index}) ${GREEN}${tag} (Stable)${NC} - Published: ${published}"
189+
fi
190+
fi
191+
((index++))
192+
done
193+
echo " 0) Exit"
194+
echo "-----------------------------------"
195+
}
196+
197+
# -----------------------------------------------------------------------------
198+
# Prompt the user to select a release and return its tag
199+
# -----------------------------------------------------------------------------
200+
select_release() {
201+
local releases=("$@")
202+
local choice
203+
read -rp "Enter the option number: " choice
204+
if [[ "$choice" =~ ^[0-9]+$ ]]; then
205+
if [ "$choice" -eq 0 ]; then
206+
echo -e "${YELLOW}Exiting.${NC}"
207+
exit 0
208+
elif [ "$choice" -ge 1 ] && [ "$choice" -le "${#releases[@]}" ]; then
209+
local selected
210+
selected="${releases[$((choice-1))]}"
211+
local tag
212+
tag=$(echo "$selected" | cut -d'|' -f1 | xargs)
213+
echo "$tag"
214+
else
215+
echo -e "${RED}Invalid selection. Please try again.${NC}" >&2
216+
select_release "${releases[@]}"
217+
fi
218+
else
219+
echo -e "${RED}Invalid input. Please enter a number.${NC}" >&2
220+
select_release "${releases[@]}"
221+
fi
222+
}
223+
224+
# -----------------------------------------------------------------------------
225+
# Execute the selected version of the PECU script
226+
# -----------------------------------------------------------------------------
227+
execute_release() {
228+
local tag="$1"
229+
echo -e "\nSelected version: ${BLUE}${tag}${NC}"
230+
echo -e "${YELLOW}Fetching and executing PECU from GitHub...${NC}"
231+
# Download and execute the script directly from GitHub using the selected tag.
232+
bash <(curl -sL "https://raw.githubusercontent.com/${GITHUB_REPO}/${tag}/proxmox-configurator.sh")
233+
}
234+
235+
# -----------------------------------------------------------------------------
236+
# Main Execution Flow
237+
# -----------------------------------------------------------------------------
238+
main() {
239+
# Check and, if necessary, install required dependencies.
240+
check_dependencies
241+
242+
show_loading_banner
243+
show_release_spinner
244+
print_banner
245+
246+
# Fetch release information.
247+
mapfile -t releases_array < <(fetch_releases)
248+
if [ "${#releases_array[@]}" -eq 0 ]; then
249+
echo -e "${RED}No releases found for repository ${GITHUB_REPO}.${NC}"
250+
exit 1
251+
fi
252+
253+
display_menu "${releases_array[@]}"
254+
255+
selected_tag=$(select_release "${releases_array[@]}")
256+
read -rp "Proceed to execute version ${selected_tag}? (y/N): " confirm
257+
if [[ "$confirm" =~ ^[Yy] ]]; then
258+
execute_release "$selected_tag"
259+
else
260+
echo -e "${YELLOW}Operation cancelled.${NC}"
261+
exit 0
262+
fi
263+
}
264+
265+
# Execute the script
266+
main

0 commit comments

Comments
 (0)