install-haskell/install-haskell.sh

81 lines
2.1 KiB
Bash
Raw Normal View History

2014-08-16 18:31:10 +00:00
#!/usr/bin/env zsh
2014-08-17 10:34:51 +00:00
normaluser=$1
(( $# < 1 )) && {
print -- "usage: ${0:t} \$USER" >&2
exit 1
}
ghcversion="7.8.3"
cabalversion="1.20.0.3"
2014-08-16 18:31:10 +00:00
archi=$(uname -m)
if [[ $(uname -s) = "Darwin" ]]; then
os="apple-darwin"
cabalos="apple-darwin-maverick"
else
cabalversion="1.20.0.1"
2014-08-16 18:31:10 +00:00
os="unknown-linux-deb7"
cabalos="unknown-linux"
2014-08-17 10:34:51 +00:00
apt-get install libgmp-dev
2014-08-16 18:31:10 +00:00
fi
tmpdir=/tmp/install-haskell
2014-08-16 18:31:10 +00:00
mkdir -p $tmpdir
cd $tmpdir
2014-08-17 10:04:01 +00:00
ghctar=ghc-${ghcversion}-${archi}-${os}.tar.xz
2014-08-17 09:33:16 +00:00
if [[ ! -e $ghctar ]]; then
2014-08-16 18:31:10 +00:00
echo "Downloading GHC..."
2014-08-17 09:33:16 +00:00
curl -O http://www.haskell.org/ghc/dist/${ghcversion}/$ghctar
2014-08-16 18:31:10 +00:00
else
echo "Using already downloaded GHC ($tmpdir)..."
fi
echo "Installing GHC..."
2014-08-17 09:33:16 +00:00
tar xJf $ghctar
2014-08-16 18:31:10 +00:00
cd ghc-${ghcversion}
2014-08-17 10:34:51 +00:00
./configure && make install
2014-08-16 18:31:10 +00:00
cd $tmpdir
echo "Downloading cabal..."
2014-08-17 10:10:54 +00:00
cabaltar=cabal-${cabalversion}-${archi}-${cabalos}.tar.gz
[[ $cabalos = "unknown-linux" ]] && cabaltar=cabal-${archi}-${cabalos}.tar.gz
2014-08-17 09:33:16 +00:00
if [[ ! -e $cabaltar ]]; then
curl -O http://www.haskell.org/cabal/release/cabal-install-$cabalversion/$cabaltar
2014-08-16 18:31:10 +00:00
else
echo "Using already downloaded cabal ($tmpdir)..."
fi
2014-08-17 09:33:16 +00:00
tar xzf $cabaltar
2014-08-17 09:24:19 +00:00
echo "Installing cabal..."
if [[ -e ./cabal ]]; then
2014-08-17 10:34:51 +00:00
mv cabal /usr/local/bin
else
2014-08-17 10:34:51 +00:00
mv ./dist/build/cabal/cabal /usr/local/bin
fi
2014-08-16 18:31:10 +00:00
2014-08-17 10:34:51 +00:00
initcabal(){
echo "Init cabal..."
cabal info >/dev/null 2>&1
2014-08-16 18:31:10 +00:00
echo "Using Stackage..."
stackageurl="stackage:http://www.stackage.org/stackage/3cb59cb0cfe26e0513c30a727d889e7b0d427efd"
2014-08-16 18:31:10 +00:00
2014-08-17 10:34:51 +00:00
# use exclusive snapshot by default.
perl -pi.bak -e 's#^remote-repo: .*$#remote-repo: '$stackageurl'#' $HOME/.cabal/config
cabal update
echo "Install useful binaries"
cabal install -j alex happy
echo "Update your PATH in .profile for cabal binaries"
echo 'export PATH=$HOME/.cabal/bin:$PATH' >> $HOME/.profile
}
sudo -u $normaluser initcabal
2014-08-16 18:31:10 +00:00
echo
echo "Congratulations"
echo "==============="
echo
echo "You should start using Haskell like a pro now"
echo "You shouldn't use cabal sandbox except if you know what you are doing."
echo "So if you follow a tutorial that use cabal sandbox, don't use it."
echo "Unless you don't mind killing some white bear and waiting a lot."