From d68a8bbfba075d3e720a80aa9268cf68849966bc Mon Sep 17 00:00:00 2001 From: deicidus <> Date: Fri, 22 Jul 2022 13:34:53 -0700 Subject: [PATCH] added bootstrap script for installing when Node is not already installed --- bootstrap.sh | 204 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 204 insertions(+) create mode 100755 bootstrap.sh diff --git a/bootstrap.sh b/bootstrap.sh new file mode 100755 index 0000000..768a96e --- /dev/null +++ b/bootstrap.sh @@ -0,0 +1,204 @@ +# This bash script installs ao-cli and its prerequisites: Node.JS (npm, nvm, node) +# This script is hosted in the ao-cli repository, so ao-cli can always be installed with: +# curl -L https://git.coalitionofinvisiblecolleges.org/autonomousorganization/ao-cli/raw/branch/main/bootstrap.js | sh + +# detect OS +if [ -f "/etc/debian_version" ]; then + DISTRO="debian" + echo "Debian, Ubuntu, or Raspbian OS detected, proceeding with Debian-compatible ao-cli installation." +elif [ -f "/etc/arch-release" ]; then + DISTRO="arch" + echo Arch- or Manjaro-based OS detected, proceeding with Arch-compatible ao-cli installation. +elif [ -f "/etc/fedora-release" ]; then + DISTRO="fedora" + echo Fedora-based OS detected, proceeding with Fedora-compatible ao-cli installation. + + # Defining helper function + function install_if_needed() { + for package in "$@" + do + if [ $(which $package) ]; then + echo $package already installed + else + sudo dnf install -y $package + fi + done + } + +elif [ $(uname | grep -c "Darwin") -eq 1 ]; then + DISTRO="mac" + echo MacOS detected, proceeding with Mac-compatible ao-cli installation. +else + echo Could not detect your OS distribution. Running this script could make a mess, so installing manually is recommended. + exit 1 +fi + +echo Updating your system... + +# update system and install prereqs (Debian) +if [ "$DISTRO" = "debian" ]; then + # update + sudo apt update -yqqq 2>/dev/null + sudo apt autoremove -yqqq + echo apt update complete + + # upgrade + sudo apt upgrade -yqqq + echo apt upgrade complete + + # more cleanup + #sudo apt-get dist-upgrade -yqqq + #sudo apt-get clean -yqqq + #sudo apt-get autoclean -yqqq + + # check for sudo install and fail if not + + # install curl + if [ $(dpkg-query -W -f='${Status}' curl 2>/dev/null | grep -c "ok installed") -eq 1 ]; then + echo curl already installed + else + sudo apt install -y curl + fi + + # install wget + if [ $(dpkg-query -W -f='${Status}' wget 2>/dev/null | grep -c "ok installed") -eq 1 ]; then + echo wget already installed + else + sudo apt install -y wget + fi + + # install git + if [ $(dpkg-query -W -f='${Status}' git 2>/dev/null | grep -c "ok installed") -eq 1 ]; then + echo git already installed + else + sudo apt install -y git + fi + +# update system and install prereqs (Arch) +elif [ "$DISTRO" = "arch" ]; then + # update, but do not automatically clean up for Arch users + sudo pacman -Syu 1>/dev/null + echo pacman update complete + + # todo: detect whether AUR is enabled here and fail if not. might be in /etc/pacman.conf. + + # install curl + if [ $(sudo pacman -Qs curl >/dev/null | grep -c "local/curl" ) -eq 0 ]; then + echo curl already installed + else + sudo pacman -S curl + fi + + # install wget + if [ $(sudo pacman -Qs wget >/dev/null | grep -c "local/wget" ) -eq 0 ]; then + echo wget already installed + else + sudo pacman -S wget + fi + +# update system and install prereqs (Fedora) +elif [ "$DISTRO" = "fedora" ]; then + # update + echo "Updating DNF..." + sudo dnf update -yqqq 2>/dev/null + sudo dnf autoremove -yqqq + echo "Update Complete!" + + # upgrade + echo "Upgrading..." + sudo dnf upgrade -yqqq + echo "Upgrade Complete" + + # install basic dependencies + install_if_needed curl wget git + +elif [ "$DISTRO" = "mac" ]; then + # install homebrew + /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" + + # update + brew update -yqqq 2>/dev/null + sudo apt autoremove -yqqq + echo apt update complete + + # upgrade + sudo apt upgrade -yqqq + echo apt upgrade complete + + # install curl + if [ $(dpkg-query -W -f='${Status}' curl 2>/dev/null | grep -c "ok installed") -eq 1 ]; then + echo curl already installed + else + sudo apt install -y curl + fi + + # install wget + if [ $(dpkg-query -W -f='${Status}' wget 2>/dev/null | grep -c "ok installed") -eq 1 ]; then + echo wget already installed + else + sudo apt install -y wget + fi + + # install git + if [ $(dpkg-query -W -f='${Status}' git 2>/dev/null | grep -c "ok installed") -eq 1 ]; then + echo git already installed + else + sudo apt install -y git + fi +fi + +# install nvm +cd ~ +if [ -f "$HOME/.nvm/nvm.sh" ]; then + . ~/.nvm/nvm.sh +fi + +if [ $(command -v nvm | grep -c "nvm") -eq 1 ]; then + NVMVERSION=`nvm --version` + echo nvm v$NVMVERSION already installed +else + git clone https://github.com/creationix/nvm.git ~/.nvm 2>/dev/null + sudo echo "source ~/.nvm/nvm.sh" >> ~/.bashrc + sudo echo "source ~/.nvm/nvm.sh" >> ~/.profile + source ~/.bashrc + source ~/.profile +fi + +NODEVERSION=`nvm current` + +# install node +if [ $(echo $NODEVERSION | grep -c "16\.") -eq 1 ]; then + echo node $NODEVERSION already installed +else + nvm install 16 #stable + nvm use 16 #stable + nvm alias default 16 #default stable +fi + +# install npm +if [ $(npm --v 2>/dev/null | grep -c "8\.") -eq 1 ]; then + NPMVERSION=`npm -v` + echo npm v$NPMVERSION already installed +else + #curl -L https://www.npmjs.com/install.sh | sh # this line might not be needed + npm install -g npm # why doesn't the npm install script install the current version? +fi + +# clone the ao-cli repository +cd ~ +if find "ao-cli" -mindepth 1 -print -quit 2>/dev/null | grep -q .; then + echo ao-cli git repository already cloned +else + git clone http://git.coalitionofinvisiblecolleges.org:3009/autonomousorganization/ao-cli.git +fi + +# install project dependencies +cd ~/ao-cli + +if [ $(npm list --depth 0 ao-cli | grep -c "@autonomousorganization/ao-cli") -eq 1 ]; then + echo ao-cli node module already installed +else + npm install +fi + +echo ao-cli is installed \ No newline at end of file