mirror of
https://github.com/woodchen-ink/docker-firefox.git
synced 2025-07-18 13:52:02 +08:00
Added way to set Firefox preferences via environment variables.
This commit is contained in:
parent
3b92cc215d
commit
5a635acffc
37
README.md
37
README.md
@ -39,6 +39,7 @@ Mozilla Firefox is a free and open-source web browser developed by Mozilla Found
|
|||||||
* [Shell Access](#shell-access)
|
* [Shell Access](#shell-access)
|
||||||
* [Increasing Shared Memory Size](#increasing-shared-memory-size)
|
* [Increasing Shared Memory Size](#increasing-shared-memory-size)
|
||||||
* [Sound Support](#sound-support)
|
* [Sound Support](#sound-support)
|
||||||
|
* [Setting Firefox Preferences Via Environment Variables](#setting-firefox-preferences-via-environment-variables)
|
||||||
* [Troubleshooting](#troubleshooting)
|
* [Troubleshooting](#troubleshooting)
|
||||||
* [Crashes](#crashes)
|
* [Crashes](#crashes)
|
||||||
* [Support or Contact](#support-or-contact)
|
* [Support or Contact](#support-or-contact)
|
||||||
@ -460,6 +461,42 @@ For Firefox to be able to use the audio device available on
|
|||||||
the host, `/dev/snd` must be exposed to the container by adding the
|
the host, `/dev/snd` must be exposed to the container by adding the
|
||||||
`--device /dev/snd` parameter to the `docker run` command.
|
`--device /dev/snd` parameter to the `docker run` command.
|
||||||
|
|
||||||
|
## Setting Firefox Preferences Via Environment Variables
|
||||||
|
|
||||||
|
Firefox preferences can be set via environment variables
|
||||||
|
passed to the containter. During the startup, a script process all these
|
||||||
|
variables and modify the preference file accordingly.
|
||||||
|
|
||||||
|
The name of the environment variable must start with `FF_PREF_`, followed by a
|
||||||
|
string of your choice. For example, `FF_PREF_MY_PREF` is a valid name.
|
||||||
|
|
||||||
|
The content of the variable should be in the format `NAME=VAL`, where `NAME` is
|
||||||
|
the name of the preference (as found in the `about:config` page) and `VAL` is
|
||||||
|
its value. A value can be one of the following type:
|
||||||
|
- string
|
||||||
|
- integer
|
||||||
|
- boolean
|
||||||
|
It is important to note that a value of type `string` should be surrounded by
|
||||||
|
double quotes. Other types don't need them.
|
||||||
|
|
||||||
|
For example, to set the `network.proxy.http` preference, one would pass the
|
||||||
|
environment variable to the container by adding the following argument to the
|
||||||
|
`docker run` command:
|
||||||
|
|
||||||
|
```
|
||||||
|
-e "FF_PREF_HTTP_PROXY=network.proxy.http=\"proxy.example.com\""
|
||||||
|
```
|
||||||
|
|
||||||
|
If a preference needs to be *removed*, its value should be set to `UNSET`. For
|
||||||
|
example:
|
||||||
|
|
||||||
|
```
|
||||||
|
-e "FF_PREF_HTTP_PROXY=network.proxy.http=UNSET
|
||||||
|
```
|
||||||
|
|
||||||
|
**NOTE**: This is an advanced usage and it is recommended to set preferences
|
||||||
|
via Firefox directly.
|
||||||
|
|
||||||
## Troubleshooting
|
## Troubleshooting
|
||||||
|
|
||||||
### Crashes
|
### Crashes
|
||||||
|
38
appdefs.xml
38
appdefs.xml
@ -48,6 +48,44 @@ For {{ defs.app.friendly_name }} to be able to use the audio device available on
|
|||||||
the host, `/dev/snd` must be exposed to the container by adding the
|
the host, `/dev/snd` must be exposed to the container by adding the
|
||||||
`--device /dev/snd` parameter to the `docker run` command.
|
`--device /dev/snd` parameter to the `docker run` command.
|
||||||
</content>
|
</content>
|
||||||
|
</section>
|
||||||
|
<section>
|
||||||
|
<title level="2">Setting {{ defs.app.friendly_name }} Preferences Via Environment Variables</title>
|
||||||
|
<content>
|
||||||
|
{{ defs.app.friendly_name }} preferences can be set via environment variables
|
||||||
|
passed to the containter. During the startup, a script process all these
|
||||||
|
variables and modify the preference file accordingly.
|
||||||
|
|
||||||
|
The name of the environment variable must start with `FF_PREF_`, followed by a
|
||||||
|
string of your choice. For example, `FF_PREF_MY_PREF` is a valid name.
|
||||||
|
|
||||||
|
The content of the variable should be in the format `NAME=VAL`, where `NAME` is
|
||||||
|
the name of the preference (as found in the `about:config` page) and `VAL` is
|
||||||
|
its value. A value can be one of the following type:
|
||||||
|
- string
|
||||||
|
- integer
|
||||||
|
- boolean
|
||||||
|
It is important to note that a value of type `string` should be surrounded by
|
||||||
|
double quotes. Other types don't need them.
|
||||||
|
|
||||||
|
For example, to set the `network.proxy.http` preference, one would pass the
|
||||||
|
environment variable to the container by adding the following argument to the
|
||||||
|
`docker run` command:
|
||||||
|
|
||||||
|
```
|
||||||
|
-e "FF_PREF_HTTP_PROXY=network.proxy.http=\"proxy.example.com\""
|
||||||
|
```
|
||||||
|
|
||||||
|
If a preference needs to be *removed*, its value should be set to `UNSET`. For
|
||||||
|
example:
|
||||||
|
|
||||||
|
```
|
||||||
|
-e "FF_PREF_HTTP_PROXY=network.proxy.http=UNSET
|
||||||
|
```
|
||||||
|
|
||||||
|
**NOTE**: This is an advanced usage and it is recommended to set preferences
|
||||||
|
via {{ defs.app.friendly_name }} directly.
|
||||||
|
</content>
|
||||||
</section>
|
</section>
|
||||||
<section>
|
<section>
|
||||||
<title level="2">Troubleshooting</title>
|
<title level="2">Troubleshooting</title>
|
||||||
|
48
rootfs/etc/cont-init.d/firefox-set-prefs-from-env.sh
Executable file
48
rootfs/etc/cont-init.d/firefox-set-prefs-from-env.sh
Executable file
@ -0,0 +1,48 @@
|
|||||||
|
#!/usr/bin/with-contenv sh
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
log() {
|
||||||
|
echo "[cont-init.d] $(basename $0): $*"
|
||||||
|
}
|
||||||
|
|
||||||
|
PREF_FILE="${1:-/config/profile/prefs.js}"
|
||||||
|
|
||||||
|
if [ -z "$PREF_FILE" ]; then
|
||||||
|
log "ERROR: Preference file not set."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
mkdir -p "$(dirname "$PREF_FILE")"
|
||||||
|
[ -f "$PREF_FILE" ] || touch "$PREF_FILE"
|
||||||
|
|
||||||
|
env | grep "^FF_PREF_" | while read ENV
|
||||||
|
do
|
||||||
|
ENAME="$(echo "$ENV" | cut -d '=' -f1)"
|
||||||
|
EVAL="$(echo "$ENV" | cut -d '=' -f2-)"
|
||||||
|
|
||||||
|
if [ -z "$EVAL" ]; then
|
||||||
|
log "Skipping environment variable '$ENAME': no value set."
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
|
||||||
|
if echo "$EVAL" | grep -q "="; then
|
||||||
|
PNAME="$(echo "$EVAL" | cut -d '=' -f1)"
|
||||||
|
PVAL="$(echo "$EVAL" | cut -d '=' -f2-)"
|
||||||
|
[ -n "$PVAL" ] || PVAL='""'
|
||||||
|
else
|
||||||
|
PNAME="$EVAL"
|
||||||
|
PVAL='""'
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "$PVAL" = "UNSET" ]; then
|
||||||
|
log "Removing preference '$PNAME'..."
|
||||||
|
sed -i "/user_pref(\"$PNAME\",.*);/d" "$PREF_FILE"
|
||||||
|
elif grep -q "user_pref(\"$PNAME\"," "$PREF_FILE"; then
|
||||||
|
log "Setting preference '$PNAME'..."
|
||||||
|
sed -i "s/user_pref(\"$PNAME\",.*);/user_pref(\"$PNAME\", $PVAL);/" "$PREF_FILE"
|
||||||
|
else
|
||||||
|
log "Setting new preference '$PNAME'..."
|
||||||
|
echo "user_pref(\"$PNAME\", $PVAL);" >> "$PREF_FILE"
|
||||||
|
fi
|
||||||
|
done
|
Loading…
x
Reference in New Issue
Block a user