A terminal client for the Mattermost chat system
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

install.sh 2.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. #!/usr/bin/env bash
  2. # This script builds and installs this package and its dependencies in a
  3. # sandbox. This script is also suitable for rebuilds during development.
  4. #
  5. # Note that this uses cabal 'new-build' operation instead of standard
  6. # install.
  7. set -e
  8. HERE=$(cd `dirname $0`; pwd)
  9. # Where dependency repos get cloned
  10. DEPS=$HERE/deps
  11. # The source for the mattermost API package
  12. MATTERMOST_API_REPO=https://github.com/matterhorn-chat/mattermost-api.git
  13. MATTERMOST_API_QC_REPO=https://github.com/matterhorn-chat/mattermost-api-qc.git
  14. ASPELL_PIPE_REPO=https://github.com/matterhorn-chat/aspell-pipe.git
  15. # Where to clone the mattermost API package
  16. MATTERMOST_API_DIR=$DEPS/mattermost-api
  17. MATTERMOST_API_QC_DIR=$DEPS/mattermost-api-qc
  18. ASPELL_PIPE_DIR=$DEPS/aspell-pipe
  19. # Whether this is a first-time install (see below)
  20. FIRST_TIME=0
  21. function init {
  22. if [ ! -d "$HERE/cabal.project.local" ]
  23. then
  24. FIRST_TIME=1
  25. echo 'packages: deps/mattermost-api/mattermost-api.cabal' >cabal.project.local
  26. echo ' deps/mattermost-api-qc/mattermost-api-qc.cabal' >>cabal.project.local
  27. echo ' deps/aspell-pipe' >>cabal.project.local
  28. fi
  29. }
  30. # clone_or_update_repo $REPO_URL $DEST_DIR
  31. #
  32. # Clones if absent; pulls otherwise.
  33. function clone_or_update_repo {
  34. mkdir -p $DEPS
  35. local branch=$1
  36. local repo=$2
  37. local destdir=$3
  38. if [ ! -d "$destdir" ]
  39. then
  40. git clone "$repo" "$destdir" 2> gitclone.err
  41. cd $destdir
  42. if ! git checkout "$branch"
  43. then
  44. echo "Branch ${branch} does not exist; using master"
  45. fi
  46. else
  47. cd $destdir && git pull
  48. fi
  49. }
  50. function install_deps {
  51. clone_or_update_repo "$(current_branch)" "$MATTERMOST_API_REPO" "$MATTERMOST_API_DIR"
  52. clone_or_update_repo "$(current_branch)" "$MATTERMOST_API_QC_REPO" "$MATTERMOST_API_QC_DIR"
  53. clone_or_update_repo "$(current_branch)" "$ASPELL_PIPE_REPO" "$ASPELL_PIPE_DIR"
  54. }
  55. function current_branch {
  56. if [[ -z "$TRAVIS_BRANCH" ]]
  57. then
  58. git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/'
  59. else
  60. echo "$TRAVIS_BRANCH"
  61. fi
  62. }
  63. function build {
  64. cd $HERE
  65. if [ $FIRST_TIME -eq 1 ]
  66. then
  67. # For first-time builds, get dependencies installed as fast as
  68. # possible.
  69. cabal new-build -j --enable-tests
  70. else
  71. # But for subsequent builds, build with -j1 to avoid suppression
  72. # of useful (e.g. warning) output.
  73. cabal new-build -j1 --enable-tests
  74. fi
  75. }
  76. init
  77. install_deps
  78. build