In order to run Firefox without allowing any changes to its configuration, I did setup a tmpfs
and from it, create two overlays before launching the browser.
Script runs fine, creates and destroys the mounts
as expected, but when booted into a launcher
, some umounts
apparently fail, and subsequent calls to Firefox complain about a running instance of themselves.
I could verify, that some mounts remain only if the scripts gets executed from the launcher
.
Here is the script:
#!/usr/bin/bash
# set variables
FOX="/usr/bin/firefox"
pkill `basename $FOX` || true
#find working directories:
#find ~ -type d -iname "*fox*"
function errout () {
zenity --info --text="$@"
exit 1
}
CACHE=~/.cache/mozilla/firefox
ZILLA=~/.mozilla/firefox
FREE=`free | awk 'NR==2 {print $4;}'`
TEMP=/mnt/tmp # this one gets built in fstab
if [[ "$FREE" -lt 200000 ]]
then
errout "zu wenig Speicherplatz"
fi
if ! test -d "$CACHE"
then
errout "$CACHE ist kein Verzeichnis"
fi
if ! test -d "$ZILLA"
then
errout "$ZILLA ist kein Verzeichnis"
fi
if ! test -d "$TEMP"
then
errout "$TEMP ist kein Verzeichnis"
fi
if [[ "$USER" == "uk" ]]
then
PWD=SUDOPASSWORD # of course not :-)
fi
echo $PWD | sudo -S true >& /dev/null
if [[ `mount | awk /^tmpfs/ | grep -cw "$TEMP"` == "0" ]]
then
sudo mount tmpfs -t tmpfs -o defaults,size=250m "$TEMP"
else
: # es ist noch nicht sicher, dass der Platz reichen wird
fi
# setup overlays:
mkdir -p "$TEMP/helpfox/"{Clower,Cupper,Cwork,Zlower,Zupper,Zwork}
sudo mount --bind "$CACHE" "$TEMP/helpfox/Clower"
sudo mount --bind "$ZILLA" "$TEMP/helpfox/Zlower"
sudo mount -t overlay overlay -olowerdir="$TEMP/helpfox/Zlower",\
upperdir="$TEMP/helpfox/Zupper",workdir="$TEMP/helpfox/Zwork" "$ZILLA"
sudo mount -t overlay overlay -olowerdir="$TEMP/helpfox/Clower",\
upperdir="$TEMP/helpfox/Cupper",workdir="$TEMP/helpfox/Cwork" "$CACHE"
sudo -k
$FOX
# destroy overlays:
sleep 2
echo $PWD | sudo -S true >& /dev/null
mount | awk '$3 ~ /helpfox/ { print $3; }' | xargs -r -l sudo umount
sudo rm -rf $TEMP/helpfox
zenity --info --text="Die Blase ist abgebaut"
sudo -k