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
|
|
|
|
2014-08-19 19:42:10 +00:00
|
|
|
userhome="$(sudo -u $normaluser echo $HOME)"
|
|
|
|
echo $userhome
|
|
|
|
|
|
|
|
if [[ -e $userhome/.cabal ]]; then
|
|
|
|
print -- "Moving your ~/.cabal to ~/old.cabal"
|
|
|
|
sudo -u $normaluser mv $HOME/{,old}.cabal
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ -e $userhome/.ghc ]]; then
|
|
|
|
print -- "Moving your ~/.ghc to ~/old.ghc"
|
|
|
|
sudo -u $normaluser mv $HOME/{,old}.ghc
|
|
|
|
fi
|
2014-08-19 15:54:23 +00:00
|
|
|
|
2015-02-07 13:39:04 +00:00
|
|
|
# 7.8.4 don't have an official apple-darwin build
|
2014-08-16 21:12:13 +00:00
|
|
|
ghcversion="7.8.3"
|
2014-08-17 10:05:42 +00:00
|
|
|
cabalversion="1.20.0.3"
|
2014-08-16 18:31:10 +00:00
|
|
|
archi=$(uname -m)
|
|
|
|
if [[ $(uname -s) = "Darwin" ]]; then
|
|
|
|
os="apple-darwin"
|
2014-08-30 07:54:25 +00:00
|
|
|
cabalos="apple-darwin-mavericks"
|
2014-08-16 18:31:10 +00:00
|
|
|
else
|
2014-09-09 20:28:52 +00:00
|
|
|
if [[ $archi = "i686" ]]; then
|
|
|
|
archi=i386
|
|
|
|
fi
|
2015-02-07 13:39:04 +00:00
|
|
|
cabalversion="1.22.0.0"
|
2014-08-16 18:31:10 +00:00
|
|
|
os="unknown-linux-deb7"
|
|
|
|
cabalos="unknown-linux"
|
2014-08-21 07:31:14 +00:00
|
|
|
# -------------------------
|
|
|
|
# apt-get install libgmp-dev
|
2014-08-16 18:31:10 +00:00
|
|
|
fi
|
|
|
|
|
2014-08-16 21:12:13 +00:00
|
|
|
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..."
|
2015-02-07 13:39:04 +00:00
|
|
|
echo "http://www.haskell.org/ghc/dist/${ghcversion}/$ghctar"
|
|
|
|
curl -LO "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
|
2015-02-07 13:39:04 +00:00
|
|
|
echo "http://www.haskell.org/cabal/release/cabal-install-$cabalversion/$cabaltar"
|
|
|
|
curl -LO "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..."
|
2014-08-17 09:35:31 +00:00
|
|
|
if [[ -e ./cabal ]]; then
|
2014-08-17 10:34:51 +00:00
|
|
|
mv cabal /usr/local/bin
|
2014-08-17 09:35:31 +00:00
|
|
|
else
|
2014-08-17 10:34:51 +00:00
|
|
|
mv ./dist/build/cabal/cabal /usr/local/bin
|
2014-08-17 09:35:31 +00:00
|
|
|
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-16 21:12:13 +00:00
|
|
|
|
2015-02-07 13:39:04 +00:00
|
|
|
echo "Using Haskell LTS for GHC 7.8"
|
|
|
|
stackageurl="stackage-lts-1.0:http://www.stackage.org/snapshot/lts-1.0"
|
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
|
2015-02-07 13:39:04 +00:00
|
|
|
sudo -u $normaluser perl -pi -e 's#-- library-profiling: False#library-profiling: True#' $HOME/.cabal/config
|
|
|
|
sudo -u $normaluser perl -pi -e 's#-- executable-profiling: False#executable-profiling: True#' $HOME/.cabal/config
|
2014-08-17 10:40:51 +00:00
|
|
|
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
|
|
|
|
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
|