5 ldd
() { LD_TRACE_LOADED_OBJECTS
=1 $
*; }
6 libs
() { ldd $
* |
awk '{print $3}'; }
8 install_file
() { # <file> [ <file> ... ]
10 dest
="$RAM_ROOT/$file"
11 [ -f $file -a ! -f $dest ] && {
12 dir
="$(dirname $dest)"
19 install_bin
() { # <file> [ <symlink> ... ]
22 [ -x "$src" ] && files
="$src $(libs $src)"
24 [ -e /lib
/ld.so
.1 ] && {
25 install_file
/lib
/ld.so
.1
28 for link
in "$@"; do {
29 dest
="$RAM_ROOT/$link"
30 dir
="$(dirname $dest)"
32 [ -f "$dest" ] ||
ln -s $src $dest
36 supivot
() { # <new_root> <old_root>
37 mount |
grep "on $1 type" 2>&- 1>&- || mount
-o bind $1 $1
38 mkdir
-p $1$2 $1/proc
$1/sys
$1/dev
$1/tmp
$1/overlay
&& \
39 mount
-o noatime
,move
/proc
$1/proc
&& \
40 pivot_root
$1 $1$2 ||
{
45 mount
-o noatime
,move
$2/sys
/sys
46 mount
-o noatime
,move
$2/dev
/dev
47 mount
-o noatime
,move
$2/tmp
/tmp
48 mount
-o noatime
,move
$2/overlay
/overlay
2>&-
52 run_ramfs
() { # <command> [...]
53 install_bin
/bin
/busybox
/bin
/ash
/bin
/sh
/bin
/mount
/bin
/umount \
54 /sbin
/pivot_root
/usr
/bin
/wget
/sbin
/reboot
/bin
/sync
/bin
/dd \
55 /bin
/grep /bin
/cp /bin
/mv /bin
/tar /usr
/bin
/md5sum "/usr/bin/[" \
56 /bin
/vi
/bin
/ls /bin
/cat /usr
/bin
/awk /usr
/bin
/hexdump \
57 /bin
/sleep /bin
/zcat
/usr
/bin
/bzcat
/usr
/bin
/printf /usr
/bin
/wc
60 for file in $RAMFS_COPY_BIN; do
63 install_file
/etc
/resolv.conf
/lib
/functions.sh
/lib
/functions.sh
/lib
/upgrade
/*.sh
$RAMFS_COPY_DATA
65 supivot
$RAM_ROOT /mnt ||
{
66 echo "Failed to switch over to ramfs. Please reboot."
70 mount
-o remount
,ro
/mnt
73 grep /overlay
/proc
/mounts
> /dev
/null
&& {
74 mount
-o noatime
,remount
,ro
/overlay
78 # spawn a new shell from ramdisk to reduce the probability of cache issues
79 exec /bin
/busybox ash
-c "$*"
82 kill_remaining
() { # [ <signal> ]
83 local sig
="${1:-TERM}"
84 echo -n "Sending $sig to remaining processes ... "
87 for stat
in /proc
/[0-9]*/stat
; do
88 [ -f "$stat" ] ||
continue
90 local pid name state ppid rest
91 read pid name state ppid rest
< $stat
92 name
="${name#(}"; name
="${name%)}"
95 read cmdline
< /proc
/$pid/cmdline
98 [ -n "$cmdline" ] ||
continue
101 # Skip essential services
102 *procd
*|
*ash
*|
*init
*|
*watchdog
*|
*ssh*|
*dropbear
*|
*telnet*|
*login
*|
*hostapd
*|
*wpa_supplicant
*) : ;;
106 if [ $pid -ne $$
] && [ $ppid -ne $$
]; then
108 kill -$sig $pid 2>/dev
/null
117 local arg
="$1"; shift
124 local default
="$1"; shift;
125 local answer
="$default"
127 [ "$INTERACTIVE" -eq 1 ] && {
129 0) echo -n "$* (y/N): ";;
130 *) echo -n "$* (Y/n): ";;
136 *) answer
="$default";;
143 [ "$VERBOSE" -ge 1 ] && echo "$@"
147 mount |
awk '($3 ~ /^\/$/) && ($5 !~ /rootfs/) { print $5 }'
150 get_image
() { # <source> [ <command> ]
156 http
://*|
ftp://*) cmd
="wget -O- -q";;
159 if [ -z "$conc" ]; then
160 local magic
="$(eval $cmd $from 2>/dev/null | dd bs=2 count=1 2>/dev/null | hexdump -n 2 -e '1/1 "%02x
"')"
167 eval "$cmd $from 2>/dev/null ${conc:+| $conc}"
171 get_image
"$@" |
dd bs
=2 count
=1 2>/dev
/null |
hexdump -v -n 2 -e '1/1 "%02x"'
175 get_image
"$@" |
dd bs
=4 count
=1 2>/dev
/null |
hexdump -v -n 4 -e '1/1 "%02x"'
178 jffs2_copy_config
() {
179 if grep rootfs_data
/proc
/mtd
>/dev
/null
; then
181 mtd
-e rootfs_data jffs2write
"$CONF_TAR" rootfs_data
184 mtd jffs2write
"$CONF_TAR" rootfs
188 default_do_upgrade
() {
190 if [ "$SAVE_CONFIG" -eq 1 ]; then
191 get_image
"$1" | mtd
-j "$CONF_TAR" write - "${PART_NAME:-image}"
193 get_image
"$1" | mtd
write - "${PART_NAME:-image}"
198 v
"Performing system upgrade..."
199 if type 'platform_do_upgrade' >/dev
/null
2>/dev
/null
; then
200 platform_do_upgrade
"$ARGV"
202 default_do_upgrade
"$ARGV"
205 if [ "$SAVE_CONFIG" -eq 1 ] && type 'platform_copy_config' >/dev
/null
2>/dev
/null
; then
209 v
"Upgrade completed"
210 [ -n "$DELAY" ] && sleep "$DELAY"
211 ask_bool
1 "Reboot" && {
212 v
"Rebooting system..."
215 echo b
2>/dev
/null
>/proc
/sysrq-trigger