七零部落格
思则大道至简,疑则谜团重重!
思则大道至简,疑则谜团重重!
出处:http://blog.csdn.net/cuterhei/article/details/19926425
#!/bin/sh
##############################################################
# Used to unzip script files generated by shc #
# Modified by cuterhei at 2014-02-26: 目录遍历 #
# Created by cuterhei at 2014-02-25 : 创建 #
##############################################################
shcd_help()
{
echo " Used to unzip script file generated by shc."
echo " Usage:"
echo " 0. shcd -h|?|-help ---- Current you see"
echo " 1. shcd inputfile ---- 解压单个文件(输出文件inpfile.bat)"
echo " 2. shcd inpfile outpfile ---- 解压单个文件(输出文件outpfile)"
echo " 3. shcd -d ---- 深层目录遍历解压(输出文件*.bat)"
echo " 4. shcd -a ---- 当前目录遍历解压(输出文件*.bat)"
exit 0
}
get_skip()
{
skip=0
while read skip_line
do
let "skip -= 1"
skl_f="none"
skipstrlist=$(echo $skip_line|tr "=" "\n")
for xs in $skipstrlist; do
if [ "$skl_f" = "none" ]; then
if [ "$xs" = "skip" ]; then
skl_f="found"
else
break;
fi
elif [ "$skl_f" = "found" ]; then
skip=$xs;
break
else
break
fi
done
if [ "$skl_f" = "found" ] || [ $skip -le -2 ]; then
break
fi
done < "$1" echo $skip } ucount=0 uncomp_shc() { skipline=$(get_skip $1) if [ "$skipline" = "" ] || [ $skipline -le 1 ]; then echo "%>_<% Skip flag not found: $1" else if tail -n +"$skipline" "$1" | gzip -cd > "$2"; then
let "ucount += 1"
echo "^_^ $ucount. Unzip $1 to $2"
else
echo "%>_<% Unzip $1 failed"
fi
fi
}
uncshc_dir()
{
echo "......Enter dir '$1' ......"
for file in $1/*
do
if [ -f $file ]; then
uncomp_shc "$file" "$file.bat"
elif [ -d $file ] && [ "$2" = "-d" ]; then
uncshc_dir "$file" "$2"
fi
done
echo "......Leave dir '$1' ......"
}
# now start to work
if [ "$#" = "0" ] || [ "$1" = "-?" ] || [ "$1" = "-h" ] || [ "$1" = "-help" ]; then
shcd_help
elif [ -f $1 ]; then
if [ "$#" = "2" ]; then
uncomp_shc "$1" "$2"
else
uncomp_shc "$1" "$1.bat"
fi
elif [ "$1" = "-d" ] || [ "$1" = "-a" ]; then
uncshc_dir . $1
else
echo "File $1 is not exist."
fi
echo "$ucount files are unzipped."
exit
# end of job