From 4e1734cccda339210372f08d7c6b02330025475f Mon Sep 17 00:00:00 2001 From: Shawn Tabrizi Date: Mon, 30 Sep 2019 22:55:07 +0200 Subject: [PATCH] Revert "Delete substrate-node-rename.sh" This reverts commit 5cd3d42aeddb203f4f18aa6f64195df90e5edb07. --- substrate-node-rename.sh | 61 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100755 substrate-node-rename.sh diff --git a/substrate-node-rename.sh b/substrate-node-rename.sh new file mode 100755 index 0000000..2d20b84 --- /dev/null +++ b/substrate-node-rename.sh @@ -0,0 +1,61 @@ +#!/usr/bin/env bash + +name=$1 +shift +author=$1 +shift + +if [[ "$name" == "" || "$name" == "-"* ]] +then + echo "Usage: substrate-node-rename " + exit 1 +fi +if [[ "$author" == "" || "$author" == "-"* ]] +then + echo "Usage: substrate-node-rename " + 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!" + exit 1 +fi + +echo "${bold}Moving project folder...${normal}" + +git 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 . -not -path '*/\.*' -type f \( -name "*.rs" -o -name "*.md" -o -name "build.sh" -o -name "Cargo.toml" -o -name "Cargo.lock" \)` + 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 "Rename Complete" + +popd >/dev/null +