-
Notifications
You must be signed in to change notification settings - Fork 3
/
rename_roll.sh
executable file
·119 lines (97 loc) · 3.2 KB
/
rename_roll.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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#!/bin/bash
# This script replaces all instances of the 'old' name of this roll template with
# a 'new' roll name. It changes file/directory names as well as the contents of
# the files inside this template roll.
usage () {
echo "$(basename "$0") -n newname [-c curname] [-h] -- program to rename the roll template
where:
-h show this help text
-n where newname is the new name for the roll
-c where curname is the current name of the roll"
}
CURNAME=
NEWNAME=
options='hn:c:'
while getopts $options option
do
case "$option" in
c ) CURNAME=$OPTARG;;
n ) NEWNAME=$OPTARG;;
h ) usage; exit;;
\? ) printf "unknown option: -%s\n" "$OPTARG" >&2; usage >&2; exit 1;;
: ) printf "missing argument for -%s\n" "$OPTARG" >&2; usage >&2; exit 1;;
* ) printf "unimplemented optio: -%s\n" "$OPTARG" >&2; usage >&2; exit 1;;
esac
done
shift $((OPTIND - 1))
# You 'must' supply a new roll name'
if [[ -z $NEWNAME ]]
then
usage
exit 1
fi
# If -c option is not specified determine it from graph file.
if [[ -z $CURNAME ]]
then
CURNAME=$(basename `ls graphs/default/*.xml` | cut -d. -f1)
fi
echo "Renaming ${CURNAME} roll to ${NEWNAME}"
ROOT=$(pwd)
echo " Changing directory names..."
DIRS=$(find . -depth -type d | grep $CURNAME)
for d in ${DIRS}
do
if [ -d ${d} ]; then
newd=$(echo ${d} | sed "s,\(.*\)"${CURNAME}"\(.*\),\1"${NEWNAME}"\2,g")
mv ./${d} ./${newd};
fi
done
cd ${ROOT}
echo " Changing file names..."
FILES=$(find . -depth -type f | grep ${CURNAME})
for f in ${FILES}
do
if [ -f ${f} ]; then
newf=$(echo ${f} | sed "s,"${CURNAME}","${NEWNAME}",g");
mv ./${f} ./${newf};
fi
done
cd ${ROOT}
echo " Changing file contents...."
FILES=`find . -depth -type f | egrep -v "rename_roll.sh"`
for f in ${FILES}
do
sed -i "s,"${CURNAME}","${NEWNAME}",g" ./${f}
done
cd ${ROOT}
echo " Removing .git directories..."
DIRS=$(find . -depth -type d -iname ".git")
for d in ${DIRS}
do
if [ -d ${d} ]; then
/bin/rm -rf ./${d};
fi
done
cd ${ROOT}
cat << EOF
The following steps are now required after using ./rename_roll.sh...
- Download or otherwise create src/${NEWNAME}/${NEWNAME}-1.0.tgz
- Upload src/${NEWNAME}/${NEWNAME}-1.0.tgz to the DL.SERVER listed in
src/${NEWNAME}/pull.mk
- Record size and git hash of src/${NEWNAME}/${NEWNAME}-1.0.tgz in
src/${NEWNAME}/binary_hashes per the instructions in src/${NEWNAME}/README.md
- Perform the desired [optional] steps listed below
- Initialize the new git repository
- Make at least one commit to the new repository
- Add annotated tags for the supported Rocks versions to the new repository
so that version.sh will provide a 'sensible' version number for the new
roll.
While not required, you should rename this directory ${NEWNAME}-roll to avoid
confusion and, optionally, perform the following additional changes...
- Remove USING.md, rename_roll.sh and src/${NEWNAME}/README.md
- [Optionally] move gen_hash.sh to a new location (ie. ~/bin) or remove it.
- If you are not going to populate the default Rocks usersguide then remove
the entire src/usersguide directory and remove the
<package>roll-${NEWNAME}-usersguide</package> entry from nodes/${NEWNAME}-base.xml
EOF
exit 0