Skip to content

Commit

Permalink
#16 Deprecate all mention of get.5e.tools
Browse files Browse the repository at this point in the history
Simplify configuration
Update dead wiki link
Update docs
  • Loading branch information
Jafner committed Feb 17, 2024
1 parent 497e602 commit 1612750
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 116 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ ENV PGID=${PGID:-1000}
COPY init.sh /init.sh
RUN apt-get update && \
apt-get -y upgrade && \
apt-get -y install curl p7zip-full megatools git jq && \
apt-get -y install curl git jq && \
chmod +x /init.sh

RUN echo "<Location /server-status>\n"\
Expand Down
15 changes: 6 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
This is a simple image for hosting your own 5eTools instance. It is based on the Apache `httpd` image and uses components of the auto-updater script from the [5eTools wiki](https://wiki.5e.tools/index.php/5eTools_Install_Guide). This image is built from [this GitHub repository](https://github.com/Jafner/5etools-docker).
This is a simple image for hosting your own 5eTools instance. It is based on the Apache `httpd` image and uses components of the auto-updater script from the [5eTools wiki](https://wiki.tercept.net/en/5eTools/InstallGuide). This image is built from [this GitHub repository](https://github.com/Jafner/5etools-docker).

# Usage
Below we talk about how to install and configure the container.
Expand Down Expand Up @@ -52,18 +52,14 @@ volumes:
The image uses environment variables to figure out how you want it to run.
By default, I assume you want to automatically download the latest files from the Github mirror. Use the environment variables in the `docker-compose.yml` file to configure things.

### SOURCE (defaults to GITHUB-NOIMG)
### IMG (defaults to FALSE)
Required unless OFFLINE_MODE=TRUE.
Expects one of "GITHUB", "GITHUB-NOIMG", "GET5ETOOLS", or "GET5ETOOLS-NOIMG". Where:
> "GITHUB" pulls from https://github.com/5etools-mirror-1/5etools-mirror-1
> "GITHUB-NOIMG" pulls from https://github.com/5etools-mirror-1/5etools-mirror-1 without image files.
> "GET5ETOOLS" pulls from https://get.5e.tools
> "GET5ETOOLS-NOIMG" pulls from https://get.5e.tools without image files.
Expects one of "TRUE", "FALSE" Where:
> "TRUE" pulls from https://github.com/5etools-mirror-2/5etools-mirror-2.github.io.git and adds https://github.com/5etools-mirror-2/5etools-img as a submodule for image files.
> "FALSE" pulls from https://github.com/5etools-mirror-2/5etools-mirror-2.github.io.git without image files.
The get.5e.tools source has been down (redirecting to 5e.tools) during development. This method is not tested.

**Note: As of December 2022, get.5e.tools has been down for several months**. The URL redirects to the main 5etools page, but does not provide packaged archives of the site like it used to. I will update this if or when the original get.5e.tools returns.

### OFFLINE_MODE
Optional. Expects "TRUE" to enable.
Setting this to true tells the server to run from the local files if available, or exits if there is no local version.
Expand Down Expand Up @@ -105,5 +101,6 @@ Then your `index.json` should look like:
]
}
```

Note the commas after each entry except the last in each array.
See the [wiki page](https://wiki.5e.tools/index.php/5eTools_Install_Guide) for more information.
13 changes: 2 additions & 11 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,8 @@ services:
ports:
- 8080:80/tcp
environment:
- SOURCE=GITHUB
# Required unless OFFLINE_MODE=TRUE and the site files are already present.
# Expects one of GITHUB, GITHUB-NOIMG, GET5ETOOLS, or GET5ETOOLS-NOIMG. Where:
# GITHUB pulls from https://github.com/5etools-mirror-2/5etools-mirror-2.github.io and adds https://github.com/5etools-mirror-2/5etools-img as a submodule
# GITHUB-NOIMG pulls from https://github.com/5etools-mirror-2/5etools-mirror-2.github.io without adding the images submodule.
# GET5ETOOLS pulls from https://get.5e.tools
# GET5ETOOLS-NOIMG pulls from https://get.5e.tools without image files.
# The get.5e.tools source has been down (redirecting to 5e.tools) during development.
# This method is not tested.
#- OFFLINE_MODE=TRUE
# Optional. Expects "TRUE" or "FALSE".
- IMG=FALSE # Set to TRUE to pull images from https://github.com/5etools-mirror-2/5etools-img (as a Git submodule)
#- OFFLINE_MODE=TRUE # Optional. Expects "TRUE" or "FALSE". Disables checking for new updates.

# Uncomment this block to use a docker-managed volume:
#volumes:
Expand Down
128 changes: 33 additions & 95 deletions init.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
#!/bin/bash
# based (loosely) on: https://wiki.5e.tools/index.php/5eTools_Install_Guide

# Print current user ID
id

# Ensure clean, non-root ownership of the htdocs directory.
# Delete index.html if it's the stock apache file. Otherwise it impedes the git clone.
chown -R $PUID:$PGID /usr/local/apache2/htdocs

# Delete index.html if it's the stock apache file. Otherwise it impedes the git clone.
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
Expand All @@ -24,108 +27,43 @@ if [ "$OFFLINE_MODE" = "TRUE" ]; then
fi
fi

# The SOURCE variable must be set if OFFLINE_MODE is not TRUE
if [ -z "${SOURCE}" ]; then
echo " === SOURCE variable not set. Expects one of \"GITHUB\", \"GET5ETOOLS\", or \"GET5ETOOLS-NOIMG\". Exiting."
exit 1
fi

# Move to the working directory for working with files.
cd /usr/local/apache2/htdocs

echo " === Checking directory permissions for /usr/local/apache2/htdocs"
ls -ld /usr/local/apache2/htdocs

SOURCE=${SOURCE}
echo "SOURCE=$SOURCE"
case $SOURCE in
GITHUB | GITHUB-NOIMG) # Source is the github mirror
DL_LINK=${GIT_URL:-https://github.com/5etools-mirror-2/5etools-mirror-2.github.io.git}
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
if ! [[ "$SOURCE" == *"NOIMG"* ]]; then # if user does want images
echo " === Pulling images from GitHub... (This will take a while)"
git submodule add -f https://github.com/5etools-mirror-2/5etools-img /usr/local/apache2/htdocs/img
fi
echo " === Pulling main files from GitHub..."
git checkout
git fetch
git pull --depth=1
VERSION=$(jq -r .version package.json) # Get version from package.json
if [[ `git status --porcelain` ]]; then
git restore .
fi
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}

echo " === Starting version $VERSION"
httpd-foreground
;;

GET5ETOOLS | GET5ETOOLS-NOIMG)
DL_LINK=https://get.5e.tools
echo " === Using get structure to download from $DL_LINK"
echo " === WARNING: This part of the script has not yet been tested. Please open an issue on the github if you have trouble."
# get remote version number
# takes three steps of wizardry. I did not write this, but it works so I don't touch it.
FILENAME=`curl -s -k -I $DL_LINK/src/|grep filename|cut -d"=" -f2 | awk '{print $1}'` # returns like "5eTools.1.134.0.zip" (with quotes)
FILENAME=${FILENAME//[$'\t\r\n"']} # remove quotes, returns like 5eTools.1.134.0.zip
REMOTE_VERSION=`basename ${FILENAME} ".zip"|sed 's/5eTools\.//'` # get version number, returns like 1.134.0
if [ "$REMOTE_VERSION" != "$VERSION" ]; then
echo " === Local version ($VERSION) outdated, updating to $REMOTE_VERSION ..."
rm ./index.html 2> /dev/null || true
echo " === Downloading new remote version..."
mkdir -p ./download
cd ./download/
curl --progress-bar -k -O -J $DL_LINK/src/ -C -

if [ "$SOURCE" != *"NOIMG"* ]; then # download images
echo " === Downloading images... "
curl --progress-bar -k -O -J $DL_LINK/img/ -C -
fi

cd ..

echo " === Extracting site..."
7z x ./download/$FILENAME -o./ -y

if [ "$SOURCE" != *"NOIMG"* ]; then # extract images
echo " === Extracting images..."
7z x ./download/$FILENAME_IMG -o./img -y
mv ./img/tmp/5et/img/* ./img
rm -r ./img/tmp
fi
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

echo " === Configuring..." # honestly I don't know enough HTML/CSS/JS to tell exactly what this part of the script does :L
find . -name \*.html -exec sed -i 's/"width=device-width, initial-scale=1"/"width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no"/' {} \;
sed -i 's/<head>/<head>\n<link rel="apple-touch-icon" href="icon\/icon-512.png">/' index.html
sed -i 's/navigator.serviceWorker.register("\/sw.js/navigator.serviceWorker.register("sw.js/' index.html
sed -i 's/navigator.serviceWorker.register("\/sw.js/navigator.serviceWorker.register("sw.js/' 5etools.html
if ! [[ "$IMG" == "TRUE" ]]; then # if user wants images
echo " === Pulling images from GitHub... (This will take a while)"
git submodule add -f $IMG_LINK /usr/local/apache2/htdocs/img
fi

echo " === Cleaning up downloads"
find ./download/ -type f ! -name "*.${VER}.zip" -exec rm {} + # delete the downloaded zip files
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

echo " === Done!"
else
echo " === Local version matches remote, no action."
fi
VERSION=$(jq -r .version package.json) # Get version from package.json
echo " === Starting version $VERSION"
httpd-foreground
;;
if [[ `git status --porcelain` ]]; then
git restore .
fi


*)
echo "SOURCE variable set incorrectly. Exiting..."
exit
;;
echo " === Starting version $VERSION"

esac
httpd-foreground

0 comments on commit 1612750

Please sign in to comment.