CRUX-ARM : Home

Home :: Documentation :: Download :: Development :: Community :: Ports :: Packages :: Bugs :: Links :: About :: Donors
Fixed issue with ncurses (FS#27)
[initrd.git] / filesystem / rc
CommitLineData
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
8BOLD="\033[1m"
9NORM="\033[0m"
10RED="\033[31m"
11GREEN="\033[32m"
12YELLOW="\033[33m"
13BLUE="\033[34m"
14OK="${BOLD}${GREEN}OK${NORM}"
15FAILED="${BOLD}${RED}FAILED${NORM}"
16
17# helper functions
18
19# check an exit value and print a colored status
20checkReturn() {
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
31find_and_mount_media() {
32 echo -e " ${BOLD}${BLUE}*${NORM} Searching for the CRUX media..."
dfd7aefe 33 mkdir -p /media
60a77e5f
JB
34 CRUXMEDIA=""
35 MMC_DEVICES="`grep -E 'mmcblk' /proc/partitions | awk '{ print $4 }'`"
36 BLOCK_DEVICES="`grep -E '[sh]d' /proc/partitions | awk '{ print $4 }'`"
37 for DEV in $MMC_DEVICES $BLOCK_DEVICES
38 do
39 DEV="/dev/$DEV"
40 mount -r $DEV /media 2> /dev/null
41 if [ $? -eq 0 ]
42 then
43 echo -e -n " ${BOLD}${GREEN}*${NORM} Found media on $DEV"
44 if [ -e /media/crux-media ]
45 then
46 echo ", CRUX media."
47 CRUXMEDIA=$DEV
48 ln -s $DEV /dev/media
49 break
50 else
51 echo ", but it's not the CRUX media."
52 umount /media
53 fi
54 else
55 echo -e " ${BOLD}${YELLOW}*${NORM} No media found on $DEV."
56 fi
57 done
b70e0e65 58
60a77e5f
JB
59 # check if the media was mounted properly. if not, spawn a shell
60 if [ ! -e /media/crux-media ]
61 then
62 echo
63 echo -e " ${BOLD}${RED}*${NORM} The CRUX media was not properly mounted!"
64 echo " Spawning a shell for you to attempt to fix this problem. If"
65 echo " you are able to find the correct device, mount it at"
66 echo " /media and then log out of this shell to continue."
67 echo " If you are NOT able to fix the problem, installation will"
68 echo " not be possible."
69 echo
70 /bin/sh
71 fi
b70e0e65 72
60a77e5f
JB
73 # check again and stop if it's still not there
74 if [ ! -e /media/crux-media ]
75 then
76 echo
77 echo -e " ${BOLD}${RED}*${NORM} The CRUX media still appears not to be"
78 echo " found and installation will not continue."
79 echo
80 else
dfd7aefe 81 # configure modules
60a77e5f
JB
82 MODULES_DIR="`find /media/crux/kernel -type d -name 'modules-*'`"
83 if [ ! -z "$MODULES_DIR" ]; then
84 ln -sf $MODULES_DIR/lib/modules /lib
85 depmod
86 fi
dfd7aefe
JB
87 # configure pkgutils
88 PKGUTILS="`find /media/crux/core -type f -name 'pkgutils#*.pkg.tar.gz'`"
89 if [ ! -z "$PKGUTILS" ]; then
90 tar -C /tmp -xzf $PKGUTILS
91 cd /usr/bin && ln -s /tmp/usr/bin/* .
92 cd /etc && ln -s /tmp/etc/* .
60a77e5f
JB
93 fi
94 fi
95}
96
97#
98# main script
99#
b70e0e65 100
60a77e5f
JB
101echo ""
102echo -e "${BOLD}CRUX-ARM 2.7 - ${BLUE}http://crux-arm.nu/${NORM}"
103echo ""
b70e0e65 104
60a77e5f
JB
105exec >/dev/console </dev/console 2>&1
106
107echo -e -n " ${BOLD}${BLUE}*${NORM} Mounting filesystems... "
dfd7aefe
JB
108mount -a && \
109mount -o remount,rw /
60a77e5f
JB
110checkReturn
111
112echo -e -n " ${BOLD}${BLUE}*${NORM} Populating /dev via mdev... "
113mdev -s
114checkReturn
115
116echo -e -n " ${BOLD}${BLUE}*${NORM} Registering mdev as hotplug agent... "
b70e0e65 117echo "/bin/mdev" > /proc/sys/kernel/hotplug
60a77e5f
JB
118checkReturn
119
120echo -e -n " ${BOLD}${BLUE}*${NORM} Creating and mounting /dev/pts... "
121mkdir /dev/pts
122mount -t devpts devpts /dev/pts
123checkReturn
124
125echo -e -n " ${BOLD}${BLUE}*${NORM} Starting kernel log daemon... "
126klogd
127checkReturn
b70e0e65 128
60a77e5f
JB
129echo -e -n " ${BOLD}${BLUE}*${NORM} Setting hostname... "
130hostname crux
131checkReturn
b70e0e65 132
60a77e5f 133echo -e -n " ${BOLD}${BLUE}*${NORM} Loading network loopback device... "
dfd7aefe
JB
134ip addr add 127.0.0.1/8 dev lo broadcast + scope host && \
135ip link set lo up && \
60a77e5f
JB
136echo "127.0.0.1 localhost crux" > /etc/hosts
137checkReturn
b70e0e65 138
60a77e5f
JB
139echo -e -n " ${BOLD}${BLUE}*${NORM} Saving boot messages... "
140dmesg > /var/log/boot
141checkReturn
b70e0e65 142
dfd7aefe 143echo -e " ${BOLD}${BLUE}*${NORM} Trying to find and mount the media installer..."
60a77e5f 144find_and_mount_media
b70e0e65 145
60a77e5f
JB
146echo
147echo "The system is coming up. Please wait."
148echo
b70e0e65
JB
149
150# End of file