diff --git a/src/main/main.ts b/src/main/main.ts index a3f1bd57e4f4c2ebd7a85fc0ee5fdd05b0bf9d31..25153181aa1e4dc70ca745d313f29aa95234960d 100644 --- a/src/main/main.ts +++ b/src/main/main.ts @@ -22,6 +22,7 @@ import { startLocalServer, installLocalServer, killLocalServer, + executeInstallStep, } from './util'; // //////////// @@ -66,6 +67,22 @@ ipcMain.handle('server:InstallLocally', (event) => { return installLocalServer(); }); +ipcMain.handle('server:install_download', (event) => { + return executeInstallStep('download_transformer_lab'); +}); + +ipcMain.handle('server:install_conda', (event) => { + return executeInstallStep('install_conda'); +}); + +ipcMain.handle('server:install_create-conda-environment', (event) => { + return executeInstallStep('create_conda_environment'); +}); + +ipcMain.handle('server:install_install-dependencies', (event) => { + return executeInstallStep('install_dependencies'); +}); + class AppUpdater { constructor() { log.transports.file.level = 'info'; diff --git a/src/main/preload.ts b/src/main/preload.ts index e5656f5ec2d15436dd87a20b15cddbb6afaed65c..0728a13c7505739f897c930d9183091b0709561b 100644 --- a/src/main/preload.ts +++ b/src/main/preload.ts @@ -17,7 +17,11 @@ export type Channels = | 'server:checkIfInstalledLocally' | 'server:checkLocalVersion' | 'server:startLocalServer' - | 'server:InstallLocally'; + | 'server:InstallLocally' + | 'server:install_download' + | 'server:install_conda' + | 'server:install_create-conda-environment' + | 'server:install_install-dependencies'; const electronHandler = { ipcRenderer: { diff --git a/src/main/util.ts b/src/main/util.ts index 7ff3e0da7181d4a8eab0c3f9c26bc8395b2e7e90..1bb738ceabf83bf6fa8d0392cab2df3e1ea764ab 100644 --- a/src/main/util.ts +++ b/src/main/util.ts @@ -73,12 +73,12 @@ export function startLocalServer() { resolve({ status: 'success', code: code }); } else { resolve({ - status: 'error', code: code , - message: 'May be fixed by running ~/.transformerlab/src/init.sh' + status: 'error', + code: code, + message: 'May be fixed by running ~/.transformerlab/src/init.sh', }); } }); - }); } @@ -105,10 +105,10 @@ export function killLocalServer() { export function installLocalServer() { console.log('Installing local server'); - const options = { shell: '/bin/sh' }; + const options = { shell: '/bin/bash' }; try { const child = exec( - 'curl https://raw.githubusercontent.com/transformerlab/transformerlab-api/main/download_and_install_remote_script.sh | sh', + 'curl https://raw.githubusercontent.com/transformerlab/transformerlab-api/main/install.sh | bash', options, (error, stdout, stderr) => { if (error) { @@ -123,3 +123,25 @@ export function installLocalServer() { console.log('Failed to install local server', err); } } + +export function executeInstallStep(argument: string) { + console.log('Downloading transformerlab-api to ~/.transformerlab/src'); + + const options = { shell: '/bin/bash' }; + try { + const child = exec( + `curl https://raw.githubusercontent.com/transformerlab/transformerlab-api/main/install.sh | bash -s -- ${argument}`, + options, + (error, stdout, stderr) => { + if (error) { + console.error(`exec error: ${error}`); + return; + } + console.log(`stdout: ${stdout}`); + console.error(`stderr: ${stderr}`); + } + ); + } catch (err) { + console.log('Failed to download Transformer Lab API', err); + } +}