From 0e2154d82700f0e868da9d083c4b9cd159aec0d3 Mon Sep 17 00:00:00 2001 From: Zen Date: Thu, 10 Feb 2022 10:31:52 -0600 Subject: [PATCH] Changes addressed let's see if it works from scratch --- .gitignore | 1 + init.sh | 84 +++++++++++ resources/lightning-service-template | 2 +- scripts/ao.sh | 217 +++++++++++++-------------- scripts/ingredients | 53 +++++++ 5 files changed, 244 insertions(+), 113 deletions(-) create mode 100755 init.sh create mode 100644 scripts/ingredients diff --git a/.gitignore b/.gitignore index 47241b6..936d640 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ images/ +.env diff --git a/init.sh b/init.sh new file mode 100755 index 0000000..48ca68d --- /dev/null +++ b/init.sh @@ -0,0 +1,84 @@ +#!/usr/bin/env bash + +# This is the initialization script for Alchemy. We can't rely on all systems being able to use 'make' or other utilities by default. +# This will ensure that everything is set up as needed. +# Bare Metal Alchemist, 2022 + +# This runs the ingredients script as part of this one, +# making sure that some basic values / variables are defined +source scripts/ingredients + +echo "" +echo -e "${GREEN}${ULINE}Environment${RESET}" +if [ -f .env ]; then + grep -v '^#' .env + export $(grep -v '^#' .env | xargs) +else + echo "No .env file found, initializing" + echo "ALCHEMY=true" > .env +fi + +echo "" +echo -e "${GREEN}${ULINE}System Basics${RESET}" +if [[ $ISA && $DISTRO && $UPDATED ]]; then + echo "Nothing to do!" +fi + +if [[ ! $ISA ]]; then + ISA=$(uname -m) + if [ $ISA == 'x86_64' ]; then + echo -e "Ayyy you got yourself an ${GREEN}x86${RESET} processor, cool" + elif [ $ISA == 'armv7l' ]; then + echo -e "I see you rockin an ${GREEN}ARM${RESET} processor, neato" + fi + echo "ISA=$ISA" >> .env +fi + +if [[ ! $DISTRO ]]; then + if [ -f "/etc/debian_version" ]; then + DISTRO="debian" + echo -e "${GREEN}Debian${RESET}, Ubuntu, or Raspbian OS detected." + elif [ -f "/etc/arch-release" ]; then + DISTRO="arch" + echo -e "${GREEN}Arch or Manjaro-based${RESET} OS detected." + elif [ -f "/etc/fedora-release" ]; then + DISTRO="fedora" + echo -e "${GREEN}Fedora${RESET} detected as the Operating System" + elif [ $(uname | grep -c "Darwin") -eq 1 ]; then + DISTRO="mac" + echo -e "${GREEN}MacOS${RESET} detected." + else + echo -e "I don't know ${RED}what OS you're running${RESET}! Cancelling this operation." + exit 1 + fi + echo "DISTRO=$DISTRO" >> .env +fi + +if [[ ! $UPDATED ]]; then + echo "" + echo "Updating the repositories..." + echo -e "(you'll probably need to input ${BLUE}your 'sudo' password${RESET} here)" + case $DISTRO in + "debian") + sudo apt update + sudo apt autoremove + sudo apt upgrade + ;; + "arch") + sudo pacman -Syu + ;; + "fedora") + sudo dnf update + sudo dnf upgrade + ;; + "mac") + install + sudo brew update + ;; + esac + echo "UPDATED=true" >> .env +fi + +echo "" +echo -e "${GREEN}${ULINE}Base Dependencies${RESET}" +install_if_needed make git wget diff --git a/resources/lightning-service-template b/resources/lightning-service-template index bec0df5..20945fb 100644 --- a/resources/lightning-service-template +++ b/resources/lightning-service-template @@ -8,7 +8,7 @@ After=network.target [Service] Type=forking NotifyAccess=all -ExecStart=LIGHTNINGD --conf HOME/.lightning/config --pid-file=HOME/.lightning/lightningd.pid +ExecStart=LIGHTNINGD --daemon --log-file HOME/.lightning/log --conf HOME/.lightning/config --pid-file=HOME/.lightning/lightningd.pid User=USER Group=USER Type=forking diff --git a/scripts/ao.sh b/scripts/ao.sh index 181cc6d..dab7b89 100755 --- a/scripts/ao.sh +++ b/scripts/ao.sh @@ -1,18 +1,9 @@ #!/bin/bash # Script for installing the base dependencies of AO and getting it running -# Zen, 2022 +# Bare Metal Alchemist, 2022 -# Font decoration for better a e s t h e t i c -RED="\e[0;31m" -GREEN="\e[0;32m" -BLUE="\e[0;34m" -BOLD="\e[1m" -ULINE="\e[4m" -RESET="\e[0m" - -# Make sure that ctrl+C actually exits the script -trap "exit" INT +source scripts/ingredients clear echo '' @@ -34,93 +25,94 @@ echo "" echo -e "This script is designed to ask you just enough questions to keep you involved in the process,\nwhile making it as easy as possible for you to get it going. \n\n${BLUE}press enter to continue${RESET}" read -echo -e "${ULINE}System Basics${RESET}" - -if [ -f "/etc/debian_version" ]; then - DISTRO="debian" - echo -e "${GREEN}Debian${RESET}, Ubuntu, or Raspbian OS detected." -elif [ -f "/etc/arch-release" ]; then - DISTRO="arch" - echo -e "${GREEN}Arch or Manjaro-based${RESET} OS detected." -elif [ -f "/etc/fedora-release" ]; then - DISTRO="fedora" - echo -e "${GREEN}Fedora${RESET} detected as the Operating System" -elif [ $(uname | grep -c "Darwin") -eq 1 ]; then - DISTRO="mac" - echo -e "${GREEN}MacOS${RESET} detected." -else - echo -e "I don't know ${RED}what OS you're running${RESET}! Cancelling this operation." - exit 1 -fi - -ARCHY=$(uname -m) - -if [ $ARCHY == 'x86_64' ]; then - echo -e "Ayyy you got yourself an ${GREEN}x86${RESET} processor, cool" -elif [ $ARCHY == 'armv7l' ]; then - echo -e "I see you rockin an ${GREEN}ARM${RESET} processor, neato" -fi - -echo "" -export ALCHEMY_DISTRO=$DISTRO -export ALCHEMY_ARCH=$ARCHY -echo "" - -echo -e "Got it! Next we're going to make sure the system's repositories (where they get their data from)\nare updated and that you have all the basic command line utilities we need to continue. \n\n${BLUE}(enter)${RESET}" -read - -# Coding Moment: generally, whenever you see something with brackets at the end of it, -# like this() or like(this), it's a function! It takes inputs and gives outputs -install_if_needed() { - for package in "$@" - do - if [ -z $(which $package 2>/dev/null) ]; then - echo "installing" $package - - case $DISTRO in - "debian") - sudo apt install -y $package - ;; - "arch") - sudo pacman -S $package --noconfirm --needed - ;; - "fedora") - sudo dnf install -y $package - ;; - "mac") - brew install $package - ;; - esac - - else - echo $package 'already installed!' - fi - done -} - -echo "Updating the repositories..." -echo -e "(you'll probably need to input ${BLUE}your 'sudo' password${RESET} here)" -case $DISTRO in - "debian") - sudo apt update - sudo apt autoremove - sudo apt upgrade - ;; - "arch") - sudo pacman -Syu - ;; - "fedora") - sudo dnf update - sudo dnf upgrade - ;; - "mac") - install - sudo brew update - ;; -esac -echo "" +# echo -e "${ULINE}System Basics${RESET}" +# +# if [ -f "/etc/debian_version" ]; then +# DISTRO="debian" +# echo -e "${GREEN}Debian${RESET}, Ubuntu, or Raspbian OS detected." +# elif [ -f "/etc/arch-release" ]; then +# DISTRO="arch" +# echo -e "${GREEN}Arch or Manjaro-based${RESET} OS detected." +# elif [ -f "/etc/fedora-release" ]; then +# DISTRO="fedora" +# echo -e "${GREEN}Fedora${RESET} detected as the Operating System" +# elif [ $(uname | grep -c "Darwin") -eq 1 ]; then +# DISTRO="mac" +# echo -e "${GREEN}MacOS${RESET} detected." +# else +# echo -e "I don't know ${RED}what OS you're running${RESET}! Cancelling this operation." +# exit 1 +# fi +# +# ARCHY=$(uname -m) +# +# if [ $ARCHY == 'x86_64' ]; then +# echo -e "Ayyy you got yourself an ${GREEN}x86${RESET} processor, cool" +# elif [ $ARCHY == 'armv7l' ]; then +# echo -e "I see you rockin an ${GREEN}ARM${RESET} processor, neato" +# fi +# +# echo "" +# export ALCHEMY_DISTRO=$DISTRO +# export ALCHEMY_ARCH=$ARCHY +# echo "" +# +# echo -e "Got it! Next we're going to make sure the system's repositories (where they get their data from)\nare updated and that you have all the basic command line utilities we need to continue. \n\n${BLUE}(enter)${RESET}" +# read +# +# # Coding Moment: generally, whenever you see something with brackets at the end of it, like this() +# # or like(this), it's a function! It takes inputs and gives (or does) something as an output +# install_if_needed() { +# for package in "$@" +# do +# if [ -z $(which $package 2>/dev/null) ]; then +# echo "installing" $package +# +# case $DISTRO in +# "debian") +# sudo apt install -y $package +# ;; +# "arch") +# sudo pacman -S $package --noconfirm --needed +# ;; +# "fedora") +# sudo dnf install -y $package +# ;; +# "mac") +# brew install $package +# ;; +# esac +# +# else +# echo $package 'already installed!' +# fi +# done +# } +# +# echo "Updating the repositories..." +# echo -e "(you'll probably need to input ${BLUE}your 'sudo' password${RESET} here)" +# case $DISTRO in +# "debian") +# sudo apt update +# sudo apt autoremove +# sudo apt upgrade +# ;; +# "arch") +# sudo pacman -Syu +# ;; +# "fedora") +# sudo dnf update +# sudo dnf upgrade +# ;; +# "mac") +# install +# sudo brew update +# ;; +# esac +# echo "" echo -e "Making sure we've got the basics..." +echo -e "(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 @@ -133,8 +125,8 @@ case $DISTRO in sudo pacman -S base-devel --noconfirm fi - install_if_needed wget python git gmp sqlite3 \ - python-mako python-pip net-tools zlib libsodium gettext + install_if_needed wget python gmp sqlite3 \ + python-mako python-pip net-tools zlib libsodium gettext dnsutil nginx ;; "mac") # install_if_needed better-computer @@ -149,7 +141,7 @@ echo "" ## ------------------- Step 2 - AO Environment Setup ------------------- # AO='' -echo -e "${BOLD}Hey!${RESET} You still there? I was wondering which ${BLUE}version of AO${RESET} you wanted to install. \n" +echo -e "${BOLD}Hey!${RESET} I was wondering which ${BLUE}version of AO${RESET} you wanted to install. \n" echo -e "${BOLD}1.${RESET} ao-3 (Vue)" echo -e "${BOLD}2.${RESET} ao-react (React)" while [[ -z $AO ]]; do @@ -178,6 +170,11 @@ if [ $AO = "3" ] || [ $AO = 'react' ]; then echo -e "${BOLD}Installing Node.js${RESET}" chmod +x scripts/nvm_install.sh scripts/nvm_install.sh + + export NVM_DIR="$HOME/.nvm" + [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm + [ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion + if [ "$SHELL" = '/bin/zsh' ]; then echo 'sourcing zshrc' source ~/.zshrc @@ -186,24 +183,17 @@ if [ $AO = "3" ] || [ $AO = 'react' ]; then fi nvm install v16.13.0 nvm alias default v16.13.0 - if [ "$SHELL" = '/bin/zsh' ]; then - echo 'sourcing zshrc' - source ~/.zshrc - else - source ~/.bashrc - fi - echo "" + nvm use default fi -# TODO: Compile Bitcoin from C to make it resistant to changes in architecture (should work for any ISA) +# Note, it would be a good idea to compile Bitcoin from C to make it resistant to changes in architecture (should work for any ISA) if [ $AO = "3" ] || [ $AO = 'react' ]; then echo -e "${BOLD}Installing Bitcoin Ecosystem${RESET}" - mkdir -p bitcoin - if [ $ALCHEMY_ARCH == 'x86_64' ] && [ ! -e images/bitcoin-22.0* ]; then + if [ $ISA == 'x86_64' ] && [ ! -e images/bitcoin-22.0* ]; then wget https://bitcoincore.org/bin/bitcoin-core-22.0/bitcoin-22.0-x86_64-linux-gnu.tar.gz -P images/ - elif [ $ALCHEMY_ARCH == 'armv7l' ] && [ ! -e images/bitcoin-22.0* ]; then + elif [ $ISA == 'armv7l' ] && [ ! -e images/bitcoin-22.0* ]; then wget https://bitcoincore.org/bin/bitcoin-core-22.0/bitcoin-22.0-arm-linux-gnueabihf.tar.gz -P images/ fi @@ -219,6 +209,10 @@ if [ $AO = "3" ] || [ $AO = 'react' ]; then pushd ~/lightning git checkout v0.10.2 ./configure + + # The latest version of mistune breaks lightning install + pip uninstall mistune + pip install --user mistune==0.8.4 sudo make sudo make install popd @@ -237,6 +231,7 @@ if [ $AO = "3" ] || [ $AO = 'react' ]; then echo "" echo -e "${BOLD}Bitcoin installed!${RESET} Let's make sure it's configured now." + mkdir -p ~/.bitcoin AUTHDEETS=$(python3 scripts/rpcauth.py ao) AUTHLINE=$(echo $AUTHDEETS | grep -o rpcauth=ao:[^[:space:]]*[[:space:]]) @@ -363,8 +358,6 @@ fi # ------------------- Step 4 - NGINX Setup ------------------- echo "" - echo "We might need to query DNS records here..." - install_if_needed dig nginx echo -e "You still there? I need to ask you some questions! \n\n${BLUE}(enter)${RESET}" read echo "" diff --git a/scripts/ingredients b/scripts/ingredients new file mode 100644 index 0000000..74d1048 --- /dev/null +++ b/scripts/ingredients @@ -0,0 +1,53 @@ +#!/bin/bash + +# Font decoration for better a e s t h e t i c +RED="\e[0;31m" +GREEN="\e[0;32m" +BLUE="\e[0;34m" +BOLD="\e[1m" +ULINE="\e[4m" +RESET="\e[0m" + +# Make sure that ctrl+C actually exits the script +trap "exit" INT + +# Give informative error messages +trap 'echo "Oops! Something went wrong on line $LINENO of this script. Exit code was $?" >&2' ERR + +# --------------- Functions --------------- +# Coding Moment: generally, whenever you see something with brackets at the end of it, like this() +# or like(this), it's a function! It takes inputs and gives (or does) something as an output + +install_if_needed() { + for package in "$@" + do + # TODO Better installation detection than "which" + if [ -z $(which $package 2>/dev/null) ]; then + echo "installing" $package + + case $DISTRO in + "debian") + sudo apt install -y $package + ;; + "arch") + sudo pacman -S $package --noconfirm --needed + ;; + "fedora") + sudo dnf install -y $package + ;; + "mac") + brew install $package + ;; + esac + else + echo $package 'already installed!' + fi + done +} + +# --------------- Environment Setup --------------- +if [ -f .env ]; then + export $(grep -v '^#' .env | xargs) +else + echo "No .env file, this might cause some issues..." +fi