Reduce binary size used by Zstd
[ouch.git] / install.sh
bloba05924fdb3ef562223c9a971bee158e3d5a61ce2
1 #! /usr/bin/sh
3 # Needs to be updated each version bump
4 VERSION="0.2.0"
6 DOWNLOAD_LOCATION="/tmp/ouch-binary"
7 INSTALLATION_LOCATION="/usr/local/bin/ouch"
8 REPO_URL="https://github.com/ouch-org/ouch"
10 # Panics script if anything fails
11 set -e
13 abort() {
14 echo "error occurred, aborting." ; exit 1
17 install() {
18 echo "Ouch v$VERSION."
20 printf "Detected system: "
21 # System detection from https://stackoverflow.com/a/27776822/9982477
22 # Go there to see a full table of what `uname -s` might output
23 case "$(uname -s)" in
24 Linux)
25 echo "Linux."
26 system_suffix="-linux-musl"
29 Darwin)
30 echo "Mac OS X."
31 system_suffix="-apple-darwin"
34 CYGWIN*|MINGW32*|MSYS*|MINGW*)
35 echo "Windows."
36 system_suffix="-pc-windows-msvc.exe"
40 echo "ERROR."
41 echo "This script only works for installing on Linux, Mac OS and Windows."
42 echo "We found '$(uname -s)' instead."
43 echo ""
44 echo "To install 'ouch' you can opt for other installation method"
45 echo "listed at $REPO_URL"
46 echo ""
47 echo "If you think this is an error, please open an issue"
48 exit 1
50 esac
52 binary_file_name="ouch-x86_64${system_suffix}"
53 binary_url="https://github.com/ouch-org/ouch/releases/download/${VERSION}/${binary_file_name}"
55 echo ""
57 # Set $downloader
58 if [ $(which curl) ]; then
59 downloader="curl"
60 downloader_command="curl -fSL $binary_url -o $DOWNLOAD_LOCATION"
61 elif [ $(which wget) ]; then
62 downloader="wget"
63 downloader_command="wget $binary_url -O $DOWNLOAD_LOCATION"
64 else
65 echo "ERROR: have not found 'curl' nor 'wget' to donwload ouch binary."
66 exit 1
69 if [ -f "$DOWNLOAD_LOCATION" ]; then
70 echo "Reusing downloaded binary at '$DOWNLOAD_LOCATION'."
71 else
72 echo "Downloading binary to '$DOWNLOAD_LOCATION' with $downloader."
73 echo "From $binary_url"
74 # Run command to download binary
75 $downloader_command
78 echo ""
80 if [ "$USER" = "root" ]; then
81 echo "Detected root user, trying to copy $DOWNLOAD_LOCATION to $INSTALLATION_LOCATION."
82 cp $DOWNLOAD_LOCATION $INSTALLATION_LOCATION
83 chmod +x $INSTALLATION_LOCATION
84 else
85 echo "Asking for \"sudo\" permissions to finish installation."
86 echo "Permission is needed to copy '$DOWNLOAD_LOCATION' to '$INSTALLATION_LOCATION'"
88 sudo cp $DOWNLOAD_LOCATION $INSTALLATION_LOCATION
89 sudo chmod +x $INSTALLATION_LOCATION
92 echo ""
94 echo "Successfully installed!"
95 echo "See $REPO_URL for usage instructions."
98 install