source: trunk/package/base-files/files/etc/preinit @ 15097

Last change on this file since 15097 was 15097, checked in by nbd, 8 years ago

rename our /bin/login script to /bin/login.sh to avoid collisions with busybox - we always use -l on telnetd anyway

  • Property svn:eol-style set to native
  • Property svn:executable set to *
File size: 2.1 KB
Line 
1#!/bin/sh
2# Copyright (C) 2006 OpenWrt.org
3export PATH=/bin:/sbin:/usr/bin:/usr/sbin
4. /etc/diag.sh
5
6failsafe_ip() {
7        ifconfig $ifname 192.168.1.1 netmask 255.255.255.0 broadcast 192.168.1.255 up
8}
9
10failsafe() {
11        [ -n "$ifname" ] && grep "$ifname" /proc/net/dev >/dev/null && {
12                failsafe_ip
13                netmsg 192.168.1.255 "Entering Failsafe!"
14                telnetd -l /bin/login.sh <> /dev/null 2>&1
15        }
16        lock /tmp/.failsafe
17        ash --login
18}
19
20mount proc /proc -t proc
21mount sysfs /sys -t sysfs
22
23size=$(awk '/MemTotal:/ {l=5242880;mt=($2*1024);print((s=mt/2)<l)&&(mt>l)?mt-l:s}' /proc/meminfo)
24mount tmpfs /tmp -t tmpfs -o size=$size,nosuid,nodev,mode=1777
25
26if grep devfs /proc/filesystems > /dev/null; then
27        mount devfs /dev -t devfs
28        M0=/dev/pty/m0
29        M1=/dev/pty/m1
30        HOTPLUG=/sbin/hotplug-call
31
32elif [ -x /sbin/hotplug2 ]; then
33        mount -t tmpfs tmpfs /dev -o size=512K
34        mknod /dev/console c 5 1
35        /sbin/hotplug2 --coldplug --set-rules-file /etc/hotplug2-init.rules
36        /sbin/hotplug2 --no-coldplug --persistent --set-rules-file /etc/hotplug2-init.rules &
37        M0=/dev/ptmx
38        M1=/dev/ptmx
39        HOTPLUG=
40
41elif [ -x /sbin/udevd ]; then
42        mount -n -t tmpfs -o mode=0755 udev /dev
43        /sbin/udevd --daemon
44        /sbin/udevtrigger
45        /sbin/udevsettle
46        M0=/dev/pty/ptmx
47        M1=/dev/pty/ptmx
48        HOTPLUG=
49fi
50
51mkdir -p /dev/pts /dev/shm
52mount devpts /dev/pts -t devpts
53
54# the shell really doesn't like having stdin/out closed
55# that's why we use /dev/pty/m0 and m1 as replacement
56# for /dev/console if there's no serial console available
57dd if=/dev/console of=/dev/null bs=1 count=0 >/dev/null 2>/dev/null && {
58        M0=/dev/console
59        M1=/dev/console
60}
61
62exec <$M0 >$M1 2>&0
63
64echo "- preinit -"
65echo "Press CTRL-C for failsafe"
66trap 'FAILSAFE=true' INT
67trap 'FAILSAFE=true' USR1
68[ -e /etc/preinit.arch ] && . /etc/preinit.arch
69set_state preinit
70echo "$HOTPLUG" > /proc/sys/kernel/hotplug
71export FAILSAFE
72eval ${FAILSAFE:+failsafe}
73lock -w /tmp/.failsafe
74
75if [ -z "$INITRAMFS" ]; then
76        mount_root
77        [ -f /sysupgrade.tgz ] && {
78                echo "- config restore -"
79                cd /
80                mv sysupgrade.tgz /tmp
81                tar xzf /tmp/sysupgrade.tgz
82                rm -f /tmp/sysupgrade.tgz
83                sync
84        }
85
86        echo "- init -"
87       
88        exec /sbin/init
89fi
Note: See TracBrowser for help on using the repository browser.