zlib_extraction.sh
1 |
#!/bin/bash |
---|---|
2 |
|
3 |
# zlib_extraction.sh ver 2.0 |
4 |
# 引数のファイルに含まれるzlib圧縮部分を抽出・展開してファイルに保存する |
5 |
# 2015.10.06 kanata |
6 |
|
7 |
if [ ! -f "${1}" ] |
8 |
then |
9 |
echo "file open error ($1)" |
10 |
exit 1 |
11 |
fi |
12 |
|
13 |
if echo "${2}" |egrep '(BOOST|boost|Boost)' >/dev/null |
14 |
then |
15 |
MODE="BOOST_MODE" |
16 |
else |
17 |
MODE="NORMAL_MODE" |
18 |
fi |
19 |
|
20 |
|
21 |
FILESIZE=`ls -l ${1}|awk '{print $5}'` |
22 |
ZLIBPART="${1##*/}" |
23 |
ZLIBPART="${ZLIBPART%.*}" |
24 |
I="0" |
25 |
FORK_COUNT="0" |
26 |
|
27 |
if [ "${MODE}" = "NORMAL_MODE" ] |
28 |
then |
29 |
#--------------# |
30 |
# シリアル処理 # |
31 |
#--------------# |
32 |
while [ "${I}" -lt "${FILESIZE}" ] |
33 |
do |
34 |
ZLIBPART_FILE="${ZLIBPART}_${I}.bin" |
35 |
cat ${1} | dd bs=1 skip=${I} | openssl zlib -d > ${ZLIBPART_FILE} 2>/dev/null |
36 |
|
37 |
if [ -s ${ZLIBPART_FILE} ] |
38 |
then |
39 |
file ${ZLIBPART_FILE} |
40 |
else |
41 |
rm -f ${ZLIBPART_FILE} |
42 |
fi |
43 |
|
44 |
echo -ne "checking.. "`printf "%d/%d" "${I}" "${FILESIZE}"`" \r" |
45 |
I=$(( I + 1 )) |
46 |
done |
47 |
|
48 |
else |
49 |
#----------# |
50 |
# 並列処理 # |
51 |
#----------# |
52 |
while [ "${I}" -lt "${FILESIZE}" ] |
53 |
do |
54 |
ZLIBPART_FILE="${ZLIBPART}_${I}.bin" |
55 |
( cat ${1} | dd bs=1 skip=${I} | openssl zlib -d > ${ZLIBPART_FILE} 2>/dev/null ; if [ -s ${ZLIBPART_FILE} ] ; then file ${ZLIBPART_FILE} ; else rm -f ${ZLIBPART_FILE} ; fi )& |
56 |
|
57 |
# 並列実行時のサブシェルが増大していくのを抑止 |
58 |
# 同時35多重までに抑止 25回に1度チェック ( 数値を弄ってチューニングできます ) |
59 |
if [ $(( I % 25 )) -eq "0" ] ; then FORK_COUNT=`ps -u |fgrep -c ${0}` ; fi |
60 |
while [ "${FORK_COUNT}" -gt "35" ] |
61 |
do |
62 |
printf "[WARNING] SubProcess Exceed Limit. fork:%s offset:%s\n" ${FORK_COUNT} ${I} |
63 |
FORK_COUNT=`ps -u |fgrep -c ${0}` |
64 |
done |
65 |
|
66 |
echo -ne "checking.. "`printf "%d/%d" "${I}" "${FILESIZE}"`" \r" |
67 |
I=$(( I + 1 )) |
68 |
done |
69 |
|
70 |
fi |
71 |
|
72 |
exit 0 |