pre-commit 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #!/bin/bash
  2. function error {
  3. echo -e "\\e[91m$1\\e[39m"
  4. exit 1
  5. }
  6. # Check dependencies
  7. jq --version &> /dev/null || error "jq is required, please install it with 'sudo apt install jq'"
  8. git --version &> /dev/null || error "git is required, please install it with 'sudo apt install git'"
  9. sha256sum --version &> /dev/null || error "sha256sum is required, please install it with 'sudo apt install coreutils'"
  10. # Check if script from build or script from hook and cd into build folder
  11. scriptDir="$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
  12. if [ "$( echo "$scriptDir" | rev | cut -d/ -f1 | rev )" == "build" ]; then
  13. cd -- "$scriptDir" &> /dev/null || exit
  14. else
  15. cd -- "$(git rev-parse --show-toplevel)/build" &> /dev/null || exit
  16. fi
  17. # Get file location (Variables) from env file
  18. homedir='../'
  19. . env.sh
  20. # Variable to update
  21. doUpdate=false
  22. # Check if there is a new app
  23. CurrentNumOfApps=$( ls "$appsfolder" | wc -l )
  24. PreviousNumOfApps=$( head -n -1 "$verificationFile" | wc -l)
  25. [[ $CurrentNumOfApps -eq $PreviousNumOfApps ]] || doUpdate=true
  26. # Check if Template or appinfo has changed
  27. sha256sum -c --quiet "$verificationFile" &> /dev/null || doUpdate=true
  28. if $doUpdate ; then
  29. # Make sure tmp folder exists
  30. mkdir -p "$( dirname -- "$verificationFile" )"
  31. echo "Updating documentation..."
  32. # Run all scripts
  33. echo "Starting joinApps.sh..."
  34. ./joinApps.sh
  35. echo "Starting generateAppList..."
  36. ./generators/generateAppList.sh
  37. echo "Starting generateDocList..."
  38. ./generators/generateDocList.sh
  39. echo "Starting generateREADME..."
  40. ./generators/generateREADME.sh
  41. echo "Starting generateToolsREADME..."
  42. ./generators/generateToolsREADME.sh
  43. echo "Update finished"
  44. # Update lastrun.sha256
  45. sha256sum "$appinfo" > "$verificationFile"
  46. find "$appsfolder" -type f -name '*.json' -exec sha256sum {} + >> "$verificationFile"
  47. # Add files to stagging
  48. git add -- "$README"
  49. git add -- "$TOOLSREADME"
  50. git add -- "$AppList"
  51. git add -- "$DocList"
  52. fi