#!/bin/bash
#encode begin
#
#endcode end
#compile=false
#Author:birdman
#Create Date:2013-04-28
#Alter Date:2013-05-02
#Description:用于加密shell编译
#Usage:sh compile.sh
function Birdman_Init()
{
source /etc/profile >> /dev/null 2>&1
ScriptName=`basename $0`
export pid="${pid}-->$ScriptName"
LogFile=`echo ${ScriptName}|awk -F. ‘{print $1}‘`.log
}
function Birdman_Compile()
{
for File in `find . -name "*.sh"|sed ‘s/\.\///‘`;do
Compile_File=${File}.x
New_File=`echo $File|awk -F. ‘{print $1}‘`
if grep -q "compile=true" $File;then
#Old_Md5=`awk ‘{if($2 ~ /‘"${New_File}"‘/)print}‘ ${Bash_VersionFile}|awk ‘{print $1}‘`
Old_Md5=`awk ‘{if($2~"^‘"${New_File}"‘$")print}‘ ${Bash_VersionFile}|awk ‘{print $1}‘`
sed -i "/${Old_Md5}/d" ${Bash_VersionFile}
shc -r -T -f $File
mv ${Compile_File} ${New_File}
md5sum ${New_File} >> ${Bash_VersionFile}
rm -rf ${File}.x.c
fi
done
}
main()
{
Bash_VersionFile="/var/www/html/BashVersion.txt"
if [ ! -f ${Bash_VersionFile} ];then
echo "Bash Version File is not exist"
exit 1
fi
Birdman_Init
Birdman_Compile
}
main
PS:
查看当前目录下所有的.sh 文件。如果文件中包含compile=true,则对脚本进行加密
本文出自 “我是一只小小鸟” 博客,请务必保留此出处http://2242558.blog.51cto.com/2232558/1545326
原文:http://2242558.blog.51cto.com/2232558/1545326