From 35c18a1364c8e052c4cd85c3e21466fd8c2105df Mon Sep 17 00:00:00 2001 From: rzadp Date: Tue, 20 Aug 2024 18:43:59 +0200 Subject: [PATCH] first steps --- .github/workflows/check-getting-started.yml | 23 ++++++ scripts/getting-started.sh | 80 ++++++++++++++------- 2 files changed, 78 insertions(+), 25 deletions(-) create mode 100644 .github/workflows/check-getting-started.yml diff --git a/.github/workflows/check-getting-started.yml b/.github/workflows/check-getting-started.yml new file mode 100644 index 0000000000000..cb589fb097acd --- /dev/null +++ b/.github/workflows/check-getting-started.yml @@ -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 diff --git a/scripts/getting-started.sh b/scripts/getting-started.sh index ce69b7ac6e3af..d4d74c96b4bff 100755 --- a/scripts/getting-started.sh +++ b/scripts/getting-started.sh @@ -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) @@ -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) @@ -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 </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 @@ -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." @@ -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 @@ -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." @@ -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