update-host-config 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #!/bin/sh
  2. exec >>/var/log/host-config.log
  3. date
  4. d=$(date '+%s')
  5. if ! curl -sLIf git.apiote.xyz >/dev/null
  6. then
  7. echo 'git.apiote.xyz is not available; exiting'
  8. exit
  9. fi
  10. echo 'pulling changes'
  11. git stash
  12. git pull
  13. if [ "$(stat -c '%Y' /usr/share/secrets/secrets.tar.age)" -gt "$d" ]
  14. then
  15. echo 'secrets are new; notifying'
  16. # TODO probably send email
  17. # # shellcheck disable=SC2016
  18. # notify-send 'Host-Config' 'There are new secrets. Decrypt using `secrets decrypt`'
  19. fi
  20. if [ "$(stat -c '%Y' /etc/apk/world)" -gt "$d" ]
  21. then
  22. echo 'world is new; fixing'
  23. apk fix
  24. fi
  25. if [ "$(stat -c '%Y' /etc/network/interfaces)" -gt "$d" ]
  26. then
  27. echo 'interfaces is new; restarting network'
  28. /etc/init.d/network restart
  29. fi
  30. for service in $(find /etc/conf.d | grep -v 'apk.new')
  31. do
  32. serviceName=$(basename "$service")
  33. if [ "$(stat -c '%Y' "$service")" -gt "$d" ] && (rc-update show | grep -e default -e boot | cut -d '|' -f 1 | tr -d ' ' | grep -q "$serviceName")
  34. then
  35. echo "config for $serviceName is new; restarting"
  36. "/etc/init.d/$serviceName" restart
  37. fi
  38. done
  39. for service in $(find /etc/init.d | grep -v 'apk.new')
  40. do
  41. serviceName=$(basename "$service")
  42. if [ "$(stat -c '%Y' "$service")" -gt "$d" ] && (rc-update show | grep -e default -e boot | cut -d '|' -f 1 | tr -d ' ' | grep -q "$serviceName")
  43. then
  44. echo "init script for $serviceName is new; restarting"
  45. "/etc/init.d/$serviceName" restart
  46. fi
  47. done