-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfigure
More file actions
executable file
·180 lines (147 loc) · 4.46 KB
/
configure
File metadata and controls
executable file
·180 lines (147 loc) · 4.46 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
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
#!/usr/bin/env bash
# configure - detect OS and install required packages
set -e
TOOLS_DIR="tools"
mkdir -p "$TOOLS_DIR"
get_os() {
case "$(uname)" in
Darwin)
echo "macos"
;;
Linux)
echo "linux"
;;
*)
echo "Unsupported OS: $(uname). Only Linux and macOS are supported."
exit 1
;;
esac
}
get_arch() {
local arch=$(uname -m)
case "$arch" in
x86_64)
echo "x86_64"
;;
aarch64|arm64)
echo "aarch64"
;;
*)
echo "Unsupported architecture: $arch. Only x86_64 and aarch64 are supported."
exit 1
;;
esac
}
get_php_version() {
local version
local composer_json="sources/composer.json"
local version=$(jq -r '.require.php' "$composer_json" | sed -E 's/^[^\d]*([0-9]+\.[0-9]+).*$/\1/')
if [ -z "$version" ]; then
echo "PHP version not found or invalid in $composer_json"
exit 1
fi
echo "$version"
}
get_download_link() {
local json_url="$1"
local php_type="$2"
local os_type="$3"
local arch_type="$4"
local php_version="$5"
local JSON=$(curl -fsSL "$json_url")
local DOWNLOAD_URL=$(echo "$JSON" | jq -r --arg OS "$os_type" --arg ARCH "$arch_type" --arg TYPE "$php_type" --arg VER_PREFIX "$php_version" '
[ .[]
| select(.name | test("-" + $TYPE + "-" + $OS + "-" + $ARCH + "\\.tar\\.gz$"))
| select(.name | test("^php-" + $VER_PREFIX + "\\.[0-9]+"))
]
| reverse
| .[0]
| .full_path
')
if [ -z "$DOWNLOAD_URL" ] || [ "$DOWNLOAD_URL" = "null" ]; then
echo "No matching PHP build found for OS=$os_type, ARCH=$arch_type, Version=$php_version"
exit 1
fi
local PROTOCOL_DOMAIN=$(echo "$json_url" | grep -oP '^(https?://[^/]+)')
echo "$PROTOCOL_DOMAIN$DOWNLOAD_URL"
}
# ---------------------------
# Function: download_and_extract
# Arguments:
# 1 - URL
# 2 - Target file name
# 3 - Path inside tar.gz to extract
# ---------------------------
download_and_extract() {
local url="$1"
local target="$TOOLS_DIR/$2"
local set_permissions="${3:-false}"
local file_name=$(basename "$url")
if [ -f "$target" ]; then
echo "✅ $target already exists, skipping download"
return
fi
echo "⬇️ Downloading and extracting $2..."
local extension="${file_name##*.}"
if [[ "$file_name" == *.tar.gz ]]; then
extension="tar.gz"
elif [[ "$file_name" == *.tar.bz2 ]]; then
extension="tar.bz2"
elif [[ "$file_name" == *.tar.xz ]]; then
extension="tar.xz"
fi
echo "📦 Extracting file_name file..."
case "$extension" in
"tar.gz" | "tgz")
curl -L "$url" | tar -xz -C "$TOOLS_DIR"
;;
"tar.bz2" | "tbz")
curl -L "$url" | tar -xj -C "$TOOLS_DIR"
;;
"tar.xz")
curl -L "$url" | tar -xj -C "$TOOLS_DIR"
;;
"zip")
curl -L "$url" | funzip | unzip -d "$TOOLS_DIR"
;;
*)
echo "❌ Unsupported file format: $file_name"
return 1
;;
esac
if [ "$set_permissions" == "true" ]; then
chmod +x "$target"
fi
echo "✅ $2 download and extraction completed"
}
download_composer() {
local url="$1"
local target="$TOOLS_DIR/composer"
local php_exec="$2"
if [ -f "$target" ]; then
echo "✅ $target already exists, skipping download"
return
fi
echo "⬇️ Installing composer using downloaded PHP..."
curl -fsSL "$url" | "$php_exec" -- --install-dir="$TOOLS_DIR" --filename="composer"
chmod +x "$target"
echo "✅ $2 installed"
}
OS=$(get_os)
ARCH=$(get_arch)
PHP_VERSION=$(get_php_version)
# Micro
php_micro_download_link=$(get_download_link "https://dl.static-php.dev/static-php-cli/bulk/?format=json" "micro" "$OS" "$ARCH" "$PHP_VERSION")
download_and_extract "$php_micro_download_link" "micro.sfx"
# PHP-CLI
php_cli_download_link=$(get_download_link "https://dl.static-php.dev/static-php-cli/bulk/?format=json" "cli" "$OS" "$ARCH" "$PHP_VERSION")
download_and_extract "$php_cli_download_link" "php" "true"
#SPC
download_and_extract \
"https://dl.static-php.dev/static-php-cli/spc-bin/nightly/spc-linux-x86_64.tar.gz" \
"spc" \
"true"
# Composer
download_composer \
"https://getcomposer.org/installer" \
"$TOOLS_DIR/php"