Using host /etc/hosts in AlienDalvik/AndroidAppSupport (AD/AAS) via bind mount on SFOS 4.5

My old solution apparently didn’t work anymore, and I feel a little uncomfortable editing system executables esp. under /usr/lib, so I took some time to investigate.

Looking at /usr/libexec/appsupport/prepare-aliendalvik.sh I find the following towards the end ofthe file:

if [ -f /usr/libexec/appsupport/alien-generate-extra-config.sh ]; then
    /usr/libexec/appsupport/alien-generate-extra-config.sh $INSTANCE_NAME $CONTAINER_CONFIG_PATH
fi

# This needs to be after all the config generation scripts have run
for CONFIG_FILE in $(ls -1 $CONTAINER_CONFIG_PATH/*_config | sort); do
    echo "lxc.include = $CONFIG_FILE" >> $CONTAINER_CONFIG_AGGREGATE_FILE
done

/usr/libexec/appsupport/alien-generate-extra-config.sh does not exist, so I presume its purpose is to add user customisation.

I created it and made it executable, with the following content:

#!/bin/sh

echo ">>> $0" >&2
echo ">>> \$1 $1" >&2
echo ">>> \$2 $2" >&2

[ "$#" -gt 1 ] && shift

echo "lxc.mount.entry = /etc/hosts system/etc/hosts none bind,create=file 0 0" > "$1/29-hosts_config"

About [ "$#" -gt 1 ] && shift:

$INSTANCE_NAME is usually empty, and not quoted, which is why $CONTAINER_CONFIG_PATH is passed to the script as the first argument and not the second.

Considering that $INSTANCE_NAME might not be empty in some scenario, this sort of shifting is required.

This could have been avoided by simply quoting the variables or changing the order around, but as I said, I prefer not to dig around in there.

Anyhow, as it is, it should be stable enough.

I tested with an Android browser without adblocking, with some sites from /etc/hosts, connection is refused, as it should be.

5 Likes