build.sh 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #!/usr/bin/env bash
  2. set -e
  3. if [ "$#" -lt 1 ] || [ "$#" -gt 2 ] || ([ "$#" == 2 ] && [ "$2" != "--no-swoole" ]); then
  4. echo "Usage:" >&2
  5. echo " $0 {version} [--no-swoole]" >&2
  6. exit 1
  7. fi
  8. version=$1
  9. noSwoole=$2
  10. phpVersion=$(php -r 'echo PHP_MAJOR_VERSION . "." . PHP_MINOR_VERSION;')
  11. [[ $noSwoole ]] && swooleSuffix="" || swooleSuffix="_swoole"
  12. distId="shlink${version}_php${phpVersion}${swooleSuffix}_dist"
  13. builtContent="./build/${distId}"
  14. projectdir=$(pwd)
  15. [[ -f ./composer.phar ]] && composerBin='./composer.phar' || composerBin='composer'
  16. # Copy project content to temp dir
  17. echo 'Copying project files...'
  18. rm -rf "${builtContent}"
  19. mkdir -p "${builtContent}"
  20. rsync -av * "${builtContent}" \
  21. --exclude=*docker* \
  22. --exclude=Dockerfile \
  23. --include=.htaccess \
  24. --exclude-from=./.dockerignore
  25. cd "${builtContent}"
  26. # Install dependencies
  27. echo "Installing dependencies with $composerBin..."
  28. composerFlags="--optimize-autoloader --no-progress --no-interaction"
  29. ${composerBin} self-update
  30. ${composerBin} install --no-dev --prefer-dist $composerFlags
  31. if [[ $noSwoole ]]; then
  32. # If generating a dist not for swoole, uninstall mezzio-swoole
  33. ${composerBin} remove mezzio/mezzio-swoole --with-all-dependencies --update-no-dev $composerFlags
  34. else
  35. # Copy mezzio helper script to vendor (deprecated - Remove with Shlink 3.0.0)
  36. cp "${projectdir}/bin/helper/mezzio-swoole" "./vendor/bin"
  37. fi
  38. # Delete development files
  39. echo 'Deleting dev files...'
  40. rm composer.*
  41. # Update shlink version in config
  42. sed -i "s/%SHLINK_VERSION%/${version}/g" config/autoload/app_options.global.php
  43. # Compressing file
  44. echo 'Compressing files...'
  45. cd "${projectdir}"/build
  46. rm -f ./${distId}.zip
  47. zip -ry ./${distId}.zip ./${distId}
  48. cd "${projectdir}"
  49. rm -rf "${builtContent}"
  50. echo 'Done!'