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

feat: add 'ipfs' to PATH on macOS and Linux #896

Merged
merged 13 commits into from
Apr 9, 2019
8 changes: 8 additions & 0 deletions assets/bin/ipfs.sh
Original file line number Diff line number Diff line change
@@ -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")")")
lidel marked this conversation as resolved.
Show resolved Hide resolved
# 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" "$@"
9 changes: 9 additions & 0 deletions assets/build/after-install.sh
Original file line number Diff line number Diff line change
@@ -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
8 changes: 8 additions & 0 deletions assets/build/after-remove.sh
Original file line number Diff line number Diff line change
@@ -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'

15 changes: 15 additions & 0 deletions electron-builder.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How does it work for snap installs?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As mentioned above, it doesn't. Only on deb for now.

confinement: strict
plugs:
Expand Down
2 changes: 2 additions & 0 deletions src/early/index.js
Original file line number Diff line number Diff line change
@@ -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)
}
30 changes: 30 additions & 0 deletions src/early/ipfs-script.js
Original file line number Diff line number Diff line change
@@ -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')) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

install.sh from a go-ipfs distribution will try to install in either /usr/local/bin or /usr/bin https://github.com/ipfs/go-ipfs/blob/622dbf7f266e513c6de00cddc5cb851aa5cbfe61/cmd/ipfs/dist/install.sh#L9

perhaps we should try and exec ipfs here to see if it exists on the users path.

logger.info('[ipfs on path] was not added, already exists')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For a subsequent PR, we could prompt the user here.

"you appear to have a version of the ipfs command line tool already. Would you like to let ipfs-desktop replace it with the a version that it can keep up to date?"

...that kind of thing.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that's the goal. I'm just making this one as simple as possible.

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)
}
}