Fix scripts in bin/ to work with the public folder
This commit is contained in:
parent
853680c352
commit
2b5182ac85
|
@ -1,2 +1,2 @@
|
|||
/games.backup.json
|
||||
/server/games.backup.json
|
||||
/public/config.js
|
||||
|
|
|
@ -9,7 +9,7 @@ WORKING_DIRECTORY="$(dirname "$(dirname "$0")")"
|
|||
|
||||
if [ -d "$WORKING_DIRECTORY/.git" ]; then
|
||||
if [ -z "$(git status --porcelain | grep '.js$')" ]; then
|
||||
sed -i -E 's/(^|\(|\s)(let|const)(\s)/\1var\3/g' "$WORKING_DIRECTORY"/*.js
|
||||
sed -i -E 's/(^|\(|\s)(let|const)(\s)/\1var\3/g' "$WORKING_DIRECTORY/public"/*.js
|
||||
else
|
||||
>&2 echo "You have untracked changes in JS files. I'm not going to mess up with your working copy."
|
||||
exit 1
|
||||
|
|
|
@ -2,6 +2,6 @@
|
|||
|
||||
exec "$(dirname "$0")/disable-const-let.sh"
|
||||
|
||||
if ! [ -f "$(dirname "$(dirname "$0")")/config.js" ]; then
|
||||
touch "$(dirname "$(dirname "$0")")/config.js"
|
||||
if ! [ -f "$(dirname "$(dirname "$0")")/public/config.js" ]; then
|
||||
touch "$(dirname "$(dirname "$0")")/public/config.js"
|
||||
fi
|
||||
|
|
|
@ -7,22 +7,56 @@ error() {
|
|||
exit 1
|
||||
}
|
||||
|
||||
if [ -z "${1+x}" ]; then
|
||||
error "Please provide the production directory in parameter."
|
||||
fi
|
||||
help() {
|
||||
cat <<EOF
|
||||
$0: - update the production.
|
||||
|
||||
This program updates Trivabble to the latest version tagged for production, and copies and prepares Trivabble for use in production.
|
||||
Trivabble is composed of two parts: the server and the client.
|
||||
The client is to be served by a regular HTTP server and lives in the public folder.
|
||||
The server is to be stored somewhere on your system that is not served by your HTTP server.
|
||||
|
||||
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.
|
||||
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"
|
||||
fi
|
||||
|
||||
PROD_DIR="$1"
|
||||
while ! [ -z "${1+x}" ]; do
|
||||
if [ "$1" = "--prod-public-dir" ]; then
|
||||
PROD_PUBLIC_DIR=$2
|
||||
shift
|
||||
shift
|
||||
elif [ "$1" = "--prod-server-dir" ]; then
|
||||
PROD_SERVER_DIR=$2
|
||||
shift
|
||||
shift
|
||||
elif [ "$1" = "--help" ] || [ "$1" = "-h" ]; then
|
||||
help
|
||||
else
|
||||
error "Unrecognized argument $1. Type --help for more information."
|
||||
fi
|
||||
done
|
||||
|
||||
if ! [ -d "$PROD_DIR" ]; then
|
||||
error "The production directory $PROD_DIR does not exist. I give up."
|
||||
if [ -z "${PROD_SERVER_DIR+x}" ]; then
|
||||
error "The server production directory is not set. Type --help for more information."
|
||||
fi
|
||||
|
||||
if [ -d "$PROD_DIR/.git" ]; then
|
||||
error "The production folder should not be a git repository."
|
||||
if [ -z "${PROD_PUBLIC_DIR+x}" ]; then
|
||||
error "The public production directory 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
|
||||
|
||||
if ! [ -d "$PROD_PUBLIC_DIR" ]; then
|
||||
error "The public production directory $PROD_PUBLIC_DIR does not exist. I give up."
|
||||
fi
|
||||
|
||||
WORKING_DIRECTORY="$(dirname "$(dirname "$0")")"
|
||||
|
@ -31,7 +65,7 @@ if ! [ -d "$WORKING_DIRECTORY/.git" ]; then
|
|||
error "Not a git repository. Cannot update."
|
||||
fi
|
||||
|
||||
if [ -f "$WORKING_DIRECTORY/games.backup.json" ]; then
|
||||
if [ -f "$WORKING_DIRECTORY/server/games.backup.json" ] || [ -f "$WORKING_DIRECTORY/games.backup.json" ]; then
|
||||
error "Your working copy has a 'games.backup.json' file. I give up."
|
||||
fi
|
||||
|
||||
|
@ -51,13 +85,9 @@ git checkout "$new_version"
|
|||
echo "Setting up production mode..."
|
||||
"$(dirname $0)"/setup_prod.sh
|
||||
|
||||
BACKUP_DIR="$WORKING_DIRECTORY/../trivabble-prod.bak"
|
||||
|
||||
echo "Backing up production to $BACKUP_DIR ..."
|
||||
rsync -avp --delete "$PROD_DIR/" "$BACKUP_DIR/"
|
||||
|
||||
echo "Sending to production..."
|
||||
rsync -avp --delete --exclude 'games.backup.json' --exclude 'config.js' --exclude '/.git' "$WORKING_DIRECTORY/" "$PROD_DIR/"
|
||||
rsync -avp --delete --exclude 'config.js' "$WORKING_DIRECTORY/public/" "$PROD_PUBLIC_DIR/"
|
||||
rsync -avp --delete --exclude 'config.js' "$WORKING_DIRECTORY/server/" "$PROD_SERVER_DIR/"
|
||||
|
||||
echo echo "Resetting the directory..."
|
||||
git reset --hard "$new_version"
|
||||
|
|
Loading…
Reference in New Issue