diff options
Diffstat (limited to 'tests.as-root/lib')
-rw-r--r-- | tests.as-root/lib | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/tests.as-root/lib b/tests.as-root/lib new file mode 100644 index 00000000..ec5e52f9 --- /dev/null +++ b/tests.as-root/lib @@ -0,0 +1,35 @@ +#!/bin/sh +# +# Copyright (C) 2012 Codethink Limited +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; version 2 of the License. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +# Helper functions for as-root tests + +loopback_rootfs() { + # Find offset partition offset in a rootfs and mount it + ROOTFS="$1" + + mv $ROOTFS $ROOTFS-unzipped.gz + gunzip $ROOTFS-unzipped.gz + + OFFSET=$(sfdisk -d $ROOTFS-unzipped | \ + grep -m 1 -o 'start=\s\+\([0-9]\+\)' | awk '{ print $2 }') + OFFSET=$(expr $OFFSET '*' 512) + + DEVICE=$(losetup --show -o "$OFFSET" -f "$ROOTFS-unzipped") + udevadm settle + + echo $DEVICE +} |