forked from paritytech/stateless-blockchain
-
Notifications
You must be signed in to change notification settings - Fork 0
/
substrate-node-rename.sh
executable file
·60 lines (48 loc) · 1.19 KB
/
substrate-node-rename.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
#!/usr/bin/env bash
name=$1
shift
author=$1
shift
if [[ "$name" == "" || "$name" == "-"* ]]
then
echo "Usage: substrate-node-rename <NAME> <AUTHOR>"
exit 1
fi
if [[ "$author" == "" || "$author" == "-"* ]]
then
echo "Usage: substrate-node-rename <NAME> <AUTHOR>"
exit 1
fi
lname="$(echo $name | tr '[:upper:]' '[:lower:]')"
dirname="${lname// /-}"
bold=$(tput bold)
normal=$(tput sgr0)
if [ -d "$dirname" ]; then
echo "Directory '$name' already exists!"
exit 1
fi
echo "${bold}Moving project folder...${normal}"
git mv substrate-node-template $dirname
pushd $dirname >/dev/null
echo "${bold}Customizing project...${normal}"
function replace {
find_this="$1"
shift
replace_with="$1"
shift
IFS=$'\n'
TEMP=$(mktemp -d "${TMPDIR:-/tmp}/.XXXXXXXXXXXX")
rmdir $TEMP
for item in `find . -not -path '*/\.*' -type f \( -name "*.rs" -o -name "*.md" -o -name "build.sh" -o -name "Cargo.toml" -o -name "Cargo.lock" \)`
do
sed "s/$find_this/$replace_with/g" "$item" > $TEMP
cat $TEMP > "$item"
done
rm -f $TEMP
}
replace "Template Node" "${name}"
replace node-template "${lname//[_ ]/-}"
replace node_template "${lname//[- ]/_}"
replace Anonymous "$author"
echo "Rename Complete"
popd >/dev/null