update.sh 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. # Stopping mailcow
  7. docker-compose down
  8. for image in "phpfpm" "dovecot" "postfix" "sogo" "unbound" "rspamd" "clamd" "fail2ban"; do
  9. if [[ ! -z $(docker images mailcow/${image} -q) ]]; then
  10. echo -e "\e[32mSaving mailcow/${image} to mailcow/${image}:${DATE}...\e[90m"
  11. docker tag mailcow/${image} mailcow/${image}:${DATE}
  12. fi
  13. done
  14. # Fix missing SSL, does not overwrite existing files
  15. [[ ! -d data/assets/ssl ]] && mkdir -p data/assets/ssl
  16. cp -n data/assets/ssl-example/*.pem data/assets/ssl/
  17. # Silently fixing remote url from andryyy to mailcow
  18. git remote set-url origin https://github.com/mailcow/mailcow-dockerized
  19. echo -e "\e[32mCommitting current status...\e[90m"
  20. git add -u
  21. git commit -am "Before update on ${DATE}" > /dev/null
  22. echo -e "\e[32mFetching updated code from remote...\e[90m"
  23. git fetch origin ${BRANCH}
  24. echo -e "\e[32mMerging local with remote code...\e[90m"
  25. git merge -Xtheirs -Xpatience -m "After update on ${DATE}"
  26. if [[ $? == 1 ]]; then
  27. echo -e "\e[31mRun into conflict, trying to fix...\e[90m"
  28. git status --porcelain | grep -E "UD|DU" | awk '{print $2}' | xargs rm -v
  29. git add -A
  30. git commit -m "After update on ${DATE}" > /dev/null
  31. git checkout .
  32. echo -e "\e[32mRemoved and recreated files if necessary.\e[90m"
  33. fi
  34. echo -e "\e[32mFetching new images, if any...\e[0m"
  35. docker-compose pull
  36. echo
  37. #echo -e "\e[32mHashes to revert to:\e[0m"
  38. #git reflog --color=always | grep "Before update on "
  39. # TODO: Menu, select hard reset, select reset to "before update" etc.
  40. #git reset --hard origin/${BRANCH}