summaryrefslogtreecommitdiff
path: root/lx-trainer-vm
diff options
context:
space:
mode:
authorJohn Ogness <john.ogness@linutronix.de>2017-12-19 09:00:18 +0100
committerJohn Ogness <john.ogness@linutronix.de>2017-12-19 09:00:18 +0100
commit0f4c957f0019657c8d1a64e11b685f93541663a8 (patch)
treeb589133138b3bf2518b88465699d977450a78660 /lx-trainer-vm
parent55c4606e9b55433f2542079a72fad609dbc94469 (diff)
dd-multi.sh: add layer support
Layers can now be specified using: --layer=tarball Signed-off-by: John Ogness <john.ogness@linutronix.de>
Diffstat (limited to 'lx-trainer-vm')
-rwxr-xr-xlx-trainer-vm/dd-multi.sh57
1 files changed, 52 insertions, 5 deletions
diff --git a/lx-trainer-vm/dd-multi.sh b/lx-trainer-vm/dd-multi.sh
index b715681..2af3798 100755
--- a/lx-trainer-vm/dd-multi.sh
+++ b/lx-trainer-vm/dd-multi.sh
@@ -4,7 +4,7 @@ set -e
usage_exit()
{
echo
- echo "usage: $0 src dest [dest]..."
+ echo "usage: $0 src [--layer=tarball]... dest [dest]..."
echo
echo "example: copying image to devs sde, sdf, sdg"
echo "$0 lx-trainer.img /dev/sde /dev/sdf /dev/sdg"
@@ -12,15 +12,40 @@ usage_exit()
exit 1
}
+if [ `id -u` -ne 0 ]; then
+ echo "error: this script must be run as root"
+ exit 1
+fi
+
# minimum 2 arguments
if [ $# -lt 2 ]; then
echo "error: invalid arguments"
usage_exit
fi
-SRC="$1"
-shift
-DESTS="$@"
+# gather arguments
+SRC=""
+LAYERS=""
+DESTS=""
+
+for arg in $@; do
+case $arg in
+--layer=*)
+ LAYERS="$LAYERS `echo $arg | sed -e 's/^--layer=//'`"
+ ;;
+--*)
+ echo "error: unknown option: $arg"
+ usage_exit
+ ;;
+*)
+ if [ -z "$SRC" ]; then
+ SRC="$arg"
+ else
+ DESTS="$DESTS $arg"
+ fi
+ ;;
+esac
+done
# source must be file or block device
if [ ! -f "$SRC" -a ! -b "$SRC" ]; then
@@ -90,9 +115,31 @@ for dest in $DESTS; do
echo 'LABEL=lxhome /home ext4 defaults 0 0' | \
tee -a ${TMP_ROOT}${dest}1/etc/fstab
+ # copy layer tarballs to /home
+ for tarball in $LAYERS; do
+ destfile="${TMP_ROOT}${dest}2/$tarball"
+ if [ -f $destfile ]; then
+ echo
+ echo "WARNING: OVERWRITING $destfile" 1>&2
+ echo
+ sleep 1
+ fi
+ cp $tarball $destfile
+ done
+
+ # remount home to /home
+ umount ${TMP_ROOT}${dest}2
+ mount ${dest}2 ${TMP_ROOT}${dest}1/home
+
+ # unpack layers
+ for tarball in $LAYERS; do
+ chroot ${TMP_ROOT}${dest}1 tar -x -f /home/$tarball --numeric-owner -C /
+ rm ${TMP_ROOT}${dest}1/home/$tarball
+ done
+
# unmount partitions
+ umount ${TMP_ROOT}${dest}1/home
umount ${TMP_ROOT}${dest}1
- umount ${TMP_ROOT}${dest}2
done
# cleanup temp directory