Merge pull request #215 from figsoda/snappy
[ouch.git] / install.sh
blobd12b572f1cb874d4c573f60242f4c421c9944783
1 #! /usr/bin/sh
3 # Needs to be updated each version bump
4 VERSION="0.3.1"
6 DOWNLOAD_LOCATION="/tmp/ouch-binary"
7 INSTALLATION_LOCATION="/usr/local/bin/ouch"
8 REPO_URL="https://github.com/ouch-org/ouch"
10 # If env var ACCESSIBLE is set (to a nonempty value), suppress output of
11 # `curl` or `wget`
14 # Panics script if anything fails
15 set -e
17 abort() {
18 echo "error occurred, aborting." ; exit 1
21 install() {
22 echo "Ouch v$VERSION."
24 printf "Detected system: "
25 # System detection from https://stackoverflow.com/a/27776822/9982477
26 # Go there to see a full table of what `uname -s` might output
27 case "$(uname -s)" in
28 Linux)
29 echo "Linux."
30 system_suffix="-linux-musl"
33 Darwin)
34 echo "Mac OS X."
35 system_suffix="-apple-darwin"
38 CYGWIN*|MINGW32*|MSYS*|MINGW*)
39 echo "Windows."
40 system_suffix="-pc-windows-msvc.exe"
44 echo "ERROR."
45 echo "This script only works for installing on Linux, Mac OS and Windows."
46 echo "We found '$(uname -s)' instead."
47 echo ""
48 echo "To install 'ouch' you can opt for other installation method"
49 echo "listed at $REPO_URL"
50 echo ""
51 echo "If you think this is an error, please open an issue"
52 exit 1
54 esac
56 binary_file_name="ouch-x86_64${system_suffix}"
57 binary_url="https://github.com/ouch-org/ouch/releases/download/${VERSION}/${binary_file_name}"
59 echo ""
61 # Set $downloader
62 downloader_quiet_flag=""
63 if [ $(which curl) ]; then
64 downloader="curl"
65 if [ "$ACCESSIBLE" ]; then downloader_quiet_flag="--silent"; fi
66 downloader_command="curl $downloader_quiet_flag -fSL $binary_url -o $DOWNLOAD_LOCATION"
67 elif [ $(which wget) ]; then
68 downloader="wget"
69 if [ "$ACCESSIBLE" ]; then downloader_quiet_flag="--quiet"; fi
70 downloader_command="wget $downloader_quiet_flag $binary_url -O $DOWNLOAD_LOCATION"
71 else
72 echo "ERROR: have not found 'curl' nor 'wget' to donwload ouch binary."
73 exit 1
76 if [ -f "$DOWNLOAD_LOCATION" ]; then
77 echo "Reusing downloaded binary at '$DOWNLOAD_LOCATION'."
78 else
79 echo "Downloading binary to '$DOWNLOAD_LOCATION' with $downloader."
80 echo "From $binary_url"
81 # Run command to download binary
82 $downloader_command
85 echo ""
87 if [ "$USER" = "root" ]; then
88 echo "Detected root user, trying to copy $DOWNLOAD_LOCATION to $INSTALLATION_LOCATION."
89 cp $DOWNLOAD_LOCATION $INSTALLATION_LOCATION
90 chmod +x $INSTALLATION_LOCATION
91 else
92 echo "Asking for \"sudo\" permissions to finish installation."
93 echo "Permission is needed to copy '$DOWNLOAD_LOCATION' to '$INSTALLATION_LOCATION'"
95 sudo cp $DOWNLOAD_LOCATION $INSTALLATION_LOCATION
96 sudo chmod +x $INSTALLATION_LOCATION
99 echo ""
101 echo "Successfully installed!"
102 echo "See $REPO_URL for usage instructions."
105 install