summaryrefslogtreecommitdiffstats
path: root/scripts/poky-chroot-run
diff options
context:
space:
mode:
authorRichard Purdie <richard@openedhand.com>2008-01-30 15:37:49 +0000
committerRichard Purdie <richard@openedhand.com>2008-01-30 15:37:49 +0000
commit2713386f233907d652935cca7158475c26a0cac7 (patch)
treee67b6d5cc1d5f386ac32025c9f6bdbf0fcb42279 /scripts/poky-chroot-run
parentf55e6e493e881453975fb038d88fcf13474ef42f (diff)
downloadpoky-2713386f233907d652935cca7158475c26a0cac7.tar.gz
scripts: Add poky-chroot scripts (credit should mainly go to Ross)
git-svn-id: https://svn.o-hand.com/repos/poky/trunk@3627 311d38ba-8fff-0310-9ca6-ca027cbcb966
Diffstat (limited to 'scripts/poky-chroot-run')
-rwxr-xr-xscripts/poky-chroot-run73
1 files changed, 73 insertions, 0 deletions
diff --git a/scripts/poky-chroot-run b/scripts/poky-chroot-run
new file mode 100755
index 0000000000..6b78e3c60b
--- /dev/null
+++ b/scripts/poky-chroot-run
@@ -0,0 +1,73 @@
1#!/bin/bash
2#
3# Runs a command within a Poky chroot
4#
5
6set -e
7
8case $# in
9 0)
10 echo "Invalid arguments."
11 echo "$ $0 <target> [command]"
12 exit 1
13 ;;
14 1)
15 ROOTFS=$1
16 shift
17 # Set $1 to be the boot script
18 set -- /usr/bin/poky-chroot-launch
19 ;;
20 *)
21 ROOTFS=$1
22 shift
23 # Now $1 onwards are the command and arguments to run
24 ;;
25esac
26
27test -f "$ROOTFS/.pokychroot" || { echo "$ROOTFS is not setup for use as a Poky chroot." ; exit 1 ;}
28
29# chrootuid doesn't handle relative paths, so ensure that the rootfs path is
30# absolute
31if test ${ROOTFS:0:1} != /; then
32 ROOTFS="$(pwd)/$ROOTFS"
33fi
34
35safe_mount() {
36 if ! mountpoint -q "$ROOTFS/$1"; then
37 sudo mount --bind $1 "$ROOTFS/$1"
38 fi
39}
40safe_umount() {
41 if mountpoint -q "$ROOTFS/$1"; then
42 sudo umount "$ROOTFS/$1"
43 fi
44}
45
46# Mount the directories we need
47for m in /dev /dev/pts /dev/shm /proc /sys /tmp; do
48 safe_mount $m
49done
50
51# Set up the environment
52export PATH=/bin:/usr/bin:/sbin:/usr/sbin
53export HOME=/home/$USER
54
55if [ ! -f "$ROOTFS/.pokychroot.init" ]; then
56 sudo chrootuid -i "$ROOTFS" $USER /bin/sh -c "/usr/bin/poky-chroot-init"
57 touch "$ROOTFS/.pokychroot.init"
58fi
59
60Xephyr :1 -ac -screen 640x480x16 &
61
62# Go go go!
63sudo chrootuid -i "$ROOTFS" $USER "$@" || /bin/true
64
65# Trap term signals so we don't kill ourselves
66trap true TERM
67# send term signal to the process group
68kill -- -$$
69
70# Unmount TODO: only umount if there are no other sessions active, somehow.
71for m in /tmp /sys /proc /dev/shm /dev/pts /dev; do
72 safe_umount $m
73done