4 rom
=$
(awk '/squashfs/ {print $2}' /proc
/mounts
)
5 jffs
=$
(awk '/jffs2/ {print $2}' /proc
/mounts
)
7 dupe
() { # <new_root> <old_root>
9 echo -n "creating directories... "
13 echo "./dev ./jffs ./mnt ./proc ./tmp"
14 # xdev skips mounted directories
19 echo -n "setting up symlinks... "
20 for file in $
(cd $2; find .
-xdev -type f
;); do
22 .
/rom
/note
) ;; #nothing
24 .
/usr
/lib
/ipkg
/info
/*) cp -af $2/$file $file;;
25 *) ln -sf /rom
/${file#./*} $file;;
28 for file in $
(cd $2; find .
-xdev -type l
;); do
29 cp -af $2/${file#./*} $file
34 pivot
() { # <new_root> <old_root>
35 mount
-o move
/proc
$1/proc
&& \
36 pivot_root
$1 $1$2 && {
37 mount
-o move
$2/dev
/dev
38 mount
-o move
$2/tmp
/tmp
39 mount
-o move
$2/jffs
/jffs
2>&-
44 mountdp
() { # <device> <mount_point> <ignored> <fs>
45 dev
=$1; mnt
=$2; shift 2; opt
=$
*
51 fopivot
() { # <rw_root> <ro_root> <dupe?>
54 mount
-t mini_fo
-o base
=/,sto
=$1 $1 /mnt
2>&- && root
=/mnt
56 [ "$3" = "1" ] && mount
-o bind $1 $1 && dupe
$1 $rom
63 fopivot
/tmp
/root
/rom
1
66 [ "${0##*/}" = "firstboot" ] && {
68 echo "You do not have a squashfs partition; aborting"
69 echo "(firstboot cannot be run on jffs2 based firmwares)"
73 [ "$1" = "switch2jffs" ] && {
75 mount
-o remount
,ro none
/ 2>&- # try to avoid fs changing while copying
76 mount
-o bind /tmp
/root
/mnt
77 mount
/dev
/mtdblock
/4 /rom
/jffs
-t jffs2
78 echo -n "copying files ... "
79 cp -a /mnt
/* /rom
/jffs
83 mount
-o move
/mnt
/tmp
/root
91 [ \
! -z "$jffs" ] && {
92 echo "firstboot has already been run"
93 echo "jffs2 partition is mounted, only resetting files"
99 mountdp
/dev
/mtdblock
/4 /jffs
-t jffs2