#!/bin/sh # Script for installing the base dependencies of AO and getting it running # Bare Metal Alchemist, 2022 . ingredients/lead source ingredients/copper source ingredients/iron source ingredients/gold clear say '' say ' d8888 .d88888b. 8888888 888 888 888 ' say ' d88888 d88P" "Y88b 888 888 888 888 ' say ' d88P888 888 888 888 888 888 888 ' say ' d88P 888 888 888 888 88888b. .d8888b 888888 8888b. 888 888 .d88b. 888d888 ' say ' d88P 888 888 888 888 888 "88b 88K 888 "88b 888 888 d8P Y8b 888P" ' say ' d88P 888 888 888 888 888 888 "Y8888b. 888 .d888888 888 888 88888888 888 ' say ' d8888888888 Y88b. .d88P 888 888 888 X88 Y88b. 888 888 888 888 Y8b. 888 ' say 'd88P 888 "Y88888P" 8888888 888 888 88888P" "Y888 "Y888888 888 888 "Y8888 888 ' say '' # ------------------- Step 1 - Baseline Setup ------------------- say "${BOLD}Hiya!${RESET} We're going to get you set up with your very own Autonomous Engine." say "" say "This script is designed to ask you just enough questions to keep you involved in the process," say "while making it as easy as possible for you to get it going." say "" ask_for nothing "${BLUE}press enter to continue${RESET}" if ! id -u > /dev/null; then say "${RED}Woah there!${RESET} Seems you're running this script as a superuser." say "" say "That might cause some issues with permissions and whatnot. Run this script as your default user (without sudo) and I'll ask you when I need superuser permissions" say "" exit 1 fi # TODO: dependencies should not be frontloaded, they should be installed as needed say "Making sure we've got the basics..." say "(you'll probably need to input ${BLUE}your 'sudo' password${RESET} here)" case $DISTRO in "debian") # Note -- I'm not sure if these are all needed but I'm not in the mood to check install_if_needed git wget sqlite3 zlib1g-dev libtool-bin autoconf autoconf-archive automake autotools-dev \ libgmp-dev libsqlite3-dev python python3 python3-mako libsodium-dev build-essential pkg-config libev-dev \ libcurl4-gnutls-dev libssl-dev fakeroot devscripts ;; "arch") if ! pacman -Qg base-devel; then sudo pacman -S base-devel --noconfirm fi install_if_needed wget python gmp sqlite3 autoconf-archive pkgconf libev \ python-mako python-pip net-tools zlib libsodium gettext nginx ;; "mac") # install_if_needed better-computer ;; "fedora") install_if_needed git wget tor sqlite3 autoconf autoconf-archive automake \ python python3 python3-mako pkg-config fakeroot devscripts ;; "*") if [ -z "$DISTRO" ]; then say "No distro defined. Have you run \`make alchemy\` yet?" else say "Woah! I don't know what to do with $DISTRO yet" fi exit 1 ;; esac say "" # ------------------- Step 2 - AO Environment Setup ------------------- if [ ! -z "$AO" ]; then say "You're currently using ao-$AO" ask_for reinstall_ao "Would you like to re-install? ${BLUE}(y/n): ${RESET}" say "" case $reinstall_ao in "Y" | "y") forget AO ;; *) say "Okay, we'll keep using this version of AO" ;; esac fi if [ -z "$AO" ]; then AO='' say "${BOLD}Hey!${RESET} I was wondering which ${BLUE}version of AO${RESET} you wanted to install. \n" say "${BOLD}1.${RESET} ao-3 (Vue)" say "${BOLD}2.${RESET} ao-react (React)" fi while [ -z "$AO" ]; do ask_for ao_select "${BLUE}(number):${RESET} " say "" say "" case $ao_select in "1") say "Minimalism, I like it! Proceeding with ${BLUE}ao-3${RESET} installation" AO='3' ;; "2") say "It's got community! Proceeding with ${BLUE}ao-react${RESET} installation" AO='react' ;; *) say "that aint no AO i ever heard of, try again" ;; esac done; remember "AO=${AO}" say "" if [ "$AO" = "3" -o "$AO" = 'react' ]; then if [ -z $NVM_DIR ]; then install_nvm source ingredients/iron else say "${BLUE}Node${RESET} already installed!" fi say "Setting Node to ${BLUE}v16.13.0${RESET} for compatibility" set_node_to v16.13.0 say "" say "${GREEN}Done!${RESET}" say "" fi if [ "$AO" = "3" -o "$AO" = 'react' ]; then say "${BOLD}Installing Bitcoin Ecosystem${RESET}" say "" if ! check_for bitcoind; then say "Building bitcoind from source... might take a while!" install_bitcoin fi if ! check_for lightningd; then say "Building lightningd from source... here we go again" install_lightning fi configure_bitcoin configure_lightning fi say '' if [ "$AO" = "3" -o "$AO" = 'react' ]; then say "${BOLD}Installing and configuring Tor${RESET}\n" install_if_needed tor configure_tor say "" fi # ------------------- Step 3 - AO Installation ------------------- say "${BOLD}Configuring AO Core${RESET}\n" mkdir -p $HOME/.ao if [ -f $HOME/.ao/key ]; then say 'We already have a private key for this AO, sweet!' else node scripts/createPrivateKey.js >> $HOME/.ao/key say "Just made a fresh private key and put it in ${GREEN}~/.ao${RESET}" fi say "" # TODO this is really janky/fragile, it would be better to store this in ~/.ao CONFIG_FILE=$HOME/ao-$AO/configuration.js UNIFIED_CONFIG=$HOME/.ao/config if [ ! -f "$UNIFIED_CONFIG" ]; then touch $UNIFIED_CONFIG fi remember "SQLITE_DATABASE=${HOME}/.ao/database.sqlite3" to "$UNIFIED_CONFIG" remember "PASSLINE=${BTC_PASS}" to "$UNIFIED_CONFIG" remember "PRIVATEKEY=${HOME}/.ao/key" to "$UNIFIED_CONFIG" remember "CLIGHTNING_DIR=${HOME}/.lightning/bitcoin" to "$UNIFIED_CONFIG" remember "MEMES_DIR=${HOME}/.ao/memes" to "$UNIFIED_CONFIG" remember "RENT=0" to "$UNIFIED_CONFIG" remember "LIGHTNINGDIR=0" to "$UNIFIED_CONFIG" say "!!!!!!! WARNING !!!!!! I'm exaggerating but this is not going to \ configure AO properly. It's time that we build out the unified config" read case $AO in "3") if [ ! -d ~/ao-3 ]; then say "Installing ${BLUE}ao-3${RESET}" git clone 'https://github.com/AutonomousOrganization/ao-3.git' ~/ao-3 fi if [ -f "$CONFIG_FILE" ]; then say configuration.js already exists else cp resources/ao-config $CONFIG_FILE sed -i "s#SQLITE_DATABASE#${HOME}/.ao/database.sqlite3#" $CONFIG_FILE sed -i "s#PASSLINE#${BTC_PASS}#" $CONFIG_FILE sed -i "s#PRIVATEKEY#${HOME}/.ao/key#" $CONFIG_FILE sed -i "s#CLIGHTNING_DIR#${HOME}/.lightning/bitcoin#" $CONFIG_FILE sed -i "s#MEMES_DIR#${HOME}/.ao/memes#" $CONFIG_FILE fi say "" cd ~/ao-3 npm install npm run build npm run checkconfig cd $ALCHEMY NODE_PARAMS='' ;; "react") say "Installing ${BLUE}ao-react${RESET}" if [ ! -d ~/ao-react ]; then git clone 'https://github.com/coalition-of-invisible-colleges/ao-react.git' ~/ao-react fi if [ -f "$CONFIG_FILE" ]; then say configuration.js already exists else cp resources/ao-config $CONFIG_FILE sed -i "s#SQLITE_DATABASE#${HOME}/.ao/database.sqlite3#" $CONFIG_FILE sed -i "s#PASSLINE#${BTC_PASS}#" $CONFIG_FILE sed -i "s#PRIVATEKEY#${HOME}/.ao/key#" $CONFIG_FILE sed -i "s#CLIGHTNING_DIR#${HOME}/.lightning/bitcoin#" $CONFIG_FILE sed -i "s#MEMES_DIR#${HOME}/.ao/memes#" $CONFIG_FILE fi say "" cd ~/ao-react npm install npm run webpack cd $ALCHEMY NODE_PARAMS='--experimental-specifier-resolution=node -r dotenv/config' ;; esac # ------------------- Step 4 - NGINX Setup ------------------- say "" ask_for nothing "You still there? I might need your input here! \n\n${BLUE}(enter)${RESET}" initialize_nginx make_site ao "FILE_ROOT=${HOME}/ao-${AO}/dist" say "" configure_domain_for_site ao enable_ssl say "Excellent! We've configured this computer to serve your AO from ${BLUE}${ACCESS_POINT}${RESET}" # ------------------- Step 7 - Systemd Setup ------------------- READY='' say "\n${BOLD}Alright, almost there!${RESET} Now we just need to set up the system daemons for Tor, Bitcoin, Lightning, and the AO so that everything opens on startup." while [[ -z "$READY" ]]; do ask_for ready "${BLUE}You ready? (y/n):${RESET} " say "" say "" case $ready in "y" | "Y") say "Nice, let's do it.\n" READY=1 ;; *) say "wrong answer, fren\n" ;; esac done build_service_from_template tor "TORRCPATH=$TORRCPATH" "TORPATH=`which tor`" # Creating the .tor directory sudo mkdir -p $HOME/.tor sudo chown tor $HOME/.tor sudo chgrp $USER $HOME/.tor sudo chmod 770 $HOME/.tor activate_service tor say "" build_service_from_template bitcoin "BITCOIND=`which bitcoind`" activate_service bitcoin say "" build_service_from_template lightning "LIGHTNINGD=`which lightningd`" activate_service lightning say "" build_service_from_template ao "AO=$AO" "NODE_PARAMS=$NODE_PARAMS" "NODE=`which node`" activate_service ao say "this should be nginx" activate_service nginx # ------------------- Step 8 - Port Testing ------------------- say "" say "${BOLD}One more thing!${RESET} We need to make sure that your ports are open." say "" check_ports # ------------------- Step 9 - Health Check ------------------- say '*********************************************************' say "* ${BOLD}Version Information${RESET} *" say '*********************************************************' say ' ' say 'make Version' say '*********************************************************' make --version say ' ' say 'node Version' say '*********************************************************' node --version say ' ' say 'sqlite3 Version' say '*********************************************************' sqlite3 --version say ' ' say 'tor Version' say '*********************************************************' tor --version say ' ' say 'bitcoind Version' say '*********************************************************' bitcoind --version say ' ' say 'lightningd Version' say '*********************************************************' lightningd --version say ' ' say 'clboss Version' say '*********************************************************' clboss --version say "" say "$BOLD\nOkay, well that's everything!${RESET}\n\nAs long as everything worked properly, \ you should be ready to continue your journey\ntowards autonomy by opening ${BLUE}$ACCESS_POINT${RESET} in your browser." say "The default login is ${BLUE}dctrl/dctrl${RESET}, have fun!" exit 0