[2014.10.10] Realize the Batch Compression with Building Par2 Repair Files of Each Items @ Linux (Update)
Limitation & Key point:01. The size of splited volumes of every items forcing limite to 1GB and the size of every reapir files is as close as possible the volume size unless the compressed source is less then 1GB.
02. If the size of the compressed source is more than 1TB, the script need to improve.
03.Par2 repaire files are building with some rules, and the rules is related with the par2 file name.
04.The script will automatically create some other files are convenient to let me troubleshoot issue and I don't want take off these files, gays can edit the shell script to delect these files yourself (but it is not easy).
05.Before you run the script, please install the rar and par2 in your linux.
06.Before you run the script, please edit some variable content and the content of target file to match your using environment and requirement, I will describe the examples at next part.
07.Before you compiler the source code of test7 ~ test9, please double confirm that you have already installed g++.
08.If the size of compressed source is less then 5GB, the script will force using method 11 (refer the next point) to build the single par2 reapire (core) file.
09.All the items run rar archiver with rr3 and about 15% par2 repair files, if the source size is less then 1GB, the level of redundancy of par2 automatically increase to 100%.
10.Please don't fill out any special characters in every script's variables, but the files name or folders name (blong with $dirWhere location) is allowed.
---releae notes---
2010/10/10 version 1.0
Source code:
A : script
Guys create the script first into at any path you like of your computer, but you need to edit the variable ($programWhere) to match your environment ( see the example ).#!/bin/sh
# improte the variables
dirWhere='/home/userid/a/'
saveWhere="/home/userid/save/"
programWhere="/home/userid/software/"
findList="/home/userid/software/source"
newNameList="/home/userid/software/target"
tempList="/home/userid/software/templist"
password="P.A.S.S.W.O.R.D"
#10.old ,11-new
par2_method="10"
rarVersion="r5d11fin"
#mode01=unpacket,mode02=packet
information_mode="02"
# check for bad situation 1
if [ ! -f "$newNameList" ] ; then
echo 'error, list does not exist'
exit
fi
# assign the path to te working directory
cd "$dirWhere"
# search and get the the name of working directory
find . -maxdepth 1 > $tempList
cat $tempList | sort > $findList
sed -i "s/\.\///g" $findList
sed -i '/^\.$/d' $findList
cd "$programWhere"
#rm -f $tempList
# check for the bad situation 2
lineTotal_01=` cat "$findList" | wc -l `
lineTotal_02=` cat "$newNameList" | wc -l`
if [ $lineTotal_01 -ne $lineTotal_02 ] ; then
echo 'error, the list numbers does not match with the folders and files nambers of working directory。'
exit
fi
#start to enter the working loop
# 初始化用來當迴圈「計數器」的變數的值
loopTimes=1
echo -e ""
echo "* The core of this scrip start working *"
echo -e ""
# 迴圈開始
while read fileName
do
echo "loopTimes=$loopTimes"
#mapping新檔名
# 新檔名 = 取出「更名列表清單」特定行數的資料
# 行數 = 迴圈計數器的值(由1開始,依序增加讀取)
lineNum=` echo $loopTimes"p" `
newFileName=` sed -n $lineNum $newNameList `
mkdir $saveWhere$newFileName
sleep 2
# 壓縮->修名->重新命名
#壓縮
if [ $loopTimes -ne 0 ] ; then
echo "$fileName" > "$dirWhere"comment
echo -e "" >> "$dirWhere"comment
#echo "* This shell script is created by bdmv.info * " >> "$dirWhere"comment
#echo "* People are only allowed to use the script for nonprofit reserch *" >> "$dirWhere"comment
rar a -m0 -hp"$password" -v1073741824b -rr3 -ep1 -z"$dirWhere"comment $saveWhere"$newFileName"/"$newFileName".$rarVersion.rr3 "$dirWhere""$fileName"
echo -e "\n\n"
echo "echo 1.rar壓縮"
echo -e "\n\n"
sleep 2
fi
#取得壓縮檔完整數量
rarFileNumber=` ls -laR $saveWhere"$newFileName" |grep "^-" |awk 'END{print NR}' `
rarFileSize=` ls -l $saveWhere"$newFileName" | awk '{ sum += $5} END { printf("%.3f\n",sum/1024/1024/1024)}'`
echo -e "\n\n"
echo "echo 2.壓縮檔數量=$rarFileNumber"
echo -e "\n\n"
sleep 2
#新增newFileName文件放置檔按資訊
echo "01.project_source $fileName" > $saveWhere$newFileName/"$newFileName".txt
echo -e "\n\n"
echo "echo 3.新增文件$newFileName.txt"
echo -e "\n\n"
sleep 2
#由來源大小取得par2所需的各項參數
du -s -b "$dirWhere""$fileName" | awk '{print $1}'| "$programWhere"test7 >> $saveWhere$newFileName/"$newFileName".txt
sed -n "1,10p" $saveWhere$newFileName/"$newFileName".txt
echo -e "\n\n"
echo "echo 4.儲存參數至$saveWhere$newFileName/"$newFileName".txt"
echo -e "\n\n"
sleep 2
#由壓縮檔數量取得par2所需的各項參數
echo "$rarFileNumber" | "$programWhere"test8 >> $saveWhere$newFileName/"$newFileName".txt
sed -n "1,12p" $saveWhere$newFileName/"$newFileName".txt
echo -e "\n\n"
echo "echo 5.儲存參數至$saveWhere$newFileName/"$newFileName".txt"
echo -e "\n\n"
sleep 2
#比對rar檔案數量做更名
#echo "$fileName" > "$dirWhere"comment
#echo -e "" >> "$dirWhere"comment
#echo "* This shell script is created by bdmv.info * " >> "$dirWhere"comment
#echo "* People are only allowed to use the script for nonprofit reserch *" >> "$dirWhere"comment
#if [ "$rarFileNumber" -gt 99 ] ; then
# rar c -p$password -z"$dirWhere"comment $saveWhere"$newFileName"/"$newFileName".$rarVersion.rr3.part001.rar
# rename.ul part "" $saveWhere"$newFileName"/* && rename.ul .rar "" $saveWhere"$newFileName"/*
# echo -e "\n\n\n"
# echo "echo 6.更名:模式1(檔案大小>1)"
#elif [ "$rarFileNumber" -gt 9 ] ; then
# rar c -p$password -z"$dirWhere"comment $saveWhere"$newFileName"/"$newFileName".$rarVersion.rr3.part01.rar
# rename.ul part "" $saveWhere"$newFileName"/* && rename.ul .rar "" $saveWhere"$newFileName"/*
# echo -e "\n\n\n"
# echo "echo 6.更名:模式1(檔案大小>1)"
if [ "$rarFileNumber" -gt 1 ] ; then
rename.ul part "" $saveWhere"$newFileName"/* && rename.ul .rar "" $saveWhere"$newFileName"/*
echo -e "\n\n\n"
echo "echo 6.更名:模式1(檔案大小>1)"
else
rar c -p$password -z"$dirWhere"comment $saveWhere"$newFileName"/"$newFileName".$rarVersion.rr3
rename -v 's/rr3$/rr3\.1/' $saveWhere"$newFileName"/*
echo -e "\n\n"
echo "echo 6.更名:模式2(檔案大小<=1)"
fi
rm "$dirWhere"comment
echo -e "\n\n"
sleep 2
#讀入參數九:count
volume_beta=` sed -n 9p $saveWhere$newFileName/$newFileName.txt | awk '{print $2}' ` #9指向count,par2 method=10
volume=` sed -n 12p $saveWhere$newFileName/$newFileName.txt | awk '{print $2}' ` #12指向count2,par2 method=11
if [ "$volume" -eq 0 ] ; then
rarVolumeFileSize=` du -S -b $saveWhere$newFileName/*rr3.* | grep rr3 | awk '{sum += $1};END{print sum}' `
else
rarVolumeFileSize=` du -S -b $saveWhere$newFileName/*rr3."$volume"* | grep rr3."$volume" | awk '{sum += $1};END{print sum}' `
fi
echo "volume=$volume"
echo "rarVolumeFileSize=$rarVolumeFileSize"
echo -e "\n\n"
echo "echo 7.取出卷數資訊計算未滿100(99)的末尾分卷大小"
echo -e "\n\n"
sleep 2
#製作數狀圖
#tree "$dirWhere""$fileName" >> $saveWhere"$newFileName"/"$newFileName".tree.txt
#sed -i 's#'$dirWhere'##' $saveWhere"$newFileName"/"$newFileName".tree.txt
#rar a -hp"$password" -ep1 $saveWhere"$newFileName"/"$newFileName".tree.rar $saveWhere"$newFileName"/"$newFileName".tree.txt
#sed -n "1,5p" "$saveWhere$newFileName"/"$newFileName".tree.txt
#echo "echo 7.Print 樹狀圖(前五列)"
#rm $saveWhere"$newFileName"/"$newFileName".tree.txt
#sleep 5
tree "$dirWhere""$fileName" >> $saveWhere"$newFileName"/"$newFileName".tree.txt
tree -d "$dirWhere""$fileName" >> $saveWhere"$newFileName"/"$newFileName".folder.tree.txt
sed -i '1d' $saveWhere"$newFileName"/"$newFileName".tree.txt
sed -i '1d' $saveWhere"$newFileName"/"$newFileName".folder.tree.txt
if [ $loopTimes -ne 1 ] ; then
echo -e "" >> $saveWhere"$newFileName"/"$newFileName".tree2.txt
echo -e "" >> $saveWhere"$newFileName"/"$newFileName".tree3.txt
fi
echo "$fileName" >> $saveWhere"$newFileName"/"$newFileName".tree2.txt
echo "$fileName" >> $saveWhere"$newFileName"/"$newFileName".tree3.txt
awk '{print $0}' $saveWhere"$newFileName"/"$newFileName".tree.txt >> $saveWhere"$newFileName"/"$newFileName".tree2.txt
awk '{print $0}' $saveWhere"$newFileName"/"$newFileName".folder.tree.txt >> $saveWhere"$newFileName"/"$newFileName".tree3.txt
awk '{print $0}' $saveWhere"$newFileName"/"$newFileName".tree2.txt > $saveWhere"$newFileName"/"$newFileName".tree.txt
awk '{print $0}' $saveWhere"$newFileName"/"$newFileName".tree3.txt > $saveWhere"$newFileName"/"$newFileName".folder.tree.txt
rm $saveWhere"$newFileName"/"$newFileName".tree2.txt
rm $saveWhere"$newFileName"/"$newFileName".tree3.txt
sed -n "1,5p" "$saveWhere$newFileName"/"$newFileName".tree.txt
sed -n "1,5p" "$saveWhere$newFileName"/"$newFileName".folder.tree.txt
echo -e "\n\n"
echo "echo 8.Print 樹狀圖*2(前五列)"
echo -e "\n\n"
sleep 3
#由count大小判定par2最末未滿100(99)分卷的檔名&強制修正par2的使用時機
if [ $rarFileNumber -lt 5 ] ; then
par2_method="11"
fi
if [ $par2_method -eq 11 ] ; then
if [ $volume -gt 0 ] ; then
volume2="$volume"00-End
volume2=` echo ""$volume"00-End" `
else
if [ $rarFileNumber -lt 10 ] ; then
volume2=1-End
else
volume2=01-End
fi
fi
else
if [ $volume -gt 0 ] ; then
if [ $volume -eq $volume_beta ] ;then
volume2="$volume"00-End
volume2=` echo ""$volume"00-End" `
elif [ $volume -gt $volume_beta ] ;then
volume2="$volume_beta"00-"$volume_beta"99
fi
else
if [ $rarFileNumber -lt 10 ] ; then
volume2=1-End
else
volume2=01-End
fi
fi
fi
echo -e "\n\n"
echo "echo 9.volume2=$volume2"
echo -e "\n\n"
sleep 2
#取得par2參數(rr/rbs/rbn2)
echo "$rarVolumeFileSize" | "$programWhere"test9 >> $saveWhere$newFileName/"$newFileName".txt
sed -n "1,15p" $saveWhere$newFileName/"$newFileName".txt
echo -e "\n\n"
echo "echo 10.新增參數13-15"
echo -e "\n\n"
sleep 2
#txt文件的變數取代
bc=` sed -n 6p $saveWhere$newFileName/$newFileName.txt | awk '{print $2}' `
rbc=` sed -n 7p $saveWhere$newFileName/$newFileName.txt | awk '{print $2}' `
rbn1=` sed -n 8p $saveWhere$newFileName/$newFileName.txt | awk '{print $2}' `
rr=` sed -n 13p $saveWhere$newFileName/$newFileName.txt | awk '{print $2}' `
rbs=` sed -n 14p $saveWhere$newFileName/$newFileName.txt | awk '{print $2}' `
rbn2=` sed -n 15p $saveWhere$newFileName/$newFileName.txt | awk '{print $2}' `
sed -i 's/$bc/'$bc'/g' $saveWhere$newFileName/$newFileName.txt
sed -i 's/$rbc/'$rbc'/g' $saveWhere$newFileName/$newFileName.txt
sed -i 's/$rbn1/'$rbn1'/g' $saveWhere$newFileName/$newFileName.txt
sed -i 's/$rr/'$rr'/g' $saveWhere$newFileName/$newFileName.txt
sed -i 's/$rbs/'$rbs'/g' $saveWhere$newFileName/$newFileName.txt
sed -i 's/$rbn2/'$rbn2'/g' $saveWhere$newFileName/$newFileName.txt
sed -i 's#$saveWhere#'$saveWhere'#g' $saveWhere$newFileName/$newFileName.txt
sed -i 's/$newFileName/'$newFileName'/g' $saveWhere$newFileName/$newFileName.txt
sed -i 's/$rarVersion/'$rarVersion'/g' $saveWhere$newFileName/$newFileName.txt
#檔案數量大於99的情況取消$volume2字串
if [ $par2_method -eq 11 ] ; then
if [ $volume -gt 0 ] ; then
sed -i 's/$volume2/'"$volume2"'/g' $saveWhere$newFileName/$newFileName.txt
else
sed -i 's#$volume2'\.'##g' $saveWhere$newFileName/$newFileName.txt
fi
else
if [ $volume -gt 0 ] ; then
if [ $volume_beta -gt 0 ] ; then
sed -i 's/$volume2/'"$volume2"'/g' $saveWhere$newFileName/$newFileName.txt
else
sed -i 's#$volume2'\.'##g' $saveWhere$newFileName/$newFileName.txt
fi
else
sed -i 's#$volume2'\.'##g' $saveWhere$newFileName/$newFileName.txt
fi
fi
sed -n "1,15p" $saveWhere$newFileName/"$newFileName".txt
echo -e "\n\n"
echo "echo 11.txt文件的變數取代"
echo -e "\n\n"
sleep 2
#dump par2 command至$newFileName.par2command.txt
sed -n "$par2_method"p $saveWhere$newFileName/$newFileName.txt|sed -r "s/(&&)/\n/g" > $saveWhere$newFileName/$newFileName.par2command.txt
if [ $par2_method -eq 10 ] ; then
volume_plus=` expr $volume_beta + 2 `
elif [ $par2_method -eq 11 ] ;then
volume_plus=` expr $volume + 2 `
fi
sed -n 1,"$volume_plus"p $saveWhere$newFileName/$newFileName.par2command.txt
echo -e "\n\n"
echo "echo 12.par2 command + cfv command"
echo -e "\n\n"
sleep 2
#執行par2與cfv製作
count=1
while [ "$count" -le "$volume_plus" ]
do
command=` sed -n "$count"p $saveWhere$newFileName/$newFileName.par2command.txt `
$command
count=` expr $count + 1 `
done
echo -e "\n\n"
echo "echo 13.par2與cfv製作完成"
echo -e "\n\n"
sleep 2
#修正sfv內容
sed -i 's#'$saveWhere$newFileName/'##' $saveWhere$newFileName/$newFileName.sfv
sed -i "/$newFileName.par2command.txt/d" $saveWhere$newFileName/$newFileName.sfv
sed -i "/$newFileName.tree.txt/d" $saveWhere$newFileName/$newFileName.sfv
sed -i "/$newFileName.folder.tree.txt/d" $saveWhere$newFileName/$newFileName.sfv
sed -i "/$newFileName.txt/d" $saveWhere$newFileName/$newFileName.sfv
awk '{print $0}' $saveWhere$newFileName/$newFileName.sfv >> "$saveWhere"ALL.FILENAME.sfv
sed -n "1,10p" $saveWhere$newFileName/$newFileName.sfv
echo "echo 14.修正sfv內容v1"
echo -e "\n\n"
sleep 2
echo -e "\n\n"
#整理$newFileName的檔案
par2FileSize=` ls -l $saveWhere"$newFileName"/*.par2 | awk '{ sum += $5} END { printf("%.3f\n",sum/1024/1024/1024)}' `
sed -i "10,11d" $saveWhere$newFileName/$newFileName.txt
sed -i -r "s/(^09.)/11\./g" $saveWhere$newFileName/$newFileName.txt
sed -i -r "s/(^08.)/10\./g" $saveWhere$newFileName/$newFileName.txt
sed -i -r "s/(^07.)/09\./g" $saveWhere$newFileName/$newFileName.txt
sed -i -r "s/(^06.)/08\./g" $saveWhere$newFileName/$newFileName.txt
sed -i -r "s/(^05.)/07\./g" $saveWhere$newFileName/$newFileName.txt
sed -i "5 i\05.size(item/rar)(gb) $rarFileSize" $saveWhere$newFileName/$newFileName.txt
sed -i "6 i\06.size(item/par2)(gb) $par2FileSize" $saveWhere$newFileName/$newFileName.txt
echo "--------par2 + cfv command--------" >>$saveWhere$newFileName/$newFileName.txt
sed -n 1,"$volume_plus"p $saveWhere$newFileName/$newFileName.par2command.txt >> $saveWhere$newFileName/$newFileName.txt
echo "##################################" >> $saveWhere$newFileName/$newFileName.txt
sed -i 's#'$saveWhere'#($saveWhere)#g' $saveWhere$newFileName/$newFileName.txt
rm $saveWhere$newFileName/$newFileName.par2command.txt
volume_plus=` expr $volume_plus + 17 `
sed -n 1,"$volume_plus"p $saveWhere"$newFileName"/"$newFileName".txt
echo -e "\n\n"
echo "echo 15.最終版$newFileName.txt內容"
echo -e "\n\n"
sleep 2
#新增mapping/target/size對照文件
echo "$newFileName" >> "$saveWhere"ALL.FILE.MAP.txt
sizegb=` sed -n 3p $saveWhere$newFileName/$newFileName.txt | awk '{print $2}' `
sizemb=` du -s "$dirWhere""$fileName" | awk '{ printf("%.3f\n",$1/1024)}' `
sed -i -r ""$loopTimes"s/$/ source|"$sizegb"GB/g" "$saveWhere"ALL.FILE.MAP.txt
sed -i -r ""$loopTimes"s/$/ source|"$sizemb"MB/g" "$saveWhere"ALL.FILE.MAP.txt
sed -i -r ""$loopTimes"s/$/ rar|"$rarFileSize"GB/g" "$saveWhere"ALL.FILE.MAP.txt
sed -i -r ""$loopTimes"s/$/ par2|"$par2FileSize"GB/g" "$saveWhere"ALL.FILE.MAP.txt
sed -i -r ""$loopTimes"s/$/ $fileName/g" "$saveWhere"ALL.FILE.MAP.txt
sed -n 1,"$loopTimes"p "$saveWhere"ALL.FILE.MAP.txt
echo -e "\n\n"
echo "echo 16.loop$loopTimes的map內容"
echo -e "\n\n"
sleep 2
#打包並刪除$newFileName.txt(保留全卷資訊)
test "$information_mode" = "01" && rar a -m0 -ep1 -hp$password $saveWhere$newFileName/$newFileName.information.rar $saveWhere$newFileName/$newFileName.txt $saveWhere$newFileName/$newFileName.tree.txt $saveWhere$newFileName/$newFileName.folder.tree.txt
#test "$information_mode" = "02" && rar a -m0 -ep1 -hp$password $saveWhere$newFileName.information.v2.rar $saveWhere$newFileName/$newFileName.sfv $saveWhere"$newFileName"/"$newFileName".$rarVersion.rr3.par2 $saveWhere$newFileName/$newFileName.txt $saveWhere$newFileName/$newFileName.tree.txt $saveWhere$newFileName/$newFileName.folder.tree.txt ; rm $saveWhere$newFileName/$newFileName.sfv ; rm $saveWhere"$newFileName"/"$newFileName".$rarVersion.rr3.par2
if [ "$information_mode" = "02" ] ; then
rar a -m0 -ep1 -hp$password $saveWhere$newFileName.information.v2.rar $saveWhere$newFileName/$newFileName.sfv $saveWhere"$newFileName"/"$newFileName".$rarVersion.rr3.par2 $saveWhere$newFileName/$newFileName.txt $saveWhere$newFileName/$newFileName.tree.txt $saveWhere$newFileName/$newFileName.folder.tree.txt
rm $saveWhere$newFileName/$newFileName.sfv
rm $saveWhere"$newFileName"/"$newFileName".$rarVersion.rr3.par2
fi
awk '{print $0}' $saveWhere$newFileName/$newFileName.txt >> "$saveWhere"ALL.FILENAME.txt
awk '{print $0}' $saveWhere$newFileName/$newFileName.tree.txt >> "$saveWhere"ALL.TREE\(PART.MODE\).txt
awk '{print $0}' $saveWhere$newFileName/$newFileName.folder.tree.txt >> "$saveWhere"ALL.FOLDER.TREE\(PART.MODE\).txt
rm $saveWhere$newFileName/$newFileName.txt
rm $saveWhere$newFileName/$newFileName.tree.txt
rm $saveWhere$newFileName/$newFileName.folder.tree.txt
echo -e "\n\n"
echo "echo 17.打包並刪除$newFileName.txt(保留全卷資訊)"
echo -e "\n\n"
sleep 2
# 迴圈計數器 + 1
loopTimes=` expr $loopTimes + 1 `
project_end=$newFileName
done < $findList
#打包全卷資訊
echo -e "" >> "$saveWhere"ALL.TREE\(FULL.MODE\).txt
echo -e "" >> "$saveWhere"ALL.FOLDER.TREE\(FULL.MODE\).txt
tree "$dirWhere" >> "$saveWhere"ALL.TREE\(FULL.MODE\).txt
tree -d "$dirWhere" >> "$saveWhere"ALL.FOLDER.TREE\(FULL.MODE\).txt
sed -i '2d' "$saveWhere""ALL.TREE(FULL.MODE).txt"
sed -i '2d' "$saveWhere""ALL.FOLDER.TREE(FULL.MODE).txt"
project_start=` sed -n 1p $newNameList `
test "$project_start" != "$project_end" && rar a -m0 -ep1 -hp$password "$saveWhere"\["$project_start"\].to.\["$project_end"\].ALL.INFORMATION.rar "$saveWhere"ALL.FILENAME.txt "$saveWhere"ALL.TREE\(PART.MODE\).txt "$saveWhere"ALL.FILE.MAP.txt "$saveWhere"ALL.TREE\(FULL.MODE\).txt "$saveWhere"ALL.FOLDER.TREE\(FULL.MODE\).txt "$saveWhere"ALL.FOLDER.TREE\(PART.MODE\).txt "$saveWhere"ALL.FILENAME.sfv && test "$information_mode" = "02" && rar a -m0 -ep1 -hp$password "$saveWhere"\("$project_start"\).to.\("$project_end"\).information.v2.packet.rar "$saveWhere"*.information.v2.rar && rm "$saveWhere"*.information.v2.rar
test "$project_start" = "$project_end" && rar a -m0 -ep1 -hp$password "$saveWhere"\["$project_end"\].ALL.INFORMATION.rar "$saveWhere"ALL.FILENAME.txt "$saveWhere"ALL.TREE\(PART.MODE\).txt "$saveWhere"ALL.FILE.MAP.txt "$saveWhere"ALL.TREE\(FULL.MODE\).txt "$saveWhere"ALL.FOLDER.TREE\(FULL.MODE\).txt "$saveWhere"ALL.FOLDER.TREE\(PART.MODE\).txt "$saveWhere"ALL.FILENAME.sfv
#刪除暫存檔
rm "$saveWhere"ALL.FILE.MAP.txt
rm "$saveWhere"ALL.FILENAME.txt
rm "$saveWhere"ALL.TREE\(PART.MODE\).txt
rm "$saveWhere"ALL.TREE\(FULL.MODE\).txt
rm "$saveWhere"ALL.FOLDER.TREE\(PART.MODE\).txt
rm "$saveWhere"ALL.FOLDER.TREE\(FULL.MODE\).txt
rm "$saveWhere"ALL.FILENAME.sfv
rm -f $findList
#rm -f $newNameList
rm -f $tempList
echo -e ""
echo "* All the jobs are finished *"
echo -e ""
Pay attention of the variables of
dirWhere=batch compressd files source
saveWhere=where are the compressed files saving as
programWhere=where are the test7 to test9 binary files saving as
findList=a specified file script will add source (file/folder) name into automatically
newNameList= the new item name of the compressed source
tempList=a specified file adding some temp information
password=password of the rar achiver
par2_method=only can select the mode 10 or 11
rarVersion=the tag name of rar version
information_mode=only can select the mode 01 or 02
And, not only fill out the absolate path of the variables of dirWhere to tempList ,but assign the file name belonging with findList、 newNameList and tempList.
Final, add the new name inforamtion into the file belonging with newNameList.
Give an example and a illustration to everyone :
1. If we hope to move the 10 folders (these name are 01、02、03... 10 )and 1 file (the name is 11) I want to do compress to the specified location(source locaion = $dirWhere = /home/id/compress/) and specify the name of the compress files of each item are c-01、c-02、c-03 ... c-11 and I want to save all the compressed volume and par2 reapir files to the another location(target location = $saveWhere = /home/id/save/)
2.I create the shell script and test7~test9 (I will describe at next part) at another location(/home/id/script/)
3.Use - P.A.S.S.W.O.R.D as the compress files' password
4.par2_method is a very complex part, I like the mode 10 but , because of people don't understand the throey of mode 10 nad 11, I suggest people use mode 11.
5.The version of rar we use to do compress is 5.11, so we use the word - r5d11fin to be the version tag.
6.Use the mode 01 to get the sparate information of every single item.
7.Edit the variable conents of shell script, like the below parameters:
dirWhere= /home/id/compress/
saveWhere=location /home/id/save/
programWhere=/home/id/script/
findList=/home/id/script/source
newNameList= /home/id/script/target
tempList=/home/id/script/temp
password="P.A.S.S.W.O.R.D"
par2_method="10"
rarVersion="r5d11fin"
information_mode="01"
8.I also need to edit the file of (newNameList) - /home/id/script/target and improte the content liking the below blockc-01
c-02
c-03
c-04
c-05
c-06
c-07
c-08
c-09
c-10Give everyone another example picture to illustrate the information_mode 2
Like the above example, the files (and folders) of left putty window belog to $dirWhere and the location of center window belong to $saveWhere.
We arrived the result to know the content of target file are G201405.No-01、G201405.No-02、G201405.No-03 ... by the illustration of deduction .
The illustration is the saame as the above example using the information mode2m people can see the center region ((G201405.No-01).to.(G201405.No-91).information.v2.packet.rar) of the illusration.
B : Other source code
The test7 ~ test9 can help the script to calculate some parameters and load the parameters into par2 to build par2 files, before running the script ,people must compiler these source codes youself and move the program into the location belong to $programWhere
How to compiler the source code, people can refer this command.g++ -c test7.cpp; g++ -o test7 test7.otest7.cpp#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <iostream>
#include <string>
#include <sstream>
using namespace std;
using std::cout;
using std::string;
//using std::basic_stringstream;
int main(int argc, char **argv)
{
FILE *instream;
int bytes_read=0;
int buffer_size=0;
char calculate;
double calculate_double;
double size;
double size2;
double multi;
double block_size;
double block_count;
double repair_number;
int count=0;
string str1;
string str2;
string str3;
string str4;
string str5;
string str6;
string str7;
string str8;
string str9;
string stra;
// char str1[];
/* open stdin for reading */
instream=fopen("/dev/stdin","r");
/* did it open? */
if(instream!=NULL){
/* read from stdin until it's end */
fgets(calculate,100,instream);
calculate = '\0';
calculate_double = atof(calculate);
size = (calculate_double / (1024*1024*1024)); //source size
size2 = size * 1.03;
if (size <= 108)
{
if (size <= 74)
multi = 1.1;
else if (size <= 81 && size > 74)
multi = 1.1 + ((1.11 - 1.1) * (size - 74) / (81 - 74));
else if (size <= 88 && size > 81)
multi = 1.11 + ((1.12 - 1.11) * (size -81) / (88 - 81));
else if (size <= 105 && size > 88)
multi = 1.12 + ((1.15 - 1.12) * (size -88) / (105 - 88));
else if (size <= 108 && size > 105)
multi = 1.15 + ((1.155 - 1.15) * (size - 105) /(108 - 105));
block_size = size2 * multi * 5;
repair_number = block_size * 0.15 / 6; //省去浮點數使用
repair_number = ceil(repair_number);
block_count = double (int (repair_number) * 6);
count = 0;
}
else if (size <=195 && size > 108)
{
if (size <= 114)
multi = 1.05;
else if (size <= 119 && size >114)
multi = 1.05 + ((1.13 - 1.05) * (size - 114) / (119 - 114));
else if (size <= 139 && size > 119)
multi = 1.13 + ((1.135 - 1.13) * (size - 119) / (139 - 119));
else if (size <= 169 && size > 139)
multi = 1.135 + ((1.14 - 1.135) * (size - 139) / (169 - 139));
else if (size <= 190 && size > 169)
multi = 1.14 + ((1.145 - 1.14) * (size -169) / (190 - 169));
else if (size <= 195 && size > 190)
multi =1.145 + ((1.149 -1.145 ) * (size - 190) / (195 - 190));
block_size = (size2 - 99) * multi * 5;
repair_number = block_size * 0.15 / 6; //省去浮點數使用
repair_number = ceil(repair_number);
block_count = double (int (repair_number) * 6);
count = 1;
}
else if (size <= 292 && size > 195)
{
if (size <= 202 )
multi = 0.5;
else if (size <= 211 && size > 202)
multi = 0.5 + ((0.65 - 0.5) * (size - 202) / (211 - 202));
else if (size <= 222 && size > 211)
multi = 0.65 + ((1.03 - 0.65) * (size - 211) / (222 - 211));
else if (size <= 239 && size > 222)
multi = 1.03 + ((1.08 - 1.03) * (size - 222) / (239 - 222));
else if (size <= 256 && size > 239)
multi = 1.08 + ((1.135 - 1.08) * (size - 239) / (256 -239));
else if (size <= 292 && size > 256)
multi = 1.135 + ((1.145 - 1.135) * (size - 256) / (292 - 256));
block_size = (size2 - 199) * multi * 5;
repair_number = block_size * 0.15 / 6; //省去浮點數使用
repair_number = ceil(repair_number);
block_count = double (int (repair_number) * 6);
count = 2;
}
else if (size <= 393 && size > 292)
{
if (size <= 310)
multi = 0.7;
else if (size <= 324 && size > 310)
multi = 0.7 + ((0.95 - 0.7) * (size - 310) / (324 - 310));
else if (size <= 330 && size > 324)
multi = 0.95 + ((1 - 0.95) * (size - 324) / (330 - 324));
else if (size <= 348 && size > 330)
multi = 1 + ((1.04 - 1) * (size -330) / (348 - 330));
else if (size <= 393 && size > 348)
multi = 1.04 + ((1.1 - 1.04) * (size - 348) / (364 - 348));
block_size = (size2 - 299) * multi * 5;
repair_number = block_size * 0.15 / 6; //省去浮點數使用
repair_number = ceil(repair_number);
block_count = double (int (repair_number) * 6);
count = 3;
}
else if (size <= 490 && size > 393)
{
if (size <= 409)
multi = 0.6;
else if (size <= 417 && size > 409)
multi = 0.6 + ((0.8 - 0.6) * (size - 409) / (417 - 409));
else if (size <= 490 && size > 417)
multi = 0.8 + ((1.1 - 0.8) * (size - 417) / (490 - 417));
block_size = (size2 - 399) * multi * 5;
repair_number = block_size * 0.15 / 6; //省去浮點數使用
repair_number = ceil(repair_number);
block_count = double (int (repair_number) * 6);
count = 4;
}
else if (size <= 587 && size > 490)
{
if (size <= 517)
multi = 0.7;
else if ( size <= 587 && size > 517)
multi = 0.7 + ((1.1 - 0.7) * (size - 517) / (587 -517));
block_size = (size2 - 499) * multi * 5;
repair_number = block_size * 0.15 / 6; //省去浮點數使用
repair_number = ceil(repair_number);
block_count = double (int (repair_number) * 6);
count = 5;
}
else if (size <= 684 && size > 587)
{
if (size <= 628)
multi = 0.85;
else if ( size <= 684 && size > 628)
multi = 0.85 + ((1.1 - 0.85) * (size -628) / ( 684 - 628));
block_size = (size2 - 599) * multi * 5;
repair_number = block_size * 0.15 / 6; //省去浮點數使用
repair_number = ceil(repair_number);
block_count = double (int (repair_number) * 6);
count = 6;
}
else
{
multi = 1;
size2 = size *1.03;
while(size2 > 100 )
{
if(count == 0)
size2 = size2 - 99;
else
size2 = size2 -100;
count = count + 1;
}
block_size = size2 * multi * 5;
repair_number = block_size * 0.15 / 6; //省去浮點數使用
repair_number = ceil(repair_number);
block_count = double (int (repair_number) * 6);
}
if(count <= 9)
{
int i;
int j;
for(i = 0 ;i <= count;i++)
{
if( i != count)
{
if(i == 0)
{
stringstream convert;
convert << i;
str1 = "par2 c -b575 -c90 -n15 -u $saveWhere$newFileName/$newFileName.$rarVersion.rr3.001-099.par2 $saveWhere$newFileName/$newFileName.$rarVersion.rr3.";
str2 = convert.str();
str3 = "*&&";
str8 = str1 + str2 + str3;
}
else
{
str1 = "par2 c -b582 -c90 -n15 -u $saveWhere$newFileName/$newFileName.$rarVersion.rr3.";
stringstream convert_i;
convert_i << i;
str2 = convert_i.str();
str3 = "00-";
// j = i + 1;
// stringstream convert_j;
// convert_j << j;
// str4 = convert_j.str();
str5 = "99.par2 $saveWhere$newFileName/$newFileName.$rarVersion.rr3.";
str6 = "*&&";
str8 = str8 + str1 + str2 + str3 + str2 +str5 + str2 + str6;
}
}
else if(i == count)
{
if(count == 0)
{
str1 = "par2 c -b$bc -c$rbc -n$rbn1 -u $saveWhere$newFileName/$newFileName.$rarVersion.rr3.$volume2.par2 $saveWhere$newFileName/$newFileName.$rarVersion.rr3.";
str2 = "par2 c -r$rr -s$rbs -n$rbn2 -u $saveWhere$newFileName/$newFileName.$rarVersion.rr3.$volume2.par2 $saveWhere$newFileName/$newFileName.$rarVersion.rr3.";
str4 = "*&&cfv -C -tsfv -f$saveWhere$newFileName/$newFileName.sfv $saveWhere$newFileName/*";
str9 = str8 + str1 + str4;
}
else
{
stringstream convert;
convert << count;
str1 = "par2 c -b$bc -c$rbc -n$rbn1 -u $saveWhere$newFileName/$newFileName.$rarVersion.rr3.$volume2.par2 $saveWhere$newFileName/$newFileName.$rarVersion.rr3.";
str2 = "par2 c -r$rr -s$rbs -n$rbn2 -u $saveWhere$newFileName/$newFileName.$rarVersion.rr3.$volume2.par2 $saveWhere$newFileName/$newFileName.$rarVersion.rr3.";
str3 = convert.str();
str4 = "*&&cfv -C -tsfv -f$saveWhere$newFileName/$newFileName.sfv $saveWhere$newFileName/*";
str9 = str8 + str1 + str3 + str4;
}
}
}
}
printf("02.size(bit) %.0f\n03.size(source)(gb) %.3f\n04.size(source*1.03)(gb) %.3f\n05.multi %.2f\n06.block_count(bc) %.0f\n07.Recovery_count(rbc) %.0f\n08.repire_number(rbn1) %.0f\n09.count1 %d\n",calculate_double,size,size2,multi,block_size,block_count,repair_number,count);
cout << str9 << endl;
fclose(instream);
}
/* if any error occured, exit with an error message */
else{
fprintf(stderr, "ERROR opening stdin. aborting.\n");
exit(1);
}
return(0);
}
test8.cpp#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <iostream>
#include <string>
#include <sstream>
using namespace std;
using std::cout;
using std::string;
//using std::basic_stringstream;
int main(int argc, char **argv)
{
FILE *instream;
int bytes_read=0;
int buffer_size=0;
char calculate;
double calculate_double;
double number;
int count;
string str1;
string str2;
string str3;
string str4;
string str5;
string str6;
string str7;
string str8;
string str9;
string stra;
// char str1[];
/* open stdin for reading */
instream=fopen("/dev/stdin","r");
/* did it open? */
if(instream!=NULL){
/* read from stdin until it's end */
fgets(calculate,100,instream);
calculate = '\0';
calculate_double = atof(calculate);
number = calculate_double; //rarFileNumber
if(number < 100)
{
count = 0;
}
else
{
count = floor((number - 1) / 100);
}
if(count <= 9)
{
int i;
int j;
for(i = 0 ;i <= count;i++)
{
if( i != count)
{
if(i == 0)
{
stringstream convert;
convert << i;
str1 = "par2 c -b575 -c90 -n15 -u $saveWhere$newFileName/$newFileName.$rarVersion.rr3.001-099.par2 $saveWhere$newFileName/$newFileName.$rarVersion.rr3.";
str2 = convert.str();
str3 = "*&&";
str8 = str1 + str2 + str3;
}
else
{
str1 = "par2 c -b582 -c90 -n15 -u $saveWhere$newFileName/$newFileName.$rarVersion.rr3.";
stringstream convert_i;
convert_i << i;
str2 = convert_i.str();
str3 = "00-";
j = i + 1;
stringstream convert_j;
convert_j << j;
str4 = convert_j.str();
str5 = "00.par2 $saveWhere$newFileName/$newFileName.$rarVersion.rr3.";
str6 = "*&&";
str8 = str8 + str1 + str2 + str3 + str4 +str5 + str2 + str6;
}
}
else if(i == count)
{
if(count == 0)
{
str1 = "par2 c -b$bc -c$rbc -n$rbn1 -u $saveWhere$newFileName/$newFileName.$rarVersion.rr3.$volume2.par2 $saveWhere$newFileName/$newFileName.$rarVersion.rr3.";
str2 = "par2 c -r$rr -s$rbs -n$rbn2 -u $saveWhere$newFileName/$newFileName.$rarVersion.rr3.$volume2.par2 $saveWhere$newFileName/$newFileName.$rarVersion.rr3.";
str4 = "*&&cfv -C -tsfv -f$saveWhere$newFileName/$newFileName.sfv $saveWhere$newFileName/*";
stra = str8 + str2 + str4;
}
else
{
stringstream convert;
convert << count;
str1 = "par2 c -b$bc -c$rbc -n$rbn1 -u $saveWhere$newFileName/$newFileName.$rarVersion.rr3.$volume2.par2 $saveWhere$newFileName/$newFileName.$rarVersion.rr3.";
str2 = "par2 c -r$rr -s$rbs -n$rbn2 -u $saveWhere$newFileName/$newFileName.$rarVersion.rr3.$volume2.par2 $saveWhere$newFileName/$newFileName.$rarVersion.rr3.";
str3 = convert.str();
str4 = "*&&cfv -C -tsfv -f$saveWhere$newFileName/$newFileName.sfv $saveWhere$newFileName/*";
stra = str8 + str2 + str3 + str4;
}
}
}
}
cout << stra << endl;
printf("12.count2 %d\n",count);
fclose(instream);
}
/* if any error occured, exit with an error message */
else{
fprintf(stderr, "ERROR opening stdin. aborting.\n");
exit(1);
}
return(0);
}
test9.cpp#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <iostream>
#include <string>
#include <sstream>
using namespace std;
using std::cout;
using std::string;
//using std::basic_stringstream;
int main(int argc, char **argv)
{
FILE *instream;
int bytes_read=0;
int buffer_size=0;
char calculate;
double calculate_double;
double size;
double size_GB;
double repair_size;
double rbn2;
double rr;
double rbs;
string str1;
string str2;
string str3;
// char str1[];
/* open stdin for reading */
instream=fopen("/dev/stdin","r");
/* did it open? */
if(instream!=NULL){
/* read from stdin until it's end */
fgets(calculate,100,instream);
calculate = '\0';
calculate_double = atof(calculate);
size = calculate_double; //bit,rarVolumeFileSize
size_GB = calculate_double / (1024*1024*1024);
repair_size = size * 0.15 / (1024*1024*1024);
rbn2 = ceil(repair_size); //N GB repair files
rr = ceil(rbn2 * (1024*1024*1024) * 100 / size); //N (GB)*1024^3修復檔/源檔大小= rr precent
rbs = ((ceil(((size * rr / 100) / (rbn2 * 7)) / 4 )) * 4);
if(size_GB < rbn2)
{
rr =100;
rbs = (ceil((size / 7) / 4) * 4);
rbn2 = 1;
}
printf("13.level(rr) %.0f\n14.block_size(rbs) %.0f\n15.repire_number(rbn2) %.0f\n",rr,rbs,rbn2);
fclose(instream);
}
/* if any error occured, exit with an error message */
else{
fprintf(stderr, "ERROR opening stdin. aborting.\n");
exit(1);
}
return(0);
}
After adding the shell script (script.sh) and move test7~test9 to the same folder, change the script's premission then we can use the scirpt to add a job.chmod 755 script.sh test7 test8 test9 && ./script.sh ---release notes---
2014/10/10 version 1.1b
1.Add new variable $dataWhere, fill out the information in real patch of data source,then the script will auto move the datato $dirWhere and move back the data after finish the cimpression.
2.The contents of test7 to test9 are the same.
2014/10/10 version 1.2b
1.Fix the variable of the part of moving files and allow the special character file/folder name!!
2.The contents of test7 to test9 are the same.
Source code of script
#!/bin/sh
# improte the variables
dataWhere='/home/userid/data/'
dirWhere='/home/userid/a/'
saveWhere="/home/userid/save/"
programWhere="/home/userid/software/"
findList="/home/userid/software/source"
newNameList="/home/userid/software/target"
tempList="/home/userid/software/templist"
password="P.A.S.S.W.O.R.D"
#10.old ,11-new
par2_method="10"
rarVersion="r5d11fin"
#mode01=unpacket,mode02=packet
information_mode="02"
#collect data
while read fileName
do
mv $dataWhere"$fileName" $dirWhere
done < $findList
echo "* The data is finish collected *"
# check for bad situation 1
if [ ! -f "$newNameList" ] ; then
echo 'error, list does not exist'
exit
fi
# assign the path to te working directory
cd "$dirWhere"
# search and get the the name of working directory
find . -maxdepth 1 > $tempList
cat $tempList | sort > $findList
sed -i "s/\.\///g" $findList
sed -i '/^\.$/d' $findList
cd "$programWhere"
#rm -f $tempList
# check for the bad situation 2
lineTotal_01=` cat "$findList" | wc -l `
lineTotal_02=` cat "$newNameList" | wc -l`
if [ $lineTotal_01 -ne $lineTotal_02 ] ; then
echo 'error, the list numbers does not match with the folders and files nambers of working directory。'
exit
fi
#start to enter the working loop
# 初始化用來當迴圈「計數器」的變數的值
loopTimes=1
echo -e ""
echo "* The core of this scrip start working *"
echo -e ""
# 迴圈開始
while read fileName
do
echo "loopTimes=$loopTimes"
#mapping新檔名
# 新檔名 = 取出「更名列表清單」特定行數的資料
# 行數 = 迴圈計數器的值(由1開始,依序增加讀取)
lineNum=` echo $loopTimes"p" `
newFileName=` sed -n $lineNum $newNameList `
mkdir $saveWhere$newFileName
sleep 2
# 壓縮->修名->重新命名
#壓縮
if [ $loopTimes -ne 0 ] ; then
echo "$fileName" > "$dirWhere"comment
echo -e "" >> "$dirWhere"comment
#echo "* This shell script is created by bdmv.info * " >> "$dirWhere"comment
#echo "* People are only allowed to use the script for nonprofit reserch *" >> "$dirWhere"comment
rar a -m0 -hp"$password" -v1073741824b -rr3 -ep1 -z"$dirWhere"comment $saveWhere"$newFileName"/"$newFileName".$rarVersion.rr3 "$dirWhere""$fileName"
echo -e "\n\n"
echo "echo 1.rar壓縮"
echo -e "\n\n"
sleep 2
fi
#取得壓縮檔完整數量
rarFileNumber=` ls -laR $saveWhere"$newFileName" |grep "^-" |awk 'END{print NR}' `
rarFileSize=` ls -l $saveWhere"$newFileName" | awk '{ sum += $5} END { printf("%.3f\n",sum/1024/1024/1024)}'`
echo -e "\n\n"
echo "echo 2.壓縮檔數量=$rarFileNumber"
echo -e "\n\n"
sleep 2
#新增newFileName文件放置檔按資訊
echo "01.project_source $fileName" > $saveWhere$newFileName/"$newFileName".txt
echo -e "\n\n"
echo "echo 3.新增文件$newFileName.txt"
echo -e "\n\n"
sleep 2
#由來源大小取得par2所需的各項參數
du -s -b "$dirWhere""$fileName" | awk '{print $1}'| "$programWhere"test7 >> $saveWhere$newFileName/"$newFileName".txt
sed -n "1,10p" $saveWhere$newFileName/"$newFileName".txt
echo -e "\n\n"
echo "echo 4.儲存參數至$saveWhere$newFileName/"$newFileName".txt"
echo -e "\n\n"
sleep 2
#由壓縮檔數量取得par2所需的各項參數
echo "$rarFileNumber" | "$programWhere"test8 >> $saveWhere$newFileName/"$newFileName".txt
sed -n "1,12p" $saveWhere$newFileName/"$newFileName".txt
echo -e "\n\n"
echo "echo 5.儲存參數至$saveWhere$newFileName/"$newFileName".txt"
echo -e "\n\n"
sleep 2
#比對rar檔案數量做更名
#echo "$fileName" > "$dirWhere"comment
#echo -e "" >> "$dirWhere"comment
#echo "* This shell script is created by bdmv.info * " >> "$dirWhere"comment
#echo "* People are only allowed to use the script for nonprofit reserch *" >> "$dirWhere"comment
#if [ "$rarFileNumber" -gt 99 ] ; then
# rar c -p$password -z"$dirWhere"comment $saveWhere"$newFileName"/"$newFileName".$rarVersion.rr3.part001.rar
# rename.ul part "" $saveWhere"$newFileName"/* && rename.ul .rar "" $saveWhere"$newFileName"/*
# echo -e "\n\n\n"
# echo "echo 6.更名:模式1(檔案大小>1)"
#elif [ "$rarFileNumber" -gt 9 ] ; then
# rar c -p$password -z"$dirWhere"comment $saveWhere"$newFileName"/"$newFileName".$rarVersion.rr3.part01.rar
# rename.ul part "" $saveWhere"$newFileName"/* && rename.ul .rar "" $saveWhere"$newFileName"/*
# echo -e "\n\n\n"
# echo "echo 6.更名:模式1(檔案大小>1)"
if [ "$rarFileNumber" -gt 1 ] ; then
rename.ul part "" $saveWhere"$newFileName"/* && rename.ul .rar "" $saveWhere"$newFileName"/*
echo -e "\n\n\n"
echo "echo 6.更名:模式1(檔案大小>1)"
else
rar c -p$password -z"$dirWhere"comment $saveWhere"$newFileName"/"$newFileName".$rarVersion.rr3
rename -v 's/rr3$/rr3\.1/' $saveWhere"$newFileName"/*
echo -e "\n\n"
echo "echo 6.更名:模式2(檔案大小<=1)"
fi
rm "$dirWhere"comment
echo -e "\n\n"
sleep 2
#讀入參數九:count
volume_beta=` sed -n 9p $saveWhere$newFileName/$newFileName.txt | awk '{print $2}' ` #9指向count,par2 method=10
volume=` sed -n 12p $saveWhere$newFileName/$newFileName.txt | awk '{print $2}' ` #12指向count2,par2 method=11
if [ "$volume" -eq 0 ] ; then
rarVolumeFileSize=` du -S -b $saveWhere$newFileName/*rr3.* | grep rr3 | awk '{sum += $1};END{print sum}' `
else
rarVolumeFileSize=` du -S -b $saveWhere$newFileName/*rr3."$volume"* | grep rr3."$volume" | awk '{sum += $1};END{print sum}' `
fi
echo "volume=$volume"
echo "rarVolumeFileSize=$rarVolumeFileSize"
echo -e "\n\n"
echo "echo 7.取出卷數資訊計算未滿100(99)的末尾分卷大小"
echo -e "\n\n"
sleep 2
#製作數狀圖
#tree "$dirWhere""$fileName" >> $saveWhere"$newFileName"/"$newFileName".tree.txt
#sed -i 's#'$dirWhere'##' $saveWhere"$newFileName"/"$newFileName".tree.txt
#rar a -hp"$password" -ep1 $saveWhere"$newFileName"/"$newFileName".tree.rar $saveWhere"$newFileName"/"$newFileName".tree.txt
#sed -n "1,5p" "$saveWhere$newFileName"/"$newFileName".tree.txt
#echo "echo 7.Print 樹狀圖(前五列)"
#rm $saveWhere"$newFileName"/"$newFileName".tree.txt
#sleep 5
tree "$dirWhere""$fileName" >> $saveWhere"$newFileName"/"$newFileName".tree.txt
tree -d "$dirWhere""$fileName" >> $saveWhere"$newFileName"/"$newFileName".folder.tree.txt
sed -i '1d' $saveWhere"$newFileName"/"$newFileName".tree.txt
sed -i '1d' $saveWhere"$newFileName"/"$newFileName".folder.tree.txt
if [ $loopTimes -ne 1 ] ; then
echo -e "" >> $saveWhere"$newFileName"/"$newFileName".tree2.txt
echo -e "" >> $saveWhere"$newFileName"/"$newFileName".tree3.txt
fi
echo "$fileName" >> $saveWhere"$newFileName"/"$newFileName".tree2.txt
echo "$fileName" >> $saveWhere"$newFileName"/"$newFileName".tree3.txt
awk '{print $0}' $saveWhere"$newFileName"/"$newFileName".tree.txt >> $saveWhere"$newFileName"/"$newFileName".tree2.txt
awk '{print $0}' $saveWhere"$newFileName"/"$newFileName".folder.tree.txt >> $saveWhere"$newFileName"/"$newFileName".tree3.txt
awk '{print $0}' $saveWhere"$newFileName"/"$newFileName".tree2.txt > $saveWhere"$newFileName"/"$newFileName".tree.txt
awk '{print $0}' $saveWhere"$newFileName"/"$newFileName".tree3.txt > $saveWhere"$newFileName"/"$newFileName".folder.tree.txt
rm $saveWhere"$newFileName"/"$newFileName".tree2.txt
rm $saveWhere"$newFileName"/"$newFileName".tree3.txt
sed -n "1,5p" "$saveWhere$newFileName"/"$newFileName".tree.txt
sed -n "1,5p" "$saveWhere$newFileName"/"$newFileName".folder.tree.txt
echo -e "\n\n"
echo "echo 8.Print 樹狀圖*2(前五列)"
echo -e "\n\n"
sleep 3
#由count大小判定par2最末未滿100(99)分卷的檔名&強制修正par2的使用時機
if [ $rarFileNumber -lt 5 ] ; then
par2_method="11"
fi
if [ $par2_method -eq 11 ] ; then
if [ $volume -gt 0 ] ; then
volume2="$volume"00-End
volume2=` echo ""$volume"00-End" `
else
if [ $rarFileNumber -lt 10 ] ; then
volume2=1-End
else
volume2=01-End
fi
fi
else
if [ $volume -gt 0 ] ; then
if [ $volume -eq $volume_beta ] ;then
volume2="$volume"00-End
volume2=` echo ""$volume"00-End" `
elif [ $volume -gt $volume_beta ] ;then
volume2="$volume_beta"00-"$volume_beta"99
fi
else
if [ $rarFileNumber -lt 10 ] ; then
volume2=1-End
else
volume2=01-End
fi
fi
fi
echo -e "\n\n"
echo "echo 9.volume2=$volume2"
echo -e "\n\n"
sleep 2
#取得par2參數(rr/rbs/rbn2)
echo "$rarVolumeFileSize" | "$programWhere"test9 >> $saveWhere$newFileName/"$newFileName".txt
sed -n "1,15p" $saveWhere$newFileName/"$newFileName".txt
echo -e "\n\n"
echo "echo 10.新增參數13-15"
echo -e "\n\n"
sleep 2
#txt文件的變數取代
bc=` sed -n 6p $saveWhere$newFileName/$newFileName.txt | awk '{print $2}' `
rbc=` sed -n 7p $saveWhere$newFileName/$newFileName.txt | awk '{print $2}' `
rbn1=` sed -n 8p $saveWhere$newFileName/$newFileName.txt | awk '{print $2}' `
rr=` sed -n 13p $saveWhere$newFileName/$newFileName.txt | awk '{print $2}' `
rbs=` sed -n 14p $saveWhere$newFileName/$newFileName.txt | awk '{print $2}' `
rbn2=` sed -n 15p $saveWhere$newFileName/$newFileName.txt | awk '{print $2}' `
sed -i 's/$bc/'$bc'/g' $saveWhere$newFileName/$newFileName.txt
sed -i 's/$rbc/'$rbc'/g' $saveWhere$newFileName/$newFileName.txt
sed -i 's/$rbn1/'$rbn1'/g' $saveWhere$newFileName/$newFileName.txt
sed -i 's/$rr/'$rr'/g' $saveWhere$newFileName/$newFileName.txt
sed -i 's/$rbs/'$rbs'/g' $saveWhere$newFileName/$newFileName.txt
sed -i 's/$rbn2/'$rbn2'/g' $saveWhere$newFileName/$newFileName.txt
sed -i 's#$saveWhere#'$saveWhere'#g' $saveWhere$newFileName/$newFileName.txt
sed -i 's/$newFileName/'$newFileName'/g' $saveWhere$newFileName/$newFileName.txt
sed -i 's/$rarVersion/'$rarVersion'/g' $saveWhere$newFileName/$newFileName.txt
#檔案數量大於99的情況取消$volume2字串
if [ $par2_method -eq 11 ] ; then
if [ $volume -gt 0 ] ; then
sed -i 's/$volume2/'"$volume2"'/g' $saveWhere$newFileName/$newFileName.txt
else
sed -i 's#$volume2'\.'##g' $saveWhere$newFileName/$newFileName.txt
fi
else
if [ $volume -gt 0 ] ; then
if [ $volume_beta -gt 0 ] ; then
sed -i 's/$volume2/'"$volume2"'/g' $saveWhere$newFileName/$newFileName.txt
else
sed -i 's#$volume2'\.'##g' $saveWhere$newFileName/$newFileName.txt
fi
else
sed -i 's#$volume2'\.'##g' $saveWhere$newFileName/$newFileName.txt
fi
fi
sed -n "1,15p" $saveWhere$newFileName/"$newFileName".txt
echo -e "\n\n"
echo "echo 11.txt文件的變數取代"
echo -e "\n\n"
sleep 2
#dump par2 command至$newFileName.par2command.txt
sed -n "$par2_method"p $saveWhere$newFileName/$newFileName.txt|sed -r "s/(&&)/\n/g" > $saveWhere$newFileName/$newFileName.par2command.txt
if [ $par2_method -eq 10 ] ; then
volume_plus=` expr $volume_beta + 2 `
elif [ $par2_method -eq 11 ] ;then
volume_plus=` expr $volume + 2 `
fi
sed -n 1,"$volume_plus"p $saveWhere$newFileName/$newFileName.par2command.txt
echo -e "\n\n"
echo "echo 12.par2 command + cfv command"
echo -e "\n\n"
sleep 2
#執行par2與cfv製作
count=1
while [ "$count" -le "$volume_plus" ]
do
command=` sed -n "$count"p $saveWhere$newFileName/$newFileName.par2command.txt `
$command
count=` expr $count + 1 `
done
echo -e "\n\n"
echo "echo 13.par2與cfv製作完成"
echo -e "\n\n"
sleep 2
#修正sfv內容
sed -i 's#'$saveWhere$newFileName/'##' $saveWhere$newFileName/$newFileName.sfv
sed -i "/$newFileName.par2command.txt/d" $saveWhere$newFileName/$newFileName.sfv
sed -i "/$newFileName.tree.txt/d" $saveWhere$newFileName/$newFileName.sfv
sed -i "/$newFileName.folder.tree.txt/d" $saveWhere$newFileName/$newFileName.sfv
sed -i "/$newFileName.txt/d" $saveWhere$newFileName/$newFileName.sfv
awk '{print $0}' $saveWhere$newFileName/$newFileName.sfv >> "$saveWhere"ALL.FILENAME.sfv
sed -n "1,10p" $saveWhere$newFileName/$newFileName.sfv
echo "echo 14.修正sfv內容v1"
echo -e "\n\n"
sleep 2
echo -e "\n\n"
#整理$newFileName的檔案
par2FileSize=` ls -l $saveWhere"$newFileName"/*.par2 | awk '{ sum += $5} END { printf("%.3f\n",sum/1024/1024/1024)}' `
sed -i "10,11d" $saveWhere$newFileName/$newFileName.txt
sed -i -r "s/(^09.)/11\./g" $saveWhere$newFileName/$newFileName.txt
sed -i -r "s/(^08.)/10\./g" $saveWhere$newFileName/$newFileName.txt
sed -i -r "s/(^07.)/09\./g" $saveWhere$newFileName/$newFileName.txt
sed -i -r "s/(^06.)/08\./g" $saveWhere$newFileName/$newFileName.txt
sed -i -r "s/(^05.)/07\./g" $saveWhere$newFileName/$newFileName.txt
sed -i "5 i\05.size(item/rar)(gb) $rarFileSize" $saveWhere$newFileName/$newFileName.txt
sed -i "6 i\06.size(item/par2)(gb) $par2FileSize" $saveWhere$newFileName/$newFileName.txt
echo "--------par2 + cfv command--------" >>$saveWhere$newFileName/$newFileName.txt
sed -n 1,"$volume_plus"p $saveWhere$newFileName/$newFileName.par2command.txt >> $saveWhere$newFileName/$newFileName.txt
echo "##################################" >> $saveWhere$newFileName/$newFileName.txt
sed -i 's#'$saveWhere'#($saveWhere)#g' $saveWhere$newFileName/$newFileName.txt
rm $saveWhere$newFileName/$newFileName.par2command.txt
volume_plus=` expr $volume_plus + 17 `
sed -n 1,"$volume_plus"p $saveWhere"$newFileName"/"$newFileName".txt
echo -e "\n\n"
echo "echo 15.最終版$newFileName.txt內容"
echo -e "\n\n"
sleep 2
#新增mapping/target/size對照文件
echo "$newFileName" >> "$saveWhere"ALL.FILE.MAP.txt
sizegb=` sed -n 3p $saveWhere$newFileName/$newFileName.txt | awk '{print $2}' `
sizemb=` du -s "$dirWhere""$fileName" | awk '{ printf("%.3f\n",$1/1024)}' `
sed -i -r ""$loopTimes"s/$/ source|"$sizegb"GB/g" "$saveWhere"ALL.FILE.MAP.txt
sed -i -r ""$loopTimes"s/$/ source|"$sizemb"MB/g" "$saveWhere"ALL.FILE.MAP.txt
sed -i -r ""$loopTimes"s/$/ rar|"$rarFileSize"GB/g" "$saveWhere"ALL.FILE.MAP.txt
sed -i -r ""$loopTimes"s/$/ par2|"$par2FileSize"GB/g" "$saveWhere"ALL.FILE.MAP.txt
sed -i -r ""$loopTimes"s/$/ $fileName/g" "$saveWhere"ALL.FILE.MAP.txt
sed -n 1,"$loopTimes"p "$saveWhere"ALL.FILE.MAP.txt
echo -e "\n\n"
echo "echo 16.loop$loopTimes的map內容"
echo -e "\n\n"
sleep 2
#打包並刪除$newFileName.txt(保留全卷資訊)
test "$information_mode" = "01" && rar a -m0 -ep1 -hp$password $saveWhere$newFileName/$newFileName.information.rar $saveWhere$newFileName/$newFileName.txt $saveWhere$newFileName/$newFileName.tree.txt $saveWhere$newFileName/$newFileName.folder.tree.txt
#test "$information_mode" = "02" && rar a -m0 -ep1 -hp$password $saveWhere$newFileName.information.v2.rar $saveWhere$newFileName/$newFileName.sfv $saveWhere"$newFileName"/"$newFileName".$rarVersion.rr3.par2 $saveWhere$newFileName/$newFileName.txt $saveWhere$newFileName/$newFileName.tree.txt $saveWhere$newFileName/$newFileName.folder.tree.txt ; rm $saveWhere$newFileName/$newFileName.sfv ; rm $saveWhere"$newFileName"/"$newFileName".$rarVersion.rr3.par2
if [ "$information_mode" = "02" ] ; then
rar a -m0 -ep1 -hp$password $saveWhere$newFileName.information.v2.rar $saveWhere$newFileName/$newFileName.sfv $saveWhere"$newFileName"/"$newFileName".$rarVersion.rr3.par2 $saveWhere$newFileName/$newFileName.txt $saveWhere$newFileName/$newFileName.tree.txt $saveWhere$newFileName/$newFileName.folder.tree.txt
rm $saveWhere$newFileName/$newFileName.sfv
rm $saveWhere"$newFileName"/"$newFileName".$rarVersion.rr3.par2
fi
awk '{print $0}' $saveWhere$newFileName/$newFileName.txt >> "$saveWhere"ALL.FILENAME.txt
awk '{print $0}' $saveWhere$newFileName/$newFileName.tree.txt >> "$saveWhere"ALL.TREE\(PART.MODE\).txt
awk '{print $0}' $saveWhere$newFileName/$newFileName.folder.tree.txt >> "$saveWhere"ALL.FOLDER.TREE\(PART.MODE\).txt
rm $saveWhere$newFileName/$newFileName.txt
rm $saveWhere$newFileName/$newFileName.tree.txt
rm $saveWhere$newFileName/$newFileName.folder.tree.txt
echo -e "\n\n"
echo "echo 17.打包並刪除$newFileName.txt(保留全卷資訊)"
echo -e "\n\n"
sleep 2
# 迴圈計數器 + 1
loopTimes=` expr $loopTimes + 1 `
project_end=$newFileName
done < $findList
#打包全卷資訊
echo -e "" >> "$saveWhere"ALL.TREE\(FULL.MODE\).txt
echo -e "" >> "$saveWhere"ALL.FOLDER.TREE\(FULL.MODE\).txt
tree "$dirWhere" >> "$saveWhere"ALL.TREE\(FULL.MODE\).txt
tree -d "$dirWhere" >> "$saveWhere"ALL.FOLDER.TREE\(FULL.MODE\).txt
sed -i '2d' "$saveWhere""ALL.TREE(FULL.MODE).txt"
sed -i '2d' "$saveWhere""ALL.FOLDER.TREE(FULL.MODE).txt"
project_start=` sed -n 1p $newNameList `
test "$project_start" != "$project_end" && rar a -m0 -ep1 -hp$password "$saveWhere"\["$project_start"\].to.\["$project_end"\].ALL.INFORMATION.rar "$saveWhere"ALL.FILENAME.txt "$saveWhere"ALL.TREE\(PART.MODE\).txt "$saveWhere"ALL.FILE.MAP.txt "$saveWhere"ALL.TREE\(FULL.MODE\).txt "$saveWhere"ALL.FOLDER.TREE\(FULL.MODE\).txt "$saveWhere"ALL.FOLDER.TREE\(PART.MODE\).txt "$saveWhere"ALL.FILENAME.sfv && test "$information_mode" = "02" && rar a -m0 -ep1 -hp$password "$saveWhere"\("$project_start"\).to.\("$project_end"\).information.v2.packet.rar "$saveWhere"*.information.v2.rar && rm "$saveWhere"*.information.v2.rar
test "$project_start" = "$project_end" && rar a -m0 -ep1 -hp$password "$saveWhere"\["$project_end"\].ALL.INFORMATION.rar "$saveWhere"ALL.FILENAME.txt "$saveWhere"ALL.TREE\(PART.MODE\).txt "$saveWhere"ALL.FILE.MAP.txt "$saveWhere"ALL.TREE\(FULL.MODE\).txt "$saveWhere"ALL.FOLDER.TREE\(FULL.MODE\).txt "$saveWhere"ALL.FOLDER.TREE\(PART.MODE\).txt "$saveWhere"ALL.FILENAME.sfv
while read fileName
do
mv $dirWhere"$fileName" $dataWhere
done < $findList
echo "* The data is finish moving back *"
#刪除暫存檔
rm "$saveWhere"ALL.FILE.MAP.txt
rm "$saveWhere"ALL.FILENAME.txt
rm "$saveWhere"ALL.TREE\(PART.MODE\).txt
rm "$saveWhere"ALL.TREE\(FULL.MODE\).txt
rm "$saveWhere"ALL.FOLDER.TREE\(PART.MODE\).txt
rm "$saveWhere"ALL.FOLDER.TREE\(FULL.MODE\).txt
rm "$saveWhere"ALL.FILENAME.sfv
rm -f $findList
#rm -f $newNameList
rm -f $tempList
echo -e ""
echo "* All the jobs are finished *"
echo -e ""
Pages:
[1]