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.

37 lines
1.0 KiB

6 months ago
  1. #!/usr/bin/bash
  2. set -Eeuo pipefail
  3. SECRET_KEY_BASE=TOTO_EST_FLUO
  4. ## FUNCTIONS
  5. function check_sudo_user {
  6. if [[ $(id -u) -eq 0 ]] || groups | grep -q sudo; then
  7. sudo --validate --prompt='sudo privilege required for further processing: '
  8. else
  9. >&2 echo 'current user not in the `sudo` group, aborted!'
  10. exit 10
  11. fi
  12. }
  13. function fetch_latest_version {
  14. sudo rm -rf /opt/egr
  15. sudo cp -r /home/pvincent/easy-going-rails /opt/egr
  16. sudo rm -rf /opt/egr/tmp/*
  17. sudo chown -R pvincent:pvincent /opt/egr
  18. }
  19. function bundle_and_populate {
  20. cd /opt/egr
  21. bundle install
  22. DATABASE_HOST=ct1.lxd RAILS_ENV=production SECRET_KEY_BASE=$SECRET_KEY_BASE rails db:migrate
  23. DATABASE_HOST=ct1.lxd RAILS_ENV=production SECRET_KEY_BASE=$SECRET_KEY_BASE rails assets:precompile
  24. }
  25. function systemd_restart {
  26. DATABASE_HOST=ct1.lxd RAILS_ENV=production SECRET_KEY_BASE=$SECRET_KEY_BASE rails server --port 7000
  27. }
  28. ## MAIN
  29. check_sudo_user
  30. fetch_latest_version
  31. bundle_and_populate
  32. systemd_restart