-
Notifications
You must be signed in to change notification settings - Fork 49
Expand file tree
/
Copy pathenv-scanner.sh
More file actions
executable file
·122 lines (104 loc) · 3.57 KB
/
env-scanner.sh
File metadata and controls
executable file
·122 lines (104 loc) · 3.57 KB
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
#!/usr/bin/env bash
# Development Environment Scanner
# Checks your toolchain with style
set -euo pipefail
# Color palette
readonly RED='\033[38;5;196m'
readonly GREEN='\033[38;5;46m'
readonly BLUE='\033[38;5;39m'
readonly PURPLE='\033[38;5;129m'
readonly YELLOW='\033[38;5;226m'
readonly GRAY='\033[38;5;242m'
readonly BOLD='\033[1m'
readonly RESET='\033[0m'
# Icons
readonly CROSS="❌"
readonly CHECK="✅"
readonly ROCKET="🚀"
readonly GEAR="⚙️"
readonly SPARKLE="✨"
header() {
echo -e "${BOLD}${BLUE}"
echo "╔═════════════════════════════════════╗"
echo "║ Development Environment Scanner ║"
echo "╚═════════════════════════════════════╝"
echo -e "${RESET}"
}
get_version() {
local tool="$1"
local flag="$2"
local version=""
case "$tool" in
docker)
# Try the format flag first, fallback to parsing regular output
if version=$(docker version --format '{{.Client.Version}}' 2>/dev/null); then
version=$(echo "$version" | tr -d '\n\r' | xargs)
elif output=$(docker --version 2>/dev/null); then
version=$(echo "$output" | grep -Eo '[0-9]+(\.[0-9]+){1,2}' | head -n 1)
else
version="unknown"
fi
[[ -z "$version" ]] && version="unknown"
;;
code)
output=$($tool $flag 2>/dev/null | head -n 1)
version=$(echo "$output" | grep -Eo '[0-9]+(\.[0-9]+){1,2}' | head -n 1)
[[ -z "$version" ]] && version="installed"
;;
*)
output=$($tool $flag 2>/dev/null | head -n 1)
version=$(echo "$output" | grep -Eo '[0-9]+(\.[0-9]+){1,2}' | head -n 1)
[[ -z "$version" ]] && version="unknown"
;;
esac
echo "$version"
}
check_tool() {
local tool="$1"
local flag="$2"
local desc="$3"
printf "${GRAY}${GEAR} Scanning${RESET} %-12s " "$tool"
if ! command -v "$tool" &>/dev/null; then
echo -e "${RED}${CROSS} Missing${RESET} ${GRAY}($desc)${RESET}"
return 1
else
local version
version=$(get_version "$tool" "$flag")
echo -e "${GREEN}${CHECK} v${version}${RESET} ${GRAY}($desc)${RESET}"
return 0
fi
}
main() {
local installed=0
local total=0
header
echo -e "${PURPLE}${SPARKLE} Validating your development stack...${RESET}\n"
# Define tools with descriptions
local tools=(
"code:-v:Code Editor"
"git:--version:Version Control"
"node:-v:JavaScript Runtime"
"docker:version:Containerization"
"go:version:Go Language"
"cargo:-V:Rust Package Manager"
"uv:-V:Python Package Manager"
)
for tool_info in "${tools[@]}"; do
IFS=':' read -r tool flag desc <<< "$tool_info"
if check_tool "$tool" "$flag" "$desc"; then
((installed++))
fi
((total++))
done
echo
# Summary
local percentage=$((installed * 100 / total))
if [[ $percentage -eq 100 ]]; then
echo -e "${GREEN}${BOLD}${ROCKET} Perfect! All tools ready (${installed}/${total})${RESET}"
elif [[ $percentage -ge 75 ]]; then
echo -e "${YELLOW}${BOLD}${GEAR} Almost there! (${installed}/${total}) tools found${RESET}"
else
echo -e "${RED}${BOLD}${CROSS} Setup incomplete (${installed}/${total}) - consider installing missing tools${RESET}"
fi
}
main "$@"