busybox/init: remove leading indent

Signed-off-by: Ian Leonard <antonlacon@gmail.com>
This commit is contained in:
Ian Leonard 2019-01-30 23:55:05 +00:00
parent e738c7bf75
commit 7ebd79ae67

View File

@ -6,74 +6,74 @@
# Copyright (C) 2009-2014 Stephan Raue (stephan@openelec.tv)
# Copyright (C) 2016-present Team LibreELEC (https://libreelec.tv)
# create directories
/usr/bin/busybox mkdir -p /dev
/usr/bin/busybox mkdir -p /proc
/usr/bin/busybox mkdir -p /sys
/usr/bin/busybox mkdir -p /tmp
/usr/bin/busybox mkdir -p /flash
/usr/bin/busybox mkdir -p /sysroot
/usr/bin/busybox mkdir -p /storage
# create directories
/usr/bin/busybox mkdir -p /dev
/usr/bin/busybox mkdir -p /proc
/usr/bin/busybox mkdir -p /sys
/usr/bin/busybox mkdir -p /tmp
/usr/bin/busybox mkdir -p /flash
/usr/bin/busybox mkdir -p /sysroot
/usr/bin/busybox mkdir -p /storage
# mount all needed special filesystems
/usr/bin/busybox mount -t devtmpfs devtmpfs /dev
/usr/bin/busybox mount -t proc proc /proc
/usr/bin/busybox mount -t sysfs sysfs /sys
# mount all needed special filesystems
/usr/bin/busybox mount -t devtmpfs devtmpfs /dev
/usr/bin/busybox mount -t proc proc /proc
/usr/bin/busybox mount -t sysfs sysfs /sys
# common functions
. /functions
# common functions
. /functions
# set needed variables
MODULE_DIR=/usr/lib/modules
# set needed variables
MODULE_DIR=/usr/lib/modules
UPDATE_ROOT=/storage/.update
UPDATE_DIR="$UPDATE_ROOT"
UPDATE_ROOT=/storage/.update
UPDATE_DIR="$UPDATE_ROOT"
UPDATE_KERNEL="KERNEL"
UPDATE_SYSTEM="SYSTEM"
IMAGE_KERNEL="@KERNEL_NAME@"
IMAGE_SYSTEM="SYSTEM"
UPDATE_KERNEL="KERNEL"
UPDATE_SYSTEM="SYSTEM"
IMAGE_KERNEL="@KERNEL_NAME@"
IMAGE_SYSTEM="SYSTEM"
BOOT_STEP="start"
MD5_FAILED="0"
RUN_FSCK="yes"
RUN_FSCK_DISKS=""
SYSLINUX_DEFAULT=""
GRUB_DEFAULT=""
BOOT_STEP="start"
MD5_FAILED="0"
RUN_FSCK="yes"
RUN_FSCK_DISKS=""
SYSLINUX_DEFAULT=""
GRUB_DEFAULT=""
NBD_DEVS="0"
FLASH_FREE_MIN="5"
NBD_DEVS="0"
FLASH_FREE_MIN="5"
INSTALLED_MEMORY=$(cat /proc/meminfo | grep 'MemTotal:' | awk '{print $2}')
SYSTEM_TORAM_LIMIT=1024000
INSTALLED_MEMORY=$(cat /proc/meminfo | grep 'MemTotal:' | awk '{print $2}')
SYSTEM_TORAM_LIMIT=1024000
LIVE="no"
LIVE="no"
BREAK_TRIPPED="no"
BREAK_TRIPPED="no"
# Get a serial number if present (eg. RPi) otherwise use MAC address from eth0
MACHINE_UID="$(cat /proc/cpuinfo | awk '/^Serial/{s=$3; gsub ("^0*","",s); print s}')"
[ -z "$MACHINE_UID" ] && MACHINE_UID="$(cat /sys/class/net/eth0/address 2>/dev/null | tr -d :)"
# Get a serial number if present (eg. RPi) otherwise use MAC address from eth0
MACHINE_UID="$(cat /proc/cpuinfo | awk '/^Serial/{s=$3; gsub ("^0*","",s); print s}')"
[ -z "$MACHINE_UID" ] && MACHINE_UID="$(cat /sys/class/net/eth0/address 2>/dev/null | tr -d :)"
# hide kernel log messages on console
echo '1 4 1 7' > /proc/sys/kernel/printk
# hide kernel log messages on console
echo '1 4 1 7' > /proc/sys/kernel/printk
# set ondemand up_threshold
if [ -e /sys/devices/system/cpu/cpufreq/ondemand/up_threshold ] ; then
# set ondemand up_threshold
if [ -e /sys/devices/system/cpu/cpufreq/ondemand/up_threshold ] ; then
echo 50 > /sys/devices/system/cpu/cpufreq/ondemand/up_threshold
fi
fi
# run platform_init script if exists
if [ -f "./platform_init" ]; then
# run platform_init script if exists
if [ -f "./platform_init" ]; then
./platform_init
fi
fi
# clear screen and hide cursor
clear
hidecursor
# clear screen and hide cursor
clear
hidecursor
# parse command line arguments
for arg in $(cat /proc/cmdline); do
# parse command line arguments
for arg in $(cat /proc/cmdline); do
case $arg in
BOOT_IMAGE=*)
IMAGE_KERNEL="${arg#*=}"
@ -163,34 +163,34 @@
BREAK="${arg#*=}"
;;
esac
done
done
if test "$DEBUG" = "yes"; then
if test "$DEBUG" = "yes"; then
exec 3>&1
else
else
exec 3>/dev/null
fi
SILENT_OUT=3
fi
SILENT_OUT=3
progress() {
progress() {
if test "$PROGRESS" = "yes"; then
echo "### $1 ###" >&2
fi
}
}
debug_msg() {
debug_msg() {
echo "$1" >&$SILENT_OUT
}
}
debug_shell() {
debug_shell() {
echo "### Starting debugging shell for boot step: $BOOT_STEP... type exit to quit ###"
showcursor
setsid cttyhack sh
}
}
error() {
error() {
# Display fatal error message
# $1:action which caused error, $2:message
# Send debug_shell output to stderr, in case caller is redirecting/consuming stdout
@ -198,9 +198,9 @@
echo "*** Error in $BOOT_STEP: $1: $2 ***" >&2
debug_shell >&2
return 1
}
}
break_after() {
break_after() {
# Start debug shell after boot step $1, and all subsequent steps
if [ $BREAK_TRIPPED == yes ]; then
debug_shell
@ -212,12 +212,12 @@
;;
esac
fi
}
}
# Mount handlers
# All handlers take the following parameters:
# $1:target, $2:mountpoint, $3:mount options, [$4:fs type]
mount_common() {
# Mount handlers
# All handlers take the following parameters:
# $1:target, $2:mountpoint, $3:mount options, [$4:fs type]
mount_common() {
# Common mount handler, handles block devices and filesystem images
MOUNT_OPTIONS="-o $3"
[ -n "$4" ] && MOUNT_OPTIONS="-t $4 $MOUNT_OPTIONS"
@ -232,9 +232,9 @@
done
[ "$ERR_ENV" -eq "0" ] && return 0
error "mount_common" "Could not mount $1"
}
}
get_iscsistart_options() {
get_iscsistart_options() {
# Convert kernel commandline ISCSI= options to iscsistart options
IFS_SAVE="$IFS"
IFS=,
@ -274,9 +274,9 @@
done
IFS="$IFS_SAVE"
}
}
mount_iscsi() {
mount_iscsi() {
# Mount iSCSI target
ISCSI_DEV="${1##*,}"
ISCSI_OPTIONS="${1%,*}"
@ -298,10 +298,10 @@
fi
mount_common "$ISCSI_DEV" "$2" "$3" "$4"
}
}
mount_nbd() {
# Mount NBD device
mount_nbd() {
# Mount NBD device
NBD_SERVER="${1%%:*}"
NBD_PORT="${1#*:}"
NBD_DEV="/dev/nbd$NBD_DEVS"
@ -312,9 +312,9 @@
mount_common "$NBD_DEV" "$2" "$3" "$4"
NBD_DEVS=$(( NBD_DEVS + 1 ))
}
}
mount_nfs() {
mount_nfs() {
# Mount NFS export
NFS_EXPORT="${1%%,*}"
NFS_OPTIONS="${1#*,}"
@ -322,13 +322,13 @@
[ "$NFS_OPTIONS" = "$1" ] && NFS_OPTIONS=
mount_common "$NFS_EXPORT" "$2" "$3,nolock,soft,timeo=3,retrans=2,rsize=32768,wsize=32768,$NFS_OPTIONS" "nfs"
}
}
mount_ubifs() {
mount_ubifs() {
mount_common "$1" "$2" "$3" "ubifs"
}
}
mount_part() {
mount_part() {
# Mount a local or network filesystem
# $1:[TYPE=]target, $2:mountpoint, $3:mount options, [$4:fs type]
progress "mount filesystem $1 ..."
@ -362,10 +362,10 @@
MOUNT_TARGET="${MOUNT_TARGET//@UID@/$MACHINE_UID}"
$MOUNT_CMD "$MOUNT_TARGET" "$2" "$3" "$4"
}
}
# mount the specified SYSTEM file and output arch from /etc/os-release
get_project_arch() {
# mount the specified SYSTEM file and output arch from /etc/os-release
get_project_arch() {
mount_part "$1" "/sysroot" "ro,loop" || return
if [ -f /sysroot/etc/os-release ]; then
@ -374,13 +374,13 @@
fi
umount /sysroot
}
}
# If the project/arch of current matches the upgrade, then it is considered compatible.
# Otherwise, mount the upgrade SYSTEM partition and, if canupdate.sh is available,
# call the script to determine if the current upgrade file can be applied on to the
# current system - 0 means it is compatible, non-zero that it is not compatible.
is_compatible() {
# If the project/arch of current matches the upgrade, then it is considered compatible.
# Otherwise, mount the upgrade SYSTEM partition and, if canupdate.sh is available,
# call the script to determine if the current upgrade file can be applied on to the
# current system - 0 means it is compatible, non-zero that it is not compatible.
is_compatible() {
local result=1
if [ "${2}" = "${3}" ]; then
@ -396,10 +396,10 @@
fi
return ${result}
}
}
# determine if the new SYSTEM file is compatible with the current SYSTEM file
check_is_compatible() {
# determine if the new SYSTEM file is compatible with the current SYSTEM file
check_is_compatible() {
local update_filename="${1}"
local old_system="${2}"
local new_system="${3}"
@ -425,9 +425,9 @@
fi
return 0
}
}
update_file() {
update_file() {
if [ -f "$UPDATE_DIR/$2" -a -f "$3" ]; then
mount -o remount,rw /flash
@ -445,9 +445,9 @@
fi
sync
fi
}
}
update_partition() {
update_partition() {
local result
if [ -f "$UPDATE_DIR/$2" -a -b "$3" ]; then
@ -456,9 +456,9 @@
StopProgress "done"
echo "${result}"
fi
}
}
update_bootloader() {
update_bootloader() {
local result
export BOOT_ROOT="/flash"
@ -475,9 +475,9 @@
fi
umount /sysroot
}
}
load_modules() {
load_modules() {
progress "Loading kernel modules"
[ ! -f "/etc/modules" ] && return
@ -486,9 +486,9 @@
insmod "$MODULE_DIR/$module.ko" || \
progress "... Failed to load kernel module $module, skipping"
done
}
}
load_splash() {
load_splash() {
local set_default_res=no
local vres
@ -557,9 +557,9 @@
debug_msg "Framebuffer splash image: $SPLASHIMAGE"
fi
fi
}
}
do_reboot() {
do_reboot() {
echo "System reboots now..."
# syncing filesystem
@ -576,9 +576,9 @@
usleep 2000000
/usr/bin/busybox reboot
}
}
force_fsck() {
force_fsck() {
echo "Filesystem corruption has been detected!"
echo "To prevent an automatic repair attempt continuing,"
echo "press any key or power off your system within the next 120 seconds"
@ -608,9 +608,9 @@
sync
poweroff
fi
}
}
check_disks() {
check_disks() {
if [ "$RUN_FSCK" = "yes" -a -n "$RUN_FSCK_DISKS" ]; then
progress "Checking disk(s): $RUN_FSCK_DISKS"
/usr/sbin/fsck -T -M -p -a $RUN_FSCK_DISKS > /dev/null 2>&1
@ -632,9 +632,9 @@
progress "No filesystem errors found, continuing..."
fi
fi
}
}
wakeonlan() {
wakeonlan() {
if [ "$STORAGE_NETBOOT" = "yes" ]; then
wol_ip=${disk%:*}
wol_ip=${wol_ip#*=}
@ -653,9 +653,9 @@
StartProgress countdown "WOL magic packet sent to $wol_ip, waiting $wol_wait seconds... " $wol_wait "done"
fi
fi
}
}
mount_flash() {
mount_flash() {
progress "Mounting flash"
wakeonlan
@ -665,9 +665,9 @@
if [ -f /flash/post-flash.sh ] ; then
. /flash/post-flash.sh
fi
}
}
mount_storage() {
mount_storage() {
progress "Mounting storage"
if [ "$LIVE" = "yes" ]; then
@ -705,10 +705,10 @@
# /storage should always be writable
mount -t tmpfs none /storage
fi
}
}
# Make last bootloader label (installer, live, run etc.) as the new default
update_bootmenu() {
# Make last bootloader label (installer, live, run etc.) as the new default
update_bootmenu() {
local crnt_default
if [ -n "$SYSLINUX_DEFAULT" -a -f /flash/syslinux.cfg ]; then
@ -738,9 +738,9 @@
fi
fi
fi
}
}
check_out_of_space() {
check_out_of_space() {
if [ "$(df /storage | awk '/[0-9]%/{print $4}')" -eq "0" ]; then
echo ""
echo "The $1 is corrupt, or there is not enough"
@ -756,9 +756,9 @@
echo ""
return 1
fi
}
}
do_cleanup() {
do_cleanup() {
StartProgress spinner "Cleaning up... "
if [ -d $UPDATE_ROOT/.tmp/mnt ]; then
@ -781,9 +781,9 @@
sync
StopProgress "done"
}
}
check_update() {
check_update() {
progress "Checking for updates"
UPDATE_TAR=$(ls -1 "$UPDATE_DIR"/*.tar 2>/dev/null | head -n 1)
UPDATE_IMG_GZ=$(ls -1 "$UPDATE_DIR"/*.img.gz 2>/dev/null | head -n 1)
@ -1021,9 +1021,9 @@
update_bootloader
do_cleanup
do_reboot
}
}
prepare_sysroot() {
prepare_sysroot() {
progress "Preparing system"
if [ "$SYSTEM_TORAM" = "no" -o "$INSTALLED_MEMORY" -lt "$SYSTEM_TORAM_LIMIT" ]; then
@ -1046,20 +1046,20 @@
fi
[ -f "/sysroot/usr/lib/systemd/systemd" ] || error "final_check" "Could not find systemd!"
}
}
# If the network is up (due to the use of the "ip" kernel parameter) and a DNS
# server is known, allow the libc resolver to use it
grep '^\(nameserver\|domain\) ' /proc/net/pnp | grep -v '^nameserver 0\.0\.0\.0$' > /etc/resolv.conf
# If the network is up (due to the use of the "ip" kernel parameter) and a DNS
# server is known, allow the libc resolver to use it
grep '^\(nameserver\|domain\) ' /proc/net/pnp | grep -v '^nameserver 0\.0\.0\.0$' > /etc/resolv.conf
if [ "${boot%%=*}" = "FILE" ]; then
if [ "${boot%%=*}" = "FILE" ]; then
error "check arguments" "boot argument can't be FILE type..."
fi
fi
debug_msg "Unique identifier for this client: ${MACHINE_UID:-NOT AVAILABLE}"
debug_msg "Unique identifier for this client: ${MACHINE_UID:-NOT AVAILABLE}"
# main boot sequence
for BOOT_STEP in \
# main boot sequence
for BOOT_STEP in \
load_modules \
check_disks \
mount_flash \
@ -1070,14 +1070,14 @@
prepare_sysroot; do
$BOOT_STEP
[ -n "$DEBUG" ] && break_after $BOOT_STEP
done
done
BOOT_STEP=final
BOOT_STEP=final
# log if booting from usb / removable storage
STORAGE=$(cat /proc/mounts | grep " /sysroot/storage " | awk '{print $1}' | awk -F '/' '{print $3}')
FLASH=$(cat /proc/mounts | grep " /sysroot/flash " | awk '{print $1}' | awk -F '/' '{print $3}')
for i in $STORAGE $FLASH ; do
# log if booting from usb / removable storage
STORAGE=$(cat /proc/mounts | grep " /sysroot/storage " | awk '{print $1}' | awk -F '/' '{print $3}')
FLASH=$(cat /proc/mounts | grep " /sysroot/flash " | awk '{print $1}' | awk -F '/' '{print $3}')
for i in $STORAGE $FLASH ; do
if [ -n "$i" ] ; then
removable="/sys/class/block/*/$i/../removable"
if [ -e $removable ] ; then
@ -1087,41 +1087,41 @@
fi
fi
fi
done
# move some special filesystems
/usr/bin/busybox mount --move /dev /sysroot/dev
/usr/bin/busybox mount --move /proc /sysroot/proc
/usr/bin/busybox mount --move /sys /sysroot/sys
/usr/bin/busybox rm -fr /tmp
done
# move some special filesystems
/usr/bin/busybox mount --move /dev /sysroot/dev
/usr/bin/busybox mount --move /proc /sysroot/proc
/usr/bin/busybox mount --move /sys /sysroot/sys
/usr/bin/busybox rm -fr /tmp
# tell OE settings addon to disable updates
if [ "$UPDATE_DISABLED" = "yes" ] ; then
# tell OE settings addon to disable updates
if [ "$UPDATE_DISABLED" = "yes" ] ; then
echo "" > /sysroot/dev/.update_disabled
fi
fi
if [ "$FLASH_NETBOOT" = "yes" ] ; then
if [ "$FLASH_NETBOOT" = "yes" ] ; then
echo "" > /sysroot/dev/.flash_netboot
fi
fi
# swap can not be used over nfs.(see scripts/mount-swap)
if [ "$STORAGE_NETBOOT" = "yes" ] ; then
# swap can not be used over nfs.(see scripts/mount-swap)
if [ "$STORAGE_NETBOOT" = "yes" ] ; then
echo "" > /sysroot/dev/.storage_netboot
fi
fi
if [ -f /sysroot/storage/.please_resize_me ] ; then
if [ -f /sysroot/storage/.please_resize_me ] ; then
INIT_UNIT="--unit=fs-resize.target"
fi
fi
BACKUP_FILE=$(ls -1 /sysroot/storage/.restore/??????????????.tar 2>/dev/null | head -n 1)
if [ -f "$BACKUP_FILE" ] ; then
BACKUP_FILE=$(ls -1 /sysroot/storage/.restore/??????????????.tar 2>/dev/null | head -n 1)
if [ -f "$BACKUP_FILE" ] ; then
INIT_UNIT="--unit=backup-restore.target"
fi
fi
if [ -f /sysroot/storage/.cache/reset_oe -o -f /sysroot/storage/.cache/reset_xbmc ] ; then
if [ -f /sysroot/storage/.cache/reset_oe -o -f /sysroot/storage/.cache/reset_xbmc ] ; then
INIT_UNIT="--unit=factory-reset.target"
fi
fi
# switch to new sysroot and start real init
exec /usr/bin/busybox switch_root /sysroot /usr/lib/systemd/systemd $INIT_ARGS $INIT_UNIT
# switch to new sysroot and start real init
exec /usr/bin/busybox switch_root /sysroot /usr/lib/systemd/systemd $INIT_ARGS $INIT_UNIT
error "switch_root" "Error in initramfs. Could not switch to new root"
error "switch_root" "Error in initramfs. Could not switch to new root"