diff --git a/assets/bin/ipfs.sh b/assets/bin/ipfs.sh new file mode 100755 index 000000000..4c74981ff --- /dev/null +++ b/assets/bin/ipfs.sh @@ -0,0 +1,8 @@ +#!/usr/bin/env bash + +# Get the full path of "resources/" directory (resolving the symlink if needed) +resources=$(dirname "$(dirname "$(test -L "$0" && readlink "$0" || echo "$0")")") +# Get the full path to ipfs binary bundled with ipfs-desktop +ipfs="$resources/app.asar.unpacked/node_modules/go-ipfs-dep/go-ipfs/ipfs" + +exec "$ipfs" "$@" diff --git a/assets/build/after-install.sh b/assets/build/after-install.sh new file mode 100755 index 000000000..eaa49c991 --- /dev/null +++ b/assets/build/after-install.sh @@ -0,0 +1,9 @@ +#!/bin/bash + +set -e + +ln -sf '/opt/${productFilename}/${executable}' '/usr/local/bin/${executable}' + +if [ ! -f /usr/local/bin/ipfs ]; then + ln -sf '/opt/${productFilename}/resources/bin/ipfs.sh' '/usr/local/bin/ipfs' +fi diff --git a/assets/build/after-remove.sh b/assets/build/after-remove.sh new file mode 100755 index 000000000..4185a8a54 --- /dev/null +++ b/assets/build/after-remove.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +# Remove broken link to ipfs-desktop binary +test -e '/usr/local/bin/${executable}' || rm -f '/usr/local/bin/${executable}' + +# Remove broken link to ipfs binary +test -e '/usr/local/bin/ipfs' || rm -f '/usr/local/bin/ipfs' + diff --git a/electron-builder.yml b/electron-builder.yml index 549773d54..cd57a5628 100644 --- a/electron-builder.yml +++ b/electron-builder.yml @@ -3,6 +3,12 @@ appId: io.ipfs.desktop directories: buildResources: assets/build +extraResources: + - from: "assets/bin" + to: "bin" + filter: + - "**/*" + mac: category: public.app-category.utilities @@ -35,6 +41,15 @@ linux: - rpm - snap +rpm: + fpm: + - "--after-install=assets/build/after-install.sh" + - "--after-remove=assets/build/after-remove.sh" + +deb: + afterInstall: assets/build/after-install.sh + afterRemove: assets/build/after-remove.sh + snap: confinement: strict plugs: diff --git a/src/early/index.js b/src/early/index.js index 07a05380b..eee885c69 100644 --- a/src/early/index.js +++ b/src/early/index.js @@ -1,6 +1,8 @@ import protocolHandlers from './protocol-handlers' +import ipfsScript from './ipfs-script' // Functions that must run on app 'will-finish-launching'. export default function (ctx) { protocolHandlers(ctx) + ipfsScript(ctx) } diff --git a/src/early/ipfs-script.js b/src/early/ipfs-script.js new file mode 100644 index 000000000..22e4419c0 --- /dev/null +++ b/src/early/ipfs-script.js @@ -0,0 +1,30 @@ +import fs from 'fs-extra' +import { join } from 'path' +import os from 'os' +import { logger } from '../utils' + +export default function () { + // Note: during runtime, we only do this for darwin. + if (os.platform() !== 'darwin') { + return + } + + // Ignore during development because the paths are not the same. + if (process.env.NODE_ENV === 'development') { + logger.info('[ipfs on path] unavailable during development') + return + } + + // Don't make any changes if IPFS already exists... + if (fs.existsSync('/usr/local/bin/ipfs')) { + logger.info('[ipfs on path] was not added, already exists') + return + } + + try { + fs.symlinkSync(join(__dirname, '../../../bin/ipfs.sh'), '/usr/local/bin/ipfs') + logger.info('[ipfs on path] added to /usr/local/bin/ipfs') + } catch (e) { + logger.error(e) + } +}