| 1 | #!/bin/sh |
| 2 | # |
| 3 | # Installation script for ipfs. It tries to move $bin in one of the |
| 4 | # directories stored in $binpaths. |
| 5 | |
| 6 | INSTALL_DIR=$(dirname $0) |
| 7 | |
| 8 | bin="$INSTALL_DIR/ipfs" |
| 9 | binpaths='/usr/local/bin /usr/bin $HOME/.local/bin' |
| 10 | |
| 11 | # This variable contains a nonzero length string in case the script fails |
| 12 | # because of missing write permissions. |
| 13 | is_write_perm_missing="" |
| 14 | |
| 15 | for raw in $binpaths; do |
| 16 | # Expand the $HOME variable. |
| 17 | binpath=$(eval echo "$raw") |
| 18 | mkdir -p "$binpath" |
| 19 | if mv "$bin" "$binpath/ipfs" ; then |
| 20 | echo "Moved $bin to $binpath" |
| 21 | exit 0 |
| 22 | else |
| 23 | if [ -d "$binpath" ] && [ ! -w "$binpath" ]; then |
| 24 | is_write_perm_missing=1 |
| 25 | fi |
| 26 | fi |
| 27 | done |
| 28 | |
| 29 | echo "We cannot install $bin in one of the directories $binpaths" |
| 30 | |
| 31 | if [ -n "$is_write_perm_missing" ]; then |
| 32 | echo "It seems that we do not have the necessary write permissions." |
| 33 | echo "Perhaps try running this script as a privileged user:" |
| 34 | echo |
| 35 | echo " sudo $0" |
| 36 | echo |
| 37 | fi |
| 38 | |
| 39 | exit 1 |