Commit | Line | Data |
---|---|---|
b70e0e65 | 1 | #!/bin/sh |
60a77e5f | 2 | |
b70e0e65 | 3 | # |
60a77e5f | 4 | # initramfs /init (busybox ash) |
b70e0e65 JB |
5 | # |
6 | ||
60a77e5f JB |
7 | # color codes and some predefined texts |
8 | BOLD="\033[1m" | |
9 | NORM="\033[0m" | |
10 | RED="\033[31m" | |
11 | GREEN="\033[32m" | |
12 | YELLOW="\033[33m" | |
13 | BLUE="\033[34m" | |
14 | OK="${BOLD}${GREEN}OK${NORM}" | |
15 | FAILED="${BOLD}${RED}FAILED${NORM}" | |
16 | ||
17 | # helper functions | |
18 | ||
19 | # check an exit value and print a colored status | |
20 | checkReturn() { | |
21 | if [ $? -ne 0 ] | |
22 | then | |
23 | echo -e $FAILED | |
24 | else | |
25 | echo -e $OK | |
26 | fi | |
27 | } | |
b70e0e65 | 28 | |
60a77e5f JB |
29 | # search for and mount the crux media, populate a tmpfs from it, |
30 | # and prepare /newroot for switch_root at the end of the script | |
31 | find_and_mount_media() { | |
32 | echo -e " ${BOLD}${BLUE}*${NORM} Searching for the CRUX media..." | |
dfd7aefe | 33 | mkdir -p /media |
06ba1c90 | 34 | MMC_DEVICES="`grep -E 'mmcblk0p' /proc/partitions | awk '{ print $4 }'`" |
60a77e5f JB |
35 | BLOCK_DEVICES="`grep -E '[sh]d' /proc/partitions | awk '{ print $4 }'`" |
36 | for DEV in $MMC_DEVICES $BLOCK_DEVICES | |
37 | do | |
38 | DEV="/dev/$DEV" | |
39 | mount -r $DEV /media 2> /dev/null | |
40 | if [ $? -eq 0 ] | |
41 | then | |
42 | echo -e -n " ${BOLD}${GREEN}*${NORM} Found media on $DEV" | |
43 | if [ -e /media/crux-media ] | |
44 | then | |
45 | echo ", CRUX media." | |
60a77e5f JB |
46 | ln -s $DEV /dev/media |
47 | break | |
48 | else | |
49 | echo ", but it's not the CRUX media." | |
50 | umount /media | |
51 | fi | |
52 | else | |
53 | echo -e " ${BOLD}${YELLOW}*${NORM} No media found on $DEV." | |
54 | fi | |
55 | done | |
b70e0e65 | 56 | |
60a77e5f JB |
57 | # check if the media was mounted properly. if not, spawn a shell |
58 | if [ ! -e /media/crux-media ] | |
59 | then | |
60 | echo | |
61 | echo -e " ${BOLD}${RED}*${NORM} The CRUX media was not properly mounted!" | |
62 | echo " Spawning a shell for you to attempt to fix this problem. If" | |
63 | echo " you are able to find the correct device, mount it at" | |
64 | echo " /media and then log out of this shell to continue." | |
65 | echo " If you are NOT able to fix the problem, installation will" | |
66 | echo " not be possible." | |
67 | echo | |
68 | /bin/sh | |
69 | fi | |
b70e0e65 | 70 | |
60a77e5f JB |
71 | # check again and stop if it's still not there |
72 | if [ ! -e /media/crux-media ] | |
73 | then | |
74 | echo | |
75 | echo -e " ${BOLD}${RED}*${NORM} The CRUX media still appears not to be" | |
76 | echo " found and installation will not continue." | |
77 | echo | |
78 | else | |
dfd7aefe | 79 | # configure modules |
eebbffc5 | 80 | MODULES="`find /media/crux/kernel -type f -name 'modules-*.tar.*' 2>/dev/null`" |
6cc6cf55 JB |
81 | if [ ! -z "$MODULES" ]; then |
82 | tar -C /tmp -xf $MODULES | |
b3584205 | 83 | cd /lib && ln -s /tmp/lib/* . |
60a77e5f JB |
84 | depmod |
85 | fi | |
dfd7aefe | 86 | # configure pkgutils |
eebbffc5 | 87 | PKGUTILS="`find /media/crux/core -type f -name 'pkgutils#*.pkg.tar.*' 2>/dev/null`" |
dfd7aefe | 88 | if [ ! -z "$PKGUTILS" ]; then |
6cc6cf55 | 89 | tar -C /tmp -xf $PKGUTILS |
dfd7aefe JB |
90 | cd /usr/bin && ln -s /tmp/usr/bin/* . |
91 | cd /etc && ln -s /tmp/etc/* . | |
60a77e5f JB |
92 | fi |
93 | fi | |
94 | } | |
95 | ||
96 | # | |
97 | # main script | |
98 | # | |
b70e0e65 | 99 | |
60a77e5f | 100 | echo "" |
c8f0f771 | 101 | echo -e "${BOLD}CRUX-ARM 3.1 - ${BLUE}http://crux-arm.nu/${NORM}" |
60a77e5f | 102 | echo "" |
b70e0e65 | 103 | |
60a77e5f JB |
104 | exec >/dev/console </dev/console 2>&1 |
105 | ||
1a72982e JB |
106 | # premature mount /proc since we need some rw operations |
107 | echo -e -n " ${BOLD}${BLUE}*${NORM} Mounting " | |
108 | echo -e -n "${BOLD}${GREEN}/proc${NORM}" | |
109 | mount -t proc proc /proc | |
110 | ||
111 | if grep -q "debug" /proc/cmdline | |
112 | then | |
113 | DEBUG=1 | |
114 | fi | |
115 | ||
116 | # dont show kernel printk messages | |
117 | PRINTK="`cat /proc/sys/kernel/printk`" | |
118 | if [ -z $DEBUG ] | |
119 | then | |
120 | echo "0" > /proc/sys/kernel/printk | |
121 | fi | |
122 | ||
123 | echo -e ", ${BOLD}${GREEN}/sys${NORM}." | |
124 | mount -t sysfs sysfs /sys | |
125 | ||
60a77e5f | 126 | echo -e -n " ${BOLD}${BLUE}*${NORM} Mounting filesystems... " |
dfd7aefe JB |
127 | mount -a && \ |
128 | mount -o remount,rw / | |
60a77e5f JB |
129 | checkReturn |
130 | ||
131 | echo -e -n " ${BOLD}${BLUE}*${NORM} Populating /dev via mdev... " | |
132 | mdev -s | |
133 | checkReturn | |
134 | ||
135 | echo -e -n " ${BOLD}${BLUE}*${NORM} Registering mdev as hotplug agent... " | |
b70e0e65 | 136 | echo "/bin/mdev" > /proc/sys/kernel/hotplug |
60a77e5f JB |
137 | checkReturn |
138 | ||
139 | echo -e -n " ${BOLD}${BLUE}*${NORM} Creating and mounting /dev/pts... " | |
140 | mkdir /dev/pts | |
141 | mount -t devpts devpts /dev/pts | |
142 | checkReturn | |
143 | ||
144 | echo -e -n " ${BOLD}${BLUE}*${NORM} Starting kernel log daemon... " | |
145 | klogd | |
146 | checkReturn | |
b70e0e65 | 147 | |
60a77e5f JB |
148 | echo -e -n " ${BOLD}${BLUE}*${NORM} Setting hostname... " |
149 | hostname crux | |
150 | checkReturn | |
b70e0e65 | 151 | |
60a77e5f | 152 | echo -e -n " ${BOLD}${BLUE}*${NORM} Loading network loopback device... " |
dfd7aefe JB |
153 | ip addr add 127.0.0.1/8 dev lo broadcast + scope host && \ |
154 | ip link set lo up && \ | |
60a77e5f JB |
155 | echo "127.0.0.1 localhost crux" > /etc/hosts |
156 | checkReturn | |
b70e0e65 | 157 | |
60a77e5f JB |
158 | echo -e -n " ${BOLD}${BLUE}*${NORM} Saving boot messages... " |
159 | dmesg > /var/log/boot | |
160 | checkReturn | |
b70e0e65 | 161 | |
1a72982e JB |
162 | # run mdev again to fix issues with mmc devices. yeah, it is weird but worked |
163 | mdev -s | |
164 | ||
dfd7aefe | 165 | echo -e " ${BOLD}${BLUE}*${NORM} Trying to find and mount the media installer..." |
60a77e5f | 166 | find_and_mount_media |
b70e0e65 | 167 | |
1a72982e JB |
168 | # debug could be necessary when are working with a new device and/or features |
169 | # and for a weird reason you can't see any output message on the console. | |
170 | # You can create a debug.sh script at topdir of your install media and redirect | |
171 | # the output to a file to inspect later | |
172 | if [ ! -z $DEBUG ]; | |
173 | then | |
06ba1c90 JB |
174 | echo -e -n " ${BOLD}${BLUE}*${NORM} Loading debug script..." |
175 | /media/debug.sh | |
176 | checkReturn | |
177 | fi | |
178 | ||
60a77e5f JB |
179 | echo |
180 | echo "The system is coming up. Please wait." | |
181 | echo | |
b70e0e65 | 182 | |
1a72982e JB |
183 | # restore kernel printk status |
184 | echo "$PRINTK" > /proc/sys/kernel/printk | |
185 | ||
b70e0e65 | 186 | # End of file |