Files
LibreELEC.tv/packages/sysutils/busybox-initramfs/scripts/init
2011-01-09 22:06:11 +01:00

145 lines
3.9 KiB
Bash
Executable File
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/bin/sh
################################################################################
# This file is part of OpenELEC - http://www.openelec.tv
# Copyright (C) 2009-2011 Stephan Raue (stephan@openelec.tv)
#      Copyright (C) 2010-2011 Roman Weber (openelec@gonzo.ch)
#
# This Program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.
#
# This Program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with OpenELEC.tv; see the file COPYING. If not, write to
# the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
# http://www.gnu.org/copyleft/gpl.html
################################################################################
UPDATE_DIR=/storage/.update
IMAGE_SYSTEM="SYSTEM"
IMAGE_KERNEL="KERNEL"
REBOOT="0"
# mount all needed special filesystems
/bin/busybox mount -t devtmpfs none /dev
/bin/busybox mount -t proc none /proc
# hide kernel log messages on console
echo '1 4 1 7' > /proc/sys/kernel/printk
# parse command line arguments
for arg in $(cat /proc/cmdline); do
case $arg in
debugging)
DEBUG=yes
;;
nosplash)
SPLASH=no
;;
bootchart)
BOOTCHART=yes
;;
fastboot)
FASTBOOT=yes
;;
esac
done
if test "$FASTBOOT" = "yes"; then
IONICE="/bin/busybox ionice -c 1 -n 0"
fi
progress() {
if test "$DEBUG" = "yes"; then
echo "### $1 ###"
fi
}
show_splash() {
if [ "$SPLASH" = "no" ]; then
break
else
if [ -f "/bin/ply-image" -a -f "/splash.png" ]; then
/bin/ply-image /splash.png
fi
fi
}
error() {
echo "Error Code: $1 that means: $2"
}
debug_shell() {
echo "### Starting debugging shell... type exit to quit ###"
/bin/busybox sh </dev/tty1 >/dev/tty1 2>&1
}
mount_part() {
progress "trying to mount $1 ..."
for i in 1 2 3 4 5 6 7 8 9 10; do
ERR_ENV=1
$IONICE /bin/busybox mount -o $3 $1 $2 > /dev/null 2>&1
[ "$?" -eq "0" ] && ERR_ENV=0 && break
/bin/busybox usleep 1000000
done
[ "$ERR_ENV" -ne "0" ] && error "INIT_4" "Could not mount $1" && debug_shell
}
update() {
if [ -f "$UPDATE_DIR/$2" ]; then
echo "updating $1..."
$IONICE /bin/busybox mount -o remount,rw /flash
$IONICE /bin/busybox mv $UPDATE_DIR/$2 $3
$IONICE /bin/busybox mount -o remount,ro /flash
$IONICE /bin/busybox sync
[ "$2" = "$IMAGE_KERNEL" ] && REBOOT="1"
fi
}
show_splash
mount_part "$boot" "/flash" "ro,noatime"
if [ -n "$disk" ]; then
mount_part "$disk" "/storage" "rw,noatime"
update "Kernel" "$IMAGE_KERNEL" "/flash/$IMAGE_KERNEL"
update "System" "$IMAGE_SYSTEM" "/flash/$IMAGE_SYSTEM"
if test "$REBOOT" -eq "1"; then
echo "System reboots now..." && \
/bin/busybox reboot
fi
fi
if [ -f "/flash/$IMAGE_SYSTEM" ]; then
mount_part "/flash/$IMAGE_SYSTEM" "/sysroot" "ro,loop"
[ "$ERR_ENV" -ne "0" ] && debug_shell
else
error "INIT_2" "Could not find system."
debug_shell
fi
# move /flash and /storage to /sysroot
/bin/busybox mount --move /flash /sysroot/flash
if [ -n "$disk" ]; then
/bin/busybox mount --move /storage /sysroot/storage
fi
# unmount all other filesystems
/bin/busybox umount /dev
/bin/busybox umount /proc
# switch to new sysroot and start real init
exec /bin/busybox switch_root /sysroot /sbin/init
error "INIT_3" "Error in initramfs. Could not switch to new root"
debug_shell