diff options
author | John Crispin <john@openwrt.org> | 2013-03-13 18:11:19 +0000 |
---|---|---|
committer | John Crispin <john@openwrt.org> | 2013-03-13 18:11:19 +0000 |
commit | f43b7934d2850c2f545736253a0f8cbe4915fdff (patch) | |
tree | 3718ca82dd27e3917a51439823bfb20a067af784 /package/base-files/files.old/lib | |
parent | 1360067c4a75cd1804710e6f25871f695d3271b2 (diff) | |
download | upstream-f43b7934d2850c2f545736253a0f8cbe4915fdff.tar.gz upstream-f43b7934d2850c2f545736253a0f8cbe4915fdff.tar.bz2 upstream-f43b7934d2850c2f545736253a0f8cbe4915fdff.zip |
make basefiles aware of procd
Signed-off-by: John Crispin <blogic@openwrt.org>
SVN-Revision: 36003
Diffstat (limited to 'package/base-files/files.old/lib')
14 files changed, 522 insertions, 0 deletions
diff --git a/package/base-files/files.old/lib/firstboot/99_10_with_fo_cleanup b/package/base-files/files.old/lib/firstboot/99_10_with_fo_cleanup new file mode 100644 index 0000000000..0181b39d49 --- /dev/null +++ b/package/base-files/files.old/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.old/lib/preinit/10_essential_fs b/package/base-files/files.old/lib/preinit/10_essential_fs new file mode 100644 index 0000000000..fc04eb7ff3 --- /dev/null +++ b/package/base-files/files.old/lib/preinit/10_essential_fs @@ -0,0 +1,25 @@ +#!/bin/sh +# Copyright (C) 2006 OpenWrt.org +# Copyright (C) 2010 Vertical Communications + +do_mount_procfs() { + mount -o noatime -t proc proc /proc +} + +do_mount_sysfs() { + mount -o noatime -tsysfs sysfs /sys +} + +calc_tmpfs_size() { + pi_size=$(awk '/MemTotal:/ {l=5242880;mt=($2*1024);print((s=mt/2)<l)&&(mt>l)?mt-l:s}' /proc/meminfo) +} + +do_mount_tmpfs() { + calc_tmpfs_size + mount -o noatime -t tmpfs -o size=$pi_size,nosuid,nodev,mode=1777 tmpfs /tmp +} + +boot_hook_add preinit_essential do_mount_procfs +boot_hook_add preinit_essential do_mount_sysfs +boot_hook_add preinit_essential do_mount_tmpfs + diff --git a/package/base-files/files.old/lib/preinit/10_indicate_preinit b/package/base-files/files.old/lib/preinit/10_indicate_preinit new file mode 100644 index 0000000000..4a0109cc17 --- /dev/null +++ b/package/base-files/files.old/lib/preinit/10_indicate_preinit @@ -0,0 +1,51 @@ +#!/bin/sh +# Copyright (C) 2006 OpenWrt.org +# Copyright (C) 2010 Vertical Communications + +preinit_ip() { + # if the preinit interface isn't specified and ifname is set in + # preinit.arch use that interface + if [ -z "$pi_ifname" ]; then + pi_ifname=$ifname + fi + + [ -n "$pi_ifname" ] && grep -q "$pi_ifname" /proc/net/dev && { + ifconfig $pi_ifname $pi_ip netmask $pi_netmask broadcast $pi_broadcast up + } +} + +preinit_ip_deconfig() { + [ -n "$pi_ifname" ] && grep -q "$pi_ifname" /proc/net/dev && { + ifconfig $pi_ifname 0.0.0.0 down + } +} + +preinit_net_echo() { + [ -n "$pi_ifname" ] && grep -q "$pi_ifname" /proc/net/dev && { + { + [ "$pi_preinit_net_messages" = "y" ] || { + [ "$pi_failsafe_net_message" = "true" ] && + [ "$pi_preinit_no_failsafe_netmsg" != "y" ] + } + } && netmsg $pi_broadcast "$1" + } +} + +preinit_echo() { + preinit_net_echo $1 + echo $1 +} + +pi_indicate_led() { + set_state preinit +} + +pi_indicate_preinit() { + echo "- preinit -" + preinit_net_echo "Doing OpenWRT Preinit\n" + pi_indicate_led +} + +boot_hook_add preinit_main preinit_ip +boot_hook_add preinit_main pi_indicate_preinit + diff --git a/package/base-files/files.old/lib/preinit/20_device_fs_mount b/package/base-files/files.old/lib/preinit/20_device_fs_mount new file mode 100644 index 0000000000..7535b3ff9d --- /dev/null +++ b/package/base-files/files.old/lib/preinit/20_device_fs_mount @@ -0,0 +1,37 @@ +#!/bin/sh +# Copyright (C) 2006 OpenWrt.org +# Copyright (C) 2010 Vertical Communications + +do_move_devtmpfs() { + local mnt="$(grep devtmpfs /proc/mounts)" + mnt="${mnt#* }"; mnt="${mnt%% *}" + + [ "$mnt" = "/dev" ] || mount -o noatime,move "$mnt" /dev +} + +do_mount_devfs() { + mount -o noatime -t devfs devfs /dev +} + +do_mount_hotplug() { + mount -t tmpfs -o noatime,mode=0755,size=512K tmpfs /dev +} + +do_mount_udev() { + mount -n -t tmpfs -o noatime,mode=0755 udev /dev +} + +choose_device_fs() { + if grep -q devtmpfs /proc/mounts; then + do_move_devtmpfs + elif grep -q devfs /proc/filesystems; then + do_mount_devfs + elif [ -x /sbin/hotplug2 ]; then + do_mount_hotplug + elif [ -x /sbin/udevd ]; then + do_mount_udev + fi +} + +boot_hook_add preinit_essential choose_device_fs + diff --git a/package/base-files/files.old/lib/preinit/30_device_fs_daemons b/package/base-files/files.old/lib/preinit/30_device_fs_daemons new file mode 100644 index 0000000000..8379e5e74f --- /dev/null +++ b/package/base-files/files.old/lib/preinit/30_device_fs_daemons @@ -0,0 +1,36 @@ +#!/bin/sh +# Copyright (C) 2006-2013 OpenWrt.org +# Copyright (C) 2010 Vertical Communications + +init_devfs() { + HOTPLUG=/sbin/hotplug-call +} + +init_hotplug2() { + [ -c /dev/console ] || mknod /dev/console c 5 1 + /sbin/hotplug2 --set-rules-file /etc/hotplug2-init.rules --no-persistent --set-coldplug-cmd /sbin/udevtrigger + /sbin/hotplug2 --set-rules-file /etc/hotplug2-init.rules --persistent & +} + +init_udev() { + [ -d /lib/udev/devices ] && cp -af /lib/udev/devices/* /dev/ + [ -c /dev/console ] || mknod -m 0600 /dev/console c 5 1 + [ -c /dev/null ] || mknod -m 0666 /dev/null c 1 3 + /sbin/udevd --daemon --resolve-names=never + /sbin/udevadm trigger + /sbin/udevadm settle +} + +init_device_fs() { + HOTPLUG= + if grep -q devfs /proc/filesystems; then + init_devfs + elif [ -x /sbin/hotplug2 ]; then + init_hotplug2 + elif [ -x /sbin/udevd ]; then + init_udev + fi +} + +boot_hook_add preinit_essential init_device_fs + diff --git a/package/base-files/files.old/lib/preinit/40_init_shm b/package/base-files/files.old/lib/preinit/40_init_shm new file mode 100644 index 0000000000..8971116a49 --- /dev/null +++ b/package/base-files/files.old/lib/preinit/40_init_shm @@ -0,0 +1,10 @@ +#!/bin/sh +# Copyright (C) 2006 OpenWrt.org +# Copyright (C) 2010 Vertical Communications + +init_shm() { + [ -d /dev/shm ] || mkdir -p /dev/shm +} + +boot_hook_add preinit_essential init_shm + diff --git a/package/base-files/files.old/lib/preinit/40_mount_devpts b/package/base-files/files.old/lib/preinit/40_mount_devpts new file mode 100644 index 0000000000..b55a7f2e8e --- /dev/null +++ b/package/base-files/files.old/lib/preinit/40_mount_devpts @@ -0,0 +1,15 @@ +#!/bin/sh +# Copyright (C) 2006 OpenWrt.org +# Copyright (C) 2010 Vertical Communications + +init_devpts() { + [ -d /dev/pts ] || mkdir -p /dev/pts +} + +do_mount_devpts() { + mount -o noatime -t devpts devpts /dev/pts +} + +boot_hook_add preinit_essential init_devpts +boot_hook_add preinit_essential do_mount_devpts + diff --git a/package/base-files/files.old/lib/preinit/50_choose_console b/package/base-files/files.old/lib/preinit/50_choose_console new file mode 100644 index 0000000000..ecbc2eaf42 --- /dev/null +++ b/package/base-files/files.old/lib/preinit/50_choose_console @@ -0,0 +1,31 @@ +#!/bin/sh +# Copyright (C) 2006-2010 OpenWrt.org +# Copyright (C) 2010 Vertical Communications + +choose_console() { + # the shell really doesn't like having stdin/out closed + # that's why we use /dev/pty/m0 and m1 (or equivalent) as replacement + # for /dev/console if there's no serial console available + + if grep -q devfs /proc/filesystems; then + M0=/dev/pty/m0 + M1=/dev/pty/m1 + M2=/dev/pty/m1 + elif [ -x /sbin/hotplug2 ]; then + M0=/dev/ptmx + M1=/dev/ptmx + M2=/dev/ptmx + elif [ -x /sbin/udevd ]; then + M0=/dev/pty/ptmx + M1=/dev/pty/ptmx + M2=/dev/pty/ptmx + fi + dd if=/dev/console of=/dev/null bs=1 count=0 >/dev/null 2>/dev/null && { + M0=/dev/console + M1=/dev/console + M2=/dev/console + } +} + +boot_hook_add preinit_essential choose_console + diff --git a/package/base-files/files.old/lib/preinit/50_indicate_regular_preinit b/package/base-files/files.old/lib/preinit/50_indicate_regular_preinit new file mode 100644 index 0000000000..9cc01f2199 --- /dev/null +++ b/package/base-files/files.old/lib/preinit/50_indicate_regular_preinit @@ -0,0 +1,12 @@ +#!/bin/sh +# Copyright (C) 2006 OpenWrt.org +# Copyright (C) 2010 Vertical Communications + +indicate_regular_preinit() { + echo "- regular preinit -" + preinit_net_echo "Continuing with Regular Preinit\n" + pi_indicate_led +} + +boot_hook_add preinit_main indicate_regular_preinit + diff --git a/package/base-files/files.old/lib/preinit/60_init_hotplug b/package/base-files/files.old/lib/preinit/60_init_hotplug new file mode 100644 index 0000000000..dc05e0ed05 --- /dev/null +++ b/package/base-files/files.old/lib/preinit/60_init_hotplug @@ -0,0 +1,10 @@ +#!/bin/sh +# Copyright (C) 2006 OpenWrt.org +# Copyright (C) 2010 Vertical Communications + +init_hotplug() { + echo "$HOTPLUG" > /proc/sys/kernel/hotplug +} + +boot_hook_add preinit_main init_hotplug + diff --git a/package/base-files/files.old/lib/preinit/80_mount_root b/package/base-files/files.old/lib/preinit/80_mount_root new file mode 100644 index 0000000000..ad24fb8ace --- /dev/null +++ b/package/base-files/files.old/lib/preinit/80_mount_root @@ -0,0 +1,10 @@ +#!/bin/sh +# Copyright (C) 2006 OpenWrt.org +# Copyright (C) 2010 Vertical Communications + +do_mount_root() { + boot_run_hook preinit_mount_root +} + +boot_hook_add preinit_main do_mount_root + diff --git a/package/base-files/files.old/lib/preinit/90_init_console b/package/base-files/files.old/lib/preinit/90_init_console new file mode 100644 index 0000000000..ca05755fd3 --- /dev/null +++ b/package/base-files/files.old/lib/preinit/90_init_console @@ -0,0 +1,14 @@ +#!/bin/sh +# Copyright (C) 2006-2010 OpenWrt.org +# Copyright (C) 2010 Vertical Communications + +init_console() { + if [ "$pi_suppress_stderr" = "y" ]; then + exec <$M0 >$M1 2>&0 + else + exec <$M0 >$M1 2>$M2 + fi +} + +boot_hook_add preinit_essential init_console + diff --git a/package/base-files/files.old/lib/preinit/99_10_run_init b/package/base-files/files.old/lib/preinit/99_10_run_init new file mode 100644 index 0000000000..fef3a503e2 --- /dev/null +++ b/package/base-files/files.old/lib/preinit/99_10_run_init @@ -0,0 +1,16 @@ +#!/bin/sh +# Copyright (C) 2006 OpenWrt.org +# Copyright (C) 2010 Vertical Communications + +run_init() { + preinit_echo "- init -" + preinit_ip_deconfig + if [ "$pi_init_suppress_stderr" = "y" ]; then + exec env - PATH=$pi_init_path $pi_init_env $pi_init_cmd 2>&0 + else + exec env - PATH=$pi_init_path $pi_init_env $pi_init_cmd + fi +} + +boot_hook_add preinit_main run_init + diff --git a/package/base-files/files.old/lib/upgrade/common.sh b/package/base-files/files.old/lib/upgrade/common.sh new file mode 100644 index 0000000000..2e123ab3cf --- /dev/null +++ b/package/base-files/files.old/lib/upgrade/common.sh @@ -0,0 +1,230 @@ +#!/bin/sh + +RAM_ROOT=/tmp/root + +ldd() { LD_TRACE_LOADED_OBJECTS=1 $*; } +libs() { ldd $* | awk '{print $3}'; } + +install_file() { # <file> [ <file> ... ] + for file in "$@"; do + dest="$RAM_ROOT/$file" + [ -f $file -a ! -f $dest ] && { + dir="$(dirname $dest)" + mkdir -p "$dir" + cp $file $dest + } + done +} + +install_bin() { # <file> [ <symlink> ... ] + src=$1 + files=$1 + [ -x "$src" ] && files="$src $(libs $src)" + install_file $files + [ -e /lib/ld-linux.so.3 ] && { + install_file /lib/ld-linux.so.3 + } + shift + for link in "$@"; do { + dest="$RAM_ROOT/$link" + dir="$(dirname $dest)" + mkdir -p "$dir" + [ -f "$dest" ] || ln -s $src $dest + }; done +} + +supivot() { # <new_root> <old_root> + mount | grep "on $1 type" 2>&- 1>&- || mount -o bind $1 $1 + mkdir -p $1$2 $1/proc $1/sys $1/dev $1/tmp $1/overlay && \ + mount -o noatime,move /proc $1/proc && \ + pivot_root $1 $1$2 || { + umount $1 $1 + return 1 + } + + mount -o noatime,move $2/sys /sys + mount -o noatime,move $2/dev /dev + mount -o noatime,move $2/tmp /tmp + mount -o noatime,move $2/overlay /overlay 2>&- + return 0 +} + +run_ramfs() { # <command> [...] + install_bin /bin/busybox /bin/ash /bin/sh /bin/mount /bin/umount \ + /sbin/pivot_root /usr/bin/wget /sbin/reboot /bin/sync /bin/dd \ + /bin/grep /bin/cp /bin/mv /bin/tar /usr/bin/md5sum "/usr/bin/[" \ + /bin/vi /bin/ls /bin/cat /usr/bin/awk /usr/bin/hexdump \ + /bin/sleep /bin/zcat /usr/bin/bzcat /usr/bin/printf /usr/bin/wc + + install_bin /sbin/mtd + for file in $RAMFS_COPY_BIN; do + install_bin $file + done + install_file /etc/resolv.conf /lib/functions.sh /lib/functions.sh /lib/upgrade/*.sh $RAMFS_COPY_DATA + + supivot $RAM_ROOT /mnt || { + echo "Failed to switch over to ramfs. Please reboot." + exit 1 + } + + mount -o remount,ro /mnt + umount -l /mnt + + grep /overlay /proc/mounts > /dev/null && { + mount -o noatime,remount,ro /overlay + umount -l /overlay + } + + # spawn a new shell from ramdisk to reduce the probability of cache issues + exec /bin/busybox ash -c "$*" +} + +kill_remaining() { # [ <signal> ] + local sig="${1:-TERM}" + echo -n "Sending $sig to remaining processes ... " + + local stat + for stat in /proc/[0-9]*/stat; do + [ -f "$stat" ] || continue + + local pid name state ppid rest + read pid name state ppid rest < $stat + name="${name#(}"; name="${name%)}" + + local cmdline + read cmdline < /proc/$pid/cmdline + + # Skip kernel threads + [ -n "$cmdline" ] || continue + + case "$name" in + # Skip essential services + *ash*|*init*|*watchdog*|*ssh*|*dropbear*|*telnet*|*login*|*hostapd*|*wpa_supplicant*) : ;; + + # Killable process + *) + if [ $pid -ne $$ ] && [ $ppid -ne $$ ]; then + echo -n "$name " + kill -$sig $pid 2>/dev/null + fi + ;; + esac + done + echo "" +} + +run_hooks() { + local arg="$1"; shift + for func in "$@"; do + eval "$func $arg" + done +} + +ask_bool() { + local default="$1"; shift; + local answer="$default" + + [ "$INTERACTIVE" -eq 1 ] && { + case "$default" in + 0) echo -n "$* (y/N): ";; + *) echo -n "$* (Y/n): ";; + esac + read answer + case "$answer" in + y*) answer=1;; + n*) answer=0;; + *) answer="$default";; + esac + } + [ "$answer" -gt 0 ] +} + +v() { + [ "$VERBOSE" -ge 1 ] && echo "$@" +} + +rootfs_type() { + mount | awk '($3 ~ /^\/$/) && ($5 !~ /rootfs/) { print $5 }' +} + +get_image() { # <source> [ <command> ] + local from="$1" + local conc="$2" + local cmd + + case "$from" in + http://*|ftp://*) cmd="wget -O- -q";; + *) cmd="cat";; + esac + if [ -z "$conc" ]; then + local magic="$(eval $cmd $from | dd bs=2 count=1 2>/dev/null | hexdump -n 2 -e '1/1 "%02x"')" + case "$magic" in + 1f8b) conc="zcat";; + 425a) conc="bzcat";; + esac + fi + + eval "$cmd $from ${conc:+| $conc}" +} + +get_magic_word() { + get_image "$@" | dd bs=2 count=1 2>/dev/null | hexdump -v -n 2 -e '1/1 "%02x"' +} + +get_magic_long() { + get_image "$@" | dd bs=4 count=1 2>/dev/null | hexdump -v -n 4 -e '1/1 "%02x"' +} + +refresh_mtd_partitions() { + mtd refresh rootfs +} + +jffs2_copy_config() { + if grep rootfs_data /proc/mtd >/dev/null; then + # squashfs+jffs2 + mtd -e rootfs_data jffs2write "$CONF_TAR" rootfs_data + else + # jffs2 + mtd jffs2write "$CONF_TAR" rootfs + fi +} + +default_do_upgrade() { + sync + if [ "$SAVE_CONFIG" -eq 1 -a -z "$USE_REFRESH" ]; then + get_image "$1" | mtd -j "$CONF_TAR" write - "${PART_NAME:-image}" + else + get_image "$1" | mtd write - "${PART_NAME:-image}" + fi +} + +do_upgrade() { + v "Performing system upgrade..." + if type 'platform_do_upgrade' >/dev/null 2>/dev/null; then + platform_do_upgrade "$ARGV" + else + default_do_upgrade "$ARGV" + fi + + [ "$SAVE_CONFIG" -eq 1 -a -n "$USE_REFRESH" ] && { + v "Refreshing partitions" + if type 'platform_refresh_partitions' >/dev/null 2>/dev/null; then + platform_refresh_partitions + else + refresh_mtd_partitions + fi + if type 'platform_copy_config' >/dev/null 2>/dev/null; then + platform_copy_config + else + jffs2_copy_config + fi + } + v "Upgrade completed" + [ -n "$DELAY" ] && sleep "$DELAY" + ask_bool 1 "Reboot" && { + v "Rebooting system..." + reboot -f + sleep 5 + echo b 2>/dev/null >/proc/sysrq-trigger + } +} |