Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore failed chmod, chmod files before packaging #131

Merged
merged 2 commits into from
Jan 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion .erb/scripts/download-swap-binaries.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,36 @@
import path from 'path';
import download from 'download';
import { emptyDir, ensureDir } from 'fs-extra';
import { chmod, emptyDir, ensureDir, stat } from 'fs-extra';
import { Binary } from '../../src/models/downloaderModel';
import { constants } from 'fs';

const swapBinDir = path.join(__dirname, '../../build/bin/swap');

async function makeFileExecutable(binary: Binary) {
const fullPath = path.join(binary.dirPath, binary.fileName);
const { mode } = await stat(fullPath);
await chmod(
fullPath,
// eslint-disable-next-line no-bitwise
mode | constants.S_IXUSR | constants.S_IXGRP | constants.S_IXOTH
);
}

const binaries = [
{
dest: path.join(swapBinDir, 'linux'),
url: 'https://github.com/comit-network/xmr-btc-swap/releases/download/0.12.0/swap_0.12.0_Linux_x86_64.tar',
filename: 'swap',
},
{
dest: path.join(swapBinDir, 'mac'),
url: 'https://github.com/comit-network/xmr-btc-swap/releases/download/0.12.0/swap_0.12.0_Darwin_x86_64.tar',
filename: 'swap',
},
{
dest: path.join(swapBinDir, 'win'),
url: 'https://github.com/comit-network/xmr-btc-swap/releases/download/0.12.0/swap_0.12.0_Windows_x86_64.zip',
filename: 'swap.exe',
},
];

Expand All @@ -28,6 +43,13 @@ Promise.all(
await download(binary.url, binary.dest, {
extract: true,
});

// Chmod binary in the directory to make them executable
await makeFileExecutable({
dirPath: binary.dest,
fileName: binary.filename,
});

console.log(`Downloaded and extracted ${binary.url} to ${binary.dest}`);
})
)
Expand Down
32 changes: 29 additions & 3 deletions .erb/scripts/download-tor-binaries.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,29 @@
import { join } from 'path';
import { emptyDir } from 'fs-extra';
import path, { join } from 'path';
import { chmod, emptyDir, stat } from 'fs-extra';
import { spawn } from 'child_process';
import { Binary } from '../../src/models/downloaderModel';
import { constants } from 'fs';

const TOR_BINARIES_GIT_URL =
'https://github.com/UnstoppableSwap/static-tor-binaries.git';
const torBuildDir = join(__dirname, '../../build/bin/tor');

async function makeFileExecutable(binary: Binary) {
const fullPath = path.join(binary.dirPath, binary.fileName);
const { mode } = await stat(fullPath);
await chmod(
fullPath,
// eslint-disable-next-line no-bitwise
mode | constants.S_IXUSR | constants.S_IXGRP | constants.S_IXOTH
);
}

const extractedTorBinaryPaths = [
[join(torBuildDir, 'linux'), 'tor'],
[join(torBuildDir, 'mac'), 'tor'],
[join(torBuildDir, 'win'), 'tor.exe'],
];

// Delete tor binaries, use Node fs API instead of spawn
// to avoid spawning a process that we need to kill.
emptyDir(torBuildDir, (error) => {
Expand All @@ -28,10 +46,18 @@ emptyDir(torBuildDir, (error) => {
console.log(`Tor Downloader Error: ${e}`);
});

ls.on('close', (code: number) => {
ls.on('close', async (code: number) => {
console.log(`Tor Downloader process exited with code ${code}`);
if (code === 0) {
console.log('Tor binaries downloaded successfully!');
await Promise.all(
extractedTorBinaryPaths.map(async (binary) => {
await makeFileExecutable({
dirPath: binary[0],
fileName: binary[1],
});
})
);
} else {
console.log('Tor binaries download failed!');
process.exit(1);
Expand Down
Loading