#!/bin/bash orig=$0.diverted if [ -z "$APP_LOCATION" ]; then echo "Error: APP_LOCATION was not defined." exit 1 fi app=/srv/app root=$app/root changes=$app/changes/0000 mnt=$app/mnt ## All these should be in the root image #mkdir -p $root $mnt #mkdir -p "$(dirname "$APP_LOCATION")" if [ -d "$changes" ]; then clean_all() { cd / mountpoint "$mnt" 2>/dev/null && umount "$mnt" } trap "clean_all" EXIT mount -t aufs -o br=$changes:$root -o udba=none none "$mnt" if [ "$?" != 0 ]; then echo "Error: aufs mount failed." exit 1 fi ln -sf "$mnt" "$APP_LOCATION" else ln -sf "$root" "$APP_LOCATION" fi "$orig" "$@"