Release 0.1.5
[ouch.git] / install.sh
blobe0bad688d54569d242345efd71a7071ec1ed5706
1 #! /usr/bin/sh
3 # Needs to be updated each version bump
4 VERSION="0.1.5"
6 DOWNLOAD_LOCATION="/tmp/ouch"
7 INSTALLATION_LOCATION="/usr/bin/ouch"
8 REPO_URL="https://github.com/vrmiguel/ouch"
10 abort() {
11 echo "error occurred, aborting." ; exit 1
14 # Panicks script if anything fails
15 set -e
17 echo "Ouch v$VERSION."
19 printf "Detected system: "
20 # System detection from https://stackoverflow.com/a/27776822/9982477
21 # Go there to see a full table of what `uname -s` might output
22 case "$(uname -s)" in
23 Darwin)
24 system_suffix="-macOS"
25 echo "Mac OS X."
28 Linux)
29 echo "Linux."
30 system_suffix="-ubuntu-18.04-glibc"
33 CYGWIN*|MINGW32*|MSYS*|MINGW*)
34 echo "Windows."
35 system_suffix=".exe"
39 echo "ERROR."
40 echo "This script only works for installing on Linux, Mac OS and Windows."
41 echo "We found '$(uname -s)' instead."
42 echo ""
43 echo "To install 'ouch' you can opt for other installation method"
44 echo "listed at $REPO_URL"
45 echo ""
46 echo "If you think this is an error, please open an issue"
47 exit 1
49 esac
51 binary_url="https://github.com/vrmiguel/ouch/releases/download/${VERSION}/ouch${system_suffix}"
53 echo ""
55 if [ -f "$DOWNLOAD_LOCATION" ]; then
56 echo "Reusing downloaded binary at '$DOWNLOAD_LOCATION'."
57 else
58 echo "Downloading binary to '$DOWNLOAD_LOCATION' with curl."
59 echo "From $binary_url"
60 curl -fSL $binary_url -o $DOWNLOAD_LOCATION
63 echo ""
65 if [ "$USER" = "root" ]; then
66 echo "Detected root user, trying to copy $DOWNLOAD_LOCATION to $INSTALLATION_LOCATION."
67 cp $DOWNLOAD_LOCATION $INSTALLATION_LOCATION || abort
68 else
69 echo "Asking for \"sudo\" permissions to finish installation."
70 echo "Permission is needed to copy '$DOWNLOAD_LOCATION' to '$INSTALLATION_LOCATION'"
72 sudo cp $DOWNLOAD_LOCATION $INSTALLATION_LOCATION || abort
75 echo ""
77 echo "Successfully installed!"
78 echo "See $REPO_URL for usage instructions."