From 5c105d9f3fd086aff195d3849dcf847d6b0bd927 Mon Sep 17 00:00:00 2001 From: blogic Date: Fri, 5 Oct 2012 10:12:53 +0000 Subject: branch Attitude Adjustment git-svn-id: svn://svn.openwrt.org/openwrt/branches/attitude_adjustment@33625 3c298f89-4303-0410-b956-a3cf2f4a3e73 --- .../files/lib/firstboot/05_firstboot_skip | 10 + .../files/lib/firstboot/10_determine_parts | 46 +++ .../files/lib/firstboot/10_no_fo_clear_overlay | 17 ++ .../files/lib/firstboot/10_reset_has_mini_fo | 12 + .../base-files/files/lib/firstboot/20_has_mini_fo | 13 + .../files/lib/firstboot/20_no_fo_mount_jffs | 15 + .../files/lib/firstboot/20_reset_clear_jffs | 14 + .../files/lib/firstboot/30_is_rootfs_mounted | 10 + .../base-files/files/lib/firstboot/30_no_fo_pivot | 11 + .../files/lib/firstboot/30_reset_copy_rom | 13 + .../files/lib/firstboot/40_copy_ramoverlay | 15 + .../files/lib/firstboot/40_no_fo_copy_ramoverlay | 14 + package/base-files/files/lib/firstboot/50_pivot | 17 ++ .../files/lib/firstboot/99_10_no_fo_cleanup | 13 + .../files/lib/firstboot/99_10_with_fo_cleanup | 25 ++ package/base-files/files/lib/functions.sh | 340 +++++++++++++++++++++ package/base-files/files/lib/functions/boot.sh | 150 +++++++++ package/base-files/files/lib/functions/network.sh | 170 +++++++++++ package/base-files/files/lib/functions/service.sh | 129 ++++++++ .../base-files/files/lib/functions/uci-defaults.sh | 230 ++++++++++++++ .../files/lib/preinit/02_default_set_state | 7 + package/base-files/files/lib/preinit/05_mount_skip | 13 + .../base-files/files/lib/preinit/10_check_for_mtd | 20 ++ .../base-files/files/lib/preinit/10_essential_fs | 25 ++ .../files/lib/preinit/10_indicate_failsafe | 18 ++ .../files/lib/preinit/10_indicate_preinit | 52 ++++ .../files/lib/preinit/20_check_jffs2_ready | 19 ++ .../files/lib/preinit/20_device_fs_mount | 37 +++ .../files/lib/preinit/30_device_fs_daemons | 36 +++ .../base-files/files/lib/preinit/30_failsafe_wait | 85 ++++++ package/base-files/files/lib/preinit/40_init_shm | 10 + .../base-files/files/lib/preinit/40_mount_devpts | 15 + .../base-files/files/lib/preinit/40_mount_jffs2 | 26 ++ .../files/lib/preinit/40_run_failsafe_hook | 13 + .../files/lib/preinit/41_merge_overlay_hooks | 24 ++ .../base-files/files/lib/preinit/50_choose_console | 31 ++ .../files/lib/preinit/50_indicate_regular_preinit | 12 + .../base-files/files/lib/preinit/60_init_hotplug | 10 + .../base-files/files/lib/preinit/70_initramfs_test | 14 + .../files/lib/preinit/70_pivot_jffs2_root | 14 + package/base-files/files/lib/preinit/80_mount_root | 10 + .../base-files/files/lib/preinit/90_init_console | 14 + .../base-files/files/lib/preinit/90_mount_no_jffs2 | 12 + .../base-files/files/lib/preinit/90_restore_config | 17 ++ .../files/lib/preinit/99_10_failsafe_login | 18 ++ .../files/lib/preinit/99_10_mount_no_mtd | 12 + .../base-files/files/lib/preinit/99_10_run_init | 16 + package/base-files/files/lib/upgrade/common.sh | 230 ++++++++++++++ .../files/lib/upgrade/keep.d/base-files-essential | 9 + 49 files changed, 2083 insertions(+) create mode 100644 package/base-files/files/lib/firstboot/05_firstboot_skip create mode 100644 package/base-files/files/lib/firstboot/10_determine_parts create mode 100644 package/base-files/files/lib/firstboot/10_no_fo_clear_overlay create mode 100644 package/base-files/files/lib/firstboot/10_reset_has_mini_fo create mode 100644 package/base-files/files/lib/firstboot/20_has_mini_fo create mode 100644 package/base-files/files/lib/firstboot/20_no_fo_mount_jffs create mode 100644 package/base-files/files/lib/firstboot/20_reset_clear_jffs create mode 100644 package/base-files/files/lib/firstboot/30_is_rootfs_mounted create mode 100644 package/base-files/files/lib/firstboot/30_no_fo_pivot create mode 100644 package/base-files/files/lib/firstboot/30_reset_copy_rom create mode 100644 package/base-files/files/lib/firstboot/40_copy_ramoverlay create mode 100644 package/base-files/files/lib/firstboot/40_no_fo_copy_ramoverlay create mode 100644 package/base-files/files/lib/firstboot/50_pivot create mode 100644 package/base-files/files/lib/firstboot/99_10_no_fo_cleanup create mode 100644 package/base-files/files/lib/firstboot/99_10_with_fo_cleanup create mode 100755 package/base-files/files/lib/functions.sh create mode 100644 package/base-files/files/lib/functions/boot.sh create mode 100644 package/base-files/files/lib/functions/network.sh create mode 100644 package/base-files/files/lib/functions/service.sh create mode 100644 package/base-files/files/lib/functions/uci-defaults.sh create mode 100644 package/base-files/files/lib/preinit/02_default_set_state create mode 100644 package/base-files/files/lib/preinit/05_mount_skip create mode 100644 package/base-files/files/lib/preinit/10_check_for_mtd create mode 100644 package/base-files/files/lib/preinit/10_essential_fs create mode 100644 package/base-files/files/lib/preinit/10_indicate_failsafe create mode 100644 package/base-files/files/lib/preinit/10_indicate_preinit create mode 100644 package/base-files/files/lib/preinit/20_check_jffs2_ready create mode 100644 package/base-files/files/lib/preinit/20_device_fs_mount create mode 100644 package/base-files/files/lib/preinit/30_device_fs_daemons create mode 100644 package/base-files/files/lib/preinit/30_failsafe_wait create mode 100644 package/base-files/files/lib/preinit/40_init_shm create mode 100644 package/base-files/files/lib/preinit/40_mount_devpts create mode 100644 package/base-files/files/lib/preinit/40_mount_jffs2 create mode 100644 package/base-files/files/lib/preinit/40_run_failsafe_hook create mode 100644 package/base-files/files/lib/preinit/41_merge_overlay_hooks create mode 100644 package/base-files/files/lib/preinit/50_choose_console create mode 100644 package/base-files/files/lib/preinit/50_indicate_regular_preinit create mode 100644 package/base-files/files/lib/preinit/60_init_hotplug create mode 100644 package/base-files/files/lib/preinit/70_initramfs_test create mode 100644 package/base-files/files/lib/preinit/70_pivot_jffs2_root create mode 100644 package/base-files/files/lib/preinit/80_mount_root create mode 100644 package/base-files/files/lib/preinit/90_init_console create mode 100644 package/base-files/files/lib/preinit/90_mount_no_jffs2 create mode 100644 package/base-files/files/lib/preinit/90_restore_config create mode 100644 package/base-files/files/lib/preinit/99_10_failsafe_login create mode 100644 package/base-files/files/lib/preinit/99_10_mount_no_mtd create mode 100644 package/base-files/files/lib/preinit/99_10_run_init create mode 100644 package/base-files/files/lib/upgrade/common.sh create mode 100644 package/base-files/files/lib/upgrade/keep.d/base-files-essential (limited to 'package/base-files/files/lib') diff --git a/package/base-files/files/lib/firstboot/05_firstboot_skip b/package/base-files/files/lib/firstboot/05_firstboot_skip new file mode 100644 index 000000000..5f44df621 --- /dev/null +++ b/package/base-files/files/lib/firstboot/05_firstboot_skip @@ -0,0 +1,10 @@ +#!/bin/sh + +check_skip() { + if [ "$firstboot_skip_next" = "true" ]; then + return 0 + else + return 1 + fi +} + diff --git a/package/base-files/files/lib/firstboot/10_determine_parts b/package/base-files/files/lib/firstboot/10_determine_parts new file mode 100644 index 000000000..3f56e32a8 --- /dev/null +++ b/package/base-files/files/lib/firstboot/10_determine_parts @@ -0,0 +1,46 @@ +#!/bin/sh + +set_mtd_part() { + partname="rootfs_data" + mtdpart="$(find_mtd_part $partname)" +} + +set_rom_part() { + rom=$(awk '/squashfs/ {print $2}' /proc/mounts) +} + +set_jffs_part() { + jffs=$(awk '/jffs2/ {print $2}' /proc/mounts) +} + +determine_mtd_part() { + set_mtd_part + if [ -z "$mtdpart" ]; then + echo "MTD partition not found." + exit 1 + fi +} + +determine_rom_part() { + check_skip || { + set_rom_part + if [ -z "$rom" ]; then + echo "You do not have a squashfs partition; aborting" + echo "(firstboot cannot be run on jffs2 based firmwares)" + exit 1 + fi + } +} + +determine_jffs2_part() { + check_skip || { + set_jffs_part + } +} + +boot_hook_add switch2jffs determine_mtd_part +boot_hook_add jffs2reset determine_mtd_part +boot_hook_add switch2jffs determine_rom_part +boot_hook_add jffs2reset determine_rom_part +boot_hook_add switch2jffs determine_jffs2_part +boot_hook_add jffs2reset determine_jffs2_part diff --git a/package/base-files/files/lib/firstboot/10_no_fo_clear_overlay b/package/base-files/files/lib/firstboot/10_no_fo_clear_overlay new file mode 100644 index 000000000..8a7d9b066 --- /dev/null +++ b/package/base-files/files/lib/firstboot/10_no_fo_clear_overlay @@ -0,0 +1,17 @@ +#!/bin/sh + +# Copyright (C) 2006-2010 OpenWrt.org +# Copyright (C) 2010 Vertical Communications + +no_fo_clear_overlay() { + # switch back to squashfs temporarily + pivot /rom /mnt + + # get rid of the old overlay + umount -l /mnt + + # another umount to get rid of the bind from /tmp/root + umount -l /mnt +} + +boot_hook_add no_fo no_fo_clear_overlay diff --git a/package/base-files/files/lib/firstboot/10_reset_has_mini_fo b/package/base-files/files/lib/firstboot/10_reset_has_mini_fo new file mode 100644 index 000000000..4e285840a --- /dev/null +++ b/package/base-files/files/lib/firstboot/10_reset_has_mini_fo @@ -0,0 +1,12 @@ +#!/bin/sh + +# Copyright (C) 2006-2010 OpenWrt.org +# Copyright (C) 2010 Vertical Communications + +reset_check_for_overlay() { + if grep -qE '(mini_fo|overlay)' /proc/filesystems; then + reset_has_fo=true + fi +} + +boot_hook_add jffs2reset reset_check_for_overlay diff --git a/package/base-files/files/lib/firstboot/20_has_mini_fo b/package/base-files/files/lib/firstboot/20_has_mini_fo new file mode 100644 index 000000000..8ca6a4fe5 --- /dev/null +++ b/package/base-files/files/lib/firstboot/20_has_mini_fo @@ -0,0 +1,13 @@ +#!/bin/sh + +# Copyright (C) 2006-2010 OpenWrt.org +# Copyright (C) 2010 Vertical Communications + +check_for_overlay() { + if ! grep -qE '(mini_fo|overlay)' /proc/filesystems; then + boot_run_hook no_fo + exit 1 + fi +} + +boot_hook_add switch2jffs check_for_overlay diff --git a/package/base-files/files/lib/firstboot/20_no_fo_mount_jffs b/package/base-files/files/lib/firstboot/20_no_fo_mount_jffs new file mode 100644 index 000000000..8a1d4e06d --- /dev/null +++ b/package/base-files/files/lib/firstboot/20_no_fo_mount_jffs @@ -0,0 +1,15 @@ +#!/bin/sh + +# Copyright (C) 2006-2010 OpenWrt.org +# Copyright (C) 2010 Vertical Communications + +no_fo_mount_jffs() { + # initialize jffs2 + mount "$mtdpart" /overlay -t jffs2 || exit + + # workaround to ensure that union can attach properly + sync + ls /overlay >/dev/null +} + +boot_hook_add no_fo no_fo_mount_jffs diff --git a/package/base-files/files/lib/firstboot/20_reset_clear_jffs b/package/base-files/files/lib/firstboot/20_reset_clear_jffs new file mode 100644 index 000000000..a3cd24fe9 --- /dev/null +++ b/package/base-files/files/lib/firstboot/20_reset_clear_jffs @@ -0,0 +1,14 @@ +#!/bin/sh + +# Copyright (C) 2006-2010 OpenWrt.org +# Copyright (C) 2010 Vertical Communications + +reset_clear_jffs() { + [ "$reset_has_fo" = "true" ] && { + rm -rf $jffs/* 2>&- + mount -o remount $jffs / 2>&- + exit 0 + } || reset_has_fo=false +} + +boot_hook_add jffs2reset reset_clear_jffs diff --git a/package/base-files/files/lib/firstboot/30_is_rootfs_mounted b/package/base-files/files/lib/firstboot/30_is_rootfs_mounted new file mode 100644 index 000000000..e2ba01d50 --- /dev/null +++ b/package/base-files/files/lib/firstboot/30_is_rootfs_mounted @@ -0,0 +1,10 @@ +#!/bin/sh + +# Copyright (C) 2006-2010 OpenWrt.org +# Copyright (C) 2010 Vertical Communications + +skip_if_rootfs_mounted() { + mount "$mtdpart" /rom/overlay -t jffs2 || exit +} + +boot_hook_add switch2jffs skip_if_rootfs_mounted diff --git a/package/base-files/files/lib/firstboot/30_no_fo_pivot b/package/base-files/files/lib/firstboot/30_no_fo_pivot new file mode 100644 index 000000000..b5c2601ee --- /dev/null +++ b/package/base-files/files/lib/firstboot/30_no_fo_pivot @@ -0,0 +1,11 @@ +#!/bin/sh + +# Copyright (C) 2006-2010 OpenWrt.org +# Copyright (C) 2010 Vertical Communications + +no_fo_pivot() { + # switch to the new (empty) jffs2 + fopivot /overlay /rom 1 +} + +boot_hook_add no_fo no_fo_pivot diff --git a/package/base-files/files/lib/firstboot/30_reset_copy_rom b/package/base-files/files/lib/firstboot/30_reset_copy_rom new file mode 100644 index 000000000..d91c68947 --- /dev/null +++ b/package/base-files/files/lib/firstboot/30_reset_copy_rom @@ -0,0 +1,13 @@ +#!/bin/sh + +# Copyright (C) 2006-2010 OpenWrt.org +# Copyright (C) 2010 Vertical Communications + +reset_copy_rom() { + [ "$reset_has_fo" != "true" ] && { + dupe $jffs $rom + exit 0 + } +} + +boot_hook_add jffs2reset reset_copy_rom diff --git a/package/base-files/files/lib/firstboot/40_copy_ramoverlay b/package/base-files/files/lib/firstboot/40_copy_ramoverlay new file mode 100644 index 000000000..39c2edacb --- /dev/null +++ b/package/base-files/files/lib/firstboot/40_copy_ramoverlay @@ -0,0 +1,15 @@ +#!/bin/sh + +# Copyright (C) 2006-2010 OpenWrt.org +# Copyright (C) 2010 Vertical Communications + +copy_ramoverlay() { + # try to avoid fs changing while copying + mount -o remount,ro none / 2>&- + # copy ramoverlay to jffs2 + echo -n "copying files ... " + cp -a /tmp/root/* /rom/overlay 2>&- + echo "done" +} + +boot_hook_add switch2jffs copy_ramoverlay diff --git a/package/base-files/files/lib/firstboot/40_no_fo_copy_ramoverlay b/package/base-files/files/lib/firstboot/40_no_fo_copy_ramoverlay new file mode 100644 index 000000000..ced7c1b66 --- /dev/null +++ b/package/base-files/files/lib/firstboot/40_no_fo_copy_ramoverlay @@ -0,0 +1,14 @@ +#!/bin/sh + +# Copyright (C) 2006-2010 OpenWrt.org +# Copyright (C) 2010 Vertical Communications + +no_fo_copy_ramoverlay() { + # copy ramoverlay to jffs2, must be done after switching + # to the new rootfs to avoid creating opaque directories + echo -n "copying files ... " + cp -a /tmp/root/* / >/dev/null 2>&1 + sync +} + +boot_hook_add no_fo no_fo_ramoverlay diff --git a/package/base-files/files/lib/firstboot/50_pivot b/package/base-files/files/lib/firstboot/50_pivot new file mode 100644 index 000000000..53801d7a8 --- /dev/null +++ b/package/base-files/files/lib/firstboot/50_pivot @@ -0,0 +1,17 @@ +#!/bin/sh + +# Copyright (C) 2006-2010 OpenWrt.org +# Copyright (C) 2010 Vertical Communications + +with_fo_pivot() { + # switch back to squashfs (temporarily) + # and park the ramdisk ontop of /tmp/root + pivot /rom /mnt + mount -o move /mnt /tmp/root + + # /overlay is the overlay + # /rom is the readonly + fopivot /overlay /rom +} + +boot_hook_add switch2jffs with_fo_pivot diff --git a/package/base-files/files/lib/firstboot/99_10_no_fo_cleanup b/package/base-files/files/lib/firstboot/99_10_no_fo_cleanup new file mode 100644 index 000000000..6dedcb1e8 --- /dev/null +++ b/package/base-files/files/lib/firstboot/99_10_no_fo_cleanup @@ -0,0 +1,13 @@ +#!/bin/sh + +# Copyright (C) 2006-2010 OpenWrt.org +# Copyright (C) 2010 Vertical Communications + +no_fo_cleanup() { + echo "done" + umount -l /overlay + umount -l /tmp/root + exit 0 +} + +boot_hook_add no_fo no_fo_cleanup diff --git a/package/base-files/files/lib/firstboot/99_10_with_fo_cleanup b/package/base-files/files/lib/firstboot/99_10_with_fo_cleanup new file mode 100644 index 000000000..0181b39d4 --- /dev/null +++ b/package/base-files/files/lib/firstboot/99_10_with_fo_cleanup @@ -0,0 +1,25 @@ +#!/bin/sh + +# Copyright (C) 2006-2010 OpenWrt.org +# Copyright (C) 2010 Vertical Communications + +with_fo_cleanup() { + # try to get rid of /tmp/root + # this will almost always fail + umount /tmp/root 2>&- + grep -q overlay /proc/filesystems && { + cd / + ( + cd /overlay + find -type l + ) | while read FILE; do + [ -z "$FILE" ] && break + if ls -la "$FILE" 2>&- | grep -q '(overlay-whiteout)'; then + rm -f "$FILE" + fi + done + } + exit 0 +} + +boot_hook_add switch2jffs with_fo_cleanup diff --git a/package/base-files/files/lib/functions.sh b/package/base-files/files/lib/functions.sh new file mode 100755 index 000000000..b3a3885f2 --- /dev/null +++ b/package/base-files/files/lib/functions.sh @@ -0,0 +1,340 @@ +#!/bin/sh +# Copyright (C) 2006-2011 OpenWrt.org +# Copyright (C) 2006 Fokus Fraunhofer + + +debug () { + ${DEBUG:-:} "$@" +} +mount() { + busybox mount "$@" +} + +# newline +N=" +" + +_C=0 +NO_EXPORT=1 +LOAD_STATE=1 +LIST_SEP=" " + +hotplug_dev() { + env -i ACTION=$1 INTERFACE=$2 /sbin/hotplug-call net +} + +append() { + local var="$1" + local value="$2" + local sep="${3:- }" + + eval "export ${NO_EXPORT:+-n} -- \"$var=\${$var:+\${$var}\${value:+\$sep}}\$value\"" +} + +list_contains() { + local var="$1" + local str="$2" + local val + + eval "val=\" \${$var} \"" + [ "${val%% $str *}" != "$val" ] +} + +list_remove() { + local var="$1" + local remove="$2" + local val + + eval "val=\" \${$var} \"" + val1="${val%% $remove *}" + [ "$val1" = "$val" ] && return + val2="${val##* $remove }" + [ "$val2" = "$val" ] && return + val="${val1## } ${val2%% }" + val="${val%% }" + eval "export ${NO_EXPORT:+-n} -- \"$var=\$val\"" +} + +config_load() { + [ -n "$IPKG_INSTROOT" ] && return 0 + uci_load "$@" +} + +reset_cb() { + config_cb() { return 0; } + option_cb() { return 0; } + list_cb() { return 0; } +} +reset_cb + +package() { + return 0 +} + +config () { + local cfgtype="$1" + local name="$2" + + export ${NO_EXPORT:+-n} CONFIG_NUM_SECTIONS=$(($CONFIG_NUM_SECTIONS + 1)) + name="${name:-cfg$CONFIG_NUM_SECTIONS}" + append CONFIG_SECTIONS "$name" + [ -n "$NO_CALLBACK" ] || config_cb "$cfgtype" "$name" + export ${NO_EXPORT:+-n} CONFIG_SECTION="$name" + export ${NO_EXPORT:+-n} "CONFIG_${CONFIG_SECTION}_TYPE=$cfgtype" +} + +option () { + local varname="$1"; shift + local value="$*" + + export ${NO_EXPORT:+-n} "CONFIG_${CONFIG_SECTION}_${varname}=$value" + [ -n "$NO_CALLBACK" ] || option_cb "$varname" "$*" +} + +list() { + local varname="$1"; shift + local value="$*" + local len + + config_get len "$CONFIG_SECTION" "${varname}_LENGTH" 0 + [ $len = 0 ] && append CONFIG_LIST_STATE "${CONFIG_SECTION}_${varname}" + len=$(($len + 1)) + config_set "$CONFIG_SECTION" "${varname}_ITEM$len" "$value" + config_set "$CONFIG_SECTION" "${varname}_LENGTH" "$len" + append "CONFIG_${CONFIG_SECTION}_${varname}" "$value" "$LIST_SEP" + list_cb "$varname" "$*" +} + +config_rename() { + local OLD="$1" + local NEW="$2" + local oldvar + local newvar + + [ -n "$OLD" -a -n "$NEW" ] || return + for oldvar in `set | grep ^CONFIG_${OLD}_ | \ + sed -e 's/\(.*\)=.*$/\1/'` ; do + newvar="CONFIG_${NEW}_${oldvar##CONFIG_${OLD}_}" + eval "export ${NO_EXPORT:+-n} \"$newvar=\${$oldvar}\"" + unset "$oldvar" + done + export ${NO_EXPORT:+-n} CONFIG_SECTIONS="$(echo " $CONFIG_SECTIONS " | sed -e "s, $OLD , $NEW ,")" + + [ "$CONFIG_SECTION" = "$OLD" ] && export ${NO_EXPORT:+-n} CONFIG_SECTION="$NEW" +} + +config_unset() { + config_set "$1" "$2" "" +} + +config_clear() { + local SECTION="$1" + local oldvar + + list_remove CONFIG_SECTIONS "$SECTION" + export ${NO_EXPORT:+-n} CONFIG_SECTIONS="${SECTION:+$CONFIG_SECTIONS}" + + for oldvar in `set | grep ^CONFIG_${SECTION:+${SECTION}_} | \ + sed -e 's/\(.*\)=.*$/\1/'` ; do + unset $oldvar + done +} + +# config_get