A Bash utility that lets you inject your own JavaScript into the index.html shipped inside Polarity Web’s Docker image and bind-mount the modified assets into your running stack. Useful for cases where a customer needs to run custom tracking or agent code in the web application.
- Lists local Docker images whose repository contains
weband helps you pick one. - Validates the selected image actually exists (
docker image inspect). - Prompts for the JavaScript file to inject (defaults to
script.js). - Copies /usr/share/caddy out of the image into
/tmp. - Injects your script just after
<head>in index.html. - Copies the modified assets to
/app/polarity-web-modified. - Prints the
docker-compose.ymlvolume snippet and SELinux relabel command you need. - Cleans up all temporary artefacts.
| Requirement | Notes |
|---|---|
| Bash 4+ | Uses mapfile and here-strings. |
| Docker 19+ | Needs permission to run docker images, docker create, docker cp, etc. |
| Local Polarity Web image | Usually tagged …/web:<version>. |
| SELinux users | The :z flag and chcon command apply when SELinux is enforcing. |
- Copy the script somewhere in your PATH:
cp copy-polarity-web.sh /home/<user>Alternatively, clone this repository into your user directory
Replace {{user}} with your user directory
cd /home/{{user}}
git clone https://github.com/breachintelligence/polarity-web-custom-index-html.git
cd polarity-web-custom-index-html
- Make the
copy-polarity-web.shscript executable:
chmod +x copy-polarity-web.sh-
Place your custom JavaScript (default: script.js) in the same directory or supply another path when prompted.
-
Run it:
./copy-polarity-web.sh- Edit /app/docker-compose.yml and add the bind-mount:
services:
web:
volumes:
- /app/polarity-web-modified:/usr/share/caddy:z- Restart the stack:
cd /app && ./down.sh && ./up.sh- If selinux is enabled and in enforcing mode you may need to run the following:
sudo chcon -Rt svirt_sandbox_file_t /app/polarity-web-modified- Re-run the script anytime Polarity Web is updated. Modifying the
docker-compose.ymlshould be a one-time operation unless the compose file has been overwritten.
The following configuration variables are used by the script. In most cases you will not need to change these defaults.
# default JS source file
SCRIPT_FILE="script.js"
# host dir for patched assets
VOLUME_PATH="/app/polarity-web-modified"
# Temp container name when copying current web container content
TEMP_CONTAINER_NAME="polarity-web-app-script-injected-temp"
# Temp location to write container content to before modifying `index.html` file
TMP_DIR="/tmp/polarity-web-tmp"
If you need to modify one of the variables you can do so by editing the value at the top of the copy-polarity-web.sh file.