ostree/gnomeos/yocto/gnomeos-run.sh

100 lines
2.5 KiB
Bash
Executable File

#!/bin/sh
# -*- indent-tabs-mode: nil; -*-
# Run built image in QEMU
#
# Copyright (C) 2011 Colin Walters <walters@verbum.org>
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2 of the License, or (at your option) any later version.
#
# This library 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
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the
# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA.
set -e
set -x
SRCDIR=`dirname $0`
WORKDIR=`pwd`
if test $(id -u) != 0; then
cat <<EOF
This script should be run as root.
EOF
exit 1
fi
usage () {
echo "$0 OSTREE_REPO_PATH"
exit 1
}
OSTREE_REPO=$1
shift
test -n "$OSTREE_REPO" || usage
ARCH=x86
BRANCH_PREFIX="gnomeos-yocto-${ARCH}-"
OBJ=gnomeos-fs.img
if (! test -f ${OBJ}); then
rm -f ${OBJ}.tmp
qemu-img create ${OBJ}.tmp 2G
mkfs.ext3 -q -F ${OBJ}.tmp
mkdir -p fs
umount fs || true
mount -o loop ${OBJ}.tmp fs
cd fs
TOPROOT_BIND_MOUNTS="home root tmp"
for d in $TOPROOT_BIND_MOUNTS; do
mkdir -m 0755 $d
done
chmod a=rwxt tmp
mkdir ostree
mkdir -p -m 0755 ./ostree/var/{log,run,tmp,spool}
cd ostree
mkdir repo
ostree --repo=repo init
ostree --repo=${OSTREE_REPO} local-clone repo
for branch in base dev; do
rev=$(ostree --repo=repo rev-parse ${BRANCH_PREFIX}${branch});
ostree --repo=repo checkout ${rev} ${BRANCH_PREFIX}${branch}-${rev}
ln -s ${BRANCH_PREFIX}${branch}-${rev} ${BRANCH_PREFIX}${branch}-current
done
cd ..
mkdir proc # needed for ostree-init
cp -a ./ostree/${BRANCH_PREFIX}base-current/usr/sbin/ostree-init .
cd ${WORKDIR}
umount fs
rmdir fs
mv ${OBJ}.tmp ${OBJ}
fi
ARGS="$@"
if ! echo $ARGS | grep -q 'init='; then
ARGS="init=/ostree-init $ARGS"
fi
if ! echo $ARGS | grep -q 'root='; then
ARGS="root=/dev/hda $ARGS"
fi
if ! echo $ARGS | grep -q 'ostree='; then
ARGS="ostree=${BRANCH_PREFIX}base-current $ARGS"
fi
exec qemu-kvm -kernel ./tmp-eglibc/deploy/images/bzImage-qemux86.bin -hda gnomeos-fs.img -net user -net nic,model=virtio -append "$ARGS"