-
Notifications
You must be signed in to change notification settings - Fork 15
/
php_cleanup
executable file
·54 lines (45 loc) · 1.34 KB
/
php_cleanup
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
44
45
46
47
48
49
50
51
52
53
54
#!/bin/bash
### This is a simple script that wraps the AWK script and handles all
### the file munging.
SCRIPTNAME=${0##*/}
## Prints a usage help message.
function print_usage() {
echo "usage: $SCRIPTNAME -p|-d [php.ini]"
}
## Check the number of arguments.
if [ $# -lt 1 ] || [ $# -gt 2 ]; then
print_usage
exit 1
fi
## Getting the input filename. By default assumes that is called
## php.ini and is on the current directory.
## Getting the input filename. By default assumes that is called
## php.ini and is on the current directory.
if [ $# -eq 2 ]; then
INPUT_FILE=$2
else
INPUT_FILE=php.ini
fi
## The AWK script that does the cleanup.
AWK_SCRIPT=$(dirname $0)/php_cleanup.awk
[ -r $AWK_SCRIPT ] || exit 0
## Create the temporary file for output.
TEMP_FILE=$(mktemp)
## Run the clean up of the php.ini file for a production environment.
while getopts pd OPT; do
case $OPT in
p|+p) # In a production environment.
$AWK_SCRIPT -v is_prod=1 $INPUT_FILE | uniq > $TEMP_FILE
;;
d|+d) # In a development environment.
$AWK_SCRIPT $INPUT_FILE | uniq > $TEMP_FILE
;;
*) # Otherwise print a usage message.
print_usage
exit 3
esac
done
shift $(( OPTIND - 1 ))
OPTIND=1
## Move the temporary file to the original one.
mv $TEMP_FILE $INPUT_FILE