update.sh 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. #!/bin/bash
  2. set -o pipefail
  3. export LC_ALL=C
  4. DATE=$(date +%Y-%m-%d_%H_%M_%S)
  5. BRANCH=$(git rev-parse --abbrev-ref HEAD)
  6. for image in "phpfpm" "dovecot" "postfix" "sogo" "unbound" "rspamd" "clamd"; do
  7. if [[ ! -z $(docker images mailcow/${image} -q) ]]; then
  8. echo -e "\e[32mSaving mailcow/${image} to mailcow/${image}:${DATE}...\e[90m"
  9. docker tag mailcow/${image} mailcow/${image}:${DATE}
  10. fi
  11. done
  12. # Silently fixing remote url from andryyy to mailcow
  13. git remote set-url origin https://github.com/mailcow/mailcow-dockerized
  14. echo -e "\e[32mCommitting current status...\e[90m"
  15. git add -u
  16. git commit -am "Before update on ${DATE}" > /dev/null
  17. echo -e "\e[32mFetching updated code from remote...\e[90m"
  18. git fetch origin master
  19. echo -e "\e[32mMerging local with remote code...\e[90m"
  20. git merge -Xtheirs -Xpatience -m "After update on ${DATE}"
  21. if [[ $? == 1 ]]; then
  22. echo -e "\e[31mRun into conflict, trying to fix...\e[90m"
  23. git status --porcelain | grep -E "UD|DU" | awk '{print $2}' | xargs rm -v
  24. git add -A
  25. git commit -m "After update on ${DATE}" > /dev/null
  26. git checkout .
  27. echo -e "\e[32mRemoved and recreated files if necessary.\e[90m"
  28. fi
  29. echo -e "\e[32mDone!\e[0m"
  30. echo
  31. echo -e "\e[32mHashes to revert to:\e[0m"
  32. git reflog --color=always | grep "Before update on "
  33. # TODO: Menu, select hard reset, select reset to "before update" etc.
  34. #git reset --hard origin/${BRANCH}