Newer
Older
backup-commander / install / install.sh
  1. #!/bin/bash
  2.  
  3. # This script must be run as the web user which must be specified as the first parameter
  4. # You may also need to use sudo to invoke the script unless you already have the correct
  5. # permissions to switch user (su)
  6.  
  7. # NOTE:
  8. # This install is designed to be run in place at the webserver location. It is not meant to be run from a
  9. # dev environment. For that use update-from-dev.sh
  10.  
  11.  
  12. # Params check
  13. if [ $# != 1 ]; then
  14. echo "There must be 1 args. Usage:"
  15. echo "./install.sh www-user"
  16. exit;
  17. fi
  18.  
  19. webuser=$1
  20.  
  21. prompt_confirm() {
  22. while true; do
  23. read -r -n 1 -p "${1:-Continue?} [y/n]: " REPLY
  24. case $REPLY in
  25. [yY]) echo ; return 0 ;;
  26. [nN]) echo ; return 1 ;;
  27. *) printf " \033[31m %s \n\033[0m" "invalid input"
  28. esac
  29. done
  30. }
  31.  
  32. echo
  33. echo "This script will git-pull and apply the latest changes"
  34. prompt_confirm "Do you wish to update?" || exit 0
  35.  
  36. echo "Switching user to $webuser"
  37. # won't work on its own. Need sudo and feed it a command string
  38. # su -s /bin/bash $webuser
  39.  
  40. sudo su -s /bin/bash $webuser << EOF
  41. git pull
  42. echo "Running install.php"
  43. php install.php
  44. EOF
  45.