-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathphp_script_4to5.sh
46 lines (36 loc) · 1.01 KB
/
php_script_4to5.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/bin/bash
# Created by hewei.chn#gmail.com 20130228
# Use This Script to Add Script Type for php Scripts.
# Version v0.1
# Usage: Generate Filelist with find or Something else.
# then ./php_script_4to5.sh [FileList] [BackPath]
function usage() {
echo "Create FileList by Find or Other tools."
echo "Usage: $0 [FileList] [BackPath]"
echo "File will be Backup into BackPath and Log in BackPath/FileList.done"
exit -1;
}
if [ $# -ne 2 ] || [ ! -s $1 ] ;then
usage $0
fi
if [ ! -d $2 ] && ! mkdir -p $2 ;then
echo "Create Dirctory $2 For Backup Failed!"
usage $0
fi
BACKUPDIR=$2
LOGS=$2/`basename ${1}`.done
cp $1 ${BACKUPDIR}/
for file in `cat $1 | grep php$`; do
echo "Deal with File ${file}"
echo -n ${file} >>${LOGS}
LINENUM=`grep "<?$" ${file} | wc -l`
if [ ${LINENUM} -gt 0 ];then
sed -i "s/<?$/<?php/g" $file
FILEDIR=`dirname ${file}`
mkdir -p ${BACKUPDIR}/${FILEDIR}
cp -f ${file} ${BACKUPDIR}/${file}
echo " Changed ${LINENUM} Lines" >>${LOGS}
else
echo " Leave Unchanged">>${LOGS}
fi
done