Skip to content

Instantly share code, notes, and snippets.

@psilore
Last active June 25, 2022 12:59
Show Gist options
  • Save psilore/a19e6f883f53dd0f366afd16ae4f17a2 to your computer and use it in GitHub Desktop.
Save psilore/a19e6f883f53dd0f366afd16ae4f17a2 to your computer and use it in GitHub Desktop.
Install script for repository with submodules and test for Git and Node

Install cmd with bash

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/<reponame>/install/HEAD/install.sh)"

install.sh

#!/bin/bash


# Prerequisites
# Test if node is installed, if not installed ask to install node
# Test if Git is installed, if not installed ask to install Git

# Explain what this script does and will do when executed, present an option to escape

USER="some-username"
REPONAME="some-repo-name"
REPOURL="git@github.com:${USER}/${REPONAME}.git"

# Functions


show_banner() {
	clear
  printf "
  __  __                   _                   
 |  \/  |   ___    _ __   | | __   ___   _ 
 | |\/| |  / _ \  | '_ \  | |/ /  / _ \ | |
 | |  | | | (_) | | | | | |   <  |  __/ | |
 |_|  |_|  \___/  |_| |_| |_|\_\  \___| |_|
                                         
Install helper script. Fuck around and find out\n"
}

check() {
  stty -echo && tput civis
  task_1 output1
  task_2 output2
  tput el

  echo "$output1"
  echo "$output2"
  tput cnorm && stty echo
}
task_1() {
    which type node> /dev/null
    if [ $? -eq 0 ]
    then
        printf '\xE2\x9C\x94 Node has already been installed.\n'
    else
        printf '%b\n' "\033[1m"Note!"\033[0m Node js is required to run the tools!"
        echo "How to install Node.js - https://nodejs.dev/learn/how-to-install-nodejs"
        exit;
    fi
}
task_2() {
    which type git> /dev/null
    if [ $? -eq 0 ]
    then
        printf '\xE2\x9C\x94 Git has already been installed.\n'
        task_3
    else
        printf '%b\n' "\033[1m"Note!"\033[0m Git is NOT required, but if you want to contribute to the docs you will need Git, eventually!"
        echo "How to install Git - https://git-scm.com/book/en/v2/Getting-Started-Installing-Git"
        exit;
    fi
}
task_3() {
    # clone repo
    # change to cloned repo directory 
    # update submodules in repo
    git clone $REPOURL
    cd $REPONAME
    sleep 2
    git submodule update --init --recursive
    $SHELL
    printf "MacOS maybe? - \360\237\246\204\n"
}
cleanup() {
    cd ..
    rm -rf $REPONAME
}
# Script

while true; do
    show_banner
    # Fix compatibillity in other shells/OS for coprocess/bash
    read -p "This script will check if reqiured tools is installed. Continue? (y/n)" yn
    case $yn in
        [Yy]* ) check; break;;
        [Nn]* ) exit 0;;
        * ) echo "Please answer yes or no.";;
    esac
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment