diff --git a/scripts/container-manager.sh b/scripts/container-manager.sh index b67d614..ce693af 100755 --- a/scripts/container-manager.sh +++ b/scripts/container-manager.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash set -x # We need to put the rootfs somewhere where we can modify some @@ -7,7 +7,6 @@ set -x # rootfs. DATA_PATH=$SNAP_COMMON/ -ROOTFS_PATH=$DATA_PATH/rootfs ANDROID_IMG=$SNAP/android.img if [ "$(id -u)" != 0 ]; then @@ -15,14 +14,14 @@ if [ "$(id -u)" != 0 ]; then exit 1 fi -if [ ! -e $ANDROID_IMG ]; then +if [ ! -e "$ANDROID_IMG" ]; then echo "ERROR: android image does not exist" exit 1 fi -if [ "$SNAP_ARCH" == "amd64" ]; then +if [ "$SNAP_ARCH" = "amd64" ]; then ARCH="x86_64-linux-gnu" -elif [ "$SNAP_ARCH" == "armhf" ]; then +elif [ "$SNAP_ARCH" = "armhf" ]; then ARCH="arm-linux-gnueabihf" else ARCH="$SNAP_ARCH-linux-gnu" @@ -32,11 +31,11 @@ start() { # Make sure our setup path for the container rootfs # is present as lxc is statically configured for # this path. - mkdir -p $SNAP_COMMON/lxc + mkdir -p "$SNAP_COMMON/lxc" # We start the bridge here as long as a oneshot service unit is not # possible. See snapcraft.yaml for further details. - $SNAP/bin/anbox-bridge.sh start + "$SNAP"/bin/anbox-bridge.sh start # Ensure FUSE support for user namespaces is enabled echo Y | tee /sys/module/fuse/parameters/userns_mounts || echo "WARNING: kernel doesn't support fuse in user namespaces" @@ -49,20 +48,22 @@ start() { fi # liblxc.so.1 is in $SNAP/lib - export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$SNAP/liblxc + export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$SNAP/liblxc" # For unknown reason we got bug reports that the container manager failed to start # because it cannot find libboost_log.so.1.58.0 To mitigate this we're adding the # lib directory as explicit search target here. - export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$SNAP/usr/lib/$ARCH + export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$SNAP/usr/lib/$ARCH" if [ -d /sys/kernel/security/apparmor ] ; then # Load the profile for our Android container - $SNAP/sbin/apparmor_parser -r $SNAP/apparmor/anbox-container.aa + "$SNAP"/sbin/apparmor_parser -r "$SNAP"/apparmor/anbox-container.aa fi - if [ -e "$SNAP_COMMON"/.enable_debug ]; then + enable_debug="$(snapctl get debug.enable)" + if [ "$enable_debug" = true ]; then export ANBOX_LOG_LEVEL=debug + export LD_DEBUG=libs fi EXTRA_ARGS= @@ -71,20 +72,20 @@ start() { EXTRA_ARGS="$EXTRA_ARGS --use-rootfs-overlay" fi - privileged_container="$(snapctl get container.privileged)" - if [ "$privileged_container" = true ]; then + enable_privileged_container="$(snapctl get container.privileged)" + if [ "$enable_privileged_container" = true ]; then EXTRA_ARGS="$EXTRA_ARGS --privileged" fi - exec $AA_EXEC $SNAP/bin/anbox-wrapper.sh container-manager \ + exec "$AA_EXEC" "$SNAP"/bin/anbox-wrapper.sh container-manager \ "$EXTRA_ARGS" \ - --data-path=$DATA_PATH \ - --android-image=$ANDROID_IMG \ + --data-path="$DATA_PATH" \ + --android-image="$ANDROID_IMG" \ --daemon } stop() { - $SNAP/bin/anbox-bridge.sh stop + "$SNAP"/bin/anbox-bridge.sh stop } case "$1" in diff --git a/scripts/snap-wrapper.sh b/scripts/snap-wrapper.sh index 60877db..061c165 100755 --- a/scripts/snap-wrapper.sh +++ b/scripts/snap-wrapper.sh @@ -29,7 +29,8 @@ export XDG_DATA_HOME="$SNAP_USER_COMMON/app-data" # configured but the actual EGL implementation is missing. export __EGL_VENDOR_LIBRARY_DIRS="$SNAP/glvnd" -if [ -e "$SNAP_COMMON"/.enable_debug ]; then +enable_debug="$(snapctl get debug.enable)" +if [ "$enable_debug" = true ]; then export ANBOX_LOG_LEVEL=debug fi @@ -37,4 +38,4 @@ if [ "$(snapctl get software-rendering.enable)" = true ]; then export ANBOX_FORCE_SOFTWARE_RENDERING=true fi -exec $SNAP/usr/bin/anbox $@ +exec "$SNAP"/usr/bin/anbox "$@" diff --git a/snap/hooks/configure b/snap/hooks/configure index 89dea03..0677cf6 100755 --- a/snap/hooks/configure +++ b/snap/hooks/configure @@ -1,9 +1,7 @@ #!/bin/sh -if [ "$(snapctl get debug.enable)" = true ]; then - touch "$SNAP_COMMON"/.enable_debug -else - rm -f "$SNAP_COMMON"/.enable_debug -fi +# We need to have something for snapd in place in order to +# allow configuration options for our snap even if the items +# are read via snapctl elsewhere in the code. exit 0