export TRIVABBLE_SERVER_PATH=/opt/trivabble-server
export TRIVABBLE_PUBLIC_PATH=/var/www/html/trivabble
- sudo useradd trivabble
+ sudo groupadd trivabble
+ sudo useradd -G trivabble trivabble
sudo mkdir -p "$TRIVABBLE_PUBLIC_PATH"
- sudo chown trivabble:www-data "$TRIVABBLE_PUBLIC_PATH"
+ sudo chown www-data:www-data "$TRIVABBLE_PUBLIC_PATH"
sudo chmod g+x "$TRIVABBLE_PUBLIC_PATH"
sudo mkdir -p "$TRIVABBLE_SERVER_PATH"
- sudo chown trivabble "$TRIVABBLE_PUBLIC_PATH"
+ sudo chown trivabble:trivabble "$TRIVABBLE_PUBLIC_PATH"
```
2. Clone the repository somewhere (in your HOME directory for instance):
Also make sure you still are in the trivabble repository.
-5. Run:
+5. Run, as a user having sudo privileges:
```sh
- sudo -H -u www-data ./bin/upgrade-prod.sh --prod-public-dir "$TRIVABBLE_PUBLIC_PATH" --prod-server-dir "$TRIVABBLE_SERVER_PATH"
+ ./bin/upgrade-prod.sh --prod-public-dir "$TRIVABBLE_PUBLIC_PATH" --prod-server-dir "$TRIVABBLE_SERVER_PATH" --trivabble-chown trivabble:trivabble --webserver-chown www-data:www-data
```
This will:
Parameters:
--prod-public-dir DIR: the path to the public directory, from which your HTTP server will serve the client
--prod-server-dir DIR: the path to the server directory, not served by your HTTP server.
+ --webserver-chown USER: the user:group chown string to use for the webserver directory
+ --trivabble-chown USER: the user:group chown string to use for the server directory
+ --no-git: do not attempt to fetch the last production revision
+ --allow-root: allow running the script as root. Must be the first parameter.
EOF
exit 0
}
if [ "$(id -u)" = "0" ]; then
- error "Not running as root. Please run me as your webserver's user for instance, using something like sudo -H -u www-data $0 $1"
+ if [ "$1" = "--allow-root" ]; then
+ shift
+ else
+ error "Not running as root. Please run me as a normal user with sudo rights, using something like sudo -H -u user $0 $@"
+ fi
fi
+NO_GIT=false
+
while ! [ -z "${1+x}" ]; do
if [ "$1" = "--prod-public-dir" ]; then
- PROD_PUBLIC_DIR=$2
+ export PROD_PUBLIC_DIR=$2
shift
shift
elif [ "$1" = "--prod-server-dir" ]; then
- PROD_SERVER_DIR=$2
+ export PROD_SERVER_DIR=$2
+ shift
+ shift
+ elif [ "$1" = "--trivabble-chown" ]; then
+ export TRIVABBLE_CHOWN=$2
+ shift
+ shift
+ elif [ "$1" = "--webserver-chown" ]; then
+ export WEBSERVER_CHOWN=$2
shift
shift
+ elif [ "$1" = "--no-git" ]; then
+ export NO_GIT=true
+ shift
elif [ "$1" = "--help" ] || [ "$1" = "-h" ]; then
help
else
error "The public production directory is not set. Type --help for more information."
fi
+if [ -z "${TRIVABBLE_CHOWN+x}" ]; then
+ error "The trivabble chown string is not set. Type --help for more information."
+fi
+
+if [ -z "${WEBSERVER_CHOWN+x}" ]; then
+ error "The webserver chown string is not set. Type --help for more information."
+fi
+
if ! [ -d "$PROD_SERVER_DIR" ]; then
error "The server production directory $PROD_SERVER_DIR does not exist. I give up."
fi
# Thx https://stackoverflow.com/questions/17414104/git-checkout-latest-tag
-echo "Fetching updates from git"
-git fetch
-new_version="$(git tag --list '[prod]*' --sort=v:refname | tail -1)"
+if ! [ "${NO_GIT}" = "true" ]; then
+ echo "Fetching updates from git"
+ git fetch
+ new_version="$(git tag --list '[prod]*' --sort=v:refname | tail -1)"
+
+ echo "Checking out ${new_version}..."
+ git checkout "$new_version"
-echo "Checking out ${new_version}..."
-git checkout "$new_version"
+ # Re-execute the updated upgrade-prod.sh script
+ # Relies on environment variables being set in the current run
+ exec "$0" --allow-root --no-git
+fi
echo "Setting up production mode..."
"$(dirname $0)"/setup_prod.sh
echo "Sending to production..."
-rsync -avp --delete --exclude 'config.js' "$WORKING_DIRECTORY/public/" "$PROD_PUBLIC_DIR/"
-rsync -avp --delete --exclude 'config.js' "$WORKING_DIRECTORY/server/" "$PROD_SERVER_DIR/"
+sudo rsync --chown="$WEBSERVER_CHOWN" -O -avp --delete --exclude 'config.js' "$WORKING_DIRECTORY/public/" "$PROD_PUBLIC_DIR/"
+sudo rsync --chown="$TRIVABBLE_CHOWN" -O -avp --delete --exclude 'games.backup.json' "$WORKING_DIRECTORY/server/" "$PROD_SERVER_DIR/"
echo echo "Resetting the directory..."
-git reset --hard "$new_version"
+git reset --hard HEAD