@@ -20,3 +20,131 @@ if [[ "${OS_TYPE}" == "Linux" ]]; then
20
20
else
21
21
PARALLEL=-j$( sysctl -n hw.logicalcpu)
22
22
fi
23
+
24
+ # Universal download utility with curl/wget compatibility
25
+ # Provides consistent interface regardless of which tool is available
26
+
27
+ # Detect available download tool (lazy initialization)
28
+ detect_download_tool ()
29
+ {
30
+ if [ -n " ${DOWNLOAD_TOOL:- } " ]; then
31
+ return 0
32
+ fi
33
+
34
+ if command -v curl > /dev/null 2>&1 ; then
35
+ DOWNLOAD_TOOL=" curl"
36
+ elif command -v wget > /dev/null 2>&1 ; then
37
+ DOWNLOAD_TOOL=" wget"
38
+ else
39
+ echo " Error: Neither curl nor wget is available" >&2
40
+ return 1
41
+ fi
42
+ }
43
+
44
+ # Download to stdout
45
+ # Usage: download_to_stdout <url>
46
+ download_to_stdout ()
47
+ {
48
+ detect_download_tool || return 1
49
+ local url=" $1 "
50
+ case " $DOWNLOAD_TOOL " in
51
+ curl)
52
+ curl -fsSL " $url "
53
+ ;;
54
+ wget)
55
+ wget -qO- " $url "
56
+ ;;
57
+ esac
58
+ }
59
+
60
+ # Download to file
61
+ # Usage: download_to_file <url> <output_file>
62
+ download_to_file ()
63
+ {
64
+ detect_download_tool || return 1
65
+ local url=" $1 "
66
+ local output=" $2 "
67
+ case " $DOWNLOAD_TOOL " in
68
+ curl)
69
+ curl -fsSL -o " $output " " $url "
70
+ ;;
71
+ wget)
72
+ wget -q -O " $output " " $url "
73
+ ;;
74
+ esac
75
+ }
76
+
77
+ # Download with headers (for API calls)
78
+ # Usage: download_with_headers <url> <header1> <header2> ...
79
+ download_with_headers ()
80
+ {
81
+ detect_download_tool || return 1
82
+ local url=" $1 "
83
+ shift
84
+ local headers=()
85
+
86
+ case " $DOWNLOAD_TOOL " in
87
+ curl)
88
+ for header in " $@ " ; do
89
+ headers+=(-H " $header " )
90
+ done
91
+ curl -fsSL " ${headers[@]} " " $url "
92
+ ;;
93
+ wget)
94
+ for header in " $@ " ; do
95
+ headers+=(--header=" $header " )
96
+ done
97
+ wget -qO- " ${headers[@]} " " $url "
98
+ ;;
99
+ esac
100
+ }
101
+
102
+ # Download silently (no progress, suitable for CI)
103
+ # Usage: download_silent <url>
104
+ download_silent ()
105
+ {
106
+ detect_download_tool || return 1
107
+ local url=" $1 "
108
+ case " $DOWNLOAD_TOOL " in
109
+ curl)
110
+ curl -fsSL " $url "
111
+ ;;
112
+ wget)
113
+ wget -qO- " $url "
114
+ ;;
115
+ esac
116
+ }
117
+
118
+ # Download with progress bar (for interactive use)
119
+ # Usage: download_with_progress <url> <output_file>
120
+ download_with_progress ()
121
+ {
122
+ detect_download_tool || return 1
123
+ local url=" $1 "
124
+ local output=" $2 "
125
+ case " $DOWNLOAD_TOOL " in
126
+ curl)
127
+ curl -fL -# -o " $output " " $url "
128
+ ;;
129
+ wget)
130
+ wget -O " $output " " $url "
131
+ ;;
132
+ esac
133
+ }
134
+
135
+ # Check if URL is accessible
136
+ # Usage: check_url <url>
137
+ # Returns: 0 if accessible, 1 otherwise
138
+ check_url ()
139
+ {
140
+ detect_download_tool || return 1
141
+ local url=" $1 "
142
+ case " $DOWNLOAD_TOOL " in
143
+ curl)
144
+ curl -fsSL --head " $url " > /dev/null 2>&1
145
+ ;;
146
+ wget)
147
+ wget --spider -q " $url " 2> /dev/null
148
+ ;;
149
+ esac
150
+ }
0 commit comments