Add offline handling

This commit is contained in:
Jafner 2021-08-01 14:22:43 -07:00
parent 9b66192226
commit d6b3f92934
2 changed files with 72 additions and 67 deletions

View File

@ -4,17 +4,9 @@ This is a simple image for hosting your own 5eTools instance. It is based on the
## Quickstart
You can quick-start this image by running:
`docker run -d -p 80:80 --rm --name 5etools-docker jafner/5etools-docker`
`docker run -d -p 80:80 --rm --name 5etools-docker -v 5etools:/usr/local/apache2/htdocs jafner/5etools-docker`
Then give the container a minute or two to come online and it will be accessible at `localhost`.
This is what each part of that command does:
```
docker run \ # this is the basic docker command to start a docker container from a given image
-d \ # this is the 'daemon' flag, which allows the container to run in the background
-p 80:80 \ # this is the port flag which maps port 80 on the host to port 80 inside the container. You can change the host port mapping to something else (such as 8080) if you already have something running on port 80.
--rm \ # this is the remove flag, it tells docker to delete the container when it stops running. This is an option for portability.
--name 5etools-docker \ # this tells docker to set the name of the new container to 5etools-docker, rather than auto-generate a name. You can change this to whatever you like.
jafner/5etools-docker # this is the docker image you want to run. jafner is the repository and 5etools-docker is the specific image.
```
When you stop the container, it will automatically delete itself, but the downloaded files will remain in the 5etools volume, so you can always start the container back up by re-running the command.
### Getting token images
You can configure the container's initialization script to download image files by setting the `IMG` environment variable:

View File

@ -2,68 +2,81 @@
# based on: https://wiki.5e.tools/index.php/5eTools_Install_Guide
echo "STARTING" > /status
curl -s get.5e.tools > /dev/null
FN=`curl -s -k -I https://get.5e.tools/src/|grep filename|cut -d"=" -f2 | awk '{print $1}'` # get filename of most recent version
FN=${FN//[$'\t\r\n"']} # remove quotes
echo "FN: $FN"
FN_IMG=`curl -s -k -I https://get.5e.tools/img/|grep filename|cut -d"=" -f2 | awk '{print $1}'` # get filename of most recent image pack
FN_IMG=${FN_IMG//[$'\t\r\n"']} # remove quotes
echo "FN_IMG: $FN_IMG"
VER=`basename ${FN} ".zip"|sed 's/5eTools\.//'` # get version number
echo "VER: $VER"
CUR=$(<version)
echo " === Remote version: $VER"
echo " === Local version: $CUR"
if [ "$VER" != "$CUR" ]
if [ $? = 0 ] # if the get.5e.tools site is accessible
then
echo " === Local version outdated, updating..."
echo -n $VER > version
echo "DOWNLOADING" > /status
echo "CHECKING FOR UPDATE" > /status
FN=`curl -s -k -I https://get.5e.tools/src/|grep filename|cut -d"=" -f2 | awk '{print $1}'` # get filename of most recent version
FN=${FN//[$'\t\r\n"']} # remove quotes
echo "FN: $FN"
FN_IMG=`curl -s -k -I https://get.5e.tools/img/|grep filename|cut -d"=" -f2 | awk '{print $1}'` # get filename of most recent image pack
FN_IMG=${FN_IMG//[$'\t\r\n"']} # remove quotes
echo "FN_IMG: $FN_IMG"
VER=`basename ${FN} ".zip"|sed 's/5eTools\.//'` # get version number
echo "VER: $VER"
CUR=$(<version)
rm ./index.html 2> /dev/null || true
echo " === Remote version: $VER"
echo " === Local version: $CUR"
echo " === Downloading new remote version..."
cd ./download/
curl --progress-bar -k -O -J https://get.5e.tools/src/ -C -
if [ "$IMG" = "true" ]; then
echo " === Downloading images === "
echo "DOWNLOADING IMAGES" > /status
curl --progress-bar -k -O -J https://get.5e.tools/img/ -C -
if [ "$VER" != "$CUR" ]
then
echo " === Local version outdated, updating..."
echo -n $VER > version
echo "DOWNLOADING" > /status
rm ./index.html 2> /dev/null || true
echo " === Downloading new remote version..."
cd ./download/
curl --progress-bar -k -O -J https://get.5e.tools/src/ -C -
if [ "$IMG" = "true" ]; then
echo " === Downloading images === "
echo "DOWNLOADING IMAGES" > /status
curl --progress-bar -k -O -J https://get.5e.tools/img/ -C -
fi
cd ..
echo " === Extracting site..."
echo "EXTRACTING" > /status
7z x ./download/$FN -o./ -y
if [ "$IMG" = "true" ]; then
echo " === Extracting images..."
echo "EXTRACTING IMAGES" > /status
7z x ./download/$FN_IMG -o./img -y
mv ./img/tmp/5et/img/* ./img
rm -r ./img/tmp
fi
echo " === Configuring..."
echo "CONFIGURING" > /status
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
echo " === Cleaning up downloads"
echo "CLEANING" > /status
find ./download/ -type f ! -name "*.${VER}.zip" -exec rm {} +
echo " === Done!"
echo "INIT" > /status
else
echo " === Local version matches remote, no action."
echo "INIT" > /status
fi
cd ..
echo " === Extracting site..."
echo "EXTRACTING" > /status
7z x ./download/$FN -o./ -y
if [ "$IMG" = "true" ]; then
echo " === Extracting images..."
echo "EXTRACTING IMAGES" > /status
7z x ./download/$FN_IMG -o./img -y
mv ./img/tmp/5et/img/* ./img
rm -r ./img/tmp
fi
echo " === Configuring..."
echo "CONFIGURING" > /status
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
echo " === Cleaning up downloads"
echo "CLEANING" > /status
find ./download/ -type f ! -name "*.${VER}.zip" -exec rm {} +
echo " === Done!"
echo "INIT" > /status
else
echo " === Local version matches remote, no action."
echo "INIT" > /status
else # if get.5e.tools is not accessible
echo " === No internet access! Checking for existing files"
if [ -f /usr/local/apache2/htdocs/version ]
then
echo " === Version file found: $(cat /usr/local/apache2/htdocs/version)"
echo " === Starting!"
else
echo " === No version file found! You need to be online to grab the 5eTools files"
exit 1
fi
httpd-foreground