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

Disable brew updates when installing a package #167

Merged
merged 3 commits into from
Jun 5, 2024
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
61 changes: 32 additions & 29 deletions electron/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ const fs = require('fs');
const os = require('os');
const sudo = require('sudo-prompt');
const process = require('process');
const axios = require("axios")
const axios = require('axios');

const Docker = require('dockerode');
const { spawnSync } = require('child_process');

const Version = '0.1.0rc34';
const Version = '0.1.0rc35';
const OperateDirectory = `${os.homedir()}/.operate`;
const VenvDir = `${OperateDirectory}/venv`;
const TempDir = `${OperateDirectory}/temp`;
Expand All @@ -22,25 +22,29 @@ const OperateCmd = `${os.homedir()}/.operate/venv/bin/operate`;
const Env = {
...process.env,
PATH: `${process.env.PATH}:/opt/homebrew/bin:/usr/local/bin`,
HOMEBREW_NO_AUTO_UPDATE: '1',
};
const SudoOptions = {
name: 'Pearl',
env: Env,
};
const TendermintUrls = {
darwin: {
x64: "https://github.com/tendermint/tendermint/releases/download/v0.34.19/tendermint_0.34.19_darwin_amd64.tar.gz",
arm64: "https://github.com/tendermint/tendermint/releases/download/v0.34.19/tendermint_0.34.19_darwin_arm64.tar.gz",
x64: 'https://github.com/tendermint/tendermint/releases/download/v0.34.19/tendermint_0.34.19_darwin_amd64.tar.gz',
arm64:
'https://github.com/tendermint/tendermint/releases/download/v0.34.19/tendermint_0.34.19_darwin_arm64.tar.gz',
},
linux: {
x64: "https://github.com/tendermint/tendermint/releases/download/v0.34.19/tendermint_0.34.19_linux_amd64.tar.gz",
arm64: "https://github.com/tendermint/tendermint/releases/download/v0.34.19/tendermint_0.34.19_linux_arm64.tar.gz",
x64: 'https://github.com/tendermint/tendermint/releases/download/v0.34.19/tendermint_0.34.19_linux_amd64.tar.gz',
arm64:
'https://github.com/tendermint/tendermint/releases/download/v0.34.19/tendermint_0.34.19_linux_arm64.tar.gz',
},
win32: {
x64: "https://github.com/tendermint/tendermint/releases/download/v0.34.19/tendermint_0.34.19_windows_amd64.tar.gz",
arm64: "https://github.com/tendermint/tendermint/releases/download/v0.34.19/tendermint_0.34.19_windows_arm64.tar.gz"
}
}
x64: 'https://github.com/tendermint/tendermint/releases/download/v0.34.19/tendermint_0.34.19_windows_amd64.tar.gz',
arm64:
'https://github.com/tendermint/tendermint/releases/download/v0.34.19/tendermint_0.34.19_windows_arm64.tar.gz',
},
};

function getBinPath(command) {
return spawnSync('/usr/bin/which', [command], { env: Env })
Expand All @@ -63,10 +67,8 @@ function appendLog(log) {
}

function runCmdUnix(command, options) {
fs.appendFileSync(
OperateInstallationLog,
`Runninng ${command} with options ${JSON.stringify(options)}`,
{ encoding: 'utf-8' },
console.log(
appendLog(`Runninng ${command} with options ${JSON.stringify(options)}`),
);
let bin = getBinPath(command);
if (!bin) {
Expand Down Expand Up @@ -133,36 +135,37 @@ async function downloadFile(url, dest) {
const response = await axios({
url,
method: 'GET',
responseType: 'stream'
responseType: 'stream',
});
response.data.pipe(writer);
return new Promise((resolve, reject) => {
writer.on('finish', resolve);
writer.on('error', reject);
});
} catch (err) {
fs.unlink(dest, () => { }); // Delete the file if there is an error
fs.unlink(dest, () => {}); // Delete the file if there is an error
console.error('Error downloading the file:', err.message);
}
}

async function installTendermintUnix() {
const cwd = process.cwd()
process.chdir(TempDir)
const cwd = process.cwd();
process.chdir(TempDir);

console.log(appendLog(`Installing tendermint for ${os.platform()}-${process.arch}`))
const url = TendermintUrls[os.platform()][process.arch]
console.log(
appendLog(`Installing tendermint for ${os.platform()}-${process.arch}`),
);
const url = TendermintUrls[os.platform()][process.arch];

console.log(appendLog(`Downloading ${url}, might take a while...`))
await downloadFile(url, `${TempDir}/tendermint.tar.gz`)
console.log(appendLog(`Downloading ${url}, might take a while...`));
await downloadFile(url, `${TempDir}/tendermint.tar.gz`);

console.log(appendLog(`Installing tendermint binary`))
await runCmdUnix("tar", ["-xvf", "tendermint.tar.gz"])
await runSudoUnix("install", "tendermint /usr/local/bin")
process.chdir(cwd)
console.log(appendLog(`Installing tendermint binary`));
await runCmdUnix('tar', ['-xvf', 'tendermint.tar.gz']);
await runSudoUnix('install', 'tendermint /usr/local/bin');
process.chdir(cwd);
}


function isDockerInstalledDarwin() {
return Boolean(getBinPath('docker'));
}
Expand Down Expand Up @@ -310,7 +313,7 @@ async function setupDarwin(ipcChannel) {
if (!isTendermintInstalledUnix()) {
ipcChannel.send('response', 'Installing Pearl Daemon');
console.log(appendLog('Installing tendermint'));
await installTendermintUnix()
await installTendermintUnix();
}

if (!fs.existsSync(VenvDir)) {
Expand Down Expand Up @@ -364,7 +367,7 @@ async function setupUbuntu(ipcChannel) {
if (!isTendermintInstalledUnix()) {
ipcChannel.send('response', 'Installing Pearl Daemon');
console.log(appendLog('Installing tendermint'));
await installTendermintUnix()
await installTendermintUnix();
}

if (!fs.existsSync(VenvDir)) {
Expand Down
7 changes: 1 addition & 6 deletions operate/services/manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -758,13 +758,8 @@ def unstake_service_on_chain_from_safe(self, hash: str) -> None:
service_id=service.chain_data.token,
staking_contract=STAKING[service.ledger_config.chain],
)
).add(
sftxb.get_staking_data(
service_id=service.chain_data.token,
staking_contract=STAKING[service.ledger_config.chain],
)
).settle()
service.chain_data.staked = True
service.chain_data.staked = False
service.store()

def fund_service( # pylint: disable=too-many-arguments
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,5 @@
"start": "electron .",
"build": "rm -rf dist/ && electron-builder build"
},
"version": "0.1.0-rc34"
"version": "0.1.0-rc35"
}
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "olas-operate-middleware"
version = "0.1.0-rc34"
version = "0.1.0-rc35"
description = ""
authors = ["David Vilela <[email protected]>", "Viraj Patel <[email protected]>"]
readme = "README.md"
Expand Down
Loading