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
Merged

Conversation

hacdias
Copy link
Member

@hacdias hacdias commented Apr 5, 2019

This adds ipfs to the PATH on Linux and macOS. Will do the Windows version on a different PR. Right now, this is what's done:

  • On macOS, on first run and on Linux, during install:
    • If /usr/local/bin/ipfs doesn't exist, we symlink to our ipfs.sh file. Otherwise we do nothing.
  • During uninstall, on Linux, we remove the symlink.

Addresses #727.

hacdias added 2 commits April 5, 2019 15:22
License: MIT
Signed-off-by: Henrique Dias <hacdias@gmail.com>
License: MIT
Signed-off-by: Henrique Dias <hacdias@gmail.com>
@ghost ghost assigned hacdias Apr 5, 2019
@ghost ghost added the in progress label Apr 5, 2019
@hacdias hacdias changed the title WIP: Add ipfs to PATH wip: add 'ipfs' to PATH Apr 5, 2019
License: MIT
Signed-off-by: Henrique Dias <hacdias@gmail.com>
@hacdias hacdias changed the title wip: add 'ipfs' to PATH feat: add 'ipfs' to PATH Apr 6, 2019
@hacdias
Copy link
Member Author

hacdias commented Apr 6, 2019

@lidel @olizilla need your feedback about what we currently do: I don't feel great about the idea of doing nothing when the user has IPFS already, but I think we have margin to play since we use a script and don't link directly to the binary.

Could you please review the scripts to see if they're OK?

@hacdias hacdias requested review from olizilla and lidel April 6, 2019 11:59
@hacdias hacdias changed the title feat: add 'ipfs' to PATH feat: add 'ipfs' to PATH on macOS and Linux Apr 6, 2019
@hacdias hacdias changed the title feat: add 'ipfs' to PATH on macOS and Linux wip: add 'ipfs' to PATH on macOS and Linux Apr 6, 2019
License: MIT
Signed-off-by: Henrique Dias <hacdias@gmail.com>
@hacdias
Copy link
Member Author

hacdias commented Apr 6, 2019

WIP update on Linux: only working on deb.

@hacdias
Copy link
Member Author

hacdias commented Apr 6, 2019

As per electron-userland/electron-builder#3436 it seems we can't run install scripts on some platforms. Ideally we could do everything on runtime. @lidel is there a way on Linux to ask permission temporarily so we can modify /usr/local/bin?

hacdias added 2 commits April 6, 2019 14:23
License: MIT
Signed-off-by: Henrique Dias <hacdias@gmail.com>
@hacdias hacdias changed the title wip: add 'ipfs' to PATH on macOS and Linux feat: add 'ipfs' to PATH on macOS and Linux Apr 6, 2019
@hacdias hacdias changed the title feat: add 'ipfs' to PATH on macOS and Linux wip: add 'ipfs' to PATH on macOS and Linux Apr 6, 2019
License: MIT
Signed-off-by: Henrique Dias <hacdias@gmail.com>
@hacdias hacdias changed the title wip: add 'ipfs' to PATH on macOS and Linux feat: add 'ipfs' to PATH on macOS and Linux Apr 6, 2019
This fixes .deb to properly create/remove symlinks
to ipfs and ipfs-desktop during the install.

Previous version created broken symlink, and wrapper script was not
included in app bundle extracted into /opt/
We now include wrapper script in resources/bin/ipfs.sh

Uninstall removes broken symlinks, making it safe if someone has ipfs
installed by other means
@ghost ghost assigned lidel Apr 6, 2019
Copy link
Member

@lidel lidel left a comment

Choose a reason for hiding this comment

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

I did quick smoke-test and found issues with afterInstall in .deb:

  1. ipfs-desktop was no longer added to PATH, symlink at /usr/local/bin/ipfs-desktop was no longer created during install (missing from custom after-install.sh)
  2. Created symlink for ipfs pointed at non-existing file:
$ ls /usr/local/bin/ipfs
lrwxrwxrwx 1 root staff 27 Apr  6 21:57 /usr/local/bin/ipfs -> /var/lib/assets/bin/ipfs.sh

$ ls /var/lib/assets/bin/ipfs.sh
ls: cannot access '/var/lib/assets/bin/ipfs.sh': No such file or directory

I fixed above and ensured wrapper script is included in bundled app under resources/bin/ipfs.sh – it should work now as expected, at least with .deb (I tested on Debian).

Note that I changed assets/bin/ipfs.sh – it did not work correctly on Linux, I assumed was also broken on MacOS (cc @olizilla), but let me know if I introduced any regressions.
If so, we may need to set different path in ipfs= on each platform.


@lidel is there a way on Linux to ask permission temporarily so we can modify /usr/local/bin?

Some systems have graphical sudo installed, such as gksudo/gksu, but that is not always enough, user needs to be added to privileged group first.

There is no easy way, because regular desktop app asking for root is considered a bad practice and will raise serious eyebrows. Adding symlink on install is the only viable option on Linux IMO.

hacdias added 2 commits April 7, 2019 09:26
License: MIT
Signed-off-by: Henrique Dias <hacdias@gmail.com>
License: MIT
Signed-off-by: Henrique Dias <hacdias@gmail.com>
@hacdias
Copy link
Member Author

hacdias commented Apr 7, 2019

@lidel yes, there were some issues on macOS, but they're fixed now 😄 Thanks for the Linux fixes.

@olizilla would you mind to try building and installing?

electron-builder.yml Outdated Show resolved Hide resolved
License: MIT
Signed-off-by: Henrique Dias <hacdias@gmail.com>
assets/bin/ipfs.sh Outdated Show resolved Hide resolved
assets/bin/ipfs.sh Show resolved Hide resolved
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.

}

// 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.


// 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')
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.

olizilla and others added 2 commits April 8, 2019 11:51
Co-Authored-By: hacdias <hacdias@gmail.com>
License: MIT
Signed-off-by: Marcin Rataj <lidel@lidel.org>
@olizilla
Copy link
Member

olizilla commented Apr 9, 2019

woo haa! It works!

$ cat `which ipfs`
#!/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" "$@"

$ ipfs version
ipfs version 0.4.19

@hacdias
Copy link
Member Author

hacdias commented Apr 9, 2019

I'm merging this and I've left a comment on the issue: #727 (comment)

@hacdias hacdias merged commit 10d964e into master Apr 9, 2019
@hacdias hacdias deleted the feat/ipfs-script branch April 9, 2019 13:49
@ghost ghost removed the in progress label Apr 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants