Skip to content

Instantly share code, notes, and snippets.

@notae
Last active August 29, 2015 14:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save notae/a01719cb1325d6b39b8c to your computer and use it in GitHub Desktop.
Save notae/a01719cb1325d6b39b8c to your computer and use it in GitHub Desktop.
GHC/Cabal initial setup script for home directory
#!/bin/sh -e
#
# Module : ghc_setup_home.sh
# Description : GHC/Cabal initial setup script for home directory
# Copyright : (c) notae@me.com, 2014
# License : BSD-style
# Maintainer : notae@me.com
# Stability : experimental
# Portability : POSIX
#
# This script do following action:
# (1) Clean GHC/Cabal directories in your home directory.
# (2) Install latest cabal from Hacakge by cabal in Haskell Platform.
# (3) Install latest ghc-mod command from Hacakge by new cabal.
#
readonly TITLE="GHC/Cabal Setup"
readonly ME=`basename $0`
readonly CP=/bin/cp
readonly RM=/bin/rm
readonly MKDIR=/bin/mkdir
readonly CABAL_SYS=/usr/bin/cabal
readonly CABAL_USR="${HOME}/Library/Haskell/bin/cabal"
readonly USR_BIN_DIR="${HOME}/Library/Haskell/bin"
readonly DEST_DIRS="${HOME}/.ghc ${HOME}/.cabal ${HOME}/Library/Haskell"
readonly SANDBOX_ID=$$
readonly SANDBOX_DIR="/tmp/ghc_setup_home-${USER}-${SANDBOX_ID}"
export PATH="${USR_BIN_DIR}:/usr/bin:/bin:/usr/sbin:/sbin"
msg ()
{
echo "================================================================"
echo ${ME}: $*
echo "================================================================"
echo
}
msg "${TITLE} was started."
msg "!! All GHC/Cabal directories in your home will be removed !!"
msg " Directories: ${DEST_DIRS}"
read -r -p "Are you sure? [y/N] " response
case ${response} in
[yY][eE][sS]|[yY])
# go through
;;
*)
msg "${TITLE} was aborted by user."
exit 255
;;
esac
msg "Cleaning up old directories ..."
${RM} -rf ${DEST_DIRS}
msg "Setup new Cabal / cabal-install ..."
${CABAL_SYS} update
${CABAL_SYS} install -j cabal-install
${CABAL_USR} update
msg "Setup ghc-mod, hlint ..."
${MKDIR} ${SANDBOX_DIR}
pushd ${SANDBOX_DIR}
${CABAL_USR} sandbox init
${CABAL_USR} install -j ghc-mod
${CP} -a .cabal-sandbox/bin/* ${USR_BIN_DIR}
${CABAL_USR} sandbox delete
popd
${RM} -rf ${SANDBOX_DIR}
msg "${TITLE} was completed."
exit 0
@notae
Copy link
Author

notae commented Aug 17, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment