#!/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 " echo exit 1 fi if [[ "$author" == "" || "$author" == "-"* ]] then echo " Usage: substrate-node-new " 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/2.0.0-6653043/substrate/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 </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 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