4 # We need to put the rootfs somewhere where we can modify some
5 # parts of the content on first boot (namely file permissions).
6 # Other than that nothing should ever modify the content of the
9 DATA_PATH=$SNAP_COMMON/
10 ANDROID_IMG=$SNAP/android.img
12 if [ "$(id -u)" != 0 ]; then
13 echo "ERROR: You need to run the container manager as root"
17 if [ ! -e "$ANDROID_IMG" ]; then
18 echo "ERROR: android image does not exist"
22 if [ "$SNAP_ARCH" = "amd64" ]; then
23 ARCH="x86_64-linux-gnu"
24 elif [ "$SNAP_ARCH" = "armhf" ]; then
25 ARCH="arm-linux-gnueabihf"
27 ARCH="$SNAP_ARCH-linux-gnu"
30 # Re-exec outside of apparmor confinement
31 if [ -d /sys/kernel/security/apparmor ] && [ "$(cat /proc/self/attr/current)" != "unconfined" ]; then
32 exec /usr/sbin/aa-exec -p unconfined -- "$0" "$@"
36 # Make sure our setup path for the container rootfs
37 # is present as lxc is statically configured for
39 mkdir -p "$SNAP_COMMON/lxc"
41 # We start the bridge here as long as a oneshot service unit is not
42 # possible. See snapcraft.yaml for further details.
43 "$SNAP"/bin/anbox-bridge.sh start
45 # Ensure FUSE support for user namespaces is enabled
46 echo Y | tee /sys/module/fuse/parameters/userns_mounts || echo "WARNING: kernel doesn't support fuse in user namespaces"
48 # liblxc.so.1 is in $SNAP/lib
49 export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$SNAP/liblxc"
51 # For unknown reason we got bug reports that the container manager failed to start
52 # because it cannot find libboost_log.so.1.58.0 To mitigate this we're adding the
53 # lib directory as explicit search target here.
54 export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$SNAP/usr/lib/$ARCH"
56 enable_debug="$(snapctl get debug.enable)"
57 if [ "$enable_debug" = true ]; then
58 export ANBOX_LOG_LEVEL=debug
63 enable_rootfs_overlay="$(snapctl get rootfs-overlay.enable)"
64 if [ "$enable_rootfs_overlay" = true ]; then
65 EXTRA_ARGS="$EXTRA_ARGS --use-rootfs-overlay"
68 enable_privileged_container="$(snapctl get container.privileged)"
69 if [ "$enable_privileged_container" = true ]; then
70 EXTRA_ARGS="$EXTRA_ARGS --privileged"
73 container_network_address=$(snapctl get container.network.address)
74 if [ -n "$container_network_address" ]; then
75 EXTRA_ARGS="$EXTRA_ARGS --container-network-address=$container_network_address"
78 container_network_gateway=$(snapctl get container.network.gateway)
79 if [ -n "$container_network_gateway" ]; then
80 EXTRA_ARGS="$EXTRA_ARGS --container-network-gateway=$container_network_gateway"
83 container_network_dns=$(snapctl get container.network.dns)
84 if [ -n "$container_network_dns" ]; then
85 EXTRA_ARGS="$EXTRA_ARGS --container-network-dns-servers=$container_network_dns"
88 # Load all relevant kernel modules
92 # Ensure we have binderfs mounted when our kernel supports it
93 if cat /proc/filesystems | grep -q binder ; then
94 mkdir -p "$SNAP_COMMON"/binderfs
95 # Remove old mounts so that we start fresh without any devices allocated
96 if cat /proc/mounts | grep -q "binder $SNAP_COMMON/binderfs" ; then
97 umount "$SNAP_COMMON"/binderfs
99 mount -t binder none "$SNAP_COMMON"/binderfs
102 exec "$SNAP"/bin/anbox-wrapper.sh container-manager \
103 --data-path="$DATA_PATH" \
104 --android-image="$ANDROID_IMG" \
110 "$SNAP"/bin/anbox-bridge.sh stop
121 echo "ERROR: Unknown command '$1'"