Skip to content

Commit

Permalink
first steps
Browse files Browse the repository at this point in the history
  • Loading branch information
rzadp committed Aug 20, 2024
1 parent 2f2640f commit 35c18a1
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 25 deletions.
23 changes: 23 additions & 0 deletions .github/workflows/check-getting-started.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Check the getting-started.sh script

on:
push:
branches:
- rzadp/getting-started
merge_group:

jobs:
check-getting-started:
runs-on: ubuntu-latest
steps:
- name: Install prerequisites
run: |
apt update
apt install -y expect
- name: Check the script
run: |
cat << EOF | expect -f -
spawn bash scripts/getting-started.sh
expect "Detected Ubuntu"
EOF
timeout-miuntes: 3
80 changes: 55 additions & 25 deletions scripts/getting-started.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ set -e

prompt() {
while true; do
echo -e "$1 [y/N]"
printf "$1 [y/N]\n"
read yn
case $yn in
[Yy]* ) return 0;; # Yes, return 0 (true)
Expand All @@ -17,7 +17,7 @@ prompt() {

prompt_default_yes() {
while true; do
echo -e "$1 [Y/n]"
printf "$1 [Y/n]\n"
read yn
case $yn in
[Yy]* ) return 0;; # Yes, return 0 (true)
Expand All @@ -28,6 +28,17 @@ prompt_default_yes() {
done
}

clone_and_enter_template() {
template="$1" # minimal, solochain, or parachain
if [ -d "${template}-template" ]; then
printf "\n✅︎ ${template}-template directory already exists. -> Entering.\n"
else
printf "\n↓ Let's grab the ${template} template from github.\n"
git clone https://github.com/paritytech/polkadot-sdk-${template}-template.git ${template}-template
fi
cd ${template}-template
}

cat <<EOF
Welcome to the
Expand All @@ -39,7 +50,7 @@ cat <<EOF
| \__/ |__/| \_/\_/|_/\_/|_/\__/ |_/ |____/|____/|_|\_\
quickstart!
⚡ We will be setting up an example template and its environment for you to experiment with.
⚡ We will help setting up the environment for you to experiment with.
EOF

# Determine OS
Expand All @@ -49,9 +60,9 @@ if [ "$os_name" = "Darwin" ]; then

# Check if brew is installed
if command -v brew >/dev/null 2>&1; then
echo -e "\n✅︎🍺 Homebrew already installed."
printf "\n✅︎🍺 Homebrew already installed.\n"
else
if prompt_default_yes "\n🍺 Homebrew is not installed. Install it?"; then
if prompt_default_yes "\n🍺 Homebrew is not installed. Install it?\n"; then
echo "🍺 Installing Homebrew."
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
else
Expand All @@ -62,9 +73,9 @@ if [ "$os_name" = "Darwin" ]; then

brew update
if command -v git >/dev/null 2>&1; then
echo -e "\n✅︎🍺 git already installed."
printf "\n✅︎🍺 git already installed.\n"
else
if prompt_default_yes "\n🍺 git seems to be missing but we will need it; install git?"; then
if prompt_default_yes "\n🍺 git seems to be missing but we will need it; install git?\n"; then
brew install git
else
echo "❌ Cannot continue without git. Aborting."
Expand All @@ -82,24 +93,26 @@ elif [ "$os_name" = "Linux" ]; then
distro=$( cat /etc/*-release | tr '[:upper:]' '[:lower:]' | grep -Poi '(debian|ubuntu|arch|fedora|opensuse)' | uniq | head -n 1 )

if [ "$distro" = "ubuntu" ]; then
echo -e "\n🐧 Detected Ubuntu. Using apt to install dependencies."
sudo apt install --assume-yes git clang curl libssl-dev protobuf-compiler
printf "\n🐧 Detected Ubuntu. Using apt to install dependencies.\n"
sudo apt -qq update
sudo apt -qq install --assume-yes git clang curl libssl-dev protobuf-compiler
elif [ "$distro" = "debian" ]; then
echo -e "\n🐧 Detected Debian. Using apt to install dependencies."
sudo apt install --assume-yes git clang curl libssl-dev llvm libudev-dev make protobuf-compiler
printf "\n🐧 Detected Debian. Using apt to install dependencies.\n"
sudo apt -qq update
sudo apt -qq install --assume-yes git clang curl libssl-dev llvm libudev-dev make protobuf-compiler
elif [ "$distro" = "arch" ]; then
echo -e "\n🐧 Detected Arch Linux. Using pacman to install dependencies."
printf "\n🐧 Detected Arch Linux. Using pacman to install dependencies.\n"
pacman -Syu --needed --noconfirm curl git clang make protobuf
elif [ "$distro" = "fedora" ]; then
echo -e "\n🐧 Detected Fedora. Using dnf to install dependencies."
printf "\n🐧 Detected Fedora. Using dnf to install dependencies.\n"
sudo dnf update
sudo dnf install clang curl git openssl-devel make protobuf-compiler
elif [ "$distro" = "opensuse" ]; then
echo -e "\n🐧 Detected openSUSE. Using zypper to install dependencies."
printf "\n🐧 Detected openSUSE. Using zypper to install dependencies.\n"
sudo zypper install clang curl git openssl-devel llvm-devel libudev-devel make protobuf
else
if prompt "\n🐧 Unknown Linux distribution. Unable to install dependencies. Continue anyway?"; then
echo -e "\n🐧 Proceeding with unknown linux distribution..."
if prompt "\n🐧 Unknown Linux distribution. Unable to install dependencies. Continue anyway?\n"; then
printf "\n🐧 Proceeding with unknown linux distribution...\n"
else
exit 1
fi
Expand All @@ -111,7 +124,7 @@ fi

# Check if rust is installed
if command -v rustc >/dev/null 2>&1; then
echo -e "\n✅︎🦀 Rust already installed."
printf "\n✅︎🦀 Rust already installed.\n"
else
if prompt_default_yes "\n🦀 Rust is not installed. Install it?"; then
echo "🦀 Installing via rustup."
Expand All @@ -131,17 +144,34 @@ if prompt_default_yes "\n🦀 Setup the Rust environment (e.g. WASM support)?";
rustup component add rust-src
fi

if [ -d "minimal-template" ]; then
echo -e "\n✅︎ minimal-template directory already exists. -> Entering."
else
echo -e "\n↓ Let's grab the minimal template from github."
git clone https://github.com/paritytech/polkadot-sdk-minimal-template.git minimal-template
if ! prompt "\nWould you like to start with one of the templates?"; then
echo "⚡ All done, the environment is ready for hacking."
exit 0
fi

while true; do
printf "\nWhich template would you like to start with?\n"
echo "1) minimal template"
echo "2) parachain template"
echo "3) solochain template"
echo "q) cancel"
read -p "#? " template
case $template in
[1]* ) clone_and_enter_template minimal; break;;
[2]* ) clone_and_enter_template parachain; break;;
[3]* ) clone_and_enter_template solochain; break;;
[qQ]* ) echo "Canceling, not using a template."; exit 0;;
* ) echo "Selection not recognized.";;
esac
done

if ! prompt_default_yes "\n⚙️ Let's compile the node? It might take a while."; then
echo "⚡ Script finished, you can continue in the ${template}-template directory."
exit 0
fi
cd minimal-template

echo -e "\n⚙️ Let's compile the node."
cargo build --release

if prompt_default_yes "\n🚀 Everything ready to go, let's run the node?"; then
if prompt_default_yes "\n🚀 Everything ready to go, let's run the node?\n"; then
cargo run --release -- --dev
fi

0 comments on commit 35c18a1

Please sign in to comment.