Skip to content

Commit

Permalink
fix npm install issues (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
adikari authored Dec 5, 2022
1 parent 288366b commit 7aafd5d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
28 changes: 25 additions & 3 deletions npm/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,20 @@ if (!fs.existsSync(bin)){
fs.mkdirSync(bin);
}

let retries = 0;
const MAX_RETRIES = 3;

const install = () => {
const tmpdir = os.tmpdir();
const req = request({ uri: tarUrl });

const tarFile = `${tmpdir}/${name}.tar.gz`;
const tarFile = `${tmpdir}/${name}-${Date.now()}.tar.gz`;
const download = fs.createWriteStream(tarFile);

if (retries > 0) {
console.log(`retrying to install safebox - retry ${retries} out of ${MAX_RETRIES}`)
}

console.log(`downloading safebox binary`);

req.on('response', res => {
Expand All @@ -41,8 +48,23 @@ const install = () => {
});

req.on('complete', () => {
cp.execSync(`tar -xf ${tarFile} -C ${tmpdir}`);
fs.copyFileSync(path.join(tmpdir, binaryName), path.join(bin, binaryName));
console.log('download complete. installing safebox.')

try {
if (!fs.existsSync(tarFile)) {
throw new Error(`${tarFile} does not exist`)
}

cp.execSync(`tar -xf ${tarFile}.test -C ${tmpdir}`);
fs.copyFileSync(path.join(tmpdir, binaryName), path.join(bin, binaryName));
} catch (error) {
console.error('failed to extract binary.', error.message)

retries += 1;
if (retries <= MAX_RETRIES) {
install();
}
}
});
};

Expand Down
2 changes: 1 addition & 1 deletion npm/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@adikari/safebox",
"version": "1.2.0",
"version": "1.2.1",
"description": "A Fast and Flexible secret manager built with love by adikari in Go",
"main": "index.js",
"bin": "./run.js",
Expand Down

0 comments on commit 7aafd5d

Please sign in to comment.