You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

90 lines
3.1 KiB

6 years ago
6 years ago
6 years ago
  1. #!/bin/bash
  2. . /etc/shlib
  3. include parse
  4. include common
  5. include pretty
  6. start=$SECONDS
  7. if [ -z "$NO_UPDATE" -a -d "/opt/apps/myc-manage" ]; then
  8. MYC_UPDATE_VERSION="${MYC_UPDATE_VERSION:-master}"
  9. Elt "Checking if myc-manage requires update..."
  10. cd /opt/apps/myc-manage
  11. REMOTE_HEAD="$(git ls-remote origin "refs/heads/${MYC_UPDATE_VERSION}" 2>/dev/null | cut -f 1)"
  12. if [ -z "$REMOTE_HEAD" ]; then
  13. err "Can't find remote branch '$MYC_UPDATE_VERSION'."
  14. echo " - Either this branch is not available on 'origin' remote." >&2
  15. echo " - Either 'origin' remote is not correctly set." >&2
  16. exit 1
  17. fi
  18. HEAD="$(git rev-parse HEAD)"
  19. if [ "$REMOTE_HEAD" != "$HEAD" ]; then
  20. print_info "new version available"
  21. Wrap -d "Update myc-manage" <<EOF || exit 1
  22. if ! [ -d "/opt/apps/myc-manage" ]; then
  23. mkdir -p /opt/apps && cd /opt/apps
  24. git clone https://git.myceliandre.fr/Myceliandre/myc-manage.git -b "$MYC_UPDATE_VERSION"
  25. else
  26. cd /opt/apps/myc-manage &&
  27. git checkout "$MYC_UPDATE_VERSION" &&
  28. git pull -r || exit 1
  29. fi
  30. ln -sfn /opt/apps/myc-manage/bin/* /usr/local/sbin/
  31. find -L /usr/local/sbin -maxdepth 1 -type l -ilname /opt/apps/myc-manage/bin/\* -delete
  32. EOF
  33. Feed || exit 1
  34. export NO_UPDATE=1
  35. exec myc-update
  36. exit 0
  37. else
  38. print_info "up to date"
  39. Feedback noop
  40. fi
  41. fi
  42. Wrap -d "Updating 0k-charms" <<EOF || exit 1
  43. cd /opt/apps/0k-charms
  44. git pull -r
  45. EOF
  46. charm --debug apply docker-host || exit 1
  47. ## there seem to be an error now within compose when trying to download let's encrypt image.
  48. Wrap -d "Updating some docker images" <<EOF || exit 1
  49. docker pull docker.0k.io/letsencrypt
  50. EOF
  51. Wrap -d "Updating cron scripts" <<EOF || exit 1
  52. for d in /etc/cron.{d,daily,hourly,monthly,weekly}; do
  53. ln -sfn "/opt/apps/myc-manage\$d/"* "\$d/" &&
  54. find -L "\$d" -maxdepth 1 -type l -ilname "/opt/apps/myc-manage\$d/"\* -delete
  55. done
  56. EOF
  57. Wrap -d "Updating sysctl scripts" <<EOF || exit 1
  58. for d in /etc/sysctl.d; do
  59. ln -sfn "/opt/apps/myc-manage\$d/"* "\$d/" &&
  60. find -L "\$d" -maxdepth 1 -type l -ilname "/opt/apps/myc-manage\$d/"\* -delete
  61. done
  62. EOF
  63. if [ -f "/root/.bashrc" ]; then
  64. Wrap -d "Enable colors in bash" <<'EOF' || exit 1
  65. sed -ri 's/^# (export LS_OPTIONS=.--color=auto.)/\1/;
  66. s/^# (eval "`dircolors`")/\1/;
  67. s/^# (alias ls='"'ls \\\$LS_OPTIONS'"')/\1/' /root/.bashrc
  68. EOF
  69. fi
  70. for keyfile in {/root,/home/debian}/.ssh/authorized_keys; do
  71. [ -e "$keyfile" ] || continue
  72. sed -ri 's%^ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDri3GHzDt0Il0jv6zLjwkge48dN9tv11sqVNnKoDeUxzk4kn7Ng5ldd3p6dYL6Pa5NDqJUAhO/d/q08IWuwfEbtj8Yc/EkahcRwVD2imPceUeDgyCaOJhq7WO4c9d9yG8PnRO2\+Zk92a9L5vuELVLr4UHIQOs2/eFRY2/ODV8ebf5L1issGzfLd/IPhX5oJwMwKfqIFOP7KPQ26duHNRq4bYOD9ePW4shfxmyQDk6dSImFat05ErT\+X7703PcPx/PX2AIqqz95zqM6M26BywAohuaD5joxKgkd/mMIJylvT8GEYDlcLMHwnM7LtwtyJ1O9dkVpsibIqGy20KlAOGPf admin@0k$%ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIMV3USt/BLnXnUk7rk8v42mISZaXBZuULbh2vx2Amk7k admin@old0kreplacement%g' "$keyfile"
  73. done
  74. printf "Update finished ${GREEN}successfully${NORMAL} ${GRAY}(in %.2fs)${NORMAL}.\n" "$((SECONDS - start))"