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-linux.so
.3 ] && {
25 install_file
/lib
/ld-linux.so
.3
28 for link
in "$@"; do {
29 dest
="$RAM_ROOT/$link"
30 dir
="$(dirname $dest)"
32 [ -f "$dest" ] ||
ln -s $src $dest
36 pivot
() { # <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/dev
$1/tmp
$1/overlay
&& \
39 mount
-o move
/proc
$1/proc
&& \
40 pivot_root
$1 $1$2 ||
{
44 mount
-o move
$2/dev
/dev
45 mount
-o move
$2/tmp
/tmp
46 mount
-o move
$2/overlay
/overlay
2>&-
50 run_ramfs
() { # <command> [...]
51 install_bin
/bin
/busybox
/bin
/ash
/bin
/sh
/bin
/mount
/bin
/umount \
52 /sbin
/pivot_root
/usr
/bin
/wget
/sbin
/reboot
/bin
/sync
/bin
/dd \
53 /bin
/grep /bin
/cp /bin
/mv /bin
/tar /usr
/bin
/md5sum "/usr/bin/[" \
54 /bin
/vi
/bin
/ls /bin
/cat /usr
/bin
/awk /usr
/bin
/hexdump \
55 /bin
/sleep /bin
/zcat
/usr
/bin
/bzcat
/usr
/bin
/printf /usr
/bin
/wc
58 for file in $RAMFS_COPY_BIN; do
61 install_file
/etc
/resolv.conf
/etc
/functions.sh
/lib
/upgrade
/*.sh
$RAMFS_COPY_DATA
63 pivot
$RAM_ROOT /mnt ||
{
64 echo "Failed to switch over to ramfs. Please reboot."
68 mount
-o remount
,ro
/mnt
71 grep /overlay
/proc
/mounts
> /dev
/null
&& {
72 mount
-o remount
,ro
/overlay
76 # spawn a new shell from ramdisk to reduce the probability of cache issues
77 exec /bin
/busybox ash
-c "$*"
80 kill_remaining
() { # [ <signal> ]
81 local sig
="${1:-TERM}"
82 echo -n "Sending $sig to remaining processes ... "
83 top
-bn1 |
while read pid ppid user stat vsz pvsz pcpu cmd args
; do
89 # Skip kernel threads and essential services
90 \
[*\
]|
*ash
*|
*init
*|
*watchdog
*|
*ssh*|
*dropbear
*|
*telnet*|
*login
*) : ;;
94 if [ $pid -ne $$
] && [ $ppid -ne $$
]; then
96 kill -$sig $pid 2>/dev
/null
105 local arg
="$1"; shift
112 local default
="$1"; shift;
113 local answer
="$default"
115 [ "$INTERACTIVE" -eq 1 ] && {
117 0) echo -n "$* (y/N): ";;
118 *) echo -n "$* (Y/n): ";;
124 *) answer
="$default";;
131 [ "$VERBOSE" -ge 1 ] && echo "$@"
135 mount |
awk '($3 ~ /^\/$/) && ($5 !~ /rootfs/) { print $5 }'
138 get_image
() { # <source> [ <command> ]
144 http
://*|
ftp://*) cmd
="wget -O- -q";;
147 if [ -z "$conc" ]; then
148 local magic
="$(eval $cmd $from | dd bs=2 count=1 2>/dev/null | hexdump -n 2 -e '1/1 "%02x
"')"
155 eval "$cmd $from ${conc:+| $conc}"
159 get_image
"$@" |
dd bs
=2 count
=1 2>/dev
/null |
hexdump -v -n 2 -e '1/1 "%02x"'
163 get_image
"$@" |
dd bs
=4 count
=1 2>/dev
/null |
hexdump -v -n 4 -e '1/1 "%02x"'
166 refresh_mtd_partitions
() {
170 jffs2_copy_config
() {
171 if grep rootfs_data
/proc
/mtd
>/dev
/null
; then
173 mtd
-e rootfs_data jffs2write
"$CONF_TAR" rootfs_data
176 mtd jffs2write
"$CONF_TAR" rootfs
180 default_do_upgrade
() {
182 if [ "$SAVE_CONFIG" -eq 1 -a -z "$USE_REFRESH" ]; then
183 get_image
"$1" | mtd
-j "$CONF_TAR" write - "${PART_NAME:-image}"
185 get_image
"$1" | mtd
write - "${PART_NAME:-image}"
190 v
"Performing system upgrade..."
191 if type 'platform_do_upgrade' >/dev
/null
2>/dev
/null
; then
192 platform_do_upgrade
"$ARGV"
194 default_do_upgrade
"$ARGV"
197 [ "$SAVE_CONFIG" -eq 1 -a -n "$USE_REFRESH" ] && {
198 v
"Refreshing partitions"
199 if type 'platform_refresh_partitions' >/dev
/null
2>/dev
/null
; then
200 platform_refresh_partitions
202 refresh_mtd_partitions
204 if type 'platform_copy_config' >/dev
/null
2>/dev
/null
; then
210 v
"Upgrade completed"
211 [ -n "$DELAY" ] && sleep "$DELAY"
212 ask_bool
1 "Reboot" && {
213 v
"Rebooting system..."
216 echo b
2>/dev
/null
>/proc
/sysrq-trigger