diff options
author | Richard Purdie <richard@openedhand.com> | 2008-01-30 15:37:49 +0000 |
---|---|---|
committer | Richard Purdie <richard@openedhand.com> | 2008-01-30 15:37:49 +0000 |
commit | 2713386f233907d652935cca7158475c26a0cac7 (patch) | |
tree | e67b6d5cc1d5f386ac32025c9f6bdbf0fcb42279 /scripts/poky-chroot-run | |
parent | f55e6e493e881453975fb038d88fcf13474ef42f (diff) | |
download | poky-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-x | scripts/poky-chroot-run | 73 |
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 | |||
6 | set -e | ||
7 | |||
8 | case $# 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 | ;; | ||
25 | esac | ||
26 | |||
27 | test -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 | ||
31 | if test ${ROOTFS:0:1} != /; then | ||
32 | ROOTFS="$(pwd)/$ROOTFS" | ||
33 | fi | ||
34 | |||
35 | safe_mount() { | ||
36 | if ! mountpoint -q "$ROOTFS/$1"; then | ||
37 | sudo mount --bind $1 "$ROOTFS/$1" | ||
38 | fi | ||
39 | } | ||
40 | safe_umount() { | ||
41 | if mountpoint -q "$ROOTFS/$1"; then | ||
42 | sudo umount "$ROOTFS/$1" | ||
43 | fi | ||
44 | } | ||
45 | |||
46 | # Mount the directories we need | ||
47 | for m in /dev /dev/pts /dev/shm /proc /sys /tmp; do | ||
48 | safe_mount $m | ||
49 | done | ||
50 | |||
51 | # Set up the environment | ||
52 | export PATH=/bin:/usr/bin:/sbin:/usr/sbin | ||
53 | export HOME=/home/$USER | ||
54 | |||
55 | if [ ! -f "$ROOTFS/.pokychroot.init" ]; then | ||
56 | sudo chrootuid -i "$ROOTFS" $USER /bin/sh -c "/usr/bin/poky-chroot-init" | ||
57 | touch "$ROOTFS/.pokychroot.init" | ||
58 | fi | ||
59 | |||
60 | Xephyr :1 -ac -screen 640x480x16 & | ||
61 | |||
62 | # Go go go! | ||
63 | sudo chrootuid -i "$ROOTFS" $USER "$@" || /bin/true | ||
64 | |||
65 | # Trap term signals so we don't kill ourselves | ||
66 | trap true TERM | ||
67 | # send term signal to the process group | ||
68 | kill -- -$$ | ||
69 | |||
70 | # Unmount TODO: only umount if there are no other sessions active, somehow. | ||
71 | for m in /tmp /sys /proc /dev/shm /dev/pts /dev; do | ||
72 | safe_umount $m | ||
73 | done | ||