-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3194 from kulla/install-sh-refactoring
Refactoring install.sh
- Loading branch information
Showing
1 changed file
with
27 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,34 @@ | ||
#!/bin/sh | ||
# | ||
# Installation script for ipfs. It tries to move $bin in one of the | ||
# directories stored in $binpaths. | ||
|
||
bin=ipfs | ||
binpaths="/usr/local/bin /usr/bin" | ||
|
||
# this script is currently brain dead. | ||
# it merely tries two locations. | ||
# in the future maybe use value of $PATH. | ||
# This variable contains a nonzero length string in case the script fails | ||
# because of missing write permissions. | ||
is_write_perm_missing="" | ||
|
||
binpath=/usr/local/bin | ||
if [ -d "$binpath" ]; then | ||
mv "$bin" "$binpath/$bin" | ||
echo "installed $binpath/$bin" | ||
exit 0 | ||
fi | ||
for binpath in $binpaths; do | ||
if mv "$bin" "$binpath/$bin" 2> /dev/null; then | ||
echo "Moved $bin to $binpath" | ||
exit 0 | ||
else | ||
if [ -d "$binpath" -a ! -w "$binpath" ]; then | ||
is_write_perm_missing=1 | ||
fi | ||
fi | ||
done | ||
|
||
echo "We cannot install $bin in one of the directories $binpaths" | ||
|
||
binpath=/usr/bin | ||
if [ -d "$binpath" ]; then | ||
mv "$bin" "$binpath/$bin" | ||
echo "installed $binpath/$bin" | ||
exit 0 | ||
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 |