2021-07-05 00:01:04 -07:00
|
|
|
#!/bin/bash
|
2024-02-16 22:14:59 -08:00
|
|
|
|
|
|
|
# Print current user ID
|
|
|
|
id
|
2021-09-29 23:48:36 -07:00
|
|
|
|
2022-12-01 18:42:26 -08:00
|
|
|
# Ensure clean, non-root ownership of the htdocs directory.
|
|
|
|
chown -R $PUID:$PGID /usr/local/apache2/htdocs
|
2024-02-16 22:14:59 -08:00
|
|
|
|
|
|
|
# Delete index.html if it's the stock apache file. Otherwise it impedes the git clone.
|
2022-12-01 18:42:26 -08:00
|
|
|
if grep -Fq '<html><body><h1>It works!</h1></body></html>' "/usr/local/apache2/htdocs/index.html"; then
|
|
|
|
rm /usr/local/apache2/htdocs/index.html
|
|
|
|
fi
|
2021-09-29 23:48:36 -07:00
|
|
|
|
2022-12-01 18:42:26 -08:00
|
|
|
# If the user doesn't want to update from a source,
|
|
|
|
# check for local version.
|
|
|
|
# If local version is found, print version and start server.
|
|
|
|
# If no local version is found, print error message and exit.
|
|
|
|
if [ "$OFFLINE_MODE" = "TRUE" ]; then
|
2022-12-03 13:23:03 -08:00
|
|
|
echo " === Offline mode is enabled. Will try to launch from local files. Checking for local version..."
|
2021-10-10 23:52:00 -07:00
|
|
|
if [ -f /usr/local/apache2/htdocs/package.json ]; then
|
|
|
|
VERSION=$(jq -r .version package.json) # Get version from package.json
|
|
|
|
echo " === Starting version $VERSION"
|
2022-12-01 18:42:26 -08:00
|
|
|
httpd-foreground
|
2021-08-01 14:22:43 -07:00
|
|
|
else
|
2021-09-29 23:48:36 -07:00
|
|
|
echo " === No local version detected. Exiting."
|
2021-08-01 14:22:43 -07:00
|
|
|
exit 1
|
2021-09-30 00:31:33 -07:00
|
|
|
fi
|
2022-12-01 18:42:26 -08:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Move to the working directory for working with files.
|
|
|
|
cd /usr/local/apache2/htdocs
|
|
|
|
|
2024-02-16 22:14:59 -08:00
|
|
|
DL_LINK=${DL_LINK:-https://github.com/5etools-mirror-2/5etools-mirror-2.github.io.git}
|
|
|
|
IMG_LINK=${IMG_LINK:-https://github.com/5etools-mirror-2/5etools-img}
|
2023-08-21 16:33:29 -07:00
|
|
|
|
2024-02-16 22:14:59 -08:00
|
|
|
echo " === Using GitHub mirror at $DL_LINK"
|
|
|
|
if [ ! -d "./.git" ]; then # if no git repository already exists
|
|
|
|
echo " === No existing git repository, creating one"
|
|
|
|
git config --global user.email "autodeploy@localhost"
|
|
|
|
git config --global user.name "AutoDeploy"
|
|
|
|
git config --global pull.rebase false # Squelch nag message
|
|
|
|
git config --global --add safe.directory '/usr/local/apache2/htdocs' # Disable directory ownership checking, required for mounted volumes
|
|
|
|
git clone $DL_LINK . # clone the repo with no files and no object history
|
|
|
|
else
|
|
|
|
echo " === Using existing git repository"
|
|
|
|
git config --global --add safe.directory '/usr/local/apache2/htdocs' # Disable directory ownership checking, required for mounted volumes
|
|
|
|
fi
|
2021-09-29 23:48:36 -07:00
|
|
|
|
2024-02-16 22:43:27 -08:00
|
|
|
if [[ "$IMG" == "TRUE" ]]; then # if user wants images
|
2024-02-16 22:14:59 -08:00
|
|
|
echo " === Pulling images from GitHub... (This will take a while)"
|
|
|
|
git submodule add -f $IMG_LINK /usr/local/apache2/htdocs/img
|
|
|
|
fi
|
2021-09-29 23:48:36 -07:00
|
|
|
|
2024-02-16 22:14:59 -08:00
|
|
|
echo " === Pulling latest files from GitHub..."
|
|
|
|
git checkout
|
|
|
|
git fetch
|
|
|
|
git pull --depth=1
|
|
|
|
VERSION=$(jq -r .version package.json) # Get version from package.json
|
2021-09-29 23:48:36 -07:00
|
|
|
|
2024-02-16 22:14:59 -08:00
|
|
|
if [[ `git status --porcelain` ]]; then
|
|
|
|
git restore .
|
|
|
|
fi
|
2022-12-03 13:23:03 -08:00
|
|
|
|
2024-02-16 22:14:59 -08:00
|
|
|
echo " === Starting version $VERSION"
|
2021-09-29 23:48:36 -07:00
|
|
|
|
2024-02-16 22:14:59 -08:00
|
|
|
httpd-foreground
|