+
+#
+# initramfs /init (busybox ash)
+#
+
+# color codes and some predefined texts
+BOLD="\033[1m"
+NORM="\033[0m"
+RED="\033[31m"
+GREEN="\033[32m"
+YELLOW="\033[33m"
+BLUE="\033[34m"
+OK="${BOLD}${GREEN}OK${NORM}"
+FAILED="${BOLD}${RED}FAILED${NORM}"
+
+# helper functions
+
+# check an exit value and print a colored status
+checkReturn() {
+ if [ $? -ne 0 ]
+ then
+ echo -e $FAILED
+ else
+ echo -e $OK
+ fi
+}
+
+# search for and mount the crux media, populate a tmpfs from it,
+# and prepare /newroot for switch_root at the end of the script
+find_and_mount_media() {
+ echo -e " ${BOLD}${BLUE}*${NORM} Searching for the CRUX media..."
+ mkdir -p /media
+ MMC_DEVICES="`grep -E 'mmcblk0p' /proc/partitions | awk '{ print $4 }'`"
+ BLOCK_DEVICES="`grep -E '[sh]d' /proc/partitions | awk '{ print $4 }'`"
+ for DEV in $MMC_DEVICES $BLOCK_DEVICES
+ do
+ DEV="/dev/$DEV"
+ mount -r $DEV /media 2> /dev/null
+ if [ $? -eq 0 ]
+ then
+ echo -e -n " ${BOLD}${GREEN}*${NORM} Found media on $DEV"
+ if [ -e /media/crux-media ]
+ then
+ echo ", CRUX media."
+ ln -s $DEV /dev/media
+ break
+ else
+ echo ", but it's not the CRUX media."
+ umount /media
+ fi
+ else
+ echo -e " ${BOLD}${YELLOW}*${NORM} No media found on $DEV."
+ fi
+ done
+
+ # check if the media was mounted properly. if not, spawn a shell
+ if [ ! -e /media/crux-media ]
+ then
+ echo
+ echo -e " ${BOLD}${RED}*${NORM} The CRUX media was not properly mounted!"
+ echo " Spawning a shell for you to attempt to fix this problem. If"
+ echo " you are able to find the correct device, mount it at"
+ echo " /media and then log out of this shell to continue."
+ echo " If you are NOT able to fix the problem, installation will"
+ echo " not be possible."
+ echo
+ /bin/sh
+ fi
+
+ # check again and stop if it's still not there
+ if [ ! -e /media/crux-media ]
+ then
+ echo
+ echo -e " ${BOLD}${RED}*${NORM} The CRUX media still appears not to be"
+ echo " found and installation will not continue."
+ echo
+ else
+ # configure modules
+ MODULES="`find /media/crux/kernel -type f -name 'modules-*.tar.*' 2>/dev/null`"
+ if [ ! -z "$MODULES" ]; then
+ tar -C /tmp -xf $MODULES
+ cd /lib && ln -s /tmp/lib/* .
+ depmod
+ fi
+ # configure pkgutils
+ PKGUTILS="`find /media/crux/core -type f -name 'pkgutils#*.pkg.tar.*' 2>/dev/null`"
+ if [ ! -z "$PKGUTILS" ]; then
+ tar -C /tmp -xf $PKGUTILS
+ cd /usr/bin && ln -s /tmp/usr/bin/* .
+ cd /etc && ln -s /tmp/etc/* .
+ fi
+ fi
+}
+