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 | |
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')
-rwxr-xr-x | scripts/poky-chroot-run | 73 | ||||
-rwxr-xr-x | scripts/poky-chroot-setup | 30 |
2 files changed, 103 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 | ||
diff --git a/scripts/poky-chroot-setup b/scripts/poky-chroot-setup new file mode 100755 index 0000000000..d85c864da7 --- /dev/null +++ b/scripts/poky-chroot-setup | |||
@@ -0,0 +1,30 @@ | |||
1 | #!/bin/bash | ||
2 | # | ||
3 | # Script to extract a poky qemux86 rootfs and prepare it for | ||
4 | # use as a chroot | ||
5 | # | ||
6 | |||
7 | set -e | ||
8 | |||
9 | case $# in | ||
10 | 2) | ||
11 | TGZ=$1 | ||
12 | TARGET=$2 | ||
13 | ;; | ||
14 | *) | ||
15 | echo "Invalid arguments, please run as:" | ||
16 | echo "$ $0 <qemux86-rootfs.tar.gz> <target-directory>" | ||
17 | exit 1 | ||
18 | esac | ||
19 | |||
20 | echo "Extracting $TGZ into $TARGET" | ||
21 | |||
22 | test -d "$TARGET" && { echo "$TARGET already exists, please remove and retry or specify a dirferent directory." ; exit 1 ; } | ||
23 | mkdir --parents "$TARGET" | ||
24 | |||
25 | tar -C "$TARGET" --exclude ./dev/\* -jxp -f "$TGZ" | ||
26 | echo "HAVE_TOUCHSCREEN=0" >> "$TARGET/etc/formfactor/machconfig" | ||
27 | echo "DISPLAY_WIDTH_PIXELS=640" >> "$TARGET/etc/formfactor/machconfig" | ||
28 | echo "DISPLAY_HEIGHT_PIXELS=480" >> "$TARGET/etc/formfactor/machconfig" | ||
29 | cp /etc/passwd "$TARGET/etc/passwd" | ||
30 | touch "$TARGET/.pokychroot" | ||