|
| 1 | +#!/usr/bin/env php |
| 2 | +<?php |
| 3 | + |
| 4 | +$postalkitVersion = "v0.1.0"; |
| 5 | +$repoUrl = "https://github.com/jayeshmepani/libpostal-ffi-python/releases/download/{$postalkitVersion}"; |
| 6 | + |
| 7 | +$targets = [ |
| 8 | + 'linux-x64' => 'libpostal-linux-x64.tar.gz', |
| 9 | + 'linux-arm64' => 'libpostal-linux-arm64.tar.gz', |
| 10 | + 'macos-x64' => 'libpostal-macos-x64.tar.gz', |
| 11 | + 'macos-arm64' => 'libpostal-macos-arm64.tar.gz', |
| 12 | + 'windows-x64' => 'libpostal-windows-x64.zip', |
| 13 | +]; |
| 14 | + |
| 15 | +$libsDir = dirname(__DIR__) . '/postalkit/libs'; |
| 16 | + |
| 17 | +foreach ($targets as $target => $filename) { |
| 18 | + $targetDir = "{$libsDir}/{$target}"; |
| 19 | + if (!is_dir($targetDir)) { |
| 20 | + mkdir($targetDir, 0777, true); |
| 21 | + } |
| 22 | + |
| 23 | + $url = "{$repoUrl}/{$filename}"; |
| 24 | + $dest = "{$targetDir}/{$filename}"; |
| 25 | + |
| 26 | + echo "Downloading {$url}...\n"; |
| 27 | + $content = file_get_contents($url); |
| 28 | + if ($content === false) { |
| 29 | + echo "Failed to download {$url}. Skipping.\n"; |
| 30 | + continue; |
| 31 | + } |
| 32 | + |
| 33 | + file_put_contents($dest, $content); |
| 34 | + |
| 35 | + echo "Extracting {$dest}...\n"; |
| 36 | + if (str_ends_with($filename, '.zip')) { |
| 37 | + $zip = new ZipArchive; |
| 38 | + if ($zip->open($dest) === TRUE) { |
| 39 | + $zip->extractTo($targetDir); |
| 40 | + $zip->close(); |
| 41 | + } else { |
| 42 | + echo "Failed to extract zip.\n"; |
| 43 | + } |
| 44 | + } else { |
| 45 | + exec("tar -xzf " . escapeshellarg($dest) . " -C " . escapeshellarg($targetDir)); |
| 46 | + } |
| 47 | + |
| 48 | + unlink($dest); |
| 49 | + echo "Successfully setup {$target}\n"; |
| 50 | +} |
0 commit comments