Skip to content

Commit

Permalink
fix download script (#19)
Browse files Browse the repository at this point in the history
* chore: fix install script

* fix npm script

* fix: safebox download script
  • Loading branch information
adikari committed Dec 17, 2022
1 parent 85ecdf9 commit cb3c518
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 801 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ SafeBox is available for many Linux distros and Windows.
$ brew install adikari/taps/safebox

# Via curl
$ curl -sSL https://raw.githubusercontent.com/adikari/safebox/main/scripts/install.sh | sh
$ curl -sSL https://raw.githubusercontent.com/monebag/safebox/main/scripts/install.sh | sh

# Via npm
$ npm install @adikari/safebox
Expand All @@ -20,7 +20,7 @@ $ npm install @adikari/safebox
$ yarn add @adikari/safebox
```

To install it directly find the right version for your machine in [releases](https://github.com/adikari/safebox/releases) page. Download and un-archive the files. Copy the `safebox` binary to the PATH or use it directly.
To install it directly find the right version for your machine in [releases](https://github.com/monebag/safebox/releases) page. Download and un-archive the files. Copy the `safebox` binary to the PATH or use it directly.

## Usage

Expand Down Expand Up @@ -146,7 +146,7 @@ echo $CONFIG2

### Release

1. Update version number [npm/package.json](https://github.com/adikari/safebox/blob/main/npm/package.json).
1. Update version number [npm/package.json](https://github.com/monebag/safebox/blob/main/npm/package.json).
2. Merge the changes to main branch.
2. Create a git tag that matches the same version number as npm package version.
3. Push the tag to github. Tag must follow semversion and prefixed with `v`. Eg. `v.1.2.3`.
Expand Down
4 changes: 2 additions & 2 deletions npm/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ const version = packageJson.version;
const platform = PLATFORM_MAPPING[process.platform];
const arch = ARCH_MAPPING[process.arch];
const ext = platform === 'win32' ? '.exe' : '';
const binaryName = `${name}.${ext}`;
const binaryUrl = `https://github.com/adikari/safebox/releases/download/v${version}/safebox_${version}_${platform}_${arch}${ext}`;
const binaryName = `${name}${ext}`;
const binaryUrl = `https://github.com/monebag/safebox/releases/download/v${version}/safebox_${version}_${platform}_${arch}${ext}`;
const bin = path.join(__dirname, "bin");

const constants = {
Expand Down
14 changes: 5 additions & 9 deletions npm/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,43 +29,39 @@ const install = () => {
const tmpdir = os.tmpdir();
const binary = path.join(tmpdir, binaryName);

const copyBinary = () => fs.copyFileSync(binary, path.join(bin, binaryName));
const copyBinary = () => {
fs.copyFileSync(binary, path.join(bin, binaryName));
}

if (fs.existsSync(binary)) {
console.log('safebox binary already downloaded');
copyBinary();
return;
}

const req = request({ uri: binaryUrl });

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

console.log(`downloading safebox binary`);

const download = fs.createWriteStream(binary);

req.on('response', res => {
if (res.statusCode !== 200) {
error(`Error downloading safebox binary. HTTP Status Code: ${res.statusCode}`);
throw new Error(`Error downloading safebox binary. HTTP Status Code: ${res.statusCode}`);
}

req.pipe(download);
});

req.on('complete', () => {
console.log('download complete. installing safebox.')

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

copyBinary();
} catch (error) {
console.error('failed to extract binary.', error.message)

retries += 1;
if (retries <= MAX_RETRIES) {
install();
Expand Down
Loading

0 comments on commit cb3c518

Please sign in to comment.