-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall-magicappbuilder.php
More file actions
148 lines (119 loc) · 4.34 KB
/
install-magicappbuilder.php
File metadata and controls
148 lines (119 loc) · 4.34 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
<?php
require_once __DIR__ . "/fn.php";
/**
* install.php
*
* Script to download and extract the latest release of MagicAppBuilder
* from GitHub into the www/MagicAppBuilder directory.
*/
$phpPath = __DIR__ . '/php';
$phpExtPath = __DIR__ . '/php/ext';
$currentPath = getenv('PATH');
$paths = explode(PATH_SEPARATOR, $currentPath);
// Add only if not already present
if (!in_array($phpPath, $paths)) {
$paths[] = $phpPath;
}
if (!in_array($phpExtPath, $paths)) {
$paths[] = $phpExtPath;
}
// Rebuild and set the new PATH
putenv('PATH=' . implode(PATH_SEPARATOR, $paths));
// Ensure necessary directories
ensureDirectory(__DIR__ . "/www");
ensureDirectory(__DIR__ . "/tmp");
ensureDirectory(__DIR__ . "/data");
ensureDirectory(__DIR__ . "/data/mysql");
ensureDirectory(__DIR__ . "/data/redis");
ensureDirectory(__DIR__ . "/logs");
ensureDirectory(__DIR__ . "/sessions");
ensureDirectory(__DIR__ . "/apache/logs");
// Replace config templates
replaceAndWrite(__DIR__ . "/config/httpd-template.conf", __DIR__ . "/config/httpd.conf");
replaceAndWrite(__DIR__ . "/config/php-template.ini", __DIR__ . "/php/php.ini");
replaceAndWrite(__DIR__ . "/config/my-template.ini", __DIR__ . "/mysql/my.ini");
replaceAndWrite(__DIR__ . "/config/redis.windows-template.conf", __DIR__ . "/redis/redis.windows.conf");
replaceAndWrite(__DIR__ . "/config/redis.windows-service-template.conf", __DIR__ . "/redis/redis.windows-service.conf");
$apiUrl = 'https://api.github.com/repos/planetbiru/magicappbuilder/releases/latest';
$targetZip = __DIR__ . '/magicappbuilder.zip';
$extractTo = __DIR__ . '/www/MagicAppBuilder';
echo COLOR_BLUE . "=== MagicAppBuilder Installer ===\n" . COLOR_NC;
// Create www folder if it doesn't exist
if (!is_dir(__DIR__ . '/www')) {
mkdir(__DIR__ . '/www', 0777, true);
} else {
@chmod(__DIR__ . '/www', 0777);
}
// Fetch latest release info from GitHub
echo "Fetching latest release info from GitHub...\n";
$releaseInfo = fetchJson($apiUrl);
if (!$releaseInfo || !isset($releaseInfo['zipball_url'])) {
echo COLOR_RED . "❌ Failed to fetch release information.\n" . COLOR_NC;
exit(1);
}
// --- Find the correct download URL from assets ---
$zipUrl = null;
if (!empty($releaseInfo['assets'])) {
foreach ($releaseInfo['assets'] as $asset) {
// Find the first asset that is a zip file
if ($asset['content_type'] === 'application/zip' || pathinfo($asset['name'], PATHINFO_EXTENSION) === 'zip') {
$zipUrl = $asset['browser_download_url'];
break;
}
}
}
// Fallback to zipball_url if no suitable asset is found
if (!$zipUrl) {
$zipUrl = $releaseInfo['zipball_url'];
}
echo "Latest release: " . COLOR_YELLOW . "{$releaseInfo['tag_name']}" . COLOR_NC . "\n";
if (!downloadFileWithProgress($zipUrl, $targetZip) || !file_exists($targetZip)) {
echo "❌ Failed to download archive.\n";
exit(1);
}
// Manually extract ZIP to www/MagicAppBuilder
echo "Extracting files...\n";
$zip = new ZipArchive();
if ($zip->open($targetZip) === true) {
if(!file_exists($extractTo))
{
mkdir($extractTo, 0777, true);
}
// GitHub zipball folder prefix (e.g., 'planetbiru-magicappbuilder-abc123/')
$firstDir = null;
for ($i = 0; $i < $zip->numFiles; $i++) {
$entry = $zip->getNameIndex($i);
if (!$firstDir) {
// Get root folder prefix from first file
$firstDir = strtok($entry, '/');
}
// Remove the root folder prefix
$relativePath = preg_replace('#^' . preg_quote($firstDir, '#') . '/#', '', $entry);
if ($relativePath === '')
{
continue;
}
$destPath = $extractTo . '/' . $relativePath;
if (substr($entry, -1) === '/') {
// Directory
if (!is_dir($destPath)) {
mkdir($destPath, 0777, true);
}
} else {
// File
$content = $zip->getFromIndex($i);
$dir = dirname($destPath);
if (!is_dir($dir)) {
mkdir($dir, 0777, true);
}
file_put_contents($destPath, $content);
}
}
$zip->close();
unlink($targetZip);
echo COLOR_GREEN . "✅ MagicAppBuilder has been installed at: www/MagicAppBuilder\n" . COLOR_NC;
} else {
echo COLOR_RED . "❌ Failed to open zip archive.\n" . COLOR_NC;
unlink($targetZip);
exit(1);
}