-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathsubstrate-node-new
executable file
·102 lines (83 loc) · 2.35 KB
/
substrate-node-new
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
#!/usr/bin/env bash
set -eo pipefail
COLOR_WHITE=$(tput setaf 7);
COLOR_MAGENTA=$(tput setaf 5);
FONT_BOLD=$(tput bold);
FONT_NORMAL=$(tput sgr0);
echo
echo -e "$COLOR_WHITE $FONT_BOLD Substrate Node Template Setup $FONT_NORMAL";
name=$1
shift
author=$1
shift
if [[ "$name" == "" || "$name" == "-"* ]]
then
echo " Usage: substrate-node-new <NAME> <AUTHOR>"
echo
exit 1
fi
if [[ "$author" == "" || "$author" == "-"* ]]
then
echo " Usage: substrate-node-new <NAME> <AUTHOR>"
echo
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!"
echo
exit 1
fi
echo "${bold} Downloading project...${normal}"
curl http://releases.parity.io/substrate/x86_64-debian:stretch/latest-v1.0/substrate-node-template.tar.gz | tar xz
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 . -type f`
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 "${bold}Initializing repository...${normal}"
git init 2>/dev/null >/dev/null
cat >.gitignore <<EOL
# Generated by Cargo
# will have compiled files and executables
**/target/
# These are backup files generated by rustfmt
**/*.rs.bk
EOL
git add * .gitignore 2>/dev/null >/dev/null
git commit -a -m "Initial clone from template node" 2>/dev/null >/dev/null
echo "${bold}Initializing WebAssembly build environment...${normal}"
./scripts/init.sh 2>/dev/null >/dev/null
./scripts/build.sh
echo "${bold}Building node...${normal}"
cargo build --release
echo
echo "${bold}Chain client created in ${dirname}${normal}."
echo "To start a dev chain, run:"
echo "$ $dirname/target/release/${lname//[_ ]/-} --dev"
echo "To create a basic Bonds UI for your chain, run:"
echo "$ substrate-ui-new $name"
echo "To push to a newly created GitHub repository, inside ${dirname}, run:"
echo "$ git remote add origin git@github.com:myusername/myprojectname && git push -u origin master"
echo
popd >/dev/null