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.
190 lines
5.1 KiB
190 lines
5.1 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 |
|
|
|
# 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 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 |
|
|
|
# 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 |
|
|
|
# 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 |
|
#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 |