Mercurial > hg > aboriginal
annotate sources/root-filesystem/sbin/init.sh @ 1804:8b464e266623 draft
Cosmetic tweak.
author | Rob Landley <rob@landley.net> |
---|---|
date | Mon, 02 Nov 2015 01:15:36 -0600 |
parents | 317e0a1e895d |
children | 297a5d07c73b |
rev | line source |
---|---|
1769
cb94b575c2d2
Switch from ash (which #errors building nommu) to hush.
Rob Landley <rob@landley.net>
parents:
1742
diff
changeset
|
1 #!/bin/hush |
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 |
1804 | 3 # Announce version |
4 sed -n 's/PRETTY_NAME="\([^"]*\)"/\1/p' /etc/os-release | |
5 | |
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
|
6 export HOME=/home |
1728
b89324905ca2
Giant redo to put simple-root-filesystem in initmpfs.
Rob Landley <rob@landley.net>
parents:
1577
diff
changeset
|
7 export PATH=/bin:/sbin |
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 |
1742
50c3a1575288
Split out hdainit.sh from the base root filesystem.
Rob Landley <rob@landley.net>
parents:
1735
diff
changeset
|
9 # Mount filesystems |
1440 | 10 mountpoint -q proc || mount -t proc proc proc |
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
|
11 mountpoint -q sys || mount -t sysfs sys sys |
1474
d97db0ec50fe
If host kernel hasn't got devtmpfs, call mdev -s. (Mostly for chroot-setup.sh.)
Rob Landley <rob@landley.net>
parents:
1440
diff
changeset
|
12 mountpoint -q dev || mount -t devtmpfs dev dev || mdev -s |
1279
8c0b1c9b6525
Mounting a tmpfs on /dev means /dev/pts isn't there, so mkdir it.
Rob Landley <rob@landley.net>
parents:
1247
diff
changeset
|
13 mkdir -p dev/pts |
1247
84ea1b53b73c
Mounting /dev/pts is useful.
Rob Landley <rob@landley.net>
parents:
1217
diff
changeset
|
14 mountpoint -q dev/pts || mount -t devpts dev/pts dev/pts |
1742
50c3a1575288
Split out hdainit.sh from the base root filesystem.
Rob Landley <rob@landley.net>
parents:
1735
diff
changeset
|
15 # /tmp inherited from initmpfs |
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
|
16 |
1483
54db423b7fef
If CPUS isn't set, calculate it. KVM or chroot can have >1.
Rob Landley <rob@landley.net>
parents:
1474
diff
changeset
|
17 # If nobody said how many CPUS to use in builds, try to figure it out. |
54db423b7fef
If CPUS isn't set, calculate it. KVM or chroot can have >1.
Rob Landley <rob@landley.net>
parents:
1474
diff
changeset
|
18 if [ -z "$CPUS" ] |
54db423b7fef
If CPUS isn't set, calculate it. KVM or chroot can have >1.
Rob Landley <rob@landley.net>
parents:
1474
diff
changeset
|
19 then |
54db423b7fef
If CPUS isn't set, calculate it. KVM or chroot can have >1.
Rob Landley <rob@landley.net>
parents:
1474
diff
changeset
|
20 export CPUS=$(echo /sys/devices/system/cpu/cpu[0-9]* | wc -w) |
54db423b7fef
If CPUS isn't set, calculate it. KVM or chroot can have >1.
Rob Landley <rob@landley.net>
parents:
1474
diff
changeset
|
21 [ "$CPUS" -lt 1 ] && CPUS=1 |
54db423b7fef
If CPUS isn't set, calculate it. KVM or chroot can have >1.
Rob Landley <rob@landley.net>
parents:
1474
diff
changeset
|
22 fi |
1038
2957c1dd95cb
Update native prompt to show amount of parallelism a build can get (indicating whether distcc is enabled).
Rob Landley <rob@landley.net>
parents:
1008
diff
changeset
|
23 export PS1='($HOST:$CPUS) \w \$ ' |
895
c1ab614da7b9
Change shell prompt in system image to start with ($HOST)
Rob Landley <rob@landley.net>
parents:
883
diff
changeset
|
24 |
1742
50c3a1575288
Split out hdainit.sh from the base root filesystem.
Rob Landley <rob@landley.net>
parents:
1735
diff
changeset
|
25 # When 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
|
26 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
|
27 then |
302
eb2aa88277e2
If a second block device exists, mount it on /home.
Rob Landley <rob@landley.net>
parents:
286
diff
changeset
|
28 |
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 # 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
|
30 |
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
|
31 # 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
|
32 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
|
33 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
|
34 |
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 # If we have no RTC, try rdate instead: |
880
b0aeb3446aa5
Some packages build differently as root than as a normal user, so add a "guest" account giving a non-root user option. Tweak mdev so it's vaguely useful. (Thanks to Vladimir Dronnikov for the idea.)
Rob Landley <rob@landley.net>
parents:
863
diff
changeset
|
36 [ "$(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
|
37 |
1742
50c3a1575288
Split out hdainit.sh from the base root filesystem.
Rob Landley <rob@landley.net>
parents:
1735
diff
changeset
|
38 # mount hda on /usr/overlay, hdb on /home, and hdc on /mnt, if available |
302
eb2aa88277e2
If a second block device exists, mount it on /home.
Rob Landley <rob@landley.net>
parents:
286
diff
changeset
|
39 |
1742
50c3a1575288
Split out hdainit.sh from the base root filesystem.
Rob Landley <rob@landley.net>
parents:
1735
diff
changeset
|
40 [ -b /dev/[hsv]da ] && |
50c3a1575288
Split out hdainit.sh from the base root filesystem.
Rob Landley <rob@landley.net>
parents:
1735
diff
changeset
|
41 mkdir -p /usr/overlay && mount /dev/[hsv]da /usr/overlay |
50c3a1575288
Split out hdainit.sh from the base root filesystem.
Rob Landley <rob@landley.net>
parents:
1735
diff
changeset
|
42 [ -b /dev/[hsv]db ] && mount -o noatime /dev/[hsv]db /home && cd /home |
50c3a1575288
Split out hdainit.sh from the base root filesystem.
Rob Landley <rob@landley.net>
parents:
1735
diff
changeset
|
43 [ -b /dev/[hsv]dc ] && mount -o ro /dev/[hsv]dc /mnt |
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 |
1217
1a24dc2bb3cb
Make sure PATH and CONSOLE are properly exported even when kernel command line doesn't provide the right data.
Rob Landley <rob@landley.net>
parents:
1215
diff
changeset
|
45 [ -z "$CONSOLE" ] && |
1a24dc2bb3cb
Make sure PATH and CONSOLE are properly exported even when kernel command line doesn't provide the right data.
Rob Landley <rob@landley.net>
parents:
1215
diff
changeset
|
46 CONSOLE="$(sed -n 's@.* console=\(/dev/\)*\([^ ]*\).*@\2@p' /proc/cmdline)" |
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
|
47 |
1742
50c3a1575288
Split out hdainit.sh from the base root filesystem.
Rob Landley <rob@landley.net>
parents:
1735
diff
changeset
|
48 # Call overlay/init if available |
50c3a1575288
Split out hdainit.sh from the base root filesystem.
Rob Landley <rob@landley.net>
parents:
1735
diff
changeset
|
49 [ -e /usr/overlay/init ] && . /usr/overlay/init |
50c3a1575288
Split out hdainit.sh from the base root filesystem.
Rob Landley <rob@landley.net>
parents:
1735
diff
changeset
|
50 |
1771
317e0a1e895d
Missed some instances of ash/hush switching.
Rob Landley <rob@landley.net>
parents:
1769
diff
changeset
|
51 [ -z "$HANDOFF" ] && echo Type exit when done. && HANDOFF=/bin/hush |
1742
50c3a1575288
Split out hdainit.sh from the base root filesystem.
Rob Landley <rob@landley.net>
parents:
1735
diff
changeset
|
52 [ -z "$CONSOLE" ] && CONSOLE=console |
1133
1ad777637d2d
Migrate oneit out of toybox into sources/toys as a standalone program, and fix it so pid 1 has / as its working directory so we can umount /home if necessary.
Rob Landley <rob@landley.net>
parents:
1117
diff
changeset
|
53 exec /sbin/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
|
54 |
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 # 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
|
56 else |
883
c48fc63b7df7
Fix a [ -z $test ] that produced multiple words for the $test part, but didn't have "$test" in quotes. I'm not sure how that ever worked.
Rob Landley <rob@landley.net>
parents:
880
diff
changeset
|
57 [ ! -z "$(grep "default for QEMU" /etc/resolv.conf)" ] && |
1117
725e41d66379
Use Google's nameserver, use ntpd to set time for chroot (if necessary), don't umount home if we didn't mount it.
Rob Landley <rob@landley.net>
parents:
1054
diff
changeset
|
58 echo "nameserver 8.8.8.8" > /etc/resolv.conf |
725e41d66379
Use Google's nameserver, use ntpd to set time for chroot (if necessary), don't umount home if we didn't mount it.
Rob Landley <rob@landley.net>
parents:
1054
diff
changeset
|
59 |
725e41d66379
Use Google's nameserver, use ntpd to set time for chroot (if necessary), don't umount home if we didn't mount it.
Rob Landley <rob@landley.net>
parents:
1054
diff
changeset
|
60 # If we have no RTC, try using ntp to set the clock |
725e41d66379
Use Google's nameserver, use ntpd to set time for chroot (if necessary), don't umount home if we didn't mount it.
Rob Landley <rob@landley.net>
parents:
1054
diff
changeset
|
61 [ "$(date +%s)" -lt 10000000 ] && ntpd -nq -p north-america.pool.ntp.org |
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. |
1771
317e0a1e895d
Missed some instances of ash/hush switching.
Rob Landley <rob@landley.net>
parents:
1769
diff
changeset
|
66 /bin/hush |
425
6a8f6cecce7c
Cleanup after chroot-setup.sh, and set nameserver.
Rob Landley <rob@landley.net>
parents:
415
diff
changeset
|
67 cd / |
1247
84ea1b53b73c
Mounting /dev/pts is useful.
Rob Landley <rob@landley.net>
parents:
1217
diff
changeset
|
68 umount ./dev/pts |
425
6a8f6cecce7c
Cleanup after chroot-setup.sh, and set nameserver.
Rob Landley <rob@landley.net>
parents:
415
diff
changeset
|
69 umount ./dev |
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 |