summaryrefslogtreecommitdiff
path: root/recipes/unionfs/unionroot-utils
diff options
context:
space:
mode:
authorDenys Dmytriyenko <denis@denix.org>2009-03-17 14:32:59 -0400
committerDenys Dmytriyenko <denis@denix.org>2009-03-17 14:32:59 -0400
commit709c4d66e0b107ca606941b988bad717c0b45d9b (patch)
tree37ee08b1eb308f3b2b6426d5793545c38396b838 /recipes/unionfs/unionroot-utils
parentfa6cd5a3b993f16c27de4ff82b42684516d433ba (diff)
rename packages/ to recipes/ per earlier agreement
See links below for more details: http://thread.gmane.org/gmane.comp.handhelds.openembedded/21326 http://thread.gmane.org/gmane.comp.handhelds.openembedded/21816 Signed-off-by: Denys Dmytriyenko <denis@denix.org> Acked-by: Mike Westerhof <mwester@dls.net> Acked-by: Philip Balister <philip@balister.org> Acked-by: Khem Raj <raj.khem@gmail.com> Acked-by: Marcin Juszkiewicz <hrw@openembedded.org> Acked-by: Koen Kooi <koen@openembedded.org> Acked-by: Frans Meulenbroeks <fransmeulenbroeks@gmail.com>
Diffstat (limited to 'recipes/unionfs/unionroot-utils')
-rwxr-xr-xrecipes/unionfs/unionroot-utils/mount.unionroot99
-rwxr-xr-xrecipes/unionfs/unionroot-utils/umount.unionroot86
2 files changed, 185 insertions, 0 deletions
diff --git a/recipes/unionfs/unionroot-utils/mount.unionroot b/recipes/unionfs/unionroot-utils/mount.unionroot
new file mode 100755
index 0000000000..ac0f9a08f1
--- /dev/null
+++ b/recipes/unionfs/unionroot-utils/mount.unionroot
@@ -0,0 +1,99 @@
+#!/bin/sh
+
+#set -x
+
+ROOTMOUNTPT=/media/realroot
+REALMOUNT=/bin/mount.busybox
+UNIONMOUNT=$0
+INCDIRS="^/media/\|^/mnt/"
+DEVICE="\/dev\/"
+
+newargs=""
+
+ONESHIFTARGS='aVhvfFilnsrw'
+TWOSHIFTARGS="pLUtOo"
+IGNOREARGS='--bind --move'
+
+resolvelink () {
+ if test -h $1; then
+ echo `readlink $1`
+ else
+ echo $1
+ fi
+}
+
+# Retrieves arguments/mount-point
+for var in $@; do
+ if [ -z "$SKIP" ]; then
+ if echo $var | grep -q "^-.*"; then
+ # argument is an option
+ if echo $var | grep -q "[$TWOSHIFTARGS]"; then
+ SKIP="yes"
+ fi
+ # mount -a
+ if echo $var | grep -q "^-[^- ]*a"; then
+ DO_FSTAB="yes"
+ fi
+ ARGS="$ARGS $var"
+ else
+ if [ -z "$MOUNT_POINT" ]; then
+ # argument apears to be the mountpoint
+ MOUNT_POINT=$var
+ else
+ # A mountpoint was found earlier, so the other non-option
+ # must be the real mountpoint, and the first non-option is a device
+ DEV_PATH="$MOUNT_POINT"
+ MOUNT_POINT="$var"
+ fi
+ fi
+ else
+ ARGS="$ARGS $var"
+ unset SKIP
+ fi
+done
+
+# Parse fstab if -a is used
+if ! [ -z "$DO_FSTAB" ]; then
+ # FIXME: This doesn't handle -t or -O
+ awk '/^[^ #]/ {print "-t " $3 " -o " $4 " " $1 " " $2}' /etc/fstab |
+ while read line; do
+ ${UNIONMOUNT} $line
+ done
+ exit 0
+fi
+
+# Get mount-point for device name, if device name is given
+if echo "$MOUNT_POINT" | grep -q "^${DEVICE}"; then
+ MOUNT_POINT_TEMP=`echo $MOUNT_POINT | sed -e "s/\//\\\\\\\\\//g"`
+ NEW_MOUNT_POINT=`awk "/$MOUNT_POINT_TEMP/ {print "'$2'"}" /etc/fstab`
+ if ! [ -z "$NEW_MOUNT_POINT" ]; then
+ MOUNT_POINT=$NEW_MOUNT_POINT
+ fi
+fi
+
+# Mount anything but /media/* and / with the real mount
+if ! (echo "$MOUNT_POINT" | grep -q "$INCDIRS" || [ "$MOUNT_POINT" = "/" ]); then
+ exec ${REALMOUNT} $@
+fi
+
+# Replace requests to mount '/' (from init scripts and such)
+# with mount ROOTMOUNTPT (the real-root mount point for the
+# unionfs'd system).
+packagedir=""
+if ([ "$MOUNT_POINT" = "/" ] || [ "$MOUNT_POINT" = "${ROOTMOUNTPT}" ]); then
+ MOUNT_POINT=${ROOTMOUNTPT}
+else
+ # FIXME: A hard-coded path is bad - see ipkg-link
+ PACKAGE_DIR="/packages"
+ x=a
+fi
+
+# Finally, mount and union-mount
+#echo "<<DEBUG>> Running command: [${REALMOUNT} $ARGS $DEV_PATH $MOUNT_POINT]"
+if ${REALMOUNT} $ARGS $DEV_PATH $MOUNT_POINT; then
+ if mkdir -p $MOUNT_POINT$PACKAGE_DIR; then
+ #echo "<<DEBUG>> Running command: [unionctl /. --add --after ${ROOTMOUNTPT} --mode rw `resolvelink $MOUNT_POINT`$PACKAGE_DIR]"
+ #unionctl /. --add --after ${ROOTMOUNTPT} --mode rw `resolvelink $MOUNT_POINT`$PACKAGE_DIR
+ unionctl /. --add `resolvelink $MOUNT_POINT`$PACKAGE_DIR
+ fi
+fi
diff --git a/recipes/unionfs/unionroot-utils/umount.unionroot b/recipes/unionfs/unionroot-utils/umount.unionroot
new file mode 100755
index 0000000000..df0eccb353
--- /dev/null
+++ b/recipes/unionfs/unionroot-utils/umount.unionroot
@@ -0,0 +1,86 @@
+#!/bin/sh
+
+#set -x
+
+ROOTMOUNTPT=/media/realroot
+REALUMOUNT=/bin/umount.busybox
+UNIONUMOUNT=$0
+INCDIRS="^/media/\|^/mnt/"
+DEVICE="\/dev\/"
+
+newargs=""
+
+ONESHIFTARGS='adflnrv'
+TWOSHIFTARGS="tO"
+
+resolvelink () {
+ if test -h $1; then
+ echo `readlink $1`
+ else
+ echo $1
+ fi
+}
+
+# Retrieves arguments/mount-point
+for var in $@; do
+ if [ -z "$SKIP" ]; then
+ if echo $var | grep -q "^-.*"; then
+ if echo $var | grep -q "[$TWOSHIFTARGS]"; then
+ SKIP="yes"
+ fi
+ if echo $var | grep -q "^-[^- ]*a"; then
+ DO_FSTAB="yes"
+ fi
+ ARGS="$ARGS $var"
+ else
+ if [ -z "$MOUNT_POINT" ]; then
+ MOUNT_POINT=$var
+ else
+ # This really shouldn't happen when unmounting
+ DEV_PATH="$MOUNT_POINT"
+ MOUNT_POINT="$var"
+ fi
+ fi
+ else
+ ARGS="$ARGS $var"
+ unset SKIP
+ fi
+done
+
+# Parse fstab if -a is used
+if ! [ -z "$DO_FSTAB" ]; then
+ # FIXME: This doesn't handle -t or -O
+ awk '/^[^ #]/ {print $1}' /etc/fstab |
+ while read line; do
+ ${UNIONUMOUNT} $line
+ done
+ exit 0
+fi
+
+# Get mount-point for device name, if device name is given
+if echo "$MOUNT_POINT" | grep -q "^${DEVICE}"; then
+ MOUNT_POINT_TEMP=`echo $MOUNT_POINT | sed -e "s/\//\\\\\\\\\//g"`
+ NEW_MOUNT_POINT=`awk "/$MOUNT_POINT_TEMP/ {print "'$2'"}" /etc/fstab`
+ if ! [ -z "$NEW_MOUNT_POINT" ]; then
+ MOUNT_POINT=$NEW_MOUNT_POINT
+ fi
+fi
+
+if ! (echo "$MOUNT_POINT" | grep -q "$INCDIRS"||[ "$MOUNT_POINT" = "/" ]); then
+ exec ${REALMOUNT} $@
+fi
+
+# Replace requests to mount '/' (from init scripts and such)
+# with mount ROOTMOUNTPT (the real-root mount point for the
+# unionfs'd system).
+packagedir=""
+if ([ "$MOUNT_POINT" = "/" ]||[ "$MOUNT_POINT" = "${ROOTMOUNTPT}" ]); then
+ MOUNT_POINT=${ROOTMOUNTPT}
+else
+ PACKAGE_DIR="/packages"
+fi
+
+# Finally, umount and union-umount
+unionctl /. --remove `resolvelink $MOUNT_POINT`$PACKAGE_DIR
+exec ${REALUMOUNT} $ARGS $MOUNT_POINT
+