You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
168 lines
4.4 KiB
168 lines
4.4 KiB
# This bash script installs ao-cli and its prerequisites: Node.JS (npm, nvm, node), as well as curl, grep, and git |
|
# This script is hosted in the ao-cli repository, so ao-cli can always be installed with: |
|
# curl -L http://git.coalitionofinvisiblecolleges.org/autonomousorganization/ao-cli/raw/branch/main/bootstrap.sh | 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 |
|
|
|
# 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 grep |
|
if [ $(dpkg-query -W -f='${Status}' git 2>/dev/null | grep -c "ok installed") -eq 1 ]; then |
|
echo grep already installed |
|
else |
|
sudo apt install -y grep |
|
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 |
|
|
|
# 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 |
|
|
|
# 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 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 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 |
|
npm install -g npm # why doesn't the npm install script install the current version? |
|
fi |
|
|
|
# install ao-cli official current version via npm |
|
npm i -g @autonomousorganization/ao-cli |
|
|
|
echo ao-cli is installed |
|
|
|
ao-cli |