Lines 84-95
Link Here
|
84 |
## |
84 |
## |
85 |
# unpack squashfs image |
85 |
# unpack squashfs image |
86 |
# |
86 |
# |
|
|
87 |
no_unsquashfs=yes |
87 |
|
88 |
|
88 |
do_install() |
89 |
do_install() |
89 |
{ |
90 |
{ |
90 |
local img="$1";shift |
91 |
local img="$1";shift |
91 |
local dst="$1";shift |
92 |
local dst="$1";shift |
92 |
local percent1= |
93 |
local percent1= |
|
|
94 |
local unpacked= |
95 |
local free= |
96 |
local live_mount= |
97 |
local retval=0 |
98 |
local curr_dir=`pwd` |
99 |
local list_du tot sd s d IFS_bak bytes_done pct_done blk_done blk_cur bytes_per_blk bytes_cur pct_cur |
100 |
|
101 |
if [ "x$no_unsquashfs" = "xyes" ] ; then |
102 |
|
103 |
live_mount="$( mount | sed '/ type squashfs /!d; s/^.* on [ ]*\([^ ]\+\) type squashfs .*$/\1/')" |
104 |
if [ "x$live_mount" = "x" ] ; then |
105 |
do_notify_error "Can't find squashfs mount point" |
106 |
return 1 |
107 |
fi |
108 |
unpacked="$(du -sb ${live_mount} | sed 's,^[ ]*\([0-9]\+\).*$,\1,')" |
109 |
if [ "x$unpacked" = "x" ] ; then |
110 |
do_notify_error "Can't calculate unpacked squashfs size" |
111 |
return 1 |
112 |
fi |
113 |
free=$(free_space "$dst") |
114 |
if [ $unpacked -gt $free ]; then |
115 |
do_notify_error "No free space to unpack squashfs image" |
116 |
return 1 |
117 |
fi |
118 |
do_notify_stage install |
119 |
|
120 |
|
121 |
cd $live_mount |
122 |
|
123 |
#tot_du=`du -sb . | sed 's,[ \t].*$,,'` |
124 |
list_du=$( |
125 |
LANG=C LC_ALL=C \ |
126 |
du -sb `ls -1 | \ |
127 |
grep -vE "^dev|^image|^media|^proc|^sys|^mnt|^sys"` | \ |
128 |
sort -r -g | \ |
129 |
tr '\n' ';' |
130 |
) |
131 |
# echo list_du:$list_du: > /tmp/i.log |
132 |
IFS_bak=$IFS |
133 |
IFS=';' |
134 |
tot=0 |
135 |
for sd in $list_du ; do |
136 |
s=`echo $sd | sed 's,[ \t].*$,,'` |
137 |
d=`echo $sd | sed 's,^[^ \t]\+[ \t]\+,,'` |
138 |
tot=`expr $s + $tot` |
139 |
done |
140 |
if test $tot -eq 0 ; then |
141 |
tot=1 |
142 |
fi |
143 |
# echo "tot:$tot" >> /tmp/i.log |
144 |
|
145 |
bytes_done=0 |
146 |
pct_done=0 |
147 |
blk_done=0 |
148 |
blk_cur=0 |
149 |
bytes_per_blk=1024 |
150 |
|
151 |
for sd in $list_du ; do |
152 |
s=`echo $sd | sed 's,[ \t].*$,,'` |
153 |
d=`echo $sd | sed 's,^[^ \t]\+[ \t]\+,,'` |
154 |
cd $live_mount |
155 |
# echo "---- dir $d -- du -sb: $s -----" >> /tmp/i.log |
156 |
blk_done=$( |
157 |
export LANG=C LC_ALL=C |
158 |
tar cf - $d \ |
159 |
| { |
160 |
cd $dst |
161 |
tar xfvR - -b 2 --checkpoint=100 |
162 |
} 2>&1 \ |
163 |
| sed '/^tar: Read/!d;s,^.*point[ \t]\+,,' \ |
164 |
| { |
165 |
blk_cur=$blk_done |
166 |
while read blk ; do |
167 |
bytes_cur=`expr $bytes_done + $blk \* $bytes_per_blk ` |
168 |
pct_cur=`expr $bytes_cur \* 100 / $tot` |
169 |
#echo blk: $blk bytes_cur: $bytes_cur pct_cur: $pct_cur >> /tmp/i.log |
170 |
if test $pct_cur -gt $pct_done ; then |
171 |
pct_done=$pct_cur |
172 |
if test $pct_done -ge 100 ; then |
173 |
pct_done=99 |
174 |
fi |
175 |
#echo MSG $pct_done % >> /tmp/i.log |
176 |
do_notify_status "$pct_done" |
177 |
fi |
178 |
blk_cur=`expr $blk_done + $blk` |
179 |
#echo blk_cur: $blk_cur >> /tmp/i.log |
180 |
done |
181 |
echo $blk_cur |
182 |
} |
183 |
) |
184 |
bytes_done=`expr $bytes_done + $s` |
185 |
pct_done=`expr $bytes_done \* 100 / $tot` |
186 |
if test $pct_done -gt 100 ; then |
187 |
pct_done=100 |
188 |
fi |
189 |
bytes_per_blk=`expr $bytes_done / $blk_done` |
190 |
#echo blk_done: $blk_done : $bytes_per_blk >>/tmp/i.log |
191 |
#echo bytes_done: $bytes_done pct_done: $pct_done >>/tmp/i.log |
192 |
#echo MSG $pct_done % >> /tmp/i.log |
193 |
#echo "====================" >> /tmp/i.log |
194 |
do_notify_status "$pct_done" |
195 |
done |
196 |
|
197 |
IFS=$IFS_bak |
198 |
|
199 |
mkdir -p -- ${dst}/{dev,mnt,proc,sys,media} |
200 |
cd ${curr_dir} |
201 |
|
202 |
else # default: |
93 |
|
203 |
|
94 |
if ! [ -r "$img" ]; then |
204 |
if ! [ -r "$img" ]; then |
95 |
do_notify_error "Can't read squashfs image $img" |
205 |
do_notify_error "Can't read squashfs image $img" |
Lines 108-121
Link Here
|
108 |
percent1="$((percent1/99))" |
218 |
percent1="$((percent1/99))" |
109 |
|
219 |
|
110 |
# calculate size necessary for unpacked squashfs image |
220 |
# calculate size necessary for unpacked squashfs image |
111 |
local unpacked=$(sqfs_size "$img") |
221 |
unpacked=$(sqfs_size "$img") |
112 |
|
222 |
|
113 |
if [ -z "$unpacked" ]; then |
223 |
if [ -z "$unpacked" ]; then |
114 |
do_notify_error "Can't calculate unpacked squashfs size" |
224 |
do_notify_error "Can't calculate unpacked squashfs size" |
115 |
return 1 |
225 |
return 1 |
116 |
fi |
226 |
fi |
117 |
|
227 |
|
118 |
local free=$(free_space "$dst") |
228 |
free=$(free_space "$dst") |
119 |
|
229 |
|
120 |
if [ $unpacked -gt $free ]; then |
230 |
if [ $unpacked -gt $free ]; then |
121 |
do_notify_error "No free space to unpack squashfs image" |
231 |
do_notify_error "No free space to unpack squashfs image" |
Lines 124-130
Link Here
|
124 |
|
234 |
|
125 |
do_notify_stage install |
235 |
do_notify_stage install |
126 |
|
236 |
|
127 |
unsquashfs -force -no-progress -info -dest "$dst" "$img" 2>/dev/null | |
237 |
{ unsquashfs -force -no-progress -info -dest "$dst" "$img" 2>/dev/null ; retval=$? ; } | |
128 |
{ |
238 |
{ |
129 |
local i=0 |
239 |
local i=0 |
130 |
local progress=0 |
240 |
local progress=0 |
Lines 138-143
Link Here
|
138 |
fi |
248 |
fi |
139 |
done |
249 |
done |
140 |
} |
250 |
} |
|
|
251 |
if [ $retval -ne 0 ] ; then |
252 |
do_notify_error "Can't read squashfs image $img" |
253 |
return 1 |
254 |
fi |
255 |
|
256 |
fi #end of unsquashfs ... |
141 |
|
257 |
|
142 |
# Set right perms on root directory of installed system |
258 |
# Set right perms on root directory of installed system |
143 |
chmod 0755 "$dst" |
259 |
chmod 0755 "$dst" |
Lines 223-226
Link Here
|
223 |
} |
339 |
} |
224 |
|
340 |
|
225 |
message_loop |
341 |
message_loop |
226 |
|
|
|