generated from ztimson/template
fixed install
This commit is contained in:
@@ -31,19 +31,14 @@ function download(url, dest) {
|
||||
});
|
||||
}
|
||||
|
||||
/** Recursively search a directory for a file by name. */
|
||||
function findFile(dir, name) {
|
||||
/** Recursively chmod all files under a directory. */
|
||||
function chmodRecursive(dir, mode) {
|
||||
for (const entry of fs.readdirSync(dir, {withFileTypes: true})) {
|
||||
const full = path.join(dir, entry.name);
|
||||
if (entry.isDirectory()) {
|
||||
const found = findFile(full, name);
|
||||
if (found) return found;
|
||||
} else if (entry.name === name) {
|
||||
return full;
|
||||
if (entry.isDirectory()) chmodRecursive(full, mode);
|
||||
else fs.chmodSync(full, mode);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
async function downloadAndExtract() {
|
||||
const platformName = PLATFORM_MAP[process.platform];
|
||||
@@ -58,16 +53,23 @@ async function downloadAndExtract() {
|
||||
console.log('Downloading kiwix-tools from:', url);
|
||||
await download(url, archivePath);
|
||||
|
||||
console.log('Extracting...');
|
||||
execFileSync('tar', ['-xf', archivePath, '-C', tmpDir]); // bsdtar handles zip too
|
||||
|
||||
await fs.promises.mkdir(BIN_DIR, {recursive: true});
|
||||
|
||||
// Copy the binary plus any DLLs sitting alongside it (Windows deps)
|
||||
for (const entry of await fs.promises.readdir(tmpDir)) {
|
||||
if(!/\.(tar|gz|zip)$/.test(entry)) await fs.promises.copyFile(path.join(tmpDir, entry), path.join(BIN_DIR, entry));
|
||||
if(process.platform !== 'win32') await fs.promises.chmod(BIN_DIR, 0o755, {recursive: true});
|
||||
console.log('Extracting...');
|
||||
execFileSync('tar', ['-xf', archivePath, '-C', BIN_DIR]); // bsdtar handles zip too
|
||||
|
||||
// Archives (tar.gz) may wrap contents in a subdirectory - flatten it into BIN_DIR
|
||||
const wrapperDir = (await fs.promises.readdir(BIN_DIR, {withFileTypes: true}))
|
||||
.find(e => e.isDirectory() && e.name.startsWith('kiwix-tools_'));
|
||||
if (wrapperDir) {
|
||||
const wrapperPath = path.join(BIN_DIR, wrapperDir.name);
|
||||
for (const entry of await fs.promises.readdir(wrapperPath)) {
|
||||
await fs.promises.rename(path.join(wrapperPath, entry), path.join(BIN_DIR, entry));
|
||||
}
|
||||
await fs.promises.rmdir(wrapperPath);
|
||||
}
|
||||
|
||||
if (process.platform !== 'win32') chmodRecursive(BIN_DIR, 0o755);
|
||||
|
||||
await fs.promises.rm(tmpDir, {recursive: true, force: true});
|
||||
console.log('Installed to:', BIN_DIR);
|
||||
|
||||
Reference in New Issue
Block a user