4
4
5
5
prompt () {
6
6
while true ; do
7
- echo -e " $1 [y/N]"
7
+ printf " $1 [y/N]\n "
8
8
read yn
9
9
case $yn in
10
10
[Yy]* ) return 0;; # Yes, return 0 (true)
@@ -17,7 +17,7 @@ prompt() {
17
17
18
18
prompt_default_yes () {
19
19
while true ; do
20
- echo -e " $1 [Y/n]"
20
+ printf " $1 [Y/n]\n "
21
21
read yn
22
22
case $yn in
23
23
[Yy]* ) return 0;; # Yes, return 0 (true)
@@ -28,6 +28,17 @@ prompt_default_yes() {
28
28
done
29
29
}
30
30
31
+ clone_and_enter_template () {
32
+ template=" $1 " # minimal, solochain, or parachain
33
+ if [ -d " ${template} -template" ]; then
34
+ printf " \n✅︎ ${template} -template directory already exists. -> Entering.\n"
35
+ else
36
+ printf " \n↓ Let's grab the ${template} template from github.\n"
37
+ git clone https://github.com/paritytech/polkadot-sdk-${template} -template.git ${template} -template
38
+ fi
39
+ cd ${template} -template
40
+ }
41
+
31
42
cat << EOF
32
43
33
44
Welcome to the
@@ -39,7 +50,7 @@ cat <<EOF
39
50
| \__/ |__/| \_/\_/|_/\_/|_/\__/ |_/ |____/|____/|_|\_\
40
51
quickstart!
41
52
42
- ⚡ We will be setting up an example template and its environment for you to experiment with.
53
+ ⚡ We will help setting up the environment for you to experiment with.
43
54
EOF
44
55
45
56
# Determine OS
@@ -49,9 +60,9 @@ if [ "$os_name" = "Darwin" ]; then
49
60
50
61
# Check if brew is installed
51
62
if command -v brew > /dev/null 2>&1 ; then
52
- echo -e " \n✅︎🍺 Homebrew already installed."
63
+ printf " \n✅︎🍺 Homebrew already installed.\n "
53
64
else
54
- if prompt_default_yes " \n🍺 Homebrew is not installed. Install it?" ; then
65
+ if prompt_default_yes " \n🍺 Homebrew is not installed. Install it?\n " ; then
55
66
echo " 🍺 Installing Homebrew."
56
67
/bin/bash -c " $( curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh) "
57
68
else
@@ -62,9 +73,9 @@ if [ "$os_name" = "Darwin" ]; then
62
73
63
74
brew update
64
75
if command -v git > /dev/null 2>&1 ; then
65
- echo -e " \n✅︎🍺 git already installed."
76
+ printf " \n✅︎🍺 git already installed.\n "
66
77
else
67
- if prompt_default_yes " \n🍺 git seems to be missing but we will need it; install git?" ; then
78
+ if prompt_default_yes " \n🍺 git seems to be missing but we will need it; install git?\n " ; then
68
79
brew install git
69
80
else
70
81
echo " ❌ Cannot continue without git. Aborting."
@@ -82,24 +93,26 @@ elif [ "$os_name" = "Linux" ]; then
82
93
distro=$( cat /etc/* -release | tr ' [:upper:]' ' [:lower:]' | grep -Poi ' (debian|ubuntu|arch|fedora|opensuse)' | uniq | head -n 1 )
83
94
84
95
if [ " $distro " = " ubuntu" ]; then
85
- echo -e " \n🐧 Detected Ubuntu. Using apt to install dependencies."
86
- sudo apt install --assume-yes git clang curl libssl-dev protobuf-compiler
96
+ printf " \n🐧 Detected Ubuntu. Using apt to install dependencies.\n"
97
+ sudo apt -qq update
98
+ sudo apt -qq install --assume-yes git clang curl libssl-dev protobuf-compiler
87
99
elif [ " $distro " = " debian" ]; then
88
- echo -e " \n🐧 Detected Debian. Using apt to install dependencies."
89
- sudo apt install --assume-yes git clang curl libssl-dev llvm libudev-dev make protobuf-compiler
100
+ printf " \n🐧 Detected Debian. Using apt to install dependencies.\n"
101
+ sudo apt -qq update
102
+ sudo apt -qq install --assume-yes git clang curl libssl-dev llvm libudev-dev make protobuf-compiler
90
103
elif [ " $distro " = " arch" ]; then
91
- echo -e " \n🐧 Detected Arch Linux. Using pacman to install dependencies."
104
+ printf " \n🐧 Detected Arch Linux. Using pacman to install dependencies.\n "
92
105
pacman -Syu --needed --noconfirm curl git clang make protobuf
93
106
elif [ " $distro " = " fedora" ]; then
94
- echo -e " \n🐧 Detected Fedora. Using dnf to install dependencies."
107
+ printf " \n🐧 Detected Fedora. Using dnf to install dependencies.\n "
95
108
sudo dnf update
96
109
sudo dnf install clang curl git openssl-devel make protobuf-compiler
97
110
elif [ " $distro " = " opensuse" ]; then
98
- echo -e " \n🐧 Detected openSUSE. Using zypper to install dependencies."
111
+ printf " \n🐧 Detected openSUSE. Using zypper to install dependencies.\n "
99
112
sudo zypper install clang curl git openssl-devel llvm-devel libudev-devel make protobuf
100
113
else
101
- if prompt " \n🐧 Unknown Linux distribution. Unable to install dependencies. Continue anyway?" ; then
102
- echo -e " \n🐧 Proceeding with unknown linux distribution..."
114
+ if prompt " \n🐧 Unknown Linux distribution. Unable to install dependencies. Continue anyway?\n " ; then
115
+ printf " \n🐧 Proceeding with unknown linux distribution...\n "
103
116
else
104
117
exit 1
105
118
fi
111
124
112
125
# Check if rust is installed
113
126
if command -v rustc > /dev/null 2>&1 ; then
114
- echo -e " \n✅︎🦀 Rust already installed."
127
+ printf " \n✅︎🦀 Rust already installed.\n "
115
128
else
116
129
if prompt_default_yes " \n🦀 Rust is not installed. Install it?" ; then
117
130
echo " 🦀 Installing via rustup."
@@ -131,17 +144,34 @@ if prompt_default_yes "\n🦀 Setup the Rust environment (e.g. WASM support)?";
131
144
rustup component add rust-src
132
145
fi
133
146
134
- if [ -d " minimal-template" ]; then
135
- echo -e " \n✅︎ minimal-template directory already exists. -> Entering."
136
- else
137
- echo -e " \n↓ Let's grab the minimal template from github."
138
- git clone https://github.com/paritytech/polkadot-sdk-minimal-template.git minimal-template
147
+ if ! prompt " \nWould you like to start with one of the templates?" ; then
148
+ echo " ⚡ All done, the environment is ready for hacking."
149
+ exit 0
150
+ fi
151
+
152
+ while true ; do
153
+ printf " \nWhich template would you like to start with?\n"
154
+ echo " 1) minimal template"
155
+ echo " 2) parachain template"
156
+ echo " 3) solochain template"
157
+ echo " q) cancel"
158
+ read -p " #? " template
159
+ case $template in
160
+ [1]* ) clone_and_enter_template minimal; break ;;
161
+ [2]* ) clone_and_enter_template parachain; break ;;
162
+ [3]* ) clone_and_enter_template solochain; break ;;
163
+ [qQ]* ) echo " Canceling, not using a template." ; exit 0;;
164
+ * ) echo " Selection not recognized." ;;
165
+ esac
166
+ done
167
+
168
+ if ! prompt_default_yes " \n⚙️ Let's compile the node? It might take a while." ; then
169
+ echo " ⚡ Script finished, you can continue in the ${template} -template directory."
170
+ exit 0
139
171
fi
140
- cd minimal-template
141
172
142
- echo -e " \n⚙️ Let's compile the node."
143
173
cargo build --release
144
174
145
- if prompt_default_yes " \n🚀 Everything ready to go, let's run the node?" ; then
175
+ if prompt_default_yes " \n🚀 Everything ready to go, let's run the node?\n " ; then
146
176
cargo run --release -- --dev
147
177
fi
0 commit comments