#!/bin/sh # # Certus Erasure Initialization Script # # Install busybox applets then mount proc, sys and devtmpfs required for booting /bin/busybox --install -s stty -echo; echo -e "\e[?25l" mount -nt proc proc /proc echo 0 >/proc/sys/kernel/printk 2>/dev/null mount -nt sysfs sysfs /sys mount -nt devtmpfs none /dev mkdir -p /dev/shm; chmod 1777 /dev/shm # Variables grep -q -w debug /proc/cmdline || quiet=yes i=`echo """^ """` IP=`egrep -o "http_server=[^ ]+" /proc/cmdline | cut -d= -f2-` # Functions nap() { if [ $SLEEP -lt 15 ] then echo -en $i"""Booting device not ready yet? Delaying... $SLEEP seconds \r""" sleep 1 fi } search() { FND=none for x in `blkid 2>/dev/null | grep 'LABEL="Certus-Erasure" TYPE="iso9660"' | cut -d: -f1 | cut -d/ -f3 | tac` do if [ ! -d /mnt/$x ] then mkdir /mnt/$x mount -n /dev/$x /mnt/$x 2>/dev/null || rmdir /mnt/$x fi if [ -e /mnt/$x/docs/$sgn ] then DEV=$x FND=yes break else umount -n /mnt/$x 2>/dev/null rmdir /mnt/$x 2>/dev/null fi done [ $FND = yes ] } lazy() { SLEEP=20 while [ $SLEEP -gt 0 -a $FND = none ] do nap let SLEEP=SLEEP-1 search done } escape() { sh umount -nl /mnt/$DEV 2>/dev/null sleep 10 /sbin/poweroff -f } # Display starting message clear echo """Starting Certus Erasure""" # Changes always in memory mount -nt tmpfs -o size=75% tmpfs /memory mkdir -p /memory/xino /memory/changes /memory/images /memory/copy2ram # Check if network booting if [ "$IP" ]; then echo $i"Attempting PXE boot" if lspci | grep -q "0200: 14e4:1692" then ./busybox modprobe broadcom 2>/dev/null # BCM57780 quirk fi for module in `lspci | grep 0200: | cut -d: -f3-4 | sed s/:/d0000/g` do M=`grep -i $module /lib/modules/$(uname -r)/modules.alias 2>/dev/null | tail -n1 | rev | cut -d" " -f1 | rev` ./busybox modprobe $M 2>/dev/null done ls /sys/class/net | grep -q eth || { for module in `find /lib/modules/$(uname -r)/kernel/drivers/net -name "*.ko" 2>/dev/null | sed 's/.ko//g'`; do ./busybox modprobe `basename $module` 2>/dev/null; ls /sys/class/net | grep -q eth && break; done; } ./busybox udhcpc >/dev/null || . fatal XZM=/memory/copy2ram; DOC=/mnt echo $i"Attempting to download Certus Erasure from the PXE server" cd $DOC /busybox wget -q http://$IP/docs/default.jpg http://$IP/docs/certus.sgn http://$IP/docs/version cd / for x in `/busybox wget -q -O- http://$IP/docs/settings | tr " " "\n" | grep -i "href.*.properties" -f2 | cut -d"<" -f1` do echo "$x" >> /tmp/settings-pxe done echo "custom_logo" >> /tmp/settings-pxe mkdir /mnt/settings for y in `cat /tmp/settings-pxe 2>/dev/null` do /busybox wget -q -O $DOC/settings/$y http://$IP/docs/settings/$y 2>/dev/null done for x in `/busybox wget -q -O- http://$IP/modules | tr " " "\n" | grep -i "href.*.certus" -f2 | cut -d"<" -f1` do echo "$x" >>/tmp/modules-pxe done if grep -q certus /tmp/modules-pxe 2>/dev/null then rm -rf /lib else echo """The PXE server is not accessible! Can't continue. Exiting...""" escape fi NUM=`grep -c '.' /tmp/modules-pxe 2>/dev/null` for y in `cat /tmp/modules-pxe 2>/dev/null` do echo -en """ ($NUM modules left) \r""" let NUM=NUM-1 /busybox wget -q -O $XZM/$y http://$IP/modules/$y 2>/dev/null done else # Make sure that optical media are initialized for x in /dev/sr*; do blkid $x >/dev/null; done # Search for *.sgn file sgn=certus.sgn search || lazy || . fatal XZM=/mnt/$DEV/modules; DOC=/mnt/$DEV/docs fi # Display Certus Erasure version echo -en " \r" version=`cat $DOC/version` echo """Release version: $version""" mkdir /opt 2>/dev/null check $XZM/003-settings.certus check $XZM/004-cegui.certus check $XZM/005-cecore.certus check $XZM/006-cescripts.certus mkdir -p /lib /opt/000 /opt/001 lspci >/tmp/lspci mount -o loop $XZM/000-kernel.certus /opt/000 mount -o loop $XZM/001-core.certus /opt/001 ln -sf /opt/000/lib/firmware /lib/firmware ln -sf /opt/000/lib/modules /lib/modules ln -sf /opt/001/lib/libc.so.6 /lib/libc.so.6 ln -sf /opt/001/lib/ld-linux.so.2 /lib/ld-linux.so.2 ln -s /opt/001/bin/kmod /bin/modprobe vga=`lspci | grep 0300: | head -n1 | cut -d: -f3-4 | sed s/:/d0000/g` driver="$(grep -i $vga /lib/modules/`uname -r`/modules.alias 2>/dev/null | head -n1 | rev | cut -d" " -f1 | rev)" # Nvidia quirk if [ ! "$driver" ] then if lspci | grep 0300: | head -n1 | cut -d: -f3 | grep -q "10de" then driver=nouveau fi fi modprobe $driver 2>/dev/null if [ ! -e /dev/fb0 ] then cp /opt/001/sbin/v86d /sbin modprobe uvesafb mode_option=1024x768-32 fi rm -r /lib ln -sf /opt/001/lib /lib ln -sf /opt/001/usr/lib /usr/lib clear /opt/001/usr/bin/fbv -a -c -u -i -k -e -r $DOC/default.jpg 2>/dev/null & # Setup aufs mount -nt aufs -o nowarn_perm,xino=/memory/xino/.aufs.xino,br:/memory/changes=rw aufs /union # Copy the modules to RAM if no PXE booting if [ ! "$IP" ] then if ! cp -a $XZM/* /memory/copy2ram then echo -e """\nNot enough RAM memory to copy Certus Erasure! Can't continue. Exiting...""" escape fi fi if ! cp -a /opt/*.certus /memory/copy2ram then echo -e """\nNot enough memory to copy Certus Erasure! Can't continue. Exiting...""" escape fi # Populate aufs with modules for x in `ls -1 /memory/copy2ram | grep \\.certus$` do mkdir -p /memory/images/$x mount -nt squashfs -o loop /memory/copy2ram/$x /memory/images/$x 2>/dev/null if [ $? -eq 0 ] then mount -no remount,add:1:/memory/images/$x=rr aufs /union else echo $i"""Cannot read the module $x! It might be corrupted.""" echo -e """\nTry to rebuild the bootable flash drive and try again. Exitig...""" escape fi done # Copy important stuff to union while [ "`pidof fbv`" ] do usleep 500000 done umount /opt/000 /opt/001 2>/dev/null rm -r /lib echo "$version" > /union/etc/version # Copy the webserver-override value (building time generated) [ -e "/union/etc/webserver" ] && chmod 664 /union/etc/webserver [ -e "$DOC/webserver-override" ] && cat $DOC/webserver-override > /union/etc/webserver 2>/dev/null # Copy the settings folder content [ -e /union/etc/settings ] || mkdir /union/etc/settings cp -a $DOC/settings/* /union/etc/settings 2>/dev/null # Copy the bysybox cp -a /bin/busybox /union/bin ln -sf /union/lib /lib cp -a $DOC/default.jpg /union/usr/share/wallpapers 2>/dev/null # The good finish exec /sbin/switch_root /union /sbin/init # The bad finish echo -e """!!CRITICAL ERROR!!\nSomething went wrong with the main process." echo -e "Please copy the debugging details printed below and report this incident to support@certus.software. Thanks!\nPress Ctrl+Alt+Del to reboot.""" echo; echo """DEBUGGING DATA:"""; echo echo """Booting parameters:"" `cat /proc/cmdline`" echo """Kernel version:"" `uname -r`" echo """Kernel modules version:"" `ls /lib/modules 2>/dev/null`" echo """Available network interfaces:"" `ls /sys/class/net`" read