Merge pull request #796 from morphis/improve-snap-scripts
Improve snap scripts to avoid common pitfalls with shell scripts
This commit is contained in:
commit
1fb397a21d
3 changed files with 24 additions and 24 deletions
|
|
@ -1,4 +1,4 @@
|
||||||
#!/bin/sh
|
#!/bin/bash
|
||||||
set -x
|
set -x
|
||||||
|
|
||||||
# We need to put the rootfs somewhere where we can modify some
|
# We need to put the rootfs somewhere where we can modify some
|
||||||
|
|
@ -7,7 +7,6 @@ set -x
|
||||||
# rootfs.
|
# rootfs.
|
||||||
|
|
||||||
DATA_PATH=$SNAP_COMMON/
|
DATA_PATH=$SNAP_COMMON/
|
||||||
ROOTFS_PATH=$DATA_PATH/rootfs
|
|
||||||
ANDROID_IMG=$SNAP/android.img
|
ANDROID_IMG=$SNAP/android.img
|
||||||
|
|
||||||
if [ "$(id -u)" != 0 ]; then
|
if [ "$(id -u)" != 0 ]; then
|
||||||
|
|
@ -15,14 +14,14 @@ if [ "$(id -u)" != 0 ]; then
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ ! -e $ANDROID_IMG ]; then
|
if [ ! -e "$ANDROID_IMG" ]; then
|
||||||
echo "ERROR: android image does not exist"
|
echo "ERROR: android image does not exist"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "$SNAP_ARCH" == "amd64" ]; then
|
if [ "$SNAP_ARCH" = "amd64" ]; then
|
||||||
ARCH="x86_64-linux-gnu"
|
ARCH="x86_64-linux-gnu"
|
||||||
elif [ "$SNAP_ARCH" == "armhf" ]; then
|
elif [ "$SNAP_ARCH" = "armhf" ]; then
|
||||||
ARCH="arm-linux-gnueabihf"
|
ARCH="arm-linux-gnueabihf"
|
||||||
else
|
else
|
||||||
ARCH="$SNAP_ARCH-linux-gnu"
|
ARCH="$SNAP_ARCH-linux-gnu"
|
||||||
|
|
@ -32,11 +31,11 @@ start() {
|
||||||
# Make sure our setup path for the container rootfs
|
# Make sure our setup path for the container rootfs
|
||||||
# is present as lxc is statically configured for
|
# is present as lxc is statically configured for
|
||||||
# this path.
|
# 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
|
# We start the bridge here as long as a oneshot service unit is not
|
||||||
# possible. See snapcraft.yaml for further details.
|
# 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
|
# 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"
|
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
|
fi
|
||||||
|
|
||||||
# liblxc.so.1 is in $SNAP/lib
|
# 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
|
# 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
|
# because it cannot find libboost_log.so.1.58.0 To mitigate this we're adding the
|
||||||
# lib directory as explicit search target here.
|
# 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
|
if [ -d /sys/kernel/security/apparmor ] ; then
|
||||||
# Load the profile for our Android container
|
# 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
|
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 ANBOX_LOG_LEVEL=debug
|
||||||
|
export LD_DEBUG=libs
|
||||||
fi
|
fi
|
||||||
|
|
||||||
EXTRA_ARGS=
|
EXTRA_ARGS=
|
||||||
|
|
@ -71,20 +72,20 @@ start() {
|
||||||
EXTRA_ARGS="$EXTRA_ARGS --use-rootfs-overlay"
|
EXTRA_ARGS="$EXTRA_ARGS --use-rootfs-overlay"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
privileged_container="$(snapctl get container.privileged)"
|
enable_privileged_container="$(snapctl get container.privileged)"
|
||||||
if [ "$privileged_container" = true ]; then
|
if [ "$enable_privileged_container" = true ]; then
|
||||||
EXTRA_ARGS="$EXTRA_ARGS --privileged"
|
EXTRA_ARGS="$EXTRA_ARGS --privileged"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
exec $AA_EXEC $SNAP/bin/anbox-wrapper.sh container-manager \
|
exec "$AA_EXEC" "$SNAP"/bin/anbox-wrapper.sh container-manager \
|
||||||
"$EXTRA_ARGS" \
|
"$EXTRA_ARGS" \
|
||||||
--data-path=$DATA_PATH \
|
--data-path="$DATA_PATH" \
|
||||||
--android-image=$ANDROID_IMG \
|
--android-image="$ANDROID_IMG" \
|
||||||
--daemon
|
--daemon
|
||||||
}
|
}
|
||||||
|
|
||||||
stop() {
|
stop() {
|
||||||
$SNAP/bin/anbox-bridge.sh stop
|
"$SNAP"/bin/anbox-bridge.sh stop
|
||||||
}
|
}
|
||||||
|
|
||||||
case "$1" in
|
case "$1" in
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,8 @@ export XDG_DATA_HOME="$SNAP_USER_COMMON/app-data"
|
||||||
# configured but the actual EGL implementation is missing.
|
# configured but the actual EGL implementation is missing.
|
||||||
export __EGL_VENDOR_LIBRARY_DIRS="$SNAP/glvnd"
|
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
|
export ANBOX_LOG_LEVEL=debug
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
@ -37,4 +38,4 @@ if [ "$(snapctl get software-rendering.enable)" = true ]; then
|
||||||
export ANBOX_FORCE_SOFTWARE_RENDERING=true
|
export ANBOX_FORCE_SOFTWARE_RENDERING=true
|
||||||
fi
|
fi
|
||||||
|
|
||||||
exec $SNAP/usr/bin/anbox $@
|
exec "$SNAP"/usr/bin/anbox "$@"
|
||||||
|
|
|
||||||
8
snap/hooks/configure
vendored
8
snap/hooks/configure
vendored
|
|
@ -1,9 +1,7 @@
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
if [ "$(snapctl get debug.enable)" = true ]; then
|
# We need to have something for snapd in place in order to
|
||||||
touch "$SNAP_COMMON"/.enable_debug
|
# allow configuration options for our snap even if the items
|
||||||
else
|
# are read via snapctl elsewhere in the code.
|
||||||
rm -f "$SNAP_COMMON"/.enable_debug
|
|
||||||
fi
|
|
||||||
|
|
||||||
exit 0
|
exit 0
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue