update-firmware 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. #!/bin/bash
  2. # (c) 2016 Freifunk Hochstift <kontakt@hochstift.freifunk.net>
  3. #
  4. DEFAULT_DIR="{{salt['pillar.get']('nodes:' ~ grains['id'] ~ ':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 "${BRANCHES}" ] || BRANCHES=${DEFAULT_BRANCHES}
  27. [ -n "${VERBOSE}" ] || VERBOSE=0
  28. if [ ! -d "${FIRMWARE_DIR}" ]; then
  29. echo "Firmware directory not found (${FIRMWARE_DIR}). Cannot update."
  30. exit 1
  31. fi
  32. if [ ! -d "${FIRMWARE_DIR}/.git" ]; then
  33. echo "Firmware directory does not seem to be a git repository. Cannot update."
  34. exit 1
  35. fi
  36. pushd ${FIRMWARE_DIR} > /dev/null
  37. # Get current version hash
  38. LAST_REVISION="$(getCurrentVersion)"
  39. if [ "$(git status --porcelain --untracked-files=no)" ]; then
  40. echo "Local changes to firmware directory. Cowardly refusing to update firmware-website.git!" >&2
  41. exit 1
  42. fi
  43. [ "${VERBOSE}" -eq "1" ] && echo "pull changes from remote repository"
  44. if ! git pull --quiet --rebase > /dev/null; then
  45. echo " => Update of firmware-website.git failed... :-(" >&2
  46. exit 2
  47. fi
  48. # Get new version hash
  49. NEW_REVISION="$(getCurrentVersion)"
  50. if [ "${LAST_REVISION}" != "${NEW_REVISION}" ] || [ "${FORCE}" -eq "1" ]; then
  51. for folder in *; do
  52. if [ -d "${folder}" -a ! -L "${folder}" ]; then
  53. createChangelog ${folder}
  54. fi
  55. done
  56. [ "${VERBOSE}" -eq "1" ] && echo ""
  57. # Get list of commits since last local version
  58. num_commits="$(git log --abbrev-commit --pretty=oneline ${LAST_REVISION}..${NEW_REVISION} | wc -l)"
  59. last_msg="$(git log --abbrev-commit --pretty=oneline ${LAST_REVISION}..${NEW_REVISION} | head -n1)"
  60. echo "Firmware-Website updated: ${num_commits} commit(s) (last: ${last_msg})"
  61. fi
  62. [ "${VERBOSE}" -eq "1" ] && echo "Finish"
  63. popd > /dev/null #${FIRMWARE_DIR}