54 lines
1020 B
Bash
Executable File
54 lines
1020 B
Bash
Executable File
#!/bin/bash
|
||
fileName=$1
|
||
projectPath=$2
|
||
PATH=PATH:/usr/bin:/usr/sbin
|
||
|
||
sleep 15
|
||
cd ~
|
||
echo "current path: $(pwd)"
|
||
if [ ! -f "$fileName" ];then
|
||
echo "文件 $fileName 不存在1!"
|
||
exit 0
|
||
fi
|
||
|
||
oriSum=$(md5sum $fileName)
|
||
oriSum="${oriSum% *}"
|
||
echo "origin file $fileName md5sum: $oriSum"
|
||
|
||
if [ ! -d "$projectPath" ]; then
|
||
echo "文件夹 $prjectPath 不存在!"
|
||
exit 0
|
||
fi
|
||
|
||
cd $projectPath
|
||
desSum=""
|
||
if [ ! -f "$fileName" ];then
|
||
cp ~/$fileName .
|
||
exit 0
|
||
else
|
||
desSum=$(md5sum $fileName)
|
||
desSum="${desSum% *}"
|
||
echo "current path: $(pwd)"
|
||
echo "destination file ${fileName} md5sum: ${desSum}"
|
||
fi
|
||
|
||
if [ ${oriSum} = ${desSum} ];then
|
||
echo "destination file is same with origin file,no need to replace"
|
||
exit 0
|
||
fi
|
||
|
||
if [ -f "$fileName"_bak2 ];then
|
||
rm "${fileName}"_bak2
|
||
fi
|
||
if [ -f "${fileName}"_bak1 ];then
|
||
mv ${fileName}_bak1 ${fileName}_bak2
|
||
fi
|
||
if [ -f "$fileName"_bak ];then
|
||
mv ${fileName}_bak ${fileName}_bak1
|
||
fi
|
||
if [ -f "$fileName" ];then
|
||
mv ${fileName} ${fileName}_bak
|
||
fi
|
||
|
||
cp ~/"${fileName}" .
|