-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathconsole.sh
90 lines (76 loc) · 1.92 KB
/
console.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/bin/sh
set -e
if [ "$#" -lt '1' -o "$1" != 'enable' -a "$1" != 'disable' ]; then
cat <<EOF
Usage: $(basename $0) STATE [file]
Where STATE is either 'enable' or 'disable'.
file is optional. By default, file is content/console.js.
This script will enable or disable the IGN++ console by (un)commenting code.
Public builds must have it disabled to pass Mozilla review.
The file should look something like this for this to work:
//CONSOLE START
// /*
...console stuff here...
//CONSOLE END
// */
EOF
exit 0
fi
if [ "$#" -lt '2' ]; then
confile='content/console.js'
else
confile="$2"
fi
# returns a sed script for finding the start and end tags
# returns to variable $sedret
# $1 - "START" or "END"
# $2 - provide if you want to replace, "enable" or "disable"
get_sed() {
if [ "$1" == 'START' ]; then
local mcomment='/\*'
local rcomment='/*'
else
local mcomment='\*/'
local rcomment='*/'
fi
if [ "$#" -lt '2' ]; then
local command="\\"
local post='p'
else
local command='s'
if [ "$2" == 'enable' ]; then
local slashes='// '
else
local slashes=''
fi
local post='\
'"$slashes$rcomment"'_'
fi
#underscores are always used for the delimiter
#since we're dealing with a lot of slashes
sedret='\_//CONSOLE '"$1"'_{
#append the next line to the pattern space
N
#search for "/*", "///*", "// /*", etc on the next line
'"$command"'_\n\(//\s*\)\?'"$mcomment"'_'"$post"'
}'
}
get_sed START
start=$(sed -n "$sedret" "$confile")
get_sed END
end=$(sed -n "$sedret" "$confile")
#make sure both the start and end tags exist
#if we don't check, we run the risk of breaking everything
if [ "$start" != '' -a "$end" != '' ]; then
get_sed START "$1"
startsed="$sedret"
get_sed END "$1"
endsed="$sedret"
sed -e "$startsed" -e "$endsed" "$confile" > "$confile.new"
cp "$confile.new" "$confile"
rm "$confile.new"
echo "Console $1d in $confile"
else
echo 'Start or end tag not found, file not altered'
exit 1
fi