| 1 | #!/bin/sh |
| 2 | |
| 3 | # |
| 4 | # initramfs /init (busybox ash) |
| 5 | # |
| 6 | |
| 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 | } |
| 28 | |
| 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..." |
| 33 | mkdir -p /media |
| 34 | MMC_DEVICES="`grep -E 'mmcblk0p' /proc/partitions | awk '{ print $4 }'`" |
| 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." |
| 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 |
| 56 | |
| 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 |
| 70 | |
| 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 |
| 79 | # configure modules |
| 80 | MODULES="`find /media/crux/kernel -type f -name 'modules-*.tar.*' 2>/dev/null`" |
| 81 | if [ ! -z "$MODULES" ]; then |
| 82 | tar -C /tmp -xf $MODULES |
| 83 | cd /lib && ln -s /tmp/lib/* . |
| 84 | depmod |
| 85 | fi |
| 86 | # configure pkgutils |
| 87 | PKGUTILS="`find /media/crux/core -type f -name 'pkgutils#*.pkg.tar.*' 2>/dev/null`" |
| 88 | if [ ! -z "$PKGUTILS" ]; then |
| 89 | tar -C /tmp -xf $PKGUTILS |
| 90 | cd /usr/bin && ln -s /tmp/usr/bin/* . |
| 91 | cd /etc && ln -s /tmp/etc/* . |
| 92 | fi |
| 93 | fi |
| 94 | } |
| 95 | |
| 96 | # |
| 97 | # main script |
| 98 | # |
| 99 | |
| 100 | echo "" |
| 101 | echo -e "${BOLD}CRUX-ARM 3.3 - ${BLUE}http://crux-arm.nu/${NORM}" |
| 102 | echo "" |
| 103 | |
| 104 | exec >/dev/console </dev/console 2>&1 |
| 105 | |
| 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 | |
| 126 | echo -e -n " ${BOLD}${BLUE}*${NORM} Mounting filesystems... " |
| 127 | mount -a && \ |
| 128 | mount -o remount,rw / |
| 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... " |
| 136 | echo "/bin/mdev" > /proc/sys/kernel/hotplug |
| 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 |
| 147 | |
| 148 | echo -e -n " ${BOLD}${BLUE}*${NORM} Setting hostname... " |
| 149 | hostname crux |
| 150 | checkReturn |
| 151 | |
| 152 | echo -e -n " ${BOLD}${BLUE}*${NORM} Loading network loopback device... " |
| 153 | ip addr add 127.0.0.1/8 dev lo broadcast + scope host && \ |
| 154 | ip link set lo up && \ |
| 155 | echo "127.0.0.1 localhost crux" > /etc/hosts |
| 156 | checkReturn |
| 157 | |
| 158 | echo -e -n " ${BOLD}${BLUE}*${NORM} Saving boot messages... " |
| 159 | dmesg > /var/log/boot |
| 160 | checkReturn |
| 161 | |
| 162 | # run mdev again to fix issues with mmc devices. yeah, it is weird but worked |
| 163 | mdev -s |
| 164 | |
| 165 | echo -e " ${BOLD}${BLUE}*${NORM} Trying to find and mount the media installer..." |
| 166 | find_and_mount_media |
| 167 | |
| 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 |
| 174 | echo -e -n " ${BOLD}${BLUE}*${NORM} Loading debug script..." |
| 175 | /media/debug.sh |
| 176 | checkReturn |
| 177 | fi |
| 178 | |
| 179 | echo |
| 180 | echo "The system is coming up. Please wait." |
| 181 | echo |
| 182 | |
| 183 | # restore kernel printk status |
| 184 | echo "$PRINTK" > /proc/sys/kernel/printk |
| 185 | |
| 186 | # End of file |