#!/bin/sh -e
#
# Stack installation script.
#
# This script is meant for quick & easy install via:
# 'curl -sSL https://get.haskellstack.org/ | sh'
# or:
# 'wget -qO- https://get.haskellstack.org/ | sh'
#
# By default, this installs 'stack' to '/usr/local/bin'.
#
# Arguments (use `... | sh -s - ARGUMENTS`)
#
# -q: reduce script's output
# -f: force over-write even if 'stack' already installed
# -d DESTDIR: change destination directory
#
# Make pull requests at:
# https://github.com/commercialhaskell/stack/blob/master/etc/scripts/get-stack.sh
#
# Note that this script will ask for root access using `sudo` in order to use
# your platform's package manager to install dependencies and to install to
# `/usr/local/bin`. If you prefer more control, follow the manual
# installation instructions for your platform at:
# https://docs.haskellstack.org/en/stable/install_and_upgrade/
#
STACK_VERSION="2.1.3"
HOME_LOCAL_BIN=" /.local/bin"
DEFAULT_DEST="/usr/local/bin/stack"
# Windows doesn't have a good place for DEST, but all CI systems (Appveyor, Travis, Azure) support /bin
DEFAULT_DEST_WINDOWS="/bin/stack"
DEST=""
QUIET=""
FORCE=""
STACK_TEMP_DIR=
# creates a temporary directory, which will be cleaned up automatically
# when the script finishes
# cleanup the temporary directory if it's been created. called automatically
# when the script exits.
# print a message to stderr and exit with error code
# print a message to stdout unless '-q' passed to script
# print a separator for post-install messages
# determines the the CPU's instruction set
# exits with code 0 if arm ISA is detected as described above
# exits with code 0 if aarch64 ISA is detected as described above
# determines 64- or 32-bit architecture
# if getconf is available, it will return the arch of the OS, as desired
# if not, it will use uname to get the arch of the CPU, though the installed
# OS could be 32-bits on a 64-bit CPU
# exits with code 0 if a 64-bit architecture is detected as described above
# prints a generic bindist notice
# Adds a 'sudo' prefix if sudo is available to execute the given command
# If not, the given command is run as is
# When requesting root permission, always show the command and never re-use cached credentials.
# Install dependencies for distros that use Apt
# Attempts an install on Ubuntu via apt, if possible
# Expects the version (in Major.Minor format, with any sub-minor removed)
# as the first and only argument
# If the version of Ubuntu is unsupported, it attempts to copy the binary
# and install the necessary dependencies explicitly.
# Attempts an install on Debian.
# Expects the single-number version as the first and only argument
# If the version of Debian is unsupported, it attempts to copy the binary
# and install the necessary dependencies explicitly.
# Attempts an install on Fedora.
# Expects the single-number version as the first and only argument
# If the version of Fedora is unsupported, it attempts to copy the binary
# and install the necessary dependencies explicitly.
# Attempts an install on CentOS.
# Expects the single-number version as the first and only argument
# If the version of CentOS is unsupported, it attempts to copy the binary
# and install the necessary dependencies explicitly.
# Attempts to install on Windows, designed for CI scripts (tested on Appveyor, Travis, Azure)
# Attempts to install on macOS.
# If 'brew' exists, installs using Homebrew. Otherwise, installs
# the generic bindist.
# Attempts to insall on FreeBSD. Installs dependencies with
# 'pkg install' and then downloads bindist.
# Alpine distro install
# Attempts to install on unsupported Linux distribution by downloading
# the bindist.
# Attempts to determine the running Linux distribution.
# Prints "DISTRO;VERSION" (distribution name and version)"."
# Attempt to install on a Linux distribution
# Determine operating system and attempt to install.
# Download a URL to file using 'curl' or 'wget'.
# Check for 'curl' or 'wget' and attempt to install 'curl' if neither found,
# or fail the script if that is not possible.
# Download a Stack bindst and install it in /usr/local/bin/stack.
# Attempt to install packages using whichever of apt-get, dnf, yum, or apk is
# available.
# Install packages using apt-get
# Install packages using dnf
# Install packages using yum
# Install packages using apk
# Install packages using pkg
# Get installed Stack version, if any
# Get installed Stack's path
# Check whether 'stack' command exists
# Check whether 'wget' command exists
# Check whether 'curl' command exists
# Check whether 'lsb_release' command exists
# Check whether 'sudo' command exists
# Check whether 'getconf' command exists
# Check whether 'brew' command exists
#has_brew() {
# has_cmd brew
#}
# Check whether 'perl' command exists
# Check whether 'apt-get' command exists
# Check whether 'yum' command exists
# Check whether 'apk' command exists
# Check whether 'dnf' command exists
# Check whether the given command exists
# Check whether the given path is listed in the PATH environment variable
# Check whether ~/.local/bin is on the PATH, and print a warning if not.
# Check whether $DEST is on the PATH, and print a warning if not.
# Check whether Stack is already installed, and print an error if it is.
while [; do
case "" in
-q|--quiet)
# This tries its best to reduce output by suppressing the script's own
# messages and passing "quiet" arguments to tools that support them.
QUIET="true"
;;
-f|--force)
FORCE="true"
;;
-d|--dest)
DEST=" /stack"
;;
*)
;;
esac
done