5 [ -x /usr
/bin
/ldd
] || 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 /bin
/mount |
grep "on $1 type" 2>&- 1>&- ||
/bin
/mount
-o bind $1 $1
38 mkdir
-p $1$2 $1/proc
$1/sys
$1/dev
$1/tmp
$1/overlay
&& \
39 /bin
/mount
-o noatime
,move
/proc
$1/proc
&& \
40 pivot_root
$1 $1$2 ||
{
45 /bin
/mount
-o noatime
,move
$2/sys
/sys
46 /bin
/mount
-o noatime
,move
$2/dev
/dev
47 /bin
/mount
-o noatime
,move
$2/tmp
/tmp
48 /bin
/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
/dd /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 \
58 /bin
/cut
/usr
/bin
/printf /bin
/sync
/bin
/mkdir
/bin
/rmdir \
59 /bin
/rm /usr
/bin
/basename /bin
/kill /bin
/chmod
63 install_bin
/sbin
/mount_root
64 install_bin
/sbin
/snapshot
65 install_bin
/sbin
/snapshot_tool
66 install_bin
/usr
/sbin
/ubiupdatevol
67 install_bin
/usr
/sbin
/ubiattach
68 install_bin
/usr
/sbin
/ubiblock
69 install_bin
/usr
/sbin
/ubiformat
70 install_bin
/usr
/sbin
/ubidetach
71 install_bin
/usr
/sbin
/ubirsvol
72 install_bin
/usr
/sbin
/ubirmvol
73 install_bin
/usr
/sbin
/ubimkvol
74 for file in $RAMFS_COPY_BIN; do
75 install_bin
${file//:/ }
77 install_file
/etc
/resolv.conf
/lib
/*.sh
/lib
/functions
/*.sh
/lib
/upgrade
/*.sh
$RAMFS_COPY_DATA
79 [ -L "/lib64" ] && ln -s /lib
$RAM_ROOT/lib64
81 supivot
$RAM_ROOT /mnt ||
{
82 echo "Failed to switch over to ramfs. Please reboot."
86 /bin
/mount
-o remount
,ro
/mnt
89 grep /overlay
/proc
/mounts
> /dev
/null
&& {
90 /bin
/mount
-o noatime
,remount
,ro
/overlay
91 /bin
/umount
-l /overlay
94 # spawn a new shell from ramdisk to reduce the probability of cache issues
95 exec /bin
/busybox ash
-c "$*"
98 kill_remaining
() { # [ <signal> ]
99 local sig
="${1:-TERM}"
100 echo -n "Sending $sig to remaining processes ... "
103 local my_ppid
=$
(cut
-d' ' -f4 /proc
/$my_pid/stat
)
104 local my_ppisupgraded
=
105 grep -q upgraded
/proc
/$my_ppid/cmdline
>/dev
/null
&& {
106 local my_ppisupgraded
=1
110 for stat
in /proc
/[0-9]*/stat
; do
111 [ -f "$stat" ] ||
continue
113 local pid name state ppid rest
114 read pid name state ppid rest
< $stat
115 name
="${name#(}"; name
="${name%)}"
118 read cmdline
< /proc
/$pid/cmdline
120 # Skip kernel threads
121 [ -n "$cmdline" ] ||
continue
123 if [ $$
-eq 1 ] ||
[ $my_ppid -eq 1 ] && [ -n "$my_ppisupgraded" ]; then
124 # Running as init process, kill everything except me
125 if [ $pid -ne $$
] && [ $pid -ne $my_ppid ]; then
127 kill -$sig $pid 2>/dev
/null
131 # Skip essential services
132 *procd
*|
*ash
*|
*init
*|
*watchdog
*|
*ssh*|
*dropbear
*|
*telnet*|
*login
*|
*hostapd
*|
*wpa_supplicant
*|
*nas
*) : ;;
136 if [ $pid -ne $$
] && [ $ppid -ne $$
]; then
138 kill -$sig $pid 2>/dev
/null
148 local arg
="$1"; shift
155 local default
="$1"; shift;
156 local answer
="$default"
158 [ "$INTERACTIVE" -eq 1 ] && {
160 0) echo -n "$* (y/N): ";;
161 *) echo -n "$* (Y/n): ";;
167 *) answer
="$default";;
174 [ "$VERBOSE" -ge 1 ] && echo "$@"
178 /bin
/mount |
awk '($3 ~ /^\/$/) && ($5 !~ /rootfs/) { print $5 }'
181 get_image
() { # <source> [ <command> ]
187 http
://*|
ftp://*) cmd
="wget -O- -q";;
190 if [ -z "$conc" ]; then
191 local magic
="$(eval $cmd $from 2>/dev/null | dd bs=2 count=1 2>/dev/null | hexdump -n 2 -e '1/1 "%02x
"')"
198 eval "$cmd $from 2>/dev/null ${conc:+| $conc}"
202 (get_image
"$@" |
dd bs
=2 count
=1 |
hexdump -v -n 2 -e '1/1 "%02x"') 2>/dev
/null
206 (get_image
"$@" |
dd bs
=4 count
=1 |
hexdump -v -n 4 -e '1/1 "%02x"') 2>/dev
/null
209 jffs2_copy_config
() {
210 if grep rootfs_data
/proc
/mtd
>/dev
/null
; then
212 mtd
-e rootfs_data jffs2write
"$CONF_TAR" rootfs_data
215 mtd jffs2write
"$CONF_TAR" rootfs
219 default_do_upgrade
() {
221 if [ "$SAVE_CONFIG" -eq 1 ]; then
222 get_image
"$1" | mtd
$MTD_CONFIG_ARGS -j "$CONF_TAR" write - "${PART_NAME:-image}"
224 get_image
"$1" | mtd
write - "${PART_NAME:-image}"
229 v
"Performing system upgrade..."
230 if type 'platform_do_upgrade' >/dev
/null
2>/dev
/null
; then
231 platform_do_upgrade
"$ARGV"
233 default_do_upgrade
"$ARGV"
236 if [ "$SAVE_CONFIG" -eq 1 ] && type 'platform_copy_config' >/dev
/null
2>/dev
/null
; then
240 v
"Upgrade completed"
241 [ -n "$DELAY" ] && sleep "$DELAY"
242 ask_bool
1 "Reboot" && {
243 v
"Rebooting system..."
246 echo b
2>/dev
/null
>/proc
/sysrq-trigger