#!/bin/bash # This script must be run as the web user which must be specified as the first parameter # You may also need to use sudo to invoke the script unless you already have the correct # permissions to switch user (su) # NOTE: # This install is designed to be run in place at the webserver location. It is not meant to be run from a # dev environment. For that use update-from-dev.sh # Params check if [ $# != 1 ]; then echo "There must be 1 args. Usage:" echo "./install.sh www-user" exit; fi webuser=$1 prompt_confirm() { while true; do read -r -n 1 -p "${1:-Continue?} [y/n]: " REPLY case $REPLY in [yY]) echo ; return 0 ;; [nN]) echo ; return 1 ;; *) printf " \033[31m %s \n\033[0m" "invalid input" esac done } echo echo "This script will git-pull and apply the latest changes" prompt_confirm "Do you wish to update?" || exit 0 echo "Switching user to $webuser" # won't work on its own. Need sudo and feed it a command string # su -s /bin/bash $webuser sudo su -s /bin/bash $webuser << EOF git pull echo "Running install.php" php install.php EOF