build.sh 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. #!/usr/bin/env bash
  2. ##########################################################################
  3. # This is the Cake bootstrapper script for Linux and OS X.
  4. # This file was downloaded from https://github.com/cake-build/resources
  5. # Feel free to change this file to fit your needs.
  6. ##########################################################################
  7. # Define directories.
  8. SCRIPT_DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
  9. TOOLS_DIR=$SCRIPT_DIR/tools
  10. ADDINS_DIR=$TOOLS_DIR/Addins
  11. MODULES_DIR=$TOOLS_DIR/Modules
  12. NUGET_EXE=$TOOLS_DIR/nuget.exe
  13. CAKE_EXE=$TOOLS_DIR/Cake/Cake.exe
  14. PACKAGES_CONFIG=$TOOLS_DIR/packages.config
  15. PACKAGES_CONFIG_MD5=$TOOLS_DIR/packages.config.md5sum
  16. ADDINS_PACKAGES_CONFIG=$ADDINS_DIR/packages.config
  17. MODULES_PACKAGES_CONFIG=$MODULES_DIR/packages.config
  18. # Define md5sum or md5 depending on Linux/OSX
  19. MD5_EXE=
  20. if [[ "$(uname -s)" == "Darwin" ]]; then
  21. MD5_EXE="md5 -r"
  22. else
  23. MD5_EXE="md5sum"
  24. fi
  25. # Define default arguments.
  26. SCRIPT="build.cake"
  27. CAKE_ARGUMENTS=()
  28. # Parse arguments.
  29. for i in "$@"; do
  30. case $1 in
  31. -s|--script) SCRIPT="$2"; shift ;;
  32. --) shift; CAKE_ARGUMENTS+=("$@"); break ;;
  33. *) CAKE_ARGUMENTS+=("$1") ;;
  34. esac
  35. shift
  36. done
  37. # Make sure the tools folder exist.
  38. if [ ! -d "$TOOLS_DIR" ]; then
  39. mkdir "$TOOLS_DIR"
  40. fi
  41. # Make sure that packages.config exist.
  42. if [ ! -f "$TOOLS_DIR/packages.config" ]; then
  43. echo "Downloading packages.config..."
  44. curl -Lsfo "$TOOLS_DIR/packages.config" https://cakebuild.net/download/bootstrapper/packages
  45. if [ $? -ne 0 ]; then
  46. echo "An error occurred while downloading packages.config."
  47. exit 1
  48. fi
  49. fi
  50. # Download NuGet if it does not exist.
  51. if [ ! -f "$NUGET_EXE" ]; then
  52. echo "Downloading NuGet..."
  53. curl -Lsfo "$NUGET_EXE" https://dist.nuget.org/win-x86-commandline/latest/nuget.exe
  54. if [ $? -ne 0 ]; then
  55. echo "An error occurred while downloading nuget.exe."
  56. exit 1
  57. fi
  58. fi
  59. # Restore tools from NuGet.
  60. pushd "$TOOLS_DIR" >/dev/null
  61. if [ ! -f "$PACKAGES_CONFIG_MD5" ] || [ "$( cat "$PACKAGES_CONFIG_MD5" | sed 's/\r$//' )" != "$( $MD5_EXE "$PACKAGES_CONFIG" | awk '{ print $1 }' )" ]; then
  62. find . -type d ! -name . ! -name 'Cake.Bakery' | xargs rm -rf
  63. fi
  64. mono "$NUGET_EXE" install -ExcludeVersion
  65. if [ $? -ne 0 ]; then
  66. echo "Could not restore NuGet tools."
  67. exit 1
  68. fi
  69. $MD5_EXE "$PACKAGES_CONFIG" | awk '{ print $1 }' >| "$PACKAGES_CONFIG_MD5"
  70. popd >/dev/null
  71. # Restore addins from NuGet.
  72. if [ -f "$ADDINS_PACKAGES_CONFIG" ]; then
  73. pushd "$ADDINS_DIR" >/dev/null
  74. mono "$NUGET_EXE" install -ExcludeVersion
  75. if [ $? -ne 0 ]; then
  76. echo "Could not restore NuGet addins."
  77. exit 1
  78. fi
  79. popd >/dev/null
  80. fi
  81. # Restore modules from NuGet.
  82. if [ -f "$MODULES_PACKAGES_CONFIG" ]; then
  83. pushd "$MODULES_DIR" >/dev/null
  84. mono "$NUGET_EXE" install -ExcludeVersion
  85. if [ $? -ne 0 ]; then
  86. echo "Could not restore NuGet modules."
  87. exit 1
  88. fi
  89. popd >/dev/null
  90. fi
  91. # Make sure that Cake has been installed.
  92. if [ ! -f "$CAKE_EXE" ]; then
  93. echo "Could not find Cake.exe at '$CAKE_EXE'."
  94. exit 1
  95. fi
  96. # Start Cake
  97. exec mono "$CAKE_EXE" $SCRIPT "${CAKE_ARGUMENTS[@]}"