Mercurial > hg > aboriginal
annotate sources/native/bin/qemu-setup.sh @ 570:0b384865cf0c
Make the init script care about PID rather than script name for determining qemu vs chroot invocation.
author | Rob Landley <rob@landley.net> |
---|---|
date | Wed, 07 Jan 2009 17:15:52 -0600 |
parents | a0a26ea9299d |
children |
rev | line source |
---|---|
482
3e9d715e4a11
Rename CROSS_BUILD_STATIC, NATIVE_NOTOOLSDIR, NATIVE_NOTOOLCHAIN and make them work properly.
Rob Landley <rob@landley.net>
parents:
473
diff
changeset
|
1 #!/tools/bin/sh |
190
12b7ecb79ad0
A little init script for mini-native.sh that gets it read to build stuff.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2 |
361
13e35e130783
Let qemu-setup.sh be called under the name chroot-setup.sh, which skips the
Rob Landley <rob@landley.net>
parents:
359
diff
changeset
|
3 # If you're doing a Linux From Scratch build, the /tools directory is |
13e35e130783
Let qemu-setup.sh be called under the name chroot-setup.sh, which skips the
Rob Landley <rob@landley.net>
parents:
359
diff
changeset
|
4 # sufficient. (Start by installing kernel headers and building a C library.) |
13e35e130783
Let qemu-setup.sh be called under the name chroot-setup.sh, which skips the
Rob Landley <rob@landley.net>
parents:
359
diff
changeset
|
5 |
13e35e130783
Let qemu-setup.sh be called under the name chroot-setup.sh, which skips the
Rob Landley <rob@landley.net>
parents:
359
diff
changeset
|
6 # Otherwise, building source packages wants things like /bin/bash and |
13e35e130783
Let qemu-setup.sh be called under the name chroot-setup.sh, which skips the
Rob Landley <rob@landley.net>
parents:
359
diff
changeset
|
7 # running the results wants /lib/ld-uClibc.so.0, so set up some directories |
13e35e130783
Let qemu-setup.sh be called under the name chroot-setup.sh, which skips the
Rob Landley <rob@landley.net>
parents:
359
diff
changeset
|
8 # and symlinks to let you easily compile source packages. |
190
12b7ecb79ad0
A little init script for mini-native.sh that gets it read to build stuff.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
9 |
415
acb61c298000
Make setup script reentrant, don't require preset PATH. Based on changes by Vladimir Dronnikov.
Rob Landley <rob@landley.net>
parents:
372
diff
changeset
|
10 # Add /tools to $PATH if it's not there |
acb61c298000
Make setup script reentrant, don't require preset PATH. Based on changes by Vladimir Dronnikov.
Rob Landley <rob@landley.net>
parents:
372
diff
changeset
|
11 |
acb61c298000
Make setup script reentrant, don't require preset PATH. Based on changes by Vladimir Dronnikov.
Rob Landley <rob@landley.net>
parents:
372
diff
changeset
|
12 if [ -d tools/bin ] && [ -z "$(echo :$PATH | tools/bin/grep :/tools/bin)" ] |
acb61c298000
Make setup script reentrant, don't require preset PATH. Based on changes by Vladimir Dronnikov.
Rob Landley <rob@landley.net>
parents:
372
diff
changeset
|
13 then |
acb61c298000
Make setup script reentrant, don't require preset PATH. Based on changes by Vladimir Dronnikov.
Rob Landley <rob@landley.net>
parents:
372
diff
changeset
|
14 [ -z "$PATH" ] && PATH=/tools/bin || PATH="$PATH":/tools/bin |
acb61c298000
Make setup script reentrant, don't require preset PATH. Based on changes by Vladimir Dronnikov.
Rob Landley <rob@landley.net>
parents:
372
diff
changeset
|
15 export PATH |
acb61c298000
Make setup script reentrant, don't require preset PATH. Based on changes by Vladimir Dronnikov.
Rob Landley <rob@landley.net>
parents:
372
diff
changeset
|
16 fi |
570
0b384865cf0c
Make the init script care about PID rather than script name for determining qemu vs chroot invocation.
Rob Landley <rob@landley.net>
parents:
552
diff
changeset
|
17 export HOME=/home |
415
acb61c298000
Make setup script reentrant, don't require preset PATH. Based on changes by Vladimir Dronnikov.
Rob Landley <rob@landley.net>
parents:
372
diff
changeset
|
18 |
190
12b7ecb79ad0
A little init script for mini-native.sh that gets it read to build stuff.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
19 # Create some temporary directories at the root level |
426
f4d6502501d7
chroot-setup.sh should also set HOME=/home
Rob Landley <rob@landley.net>
parents:
425
diff
changeset
|
20 mkdir -p {proc,sys,dev,etc,tmp,home} |
415
acb61c298000
Make setup script reentrant, don't require preset PATH. Based on changes by Vladimir Dronnikov.
Rob Landley <rob@landley.net>
parents:
372
diff
changeset
|
21 [ ! -e bin ] && ln -s tools/bin bin |
acb61c298000
Make setup script reentrant, don't require preset PATH. Based on changes by Vladimir Dronnikov.
Rob Landley <rob@landley.net>
parents:
372
diff
changeset
|
22 [ ! -e lib ] && ln -s tools/lib lib |
acb61c298000
Make setup script reentrant, don't require preset PATH. Based on changes by Vladimir Dronnikov.
Rob Landley <rob@landley.net>
parents:
372
diff
changeset
|
23 [ ! -e usr ] && ln -s tools usr |
190
12b7ecb79ad0
A little init script for mini-native.sh that gets it read to build stuff.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
24 |
12b7ecb79ad0
A little init script for mini-native.sh that gets it read to build stuff.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
25 # Populate /dev |
415
acb61c298000
Make setup script reentrant, don't require preset PATH. Based on changes by Vladimir Dronnikov.
Rob Landley <rob@landley.net>
parents:
372
diff
changeset
|
26 mountpoint -q sys || mount -t sysfs sys sys |
acb61c298000
Make setup script reentrant, don't require preset PATH. Based on changes by Vladimir Dronnikov.
Rob Landley <rob@landley.net>
parents:
372
diff
changeset
|
27 mountpoint -q dev || mount -t tmpfs dev dev |
190
12b7ecb79ad0
A little init script for mini-native.sh that gets it read to build stuff.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
28 mdev -s |
12b7ecb79ad0
A little init script for mini-native.sh that gets it read to build stuff.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
29 |
361
13e35e130783
Let qemu-setup.sh be called under the name chroot-setup.sh, which skips the
Rob Landley <rob@landley.net>
parents:
359
diff
changeset
|
30 # Mount /proc is there |
415
acb61c298000
Make setup script reentrant, don't require preset PATH. Based on changes by Vladimir Dronnikov.
Rob Landley <rob@landley.net>
parents:
372
diff
changeset
|
31 mountpoint -q proc || mount -t proc proc proc |
361
13e35e130783
Let qemu-setup.sh be called under the name chroot-setup.sh, which skips the
Rob Landley <rob@landley.net>
parents:
359
diff
changeset
|
32 |
13e35e130783
Let qemu-setup.sh be called under the name chroot-setup.sh, which skips the
Rob Landley <rob@landley.net>
parents:
359
diff
changeset
|
33 # If we're running under qemu, do some more setup |
570
0b384865cf0c
Make the init script care about PID rather than script name for determining qemu vs chroot invocation.
Rob Landley <rob@landley.net>
parents:
552
diff
changeset
|
34 if [ $$ -eq 1 ] |
361
13e35e130783
Let qemu-setup.sh be called under the name chroot-setup.sh, which skips the
Rob Landley <rob@landley.net>
parents:
359
diff
changeset
|
35 then |
302
eb2aa88277e2
If a second block device exists, mount it on /home.
Rob Landley <rob@landley.net>
parents:
286
diff
changeset
|
36 |
361
13e35e130783
Let qemu-setup.sh be called under the name chroot-setup.sh, which skips the
Rob Landley <rob@landley.net>
parents:
359
diff
changeset
|
37 # Note that 10.0.2.2 forwards to 127.0.0.1 on the host. |
13e35e130783
Let qemu-setup.sh be called under the name chroot-setup.sh, which skips the
Rob Landley <rob@landley.net>
parents:
359
diff
changeset
|
38 |
13e35e130783
Let qemu-setup.sh be called under the name chroot-setup.sh, which skips the
Rob Landley <rob@landley.net>
parents:
359
diff
changeset
|
39 # Setup networking for QEMU (needs /proc) |
13e35e130783
Let qemu-setup.sh be called under the name chroot-setup.sh, which skips the
Rob Landley <rob@landley.net>
parents:
359
diff
changeset
|
40 echo "nameserver 10.0.2.3" > /etc/resolv.conf |
13e35e130783
Let qemu-setup.sh be called under the name chroot-setup.sh, which skips the
Rob Landley <rob@landley.net>
parents:
359
diff
changeset
|
41 ifconfig eth0 10.0.2.15 |
13e35e130783
Let qemu-setup.sh be called under the name chroot-setup.sh, which skips the
Rob Landley <rob@landley.net>
parents:
359
diff
changeset
|
42 route add default gw 10.0.2.2 |
190
12b7ecb79ad0
A little init script for mini-native.sh that gets it read to build stuff.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
43 |
361
13e35e130783
Let qemu-setup.sh be called under the name chroot-setup.sh, which skips the
Rob Landley <rob@landley.net>
parents:
359
diff
changeset
|
44 # If we have no RTC, try rdate instead: |
552
a0a26ea9299d
Use -lt to more reliably compare numbers in shell script.
Rob Landley <rob@landley.net>
parents:
482
diff
changeset
|
45 [ `date +%s` -lt 1000 ] && rdate 10.0.2.2 # or time-b.nist.gov |
361
13e35e130783
Let qemu-setup.sh be called under the name chroot-setup.sh, which skips the
Rob Landley <rob@landley.net>
parents:
359
diff
changeset
|
46 |
13e35e130783
Let qemu-setup.sh be called under the name chroot-setup.sh, which skips the
Rob Landley <rob@landley.net>
parents:
359
diff
changeset
|
47 # If there's a /dev/hdb or /dev/sdb, mount it on home |
302
eb2aa88277e2
If a second block device exists, mount it on /home.
Rob Landley <rob@landley.net>
parents:
286
diff
changeset
|
48 |
361
13e35e130783
Let qemu-setup.sh be called under the name chroot-setup.sh, which skips the
Rob Landley <rob@landley.net>
parents:
359
diff
changeset
|
49 [ -b /dev/hdb ] && HOMEDEV=/dev/hdb |
13e35e130783
Let qemu-setup.sh be called under the name chroot-setup.sh, which skips the
Rob Landley <rob@landley.net>
parents:
359
diff
changeset
|
50 [ -b /dev/sdb ] && HOMEDEV=/dev/sdb |
13e35e130783
Let qemu-setup.sh be called under the name chroot-setup.sh, which skips the
Rob Landley <rob@landley.net>
parents:
359
diff
changeset
|
51 if [ ! -z "$HOMEDEV" ] |
13e35e130783
Let qemu-setup.sh be called under the name chroot-setup.sh, which skips the
Rob Landley <rob@landley.net>
parents:
359
diff
changeset
|
52 then |
13e35e130783
Let qemu-setup.sh be called under the name chroot-setup.sh, which skips the
Rob Landley <rob@landley.net>
parents:
359
diff
changeset
|
53 mount $HOMEDEV /home |
13e35e130783
Let qemu-setup.sh be called under the name chroot-setup.sh, which skips the
Rob Landley <rob@landley.net>
parents:
359
diff
changeset
|
54 fi |
570
0b384865cf0c
Make the init script care about PID rather than script name for determining qemu vs chroot invocation.
Rob Landley <rob@landley.net>
parents:
552
diff
changeset
|
55 |
0b384865cf0c
Make the init script care about PID rather than script name for determining qemu vs chroot invocation.
Rob Landley <rob@landley.net>
parents:
552
diff
changeset
|
56 echo Type exit when done. |
0b384865cf0c
Make the init script care about PID rather than script name for determining qemu vs chroot invocation.
Rob Landley <rob@landley.net>
parents:
552
diff
changeset
|
57 exec /tools/bin/oneit -c /dev/"$(dmesg | sed -n '/^Kernel command line:/s@.* console=\(/dev/\)*\([^ ]*\).*@\2@p')" /tools/bin/ash |
0b384865cf0c
Make the init script care about PID rather than script name for determining qemu vs chroot invocation.
Rob Landley <rob@landley.net>
parents:
552
diff
changeset
|
58 |
0b384865cf0c
Make the init script care about PID rather than script name for determining qemu vs chroot invocation.
Rob Landley <rob@landley.net>
parents:
552
diff
changeset
|
59 # If we're not PID 1, it's probably a chroot. |
425
6a8f6cecce7c
Cleanup after chroot-setup.sh, and set nameserver.
Rob Landley <rob@landley.net>
parents:
415
diff
changeset
|
60 else |
6a8f6cecce7c
Cleanup after chroot-setup.sh, and set nameserver.
Rob Landley <rob@landley.net>
parents:
415
diff
changeset
|
61 echo "nameserver 4.2.2.1" > /etc/resolv.conf |
302
eb2aa88277e2
If a second block device exists, mount it on /home.
Rob Landley <rob@landley.net>
parents:
286
diff
changeset
|
62 |
570
0b384865cf0c
Make the init script care about PID rather than script name for determining qemu vs chroot invocation.
Rob Landley <rob@landley.net>
parents:
552
diff
changeset
|
63 # Switch to a shell with command history. |
372
37c8a6c9a493
Teach qemu-setup.sh to use oneit so ctrl-c works under the emulator. Also
Rob Landley <rob@landley.net>
parents:
369
diff
changeset
|
64 |
570
0b384865cf0c
Make the init script care about PID rather than script name for determining qemu vs chroot invocation.
Rob Landley <rob@landley.net>
parents:
552
diff
changeset
|
65 echo Type exit when done. |
425
6a8f6cecce7c
Cleanup after chroot-setup.sh, and set nameserver.
Rob Landley <rob@landley.net>
parents:
415
diff
changeset
|
66 /tools/bin/ash |
6a8f6cecce7c
Cleanup after chroot-setup.sh, and set nameserver.
Rob Landley <rob@landley.net>
parents:
415
diff
changeset
|
67 cd / |
6a8f6cecce7c
Cleanup after chroot-setup.sh, and set nameserver.
Rob Landley <rob@landley.net>
parents:
415
diff
changeset
|
68 umount ./dev |
6a8f6cecce7c
Cleanup after chroot-setup.sh, and set nameserver.
Rob Landley <rob@landley.net>
parents:
415
diff
changeset
|
69 umount ./home |
6a8f6cecce7c
Cleanup after chroot-setup.sh, and set nameserver.
Rob Landley <rob@landley.net>
parents:
415
diff
changeset
|
70 umount ./sys |
6a8f6cecce7c
Cleanup after chroot-setup.sh, and set nameserver.
Rob Landley <rob@landley.net>
parents:
415
diff
changeset
|
71 umount ./proc |
6a8f6cecce7c
Cleanup after chroot-setup.sh, and set nameserver.
Rob Landley <rob@landley.net>
parents:
415
diff
changeset
|
72 sync |
6a8f6cecce7c
Cleanup after chroot-setup.sh, and set nameserver.
Rob Landley <rob@landley.net>
parents:
415
diff
changeset
|
73 fi |