-
Notifications
You must be signed in to change notification settings - Fork 13
/
rename-vmod-script
executable file
·49 lines (40 loc) · 1.28 KB
/
rename-vmod-script
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
#!/bin/bash
#
# Script to rename libvmod-example into libvmod-foo.
# (where "foo" is your new vmod name, of course.)
#
# Leaves the changes uncommitted in the working tree, so you get to fix any
# unintended changes.
#
# Author: Lasse Karstensen <[email protected]>, September 2014.
#
set -o errexit
NAME=$1
if [ -z "$NAME" ]; then
echo "Usage: $0 <new-vmod-name-without-libvmod-prefix>"
echo "Rename libvmod-example source tree."
echo "If the name is an acronym, you can use capital letters."
echo
exit -1
fi
SYM_NAME=${NAME,,*}
CAP_NAME=${NAME^?}
UPP_NAME=${NAME^^?}
if ! git diff-index --quiet HEAD --; then
echo "ERROR: Need a clean working tree. Run \"git stash\" first."
exit -2
fi
git mv src/vmod_example.c src/vmod_${SYM_NAME}.c
git mv src/vmod_example.vcc src/vmod_${SYM_NAME}.vcc
git grep -z -l example | xargs -0 sed -i -s -e "s/example/${SYM_NAME}/g"
git grep -z -l Example | xargs -0 sed -i -s -e "s/Example/${CAP_NAME}/g"
git grep -z -l EXAMPLE | xargs -0 sed -i -s -e "s/EXAMPLE/${UPP_NAME}/g"
sed -i '/circleci.com\/gh\/varnishcache\/libvmod-example/d' README.rst
git rm -f rename-vmod-script
# restore foreign files
git checkout -- m4/
cat <<EOF
All done.
For your cut&paste needs:
git commit -a -m "Automatic rename of libvmod-example to libvmod-${SYM_NAME}."
EOF