#!/bin/bash # To be able to use the script it must be made executable: # chmod +x CopyBoilerplate.sh # # Call of the script: # ~/CopyBoilerplate.sh cloneInSameFolder=false # Clone via SSH or HTTPS? cloneType="HTTPS" # Name of your Boilerplate (username/name) BoilerplateRepo="jonnitto/Boilerplate" yellowStyle="$(tput setaf 11)" headlineStyle="$(tput bold)$(tput setaf 15)" redStyle="$(tput setaf 9)" greenStyle="$(tput setaf 10)" resetStyle="$(tput sgr0)" prompt() { echo echo $1 echo -n "» " read inputvalue } echoStatus() { echo echo echo "-----[" $1 "]-----" echo } echoError() { echo echo echo ${redStyle}$1${resetStyle} echo } exitInstall() { echo echo echoStatus "${yellowStyle}No actions were taken${resetStyle}" echo echo exit 1 } testFolder() { if [ "$cloneInSameFolder" = true ] ; then if [ "$(ls -A)" ] ; then echoError "The current folder must be empty" exit 0 fi fi } setRepoName() { Please specify the URL of the empty repository prompt "Please enter the URL of the ${yellowStyle}empty repository${resetStyle} (e. g. https://github.com/jonnitto/WebsiteCom)" case $inputvalue in exit|Exit|EXIT|abort|stop|ABORT|STOP) exitInstall ;; *) # String prüfen if echo "$inputvalue" | grep -q "\.git$" ; then echoError "Please specify the URL without .git" setRepoName elif echo "$inputvalue" | grep -q "\/$" ; then echoError "Please specify name without a slash (/) at the end" setRepoName elif echo "$inputvalue" | grep -q "^https:\/\/github\.com" ; then export REPO_URL=${inputvalue} export REPO_URL_PLAIN="${inputvalue/https:\/\/github.com\//}" export REPO_NAME="${REPO_URL_PLAIN#*\/}" if [ "$cloneInSameFolder" = true ] ; then export REPO_FOLDER="." else export REPO_FOLDER=$REPO_NAME fi else echoError "Please provide complete URL (including https://github.com)" setRepoName fi ;; esac } copyBoilerplate() { if [ "$cloneType" = "HTTPS" ] ; then git clone https://github.com/${BoilerplateRepo}.git ${REPO_FOLDER} elif [ "$cloneType" = "SSH" ] ; then git clone git@github.com:${BoilerplateRepo}.git ${REPO_FOLDER} fi cd ${REPO_FOLDER} && rm -rf .git } initGit() { git init if [ "$cloneType" = "HTTPS" ] ; then git remote add origin https://github.com/${REPO_URL_PLAIN}.git elif [ "$cloneType" = "SSH" ] ; then git remote add origin git@github.com:${REPO_URL_PLAIN}.git fi git fetch if [ "$(find .git/objects -type f)" ] ; then echoError "Please specify empty repository" if [ "$cloneInSameFolder" = true ] ; then rm -rf ..?* .[!.]* * else cd .. rm -rf ${REPO_FOLDER} fi exit 0 else git add . git commit -m "TASK: Copy from Boilerplate" git push -u origin master fi } installComponents() { composer update yarn } cloneFeedback() { echo echo echo echoStatus "${greenStyle}Copy boilerplate with ${cloneType}${resetStyle}" } cloneActions() { clear testFolder cloneFeedback setRepoName copyBoilerplate initGit installComponents } cloneActions exit 0