kubo/cmd/ipfs/dist/install.sh
Volker Mische a049ba9d17
fix: installation without sudo (#8715)
* fix: installation without sudo

I think it's good practice that users don't need to run `sudo`
to install something just to try it out. With this change, the
local bin directory is tried first, which usually is also in the
`PATH`. This way the installation script can be run without
`sudo` and should still work.

* fix: try local path last and support spaces in $HOME

Try the `$HOME/.local/bin` path last, so that the script is backwards
compatible. Also make sure that it works even if there are spaces in
the directory set by `$HOME`.
2022-02-16 08:54:29 -05:00

39 lines
926 B
Bash
Executable File

#!/bin/sh
#
# Installation script for ipfs. It tries to move $bin in one of the
# directories stored in $binpaths.
INSTALL_DIR=$(dirname $0)
bin="$INSTALL_DIR/ipfs"
binpaths='/usr/local/bin /usr/bin $HOME/.local/bin'
# This variable contains a nonzero length string in case the script fails
# because of missing write permissions.
is_write_perm_missing=""
for raw in $binpaths; do
# Expand the $HOME variable.
binpath=$(eval echo "$raw")
if mv "$bin" "$binpath/ipfs" ; then
echo "Moved $bin to $binpath"
exit 0
else
if [ -d "$binpath" ] && [ ! -w "$binpath" ]; then
is_write_perm_missing=1
fi
fi
done
echo "We cannot install $bin in one of the directories $binpaths"
if [ -n "$is_write_perm_missing" ]; then
echo "It seems that we do not have the necessary write permissions."
echo "Perhaps try running this script as a privileged user:"
echo
echo " sudo $0"
echo
fi
exit 1