Mercurial > hg > aboriginal
annotate sources/native/sbin/init.sh @ 863:4bfe2b34dd9f
Largeish refactoring/simplification of run-emulator.sh and associated code. Now automatically sets up the distcc trick if the appropriate $ARCH-cc toolchain is in the $PATH (or the current directory).
author | Rob Landley <rob@landley.net> |
---|---|
date | Mon, 26 Oct 2009 06:09:29 -0500 |
parents | f448815e20b0 |
children | b0aeb3446aa5 |
rev | line source |
---|---|
783
db06a8c1bfed
Lots of changes to move buildall.sh functionality into build.sh.
Rob Landley <rob@landley.net>
parents:
741
diff
changeset
|
1 #!/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 # 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
|
4 # 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
|
5 # 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
|
6 |
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
|
7 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
|
8 |
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 # 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
|
10 mountpoint -q sys || mount -t sysfs sys sys |
688
78cbd428d60e
Feed noatime flag to init.sh mounts.
Rob Landley <rob@landley.net>
parents:
673
diff
changeset
|
11 mountpoint -q dev || mount -t tmpfs -o noatime 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
|
12 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
|
13 |
790
188a182b1a7f
Remove some leftover /tools residue.
Rob Landley <rob@landley.net>
parents:
783
diff
changeset
|
14 # Make sure /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
|
15 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
|
16 |
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
|
17 # 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
|
18 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
|
19 then |
302
eb2aa88277e2
If a second block device exists, mount it on /home.
Rob Landley <rob@landley.net>
parents:
286
diff
changeset
|
20 |
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
|
21 # 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
|
22 |
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
|
23 # 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
|
24 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
|
25 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
|
26 |
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
|
27 # 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
|
28 [ `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
|
29 |
863
4bfe2b34dd9f
Largeish refactoring/simplification of run-emulator.sh and associated code. Now automatically sets up the distcc trick if the appropriate $ARCH-cc toolchain is in the $PATH (or the current directory).
Rob Landley <rob@landley.net>
parents:
836
diff
changeset
|
30 mount -t tmpfs /tmp /tmp |
4bfe2b34dd9f
Largeish refactoring/simplification of run-emulator.sh and associated code. Now automatically sets up the distcc trick if the appropriate $ARCH-cc toolchain is in the $PATH (or the current directory).
Rob Landley <rob@landley.net>
parents:
836
diff
changeset
|
31 |
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 # 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
|
33 |
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
|
34 [ -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
|
35 [ -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
|
36 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
|
37 then |
688
78cbd428d60e
Feed noatime flag to init.sh mounts.
Rob Landley <rob@landley.net>
parents:
673
diff
changeset
|
38 mount -o noatime $HOMEDEV /home |
863
4bfe2b34dd9f
Largeish refactoring/simplification of run-emulator.sh and associated code. Now automatically sets up the distcc trick if the appropriate $ARCH-cc toolchain is in the $PATH (or the current directory).
Rob Landley <rob@landley.net>
parents:
836
diff
changeset
|
39 else |
4bfe2b34dd9f
Largeish refactoring/simplification of run-emulator.sh and associated code. Now automatically sets up the distcc trick if the appropriate $ARCH-cc toolchain is in the $PATH (or the current directory).
Rob Landley <rob@landley.net>
parents:
836
diff
changeset
|
40 mount -t tmpfs /home /home |
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
|
41 fi |
863
4bfe2b34dd9f
Largeish refactoring/simplification of run-emulator.sh and associated code. Now automatically sets up the distcc trick if the appropriate $ARCH-cc toolchain is in the $PATH (or the current directory).
Rob Landley <rob@landley.net>
parents:
836
diff
changeset
|
42 cd /home |
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
|
43 |
833
18fa21056b01
System Images' sbin/init.sh should mount /dev/hdc (if it exists) on /mnt, and then run /mnt/init (instead of a shell prompt) if that exists.
Rob Landley <rob@landley.net>
parents:
790
diff
changeset
|
44 [ -b /dev/hdc ] && MNTDEV=/dev/hdc |
18fa21056b01
System Images' sbin/init.sh should mount /dev/hdc (if it exists) on /mnt, and then run /mnt/init (instead of a shell prompt) if that exists.
Rob Landley <rob@landley.net>
parents:
790
diff
changeset
|
45 [ -b /dev/sdc ] && MNTDEV=/dev/sdc |
18fa21056b01
System Images' sbin/init.sh should mount /dev/hdc (if it exists) on /mnt, and then run /mnt/init (instead of a shell prompt) if that exists.
Rob Landley <rob@landley.net>
parents:
790
diff
changeset
|
46 if [ ! -z "$MNTDEV" ] |
18fa21056b01
System Images' sbin/init.sh should mount /dev/hdc (if it exists) on /mnt, and then run /mnt/init (instead of a shell prompt) if that exists.
Rob Landley <rob@landley.net>
parents:
790
diff
changeset
|
47 then |
18fa21056b01
System Images' sbin/init.sh should mount /dev/hdc (if it exists) on /mnt, and then run /mnt/init (instead of a shell prompt) if that exists.
Rob Landley <rob@landley.net>
parents:
790
diff
changeset
|
48 mount -o ro $MNTDEV /mnt |
18fa21056b01
System Images' sbin/init.sh should mount /dev/hdc (if it exists) on /mnt, and then run /mnt/init (instead of a shell prompt) if that exists.
Rob Landley <rob@landley.net>
parents:
790
diff
changeset
|
49 fi |
18fa21056b01
System Images' sbin/init.sh should mount /dev/hdc (if it exists) on /mnt, and then run /mnt/init (instead of a shell prompt) if that exists.
Rob Landley <rob@landley.net>
parents:
790
diff
changeset
|
50 |
18fa21056b01
System Images' sbin/init.sh should mount /dev/hdc (if it exists) on /mnt, and then run /mnt/init (instead of a shell prompt) if that exists.
Rob Landley <rob@landley.net>
parents:
790
diff
changeset
|
51 CONSOLE="$(dmesg | |
18fa21056b01
System Images' sbin/init.sh should mount /dev/hdc (if it exists) on /mnt, and then run /mnt/init (instead of a shell prompt) if that exists.
Rob Landley <rob@landley.net>
parents:
790
diff
changeset
|
52 sed -n '/^Kernel command line:/s@.* console=\(/dev/\)*\([^ ]*\).*@\2@p')" |
18fa21056b01
System Images' sbin/init.sh should mount /dev/hdc (if it exists) on /mnt, and then run /mnt/init (instead of a shell prompt) if that exists.
Rob Landley <rob@landley.net>
parents:
790
diff
changeset
|
53 |
863
4bfe2b34dd9f
Largeish refactoring/simplification of run-emulator.sh and associated code. Now automatically sets up the distcc trick if the appropriate $ARCH-cc toolchain is in the $PATH (or the current directory).
Rob Landley <rob@landley.net>
parents:
836
diff
changeset
|
54 if [ -z "$DISTCC_HOSTS" ] |
4bfe2b34dd9f
Largeish refactoring/simplification of run-emulator.sh and associated code. Now automatically sets up the distcc trick if the appropriate $ARCH-cc toolchain is in the $PATH (or the current directory).
Rob Landley <rob@landley.net>
parents:
836
diff
changeset
|
55 then |
4bfe2b34dd9f
Largeish refactoring/simplification of run-emulator.sh and associated code. Now automatically sets up the distcc trick if the appropriate $ARCH-cc toolchain is in the $PATH (or the current directory).
Rob Landley <rob@landley.net>
parents:
836
diff
changeset
|
56 echo "Not using distcc." |
4bfe2b34dd9f
Largeish refactoring/simplification of run-emulator.sh and associated code. Now automatically sets up the distcc trick if the appropriate $ARCH-cc toolchain is in the $PATH (or the current directory).
Rob Landley <rob@landley.net>
parents:
836
diff
changeset
|
57 else |
4bfe2b34dd9f
Largeish refactoring/simplification of run-emulator.sh and associated code. Now automatically sets up the distcc trick if the appropriate $ARCH-cc toolchain is in the $PATH (or the current directory).
Rob Landley <rob@landley.net>
parents:
836
diff
changeset
|
58 echo "Distcc acceleration enabled." |
4bfe2b34dd9f
Largeish refactoring/simplification of run-emulator.sh and associated code. Now automatically sets up the distcc trick if the appropriate $ARCH-cc toolchain is in the $PATH (or the current directory).
Rob Landley <rob@landley.net>
parents:
836
diff
changeset
|
59 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
|
60 echo Type exit when done. |
833
18fa21056b01
System Images' sbin/init.sh should mount /dev/hdc (if it exists) on /mnt, and then run /mnt/init (instead of a shell prompt) if that exists.
Rob Landley <rob@landley.net>
parents:
790
diff
changeset
|
61 |
18fa21056b01
System Images' sbin/init.sh should mount /dev/hdc (if it exists) on /mnt, and then run /mnt/init (instead of a shell prompt) if that exists.
Rob Landley <rob@landley.net>
parents:
790
diff
changeset
|
62 HANDOFF=/bin/ash |
18fa21056b01
System Images' sbin/init.sh should mount /dev/hdc (if it exists) on /mnt, and then run /mnt/init (instead of a shell prompt) if that exists.
Rob Landley <rob@landley.net>
parents:
790
diff
changeset
|
63 [ -e /mnt/init ] && HANDOFF=/mnt/init |
18fa21056b01
System Images' sbin/init.sh should mount /dev/hdc (if it exists) on /mnt, and then run /mnt/init (instead of a shell prompt) if that exists.
Rob Landley <rob@landley.net>
parents:
790
diff
changeset
|
64 exec /bin/oneit -c /dev/"$CONSOLE" "$HANDOFF" |
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 |
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
|
66 # 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
|
67 else |
836
f448815e20b0
Vladimir Dronnikov requested init.sh not overwrite resolv.conf unnecessarily.
Rob Landley <rob@landley.net>
parents:
833
diff
changeset
|
68 [ ! -z $(grep "default for QEMU" /etc/resolv.conf) ] && |
f448815e20b0
Vladimir Dronnikov requested init.sh not overwrite resolv.conf unnecessarily.
Rob Landley <rob@landley.net>
parents:
833
diff
changeset
|
69 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
|
70 |
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
|
71 # 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
|
72 |
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
|
73 echo Type exit when done. |
790
188a182b1a7f
Remove some leftover /tools residue.
Rob Landley <rob@landley.net>
parents:
783
diff
changeset
|
74 /bin/ash |
425
6a8f6cecce7c
Cleanup after chroot-setup.sh, and set nameserver.
Rob Landley <rob@landley.net>
parents:
415
diff
changeset
|
75 cd / |
6a8f6cecce7c
Cleanup after chroot-setup.sh, and set nameserver.
Rob Landley <rob@landley.net>
parents:
415
diff
changeset
|
76 umount ./dev |
6a8f6cecce7c
Cleanup after chroot-setup.sh, and set nameserver.
Rob Landley <rob@landley.net>
parents:
415
diff
changeset
|
77 umount ./home |
6a8f6cecce7c
Cleanup after chroot-setup.sh, and set nameserver.
Rob Landley <rob@landley.net>
parents:
415
diff
changeset
|
78 umount ./sys |
6a8f6cecce7c
Cleanup after chroot-setup.sh, and set nameserver.
Rob Landley <rob@landley.net>
parents:
415
diff
changeset
|
79 umount ./proc |
6a8f6cecce7c
Cleanup after chroot-setup.sh, and set nameserver.
Rob Landley <rob@landley.net>
parents:
415
diff
changeset
|
80 sync |
6a8f6cecce7c
Cleanup after chroot-setup.sh, and set nameserver.
Rob Landley <rob@landley.net>
parents:
415
diff
changeset
|
81 fi |