install-haskell/install-haskell.sh

92 lines
2.7 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
}
2014-08-19 15:54:23 +00:00
userhome=$(sudo -u $normaluser echo $HOME)
[[ -e $userhome/.cabal ]] && sudo -u $normaluser mv $HOME/{,old}.cabal
[[ -e $userhome/.ghc ]] && sudo -u $normaluser mv $HOME/{,old}.ghc
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:40:51 +00:00
echo "Init cabal..."
sudo -u $normaluser cabal info >/dev/null 2>&1
2014-08-19 19:36:29 +00:00
echo "Using Stackage build for GHC 7.8, 2014-08-17 exclusive..."
stackageurl="stackage:http://www.stackage.org/stackage/44dd460d063f344de0da3bfe984e1ac816f18469"
2014-08-16 18:31:10 +00:00
2014-08-17 10:40:51 +00:00
# use exclusive snapshot by default.
sudo -u $normaluser perl -pi.bak -e 's#^remote-repo: .*$#remote-repo: '$stackageurl'#' $HOME/.cabal/config
sudo -u $normaluser cabal update
echo "Install useful binaries"
sudo -u $normaluser cabal install -j alex happy
2014-08-17 10:34:51 +00:00
2014-08-17 10:40:51 +00:00
echo "Update your PATH in .profile for cabal binaries"
2014-08-17 10:50:02 +00:00
sudo -u $normaluser echo 'export PATH=$HOME/.cabal/bin:$PATH' >> $HOME/.profile
2014-08-16 18:31:10 +00:00
2014-08-19 19:36:29 +00:00
echo "[Stackage build] "
echo $stackageurl
2014-08-16 18:31:10 +00:00
echo
2014-08-19 19:36:29 +00:00
echo "If some package are missing, that means they are not considered stable."
echo "Ask gently the package maintainer to add its package to stackage."
echo
print -P -- "You could also use an %Binclusive%b build."
echo "Packages not in exclusive build aren't be garanteed to build thought."
echo
echo "================"
echo "Congratulations\!"
echo "================"
2014-08-16 18:31:10 +00:00
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."
2014-08-19 19:36:29 +00:00
echo