Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/busybox ash
- # /etc/init.d/rcS: main init script
- # usage: error [MESSAGE]
- # outputs an error message and does things common to all errors during init
- error()
- {
- echo
- echo "Error: $1."
- echo
- read -p "Press any key to continue. " DUMMY
- echo
- }
- # mount all virtual file systems
- /bin/busybox mount -a
- /bin/busybox mount -o remount,rw /
- # filter boot codes; inspired by the Tiny Core init script
- for i in `/bin/busybox cat /proc/cmdline`; do
- case $i in
- "swap="*)
- swapPartition="${i#*=}"
- ;;
- "dhcp="*)
- interface="${i#*=}"
- ;;
- "wait="*)
- seconds="${i#*=}"
- ;;
- "blacklist="*)
- module="${i#*=}"
- echo "Blacklisting $module"
- echo "blacklist $module" >> /etc/modprobe.conf
- ;;
- "live")
- live="true"
- ;;
- esac
- done
- echo "Starting logging services"
- # start logging daemons
- /bin/busybox klogd
- /bin/busybox syslogd
- # start mdev to create device nodes in /dev
- /bin/busybox mdev -s
- # pause, if the user passed the "wait" boot code
- if [ "$seconds" != "" ]; then
- if [ "$((seconds + 1))" -le "1" ]; then
- error "the number of seconds to pause must be a positive integer"
- else
- echo "Pausing for $seconds seconds"
- /bin/busybox sleep $seconds
- fi
- fi
- # set up swap, if the user passed the "swap" boot code
- if [ "$swapPartition" != "" ]; then
- if [ -b "$swapPartition" ]; then
- echo "Setting up swap on $swapPartition"
- /bin/busybox mkswap $swapPartition
- /bin/busybox swapon $swapPartition
- echo "$swapPartition swap swap defaults 0 0" >> /etc/fstab
- else
- error "the swap partition \"$swapPartition\" does not exist"
- fi
- fi
- # set the hostname
- /bin/busybox hostname -F /etc/hostname
- # bring up a loopback device
- /bin/busybox ifconfig lo 127.0.0.1 up
- /bin/busybox route add -net 127.0.0.0 netmask 255.0.0.0 lo
- . /etc/calfrc
- echo "Searching partitions for Calf files"
- cd /sys/class/block
- for partition in `/bin/busybox ls -1 s*[0-9]`; do
- /bin/busybox mkdir /mnt/$partition
- /bin/busybox mount /dev/$partition /mnt/$partition > /dev/null 2>&1
- case $? in
- "0") # if the partition mounting succeeded
- calfSfs=`/bin/busybox find /mnt/$partition -maxdepth 2 -type f -name calf-$calfVersion.sfs | /bin/busybox head -1`
- # if a calf sfs was found
- if [ "$calfSfs" != "" ]; then
- # loaded the calf sfs
- /usr/bin/loadsfs "$calfSfs" /mnt/calf/calfro > /dev/null 2>&1
- case $? in
- "0") # if the sfs loading succeeded
- # link /mnt/home to the partition mount point
- /bin/busybox ln -s $partition /mnt/home
- # run udev to load the modules included in the sfs
- echo "Loading drivers"
- /sbin/udevd --daemon
- /sbin/udevadm trigger
- /sbin/udevadm settle
- # start a dhcp client on $interface, is the user passed the "dhcp" boot code
- if [ "$interface" != "" ]; then
- if [ -d "/sys/class/net/$interface" ]; then
- echo "Starting a DHCP client on $interface"
- /bin/busybox ifconfig $interface up
- /bin/busybox udhcpc -i $interface
- case $? in
- "1")
- error "failed to start a DHCP client on the interface \"$interface\""
- ;;
- esac
- else
- error "the network interface \"$interface\" does not exist"
- fi
- fi
- # if not running live, load the extensions and the save file
- if [ "$live" != "true" ]; then
- # the directory containing the sfs
- calfDirectory=`/bin/busybox dirname $calfSfs`
- unset calfSfs
- # if the calf directory also contains extensions, load them
- if [ -d "$calfDirectory/calf-extensions" ]; then
- echo "Loading extensions"
- for extension in `/bin/busybox find "$calfDirectory/calf-extensions" -name *.sfs -type f`; do
- /usr/bin/loadsfs $extension
- done
- fi
- # if it's a writeable partition, it must be XdY
- case "${partition:1:1}" in
- "d")
- # if the calf directory does not contain a save file, offer the user to create one
- if [ ! -f "$calfDirectory/calfsave.img" ]; then
- echo "No save file named \"calfsave.img\" found."
- while [[ "$reply" != "n" && "$reply" != "y" ]]; do
- read -p "Would you like to create a save file so your session is saved? (y/n) " reply
- done
- case $reply in
- "y") # if the user chose to create a save file
- while [ "$((size + 1))" -le "1" ]; do
- read -p "Size (in MB): " size
- done
- echo "Creating the save file"
- /bin/busybox dd if=/dev/zero of="$calfDirectory/calfsave.img" bs=1024 count=${size}000 > /dev/null 2>&1
- case $? in
- "0") # if the save file creation succeeded
- echo "Creating a file system on the save file"
- /bin/busybox mkfs.ext2 -q -m 0 -F "$calfDirectory/calfsave.img" > /dev/null 2>&1
- case $? in
- "1") # if the file system creation failed
- if [ -f "$calfDirectory/calfsave.img" ]; then
- /bin/busybox rm "$calfDirectory/calfsave.img" > /dev/null 2>&1
- fi
- error "failed to create a save file"
- esac
- ;;
- 1) # if the save file creation failed
- if [ -f "$calfDirectory/calfsave.img" ]; then
- /bin/busybox rm "$calfDirectory/calfsave.img" > /dev/null 2>&1
- fi
- error "failed to create a save file"
- ;;
- esac
- esac
- fi
- # check again whether a save file exists, in case it was created earlier
- if [ -f "$calfDirectory/calfsave.img" ]; then
- echo "Loading the save file"
- /bin/busybox mkdir /mnt/calf/calfrw
- /bin/busybox mount "$calfDirectory/calfsave.img" /mnt/calf/calfrw -o loop > /dev/null 2>&1
- case $? in
- "0") # if the save file mounting succeeded
- # link directories to the save file
- if [ ! -d /mnt/calf/calfrw/root ]; then
- /bin/busybox mv /root /mnt/calf/calfrw
- else
- /bin/busybox rm -rf /root
- fi
- ln -s /mnt/calf/calfrw/root /root
- if [ ! -d /mnt/calf/calfrw/opt ]; then
- /bin/busybox mv /opt /mnt/calf/calfrw
- else
- /bin/busybox rm -rf /opt
- fi
- ln -s /mnt/calf/calfrw/opt /opt
- if [ ! -d /mnt/calf/calfrw/usr/local ]; then
- /bin/busybox mkdir /mnt/calf/calfrw/usr
- /bin/busybox mv /usr/local /mnt/calf/calfrw/usr
- else
- /bin/busybox rm -rf /usr/local
- fi
- ln -s /mnt/calf/calfrw/usr/local /usr/local
- ;;
- 1) # if the save file mounting failed
- /bin/busybox rmdir /mnt/calf/calfrw
- error "failed to mount the save file"
- ;;
- esac
- fi
- ;;
- esac
- fi
- ;;
- 1) # if the sfs loading failed
- error "failed to load calf-$calfVersion.sfs"
- ;;
- esac
- fi
- /bin/busybox umount /mnt/$partition > /dev/null 2>&1
- case $? in
- "0") # if the partition unmounting succeeded
- /bin/busybox rmdir /mnt/$partition
- ;;
- esac
- ;;
- *) # if the partition mounting failed
- /bin/busybox rmdir /mnt/$partition
- ;;
- esac
- done
- # fix some problematic permissions
- /bin/busybox chmod 4755 /bin/busybox
- /bin/busybox chown -R calf /home/calf
- /bin/busybox chmod 777 /home/calf
- cd /etc/init.d
- # start services (such as ALSA)
- for service in `/bin/busybox ls -1`; do
- if [[ "$service" != "rcS" && "$service" != "shutdown" ]]; then
- ./$service start
- fi
- done
- # start stuff in /root/Startup
- if [ -d /root/Startup ]; then
- cd /root/Startup
- for i in `/bin/busybox ls -1`; do
- ./$i &
- done
- fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement