Browse Source

Changes addressed let's see if it works from scratch

main
Zen 3 years ago
parent
commit
0e2154d827
  1. 1
      .gitignore
  2. 84
      init.sh
  3. 2
      resources/lightning-service-template
  4. 217
      scripts/ao.sh
  5. 53
      scripts/ingredients

1
.gitignore vendored

@ -1 +1,2 @@
images/ images/
.env

84
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

2
resources/lightning-service-template

@ -8,7 +8,7 @@ After=network.target
[Service] [Service]
Type=forking Type=forking
NotifyAccess=all 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 User=USER
Group=USER Group=USER
Type=forking Type=forking

217
scripts/ao.sh

@ -1,18 +1,9 @@
#!/bin/bash #!/bin/bash
# Script for installing the base dependencies of AO and getting it running # 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 source scripts/ingredients
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
clear clear
echo '' 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}" 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 read
echo -e "${ULINE}System Basics${RESET}" # echo -e "${ULINE}System Basics${RESET}"
#
if [ -f "/etc/debian_version" ]; then # if [ -f "/etc/debian_version" ]; then
DISTRO="debian" # DISTRO="debian"
echo -e "${GREEN}Debian${RESET}, Ubuntu, or Raspbian OS detected." # echo -e "${GREEN}Debian${RESET}, Ubuntu, or Raspbian OS detected."
elif [ -f "/etc/arch-release" ]; then # elif [ -f "/etc/arch-release" ]; then
DISTRO="arch" # DISTRO="arch"
echo -e "${GREEN}Arch or Manjaro-based${RESET} OS detected." # echo -e "${GREEN}Arch or Manjaro-based${RESET} OS detected."
elif [ -f "/etc/fedora-release" ]; then # elif [ -f "/etc/fedora-release" ]; then
DISTRO="fedora" # DISTRO="fedora"
echo -e "${GREEN}Fedora${RESET} detected as the Operating System" # echo -e "${GREEN}Fedora${RESET} detected as the Operating System"
elif [ $(uname | grep -c "Darwin") -eq 1 ]; then # elif [ $(uname | grep -c "Darwin") -eq 1 ]; then
DISTRO="mac" # DISTRO="mac"
echo -e "${GREEN}MacOS${RESET} detected." # echo -e "${GREEN}MacOS${RESET} detected."
else # else
echo -e "I don't know ${RED}what OS you're running${RESET}! Cancelling this operation." # echo -e "I don't know ${RED}what OS you're running${RESET}! Cancelling this operation."
exit 1 # exit 1
fi # fi
#
ARCHY=$(uname -m) # ARCHY=$(uname -m)
#
if [ $ARCHY == 'x86_64' ]; then # if [ $ARCHY == 'x86_64' ]; then
echo -e "Ayyy you got yourself an ${GREEN}x86${RESET} processor, cool" # echo -e "Ayyy you got yourself an ${GREEN}x86${RESET} processor, cool"
elif [ $ARCHY == 'armv7l' ]; then # elif [ $ARCHY == 'armv7l' ]; then
echo -e "I see you rockin an ${GREEN}ARM${RESET} processor, neato" # echo -e "I see you rockin an ${GREEN}ARM${RESET} processor, neato"
fi # fi
#
echo "" # echo ""
export ALCHEMY_DISTRO=$DISTRO # export ALCHEMY_DISTRO=$DISTRO
export ALCHEMY_ARCH=$ARCHY # export ALCHEMY_ARCH=$ARCHY
echo "" # 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}" # 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 # read
#
# Coding Moment: generally, whenever you see something with brackets at the end of it, # # Coding Moment: generally, whenever you see something with brackets at the end of it, like this()
# like this() or like(this), it's a function! It takes inputs and gives outputs # # or like(this), it's a function! It takes inputs and gives (or does) something as an output
install_if_needed() { # install_if_needed() {
for package in "$@" # for package in "$@"
do # do
if [ -z $(which $package 2>/dev/null) ]; then # if [ -z $(which $package 2>/dev/null) ]; then
echo "installing" $package # echo "installing" $package
#
case $DISTRO in # case $DISTRO in
"debian") # "debian")
sudo apt install -y $package # sudo apt install -y $package
;; # ;;
"arch") # "arch")
sudo pacman -S $package --noconfirm --needed # sudo pacman -S $package --noconfirm --needed
;; # ;;
"fedora") # "fedora")
sudo dnf install -y $package # sudo dnf install -y $package
;; # ;;
"mac") # "mac")
brew install $package # brew install $package
;; # ;;
esac # esac
#
else # else
echo $package 'already installed!' # echo $package 'already installed!'
fi # fi
done # done
} # }
#
echo "Updating the repositories..." # echo "Updating the repositories..."
echo -e "(you'll probably need to input ${BLUE}your 'sudo' password${RESET} here)" # echo -e "(you'll probably need to input ${BLUE}your 'sudo' password${RESET} here)"
case $DISTRO in # case $DISTRO in
"debian") # "debian")
sudo apt update # sudo apt update
sudo apt autoremove # sudo apt autoremove
sudo apt upgrade # sudo apt upgrade
;; # ;;
"arch") # "arch")
sudo pacman -Syu # sudo pacman -Syu
;; # ;;
"fedora") # "fedora")
sudo dnf update # sudo dnf update
sudo dnf upgrade # sudo dnf upgrade
;; # ;;
"mac") # "mac")
install # install
sudo brew update # sudo brew update
;; # ;;
esac # esac
echo "" # echo ""
echo -e "Making sure we've got the basics..." 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 case $DISTRO in
"debian") "debian")
# Note -- I'm not sure if these are all needed but I'm not in the mood to check # 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 sudo pacman -S base-devel --noconfirm
fi fi
install_if_needed wget python git gmp sqlite3 \ install_if_needed wget python gmp sqlite3 \
python-mako python-pip net-tools zlib libsodium gettext python-mako python-pip net-tools zlib libsodium gettext dnsutil nginx
;; ;;
"mac") "mac")
# install_if_needed better-computer # install_if_needed better-computer
@ -149,7 +141,7 @@ echo ""
## ------------------- Step 2 - AO Environment Setup ------------------- ## ------------------- Step 2 - AO Environment Setup -------------------
# #
AO='' 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}1.${RESET} ao-3 (Vue)"
echo -e "${BOLD}2.${RESET} ao-react (React)" echo -e "${BOLD}2.${RESET} ao-react (React)"
while [[ -z $AO ]]; do while [[ -z $AO ]]; do
@ -178,6 +170,11 @@ if [ $AO = "3" ] || [ $AO = 'react' ]; then
echo -e "${BOLD}Installing Node.js${RESET}" echo -e "${BOLD}Installing Node.js${RESET}"
chmod +x scripts/nvm_install.sh chmod +x scripts/nvm_install.sh
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 if [ "$SHELL" = '/bin/zsh' ]; then
echo 'sourcing zshrc' echo 'sourcing zshrc'
source ~/.zshrc source ~/.zshrc
@ -186,24 +183,17 @@ if [ $AO = "3" ] || [ $AO = 'react' ]; then
fi fi
nvm install v16.13.0 nvm install v16.13.0
nvm alias default v16.13.0 nvm alias default v16.13.0
if [ "$SHELL" = '/bin/zsh' ]; then nvm use default
echo 'sourcing zshrc'
source ~/.zshrc
else
source ~/.bashrc
fi
echo ""
fi 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 if [ $AO = "3" ] || [ $AO = 'react' ]; then
echo -e "${BOLD}Installing Bitcoin Ecosystem${RESET}" 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/ 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/ wget https://bitcoincore.org/bin/bitcoin-core-22.0/bitcoin-22.0-arm-linux-gnueabihf.tar.gz -P images/
fi fi
@ -219,6 +209,10 @@ if [ $AO = "3" ] || [ $AO = 'react' ]; then
pushd ~/lightning pushd ~/lightning
git checkout v0.10.2 git checkout v0.10.2
./configure ./configure
# The latest version of mistune breaks lightning install
pip uninstall mistune
pip install --user mistune==0.8.4
sudo make sudo make
sudo make install sudo make install
popd popd
@ -237,6 +231,7 @@ if [ $AO = "3" ] || [ $AO = 'react' ]; then
echo "" echo ""
echo -e "${BOLD}Bitcoin installed!${RESET} Let's make sure it's configured now." echo -e "${BOLD}Bitcoin installed!${RESET} Let's make sure it's configured now."
mkdir -p ~/.bitcoin
AUTHDEETS=$(python3 scripts/rpcauth.py ao) AUTHDEETS=$(python3 scripts/rpcauth.py ao)
AUTHLINE=$(echo $AUTHDEETS | grep -o rpcauth=ao:[^[:space:]]*[[:space:]]) AUTHLINE=$(echo $AUTHDEETS | grep -o rpcauth=ao:[^[:space:]]*[[:space:]])
@ -363,8 +358,6 @@ fi
# ------------------- Step 4 - NGINX Setup ------------------- # ------------------- Step 4 - NGINX Setup -------------------
echo "" 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}" echo -e "You still there? I need to ask you some questions! \n\n${BLUE}(enter)${RESET}"
read read
echo "" echo ""

53
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
Loading…
Cancel
Save