busybox-initramfs: init: cleanup (another one)

This commit is contained in:
Stefan Saraev 2013-05-25 19:03:12 +03:00 committed by Stephan Raue
parent daaef706f2
commit 7bcf5c549f

View File

@ -58,7 +58,7 @@
echo '1 4 1 7' > /proc/sys/kernel/printk echo '1 4 1 7' > /proc/sys/kernel/printk
# clear screen and hide cursor # clear screen and hide cursor
/bin/busybox clear clear
echo 0 > /sys/devices/virtual/graphics/fbcon/cursor_blink echo 0 > /sys/devices/virtual/graphics/fbcon/cursor_blink
# parse command line arguments # parse command line arguments
@ -122,7 +122,7 @@
# show cursor # show cursor
echo 0 > /sys/devices/virtual/graphics/fbcon/cursor_blink echo 0 > /sys/devices/virtual/graphics/fbcon/cursor_blink
/bin/busybox sh </dev/tty1 >/dev/tty1 2>&1 sh </dev/tty1 >/dev/tty1 2>&1
} }
error() { error() {
@ -130,7 +130,7 @@
# $1:action which caused error, $2:message # $1:action which caused error, $2:message
echo "*** Error in $BOOT_STEP: $1: $2 ***" echo "*** Error in $BOOT_STEP: $1: $2 ***"
if [ -z "$DEBUG" ]; then if [ -z "$DEBUG" ]; then
/bin/busybox halt halt
else else
debug_shell debug_shell
fi fi
@ -157,10 +157,10 @@
for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15; do for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15; do
ERR_ENV=1 ERR_ENV=1
/bin/busybox mount $MOUNT_OPTIONS $1 $2 >&$SILENT_OUT 2>&1 mount $MOUNT_OPTIONS $1 $2 >&$SILENT_OUT 2>&1
[ "$?" -eq "0" ] && ERR_ENV=0 && break [ "$?" -eq "0" ] && ERR_ENV=0 && break
/bin/busybox usleep 1000000 usleep 1000000
done done
[ "$ERR_ENV" -ne "0" ] && error "mount_common" "Could not mount $1" [ "$ERR_ENV" -ne "0" ] && error "mount_common" "Could not mount $1"
} }
@ -246,7 +246,7 @@
NBD_PORT="${1#*:}" NBD_PORT="${1#*:}"
NBD_DEV="/dev/nbd$NBD_DEVS" NBD_DEV="/dev/nbd$NBD_DEVS"
/bin/busybox nbd-client $NBD_SERVER $NBD_PORT $NBD_DEV >&$SILENT_OUT 2>&1 || \ nbd-client $NBD_SERVER $NBD_PORT $NBD_DEV >&$SILENT_OUT 2>&1 || \
error "nbd-client" "Could not connect to NBD server $1" error "nbd-client" "Could not connect to NBD server $1"
mount_common "$NBD_DEV" "$2" "$3" "$4" mount_common "$NBD_DEV" "$2" "$3" "$4"
@ -304,13 +304,13 @@
update() { update() {
if [ -f "$UPDATE_DIR/$2" -a -f "$3" ]; then if [ -f "$UPDATE_DIR/$2" -a -f "$3" ]; then
echo "updating $1..." echo "updating $1..."
/bin/busybox mount -o remount,rw /flash mount -o remount,rw /flash
/bin/busybox mv $UPDATE_DIR/$2 $3 mv $UPDATE_DIR/$2 $3
# loopback file needs writable /flash all the time # loopback file needs writable /flash all the time
if [ "${disk%%=*}" != "FILE" ]; then if [ "${disk%%=*}" != "FILE" ]; then
/bin/busybox mount -o remount,ro /flash mount -o remount,ro /flash
fi fi
/bin/busybox sync sync
fi fi
} }
@ -322,8 +322,8 @@
if [ -f $SYSTEM_ROOT/usr/share/bootloader/update.sh ]; then if [ -f $SYSTEM_ROOT/usr/share/bootloader/update.sh ]; then
echo "updating Bootloader..." echo "updating Bootloader..."
/bin/busybox sh $SYSTEM_ROOT/usr/share/bootloader/update.sh sh $SYSTEM_ROOT/usr/share/bootloader/update.sh
/bin/busybox sync sync
fi fi
umount /sysroot umount /sysroot
@ -335,7 +335,7 @@
[ ! -f "/etc/modules" ] && return [ ! -f "/etc/modules" ] && return
for module in $(cat /etc/modules); do for module in $(cat /etc/modules); do
progress "Loading kernel module $module" progress "Loading kernel module $module"
/bin/busybox insmod "$MODULE_DIR/$module.ko" || \ insmod "$MODULE_DIR/$module.ko" || \
progress "... Failed to load kernel module $module, skipping" progress "... Failed to load kernel module $module, skipping"
done done
} }
@ -376,11 +376,11 @@
if [ "${disk%%=*}" = "FILE" ]; then if [ "${disk%%=*}" = "FILE" ]; then
target="${disk%%,*}" target="${disk%%,*}"
storage_loop_file="/flash/${target#*=}" storage_loop_file="/flash/${target#*=}"
/bin/busybox mount -o remount,rw /flash mount -o remount,rw /flash
if [ ! -f "$storage_loop_file" ]; then if [ ! -f "$storage_loop_file" ]; then
echo "Creating storage loopback file: $storage_loop_file..." echo "Creating storage loopback file: $storage_loop_file..."
STORAGE_USE=$(/bin/busybox df /flash/ | awk '/[0-9]%/{print $4}') STORAGE_USE=$(df /flash/ | awk '/[0-9]%/{print $4}')
STORAGE_USE=$(($STORAGE_USE / 1024 - $LIVE_FLASH_FREE_MIN)) STORAGE_USE=$(($STORAGE_USE / 1024 - $LIVE_FLASH_FREE_MIN))
options="${disk#*,}" options="${disk#*,}"
@ -407,14 +407,14 @@
mount_part "/flash/$IMAGE_SYSTEM" "/sysroot" "ro,loop" mount_part "/flash/$IMAGE_SYSTEM" "/sysroot" "ro,loop"
echo "Creating empty file, this can take a long time..." echo "Creating empty file, this can take a long time..."
/sysroot/bin/busybox dd if=/dev/zero of="$storage_loop_file" bs=1M count=$STORAGE_USE &>/dev/null /sysrootdd if=/dev/zero of="$storage_loop_file" bs=1M count=$STORAGE_USE &>/dev/null
echo "Formating to EXT4 filesystem, this can take a long time..." echo "Formating to EXT4 filesystem, this can take a long time..."
LD_LIBRARY_PATH=/sysroot/usr/lib /sysroot/sbin/mkfs.ext4 -F -L StorageLive "$storage_loop_file" &>/dev/null LD_LIBRARY_PATH=/sysroot/usr/lib /sysroot/sbin/mkfs.ext4 -F -L StorageLive "$storage_loop_file" &>/dev/null
/bin/busybox sync sync
umount /sysroot umount /sysroot
echo "Done..." echo "Done..."
/bin/busybox usleep 2000000 usleep 2000000
fi fi
mount_part "FILE=$storage_loop_file" "/storage" "loop,rw,noatime" mount_part "FILE=$storage_loop_file" "/storage" "loop,rw,noatime"
@ -422,11 +422,11 @@
fi fi
if [ -n "$OVERLAY" ]; then if [ -n "$OVERLAY" ]; then
OVERLAY_DIR=`cat /sys/class/net/eth0/address | /bin/busybox tr -d :` OVERLAY_DIR=`cat /sys/class/net/eth0/address | tr -d :`
mount_part "$disk" "/storage" "rw,noatime" mount_part "$disk" "/storage" "rw,noatime"
mkdir -p /storage/$OVERLAY_DIR mkdir -p /storage/$OVERLAY_DIR
/bin/busybox umount /storage umount /storage
# split $disk into $target,$options so we can append $OVERLAY_DIR # split $disk into $target,$options so we can append $OVERLAY_DIR
options="${disk#*,}" options="${disk#*,}"
@ -457,26 +457,26 @@
# check md5 sums if .nocheck doesn't exist # check md5 sums if .nocheck doesn't exist
if [ "$MD5_NOCHECK" -eq "0" -a -f "$UPDATE_DIR/${UPDATE_KERNEL}.md5" -a -f "$UPDATE_DIR/${UPDATE_SYSTEM}.md5" ] ; then if [ "$MD5_NOCHECK" -eq "0" -a -f "$UPDATE_DIR/${UPDATE_KERNEL}.md5" -a -f "$UPDATE_DIR/${UPDATE_SYSTEM}.md5" ] ; then
/bin/busybox sed -i 's#target#/storage/.update#g' "$UPDATE_DIR/${UPDATE_KERNEL}.md5" sed -i 's#target#/storage/.update#g' "$UPDATE_DIR/${UPDATE_KERNEL}.md5"
/bin/busybox sed -i 's#target#/storage/.update#g' "$UPDATE_DIR/${UPDATE_SYSTEM}.md5" sed -i 's#target#/storage/.update#g' "$UPDATE_DIR/${UPDATE_SYSTEM}.md5"
echo "Checking ${UPDATE_KERNEL}.md5..." echo "Checking ${UPDATE_KERNEL}.md5..."
/bin/busybox md5sum -c "$UPDATE_DIR/${UPDATE_KERNEL}.md5" || MD5_FAILED="1" md5sum -c "$UPDATE_DIR/${UPDATE_KERNEL}.md5" || MD5_FAILED="1"
echo "Checking ${UPDATE_SYSTEM}.md5..." echo "Checking ${UPDATE_SYSTEM}.md5..."
/bin/busybox md5sum -c "$UPDATE_DIR/${UPDATE_SYSTEM}.md5" || MD5_FAILED="1" md5sum -c "$UPDATE_DIR/${UPDATE_SYSTEM}.md5" || MD5_FAILED="1"
else else
echo "missing ${UPDATE_KERNEL}.md5 or ${UPDATE_SYSTEM}.md5..." echo "missing ${UPDATE_KERNEL}.md5 or ${UPDATE_SYSTEM}.md5..."
MD5_FAILED="1" MD5_FAILED="1"
fi fi
# get sizes # get sizes
FLASH_FREE=$(/bin/busybox df /flash/ | awk '/[0-9]%/{print $4}') FLASH_FREE=$(df /flash/ | awk '/[0-9]%/{print $4}')
FLASH_FREE=$(( $FLASH_FREE * 1024 )) FLASH_FREE=$(( $FLASH_FREE * 1024 ))
OLD_KERNEL=$(/bin/busybox stat -t "/flash/$IMAGE_KERNEL" | awk '{print $2}') OLD_KERNEL=$(stat -t "/flash/$IMAGE_KERNEL" | awk '{print $2}')
OLD_SYSTEM=$(/bin/busybox stat -t "/flash/$IMAGE_SYSTEM" | awk '{print $2}') OLD_SYSTEM=$(stat -t "/flash/$IMAGE_SYSTEM" | awk '{print $2}')
NEW_KERNEL=$(/bin/busybox stat -t "$UPDATE_DIR/$UPDATE_KERNEL" | awk '{print $2}') NEW_KERNEL=$(stat -t "$UPDATE_DIR/$UPDATE_KERNEL" | awk '{print $2}')
NEW_SYSTEM=$(/bin/busybox stat -t "$UPDATE_DIR/$UPDATE_SYSTEM" | awk '{print $2}') NEW_SYSTEM=$(stat -t "$UPDATE_DIR/$UPDATE_SYSTEM" | awk '{print $2}')
# old KERNEL+SYSTEM+free space - new KERNEL+SYSTEM must be higher then 5MB # old KERNEL+SYSTEM+free space - new KERNEL+SYSTEM must be higher then 5MB
# at least 5MB free after update # at least 5MB free after update
@ -500,24 +500,24 @@
update_bootloader update_bootloader
REBOOT="1" REBOOT="1"
else else
/bin/busybox rm -rf $UPDATE_DIR/[0-9a-zA-Z]* &>/dev/null rm -rf $UPDATE_DIR/[0-9a-zA-Z]* &>/dev/null
echo "md5 check failed. normal startup in 30s..." echo "md5 check failed. normal startup in 30s..."
/bin/busybox sync sync
/bin/busybox usleep 30000000 usleep 30000000
fi fi
/bin/busybox rm -rf $UPDATE_DIR/[0-9a-zA-Z]* &>/dev/null rm -rf $UPDATE_DIR/[0-9a-zA-Z]* &>/dev/null
else else
/bin/busybox rm -rf $UPDATE_DIR/[0-9a-zA-Z]* &>/dev/null rm -rf $UPDATE_DIR/[0-9a-zA-Z]* &>/dev/null
echo "size check failed. normal startup in 30s..." echo "size check failed. normal startup in 30s..."
/bin/busybox sync sync
/bin/busybox usleep 30000000 usleep 30000000
fi fi
fi fi
if test "$REBOOT" -eq "1"; then if test "$REBOOT" -eq "1"; then
echo "System reboots now..." echo "System reboots now..."
/bin/busybox usleep 2000000 usleep 2000000
/bin/busybox reboot reboot
fi fi
} }
@ -531,10 +531,10 @@
mount_part "/dev/$IMAGE_SYSTEM" "/sysroot" "ro,loop" mount_part "/dev/$IMAGE_SYSTEM" "/sysroot" "ro,loop"
fi fi
/bin/busybox mount --move /flash /sysroot/flash mount --move /flash /sysroot/flash
if [ -n "$disk" ]; then if [ -n "$disk" ]; then
/bin/busybox mount --move /storage /sysroot/storage mount --move /storage /sysroot/storage
fi fi
[ -f "/sysroot/sbin/init" ] || error "final_check" "Could not find system." [ -f "/sysroot/sbin/init" ] || error "final_check" "Could not find system."