update-firmware 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. #!/bin/bash
  2. # (c) 2016 Freifunk Hochstift <kontakt@hochstift.freifunk.net>
  3. #
  4. DEFAULT_DIR="{{ salt['pillar.get']('node:path:firmware') }}"
  5. DEFAULT_BRANCHES="stable testing experimental"
  6. getCurrentVersion() {
  7. # Get hash from latest revision
  8. git log --format=format:%H -1 | tr -d '\n'
  9. }
  10. function createChangelog {
  11. VERSION=$1
  12. VERSION_DIR=${FIRMWARE_DIR}/${VERSION}
  13. if [ ! -d "${VERSION_DIR}" ]; then
  14. echo "${VERSION} directory not found (${VERSION_DIR})."
  15. return 1
  16. fi
  17. rm -f ${VERSION_DIR}/Changelog.html
  18. if [ -r "${VERSION_DIR}/Changelog.md" ]; then
  19. [ "${VERBOSE}" -eq "1" ] && echo "create ${VERSION}/Changelog.html"
  20. pandoc -f markdown -t html5 -o ${VERSION_DIR}/Changelog.html -s -V pagetitle="FFHO Changelog (${VERSION})" ${VERSION_DIR}/Changelog.md > /dev/null
  21. [ "$?" -eq "0" ] || echo "failed to create ${VERSION}/Changelog.html"
  22. fi
  23. return 0
  24. }
  25. [ -n "${FIRMWARE_DIR}" ] || FIRMWARE_DIR=${DEFAULT_DIR}
  26. [ -n "${FORCE}" ] || FORCE=0
  27. [ -n "${BRANCHES}" ] || BRANCHES=${DEFAULT_BRANCHES}
  28. [ -n "${VERBOSE}" ] || VERBOSE=0
  29. if [ ! -d "${FIRMWARE_DIR}" ]; then
  30. echo "Firmware directory not found (${FIRMWARE_DIR}). Cannot update."
  31. exit 1
  32. fi
  33. if [ ! -d "${FIRMWARE_DIR}/.git" ]; then
  34. echo "Firmware directory does not seem to be a git repository. Cannot update."
  35. exit 1
  36. fi
  37. pushd ${FIRMWARE_DIR} > /dev/null
  38. # Get current version hash
  39. LAST_REVISION="$(getCurrentVersion)"
  40. if [ "$(git status --porcelain --untracked-files=no)" ]; then
  41. echo "Local changes to firmware directory. Cowardly refusing to update firmware-website.git!" >&2
  42. exit 1
  43. fi
  44. [ "${VERBOSE}" -eq "1" ] && echo "pull changes from remote repository"
  45. if ! git pull --quiet --rebase > /dev/null; then
  46. echo " => Update of firmware-website.git failed... :-(" >&2
  47. exit 2
  48. fi
  49. # Get new version hash
  50. NEW_REVISION="$(getCurrentVersion)"
  51. if [ "${LAST_REVISION}" != "${NEW_REVISION}" ] || [ "${FORCE}" -eq "1" ]; then
  52. for folder in *; do
  53. if [ -d "${folder}" -a ! -L "${folder}" ]; then
  54. createChangelog ${folder}
  55. fi
  56. done
  57. [ "${VERBOSE}" -eq "1" ] && echo ""
  58. # Get list of commits since last local version
  59. num_commits="$(git log --abbrev-commit --pretty=oneline ${LAST_REVISION}..${NEW_REVISION} | wc -l)"
  60. last_msg="$(git log --abbrev-commit --pretty=oneline ${LAST_REVISION}..${NEW_REVISION} | head -n1)"
  61. # Update models.json
  62. scripts/buildModels.py stable models.json
  63. echo "Firmware-Website updated: ${num_commits} commit(s) (last: ${last_msg})"
  64. fi
  65. [ "${VERBOSE}" -eq "1" ] && echo "Finish"
  66. popd > /dev/null #${FIRMWARE_DIR}