install.ts 797 Bytes
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
import * as fs from 'fs'
import { exec as cbExec } from 'child_process'
import * as path from 'path'
import { promisify } from 'util'

const app = process && process.type === 'renderer' ? require('@electron/remote').app : require('electron').app
const ollama = app.isPackaged ? path.join(process.resourcesPath, 'ollama') : path.resolve(process.cwd(), '..', 'ollama')
const exec = promisify(cbExec)
const symlinkPath = '/usr/local/bin/ollama'

export function installed() {
  return fs.existsSync(symlinkPath) && fs.readlinkSync(symlinkPath) === ollama
}

export async function install() {
16
17
  const command = `do shell script "mkdir -p ${path.dirname(
    symlinkPath
18
  )} && ln -F -s \\"${ollama}\\" \\"${symlinkPath}\\"" with administrator privileges`
19

Jeffrey Morgan's avatar
Jeffrey Morgan committed
20
  await exec(`osascript -e '${command}'`)
21
}