diff --git a/Makefile b/Makefile index 5b56d86..91cfb06 100644 --- a/Makefile +++ b/Makefile @@ -1,29 +1,80 @@ -# This Makefile exists because it's my favorite way to simplify running groups of commands directly from the command line -# -# Variables -IMAGE := raspios_lite_arm64.zip -DOWNLOAD_LINK := https://downloads.raspberrypi.org/raspios_lite_arm64/images/raspios_lite_arm64-2021-11-08/2021-10-30-raspios-bullseye-arm64-lite.zip +# This Makefile exists because it's my favorite way to simplify running +# groups of commands directly from the command line +# -- Bare Metal Alchemist, 2022 + +alchemy: + @chmod +x recipes/alchemy.sh + @recipes/alchemy.sh aesthetic: - @chmod +x scripts/init.sh - @scripts/init.sh + @chmod +x recipes/init.sh + @recipes/init.sh autonomy: - @chmod +x scripts/ao.sh - @scripts/ao.sh + @chmod +x recipes/ao.sh + @recipes/ao.sh acquisition: - @chmod +x scripts/get-image.sh - @scripts/get-image.sh + @chmod +x recipes/get-image.sh + @recipes/get-image.sh imbuement: - @chmod +x scripts/write-image.sh - @scripts/write-image.sh + @chmod +x recipes/write-image.sh + @recipes/write-image.sh preparations: - @chmod +x scripts/prep-rpi-usb.sh - @scripts/prep-rpi-usb.sh + @chmod +x recipes/prep-rpi-usb.sh + @recipes/prep-rpi-usb.sh + +prosperity: + @echo "This will install prestashop eventually" manifest: - @chmod +x scripts/wordpress.sh - @scripts/wordpress.sh + @chmod +x recipes/wordpress.sh + @recipes/wordpress.sh + +help: + @echo "We'll get there!" + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +# This is just for fun! +something: + @echo "You might need to be a little more creative than that..." + +cool: + @echo "Maybe try 'make help' if you're confused?" diff --git a/ingredients/lead b/ingredients/lead new file mode 100644 index 0000000..332ceeb --- /dev/null +++ b/ingredients/lead @@ -0,0 +1,95 @@ +#!/bin/sh +# Bare Metal Alchemist, 2022 + +############################################# +# Lead - ♄ # +############################################# + +# The most basic ingredient in an Alchemy recipe, lead is used in all +# recipes in this repository to standardize some simple things that I +# rely on to make scripts concise and pleasant to use + +# --------------- Escape Codes --------------- +# These constants are used to add color and text formatting to the +# terminal's output -- Further reading: ANSI Escape Codes +RED="\e[0;31m" +GREEN="\e[0;32m" +BLUE="\e[0;34m" +BOLD="\e[1m" +ULINE="\e[4m" +RESET="\e[0m" + +# --------------- Traps --------------- + +# Traps, in the case of shell scripting, listen for certain signals +# that are broadcast by the system and execute a command in response + +# Make sure that ctrl+C consistently exits the script +trap "exit" INT + +# Give informative error messages when we receive ERR +trap 'echo -e "${RED}Oops!${RESET} Something went wrong on line $LINENO of this script. Exit code was $?" >&2' ERR + + +# --------------- Environment Setup --------------- + +if [ -f .env ]; then + export $(grep -v '^#' .env | xargs) +else + if [ -z $ALCHEMY ]; then + echo "No .env file, this might cause some issues..." + fi +fi + + +# --------------- 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 + +# This one installs utilities to your OS (If you need them!) +install_if_needed() { + for package in "$@" # $@ means "all the arguments you passed + do + + case $DISTRO in + "debian") + # TODO Better installation detection than "which" + if [ -z $(which $package 2>/dev/null) ]; then + echo "installing" $package + sudo apt install -y $package + else + echo $package 'already installed!' + fi + ;; + "arch") + if pacman -Qi $package &>/dev/null; then + echo $package 'already installed!' + else + echo "installing" $package + sudo pacman -S $package --noconfirm --needed + fi + ;; + "fedora") + # TODO Better installation detection than "which" + if [ -z $(which $package 2>/dev/null) ]; then + echo "installing" $package + sudo dnf install -y $package + else + echo $package 'already installed!' + fi + ;; + "mac") + # TODO Better installation detection than "which" + if [ -z $(which $package 2>/dev/null) ]; then + echo "installing" $package + brew install $package + else + echo $package 'already installed!' + fi + ;; + esac + done +} + diff --git a/init.sh b/recipes/alchemy.sh similarity index 61% rename from init.sh rename to recipes/alchemy.sh index 0a3ac11..8772843 100755 --- a/init.sh +++ b/recipes/alchemy.sh @@ -1,20 +1,37 @@ -#!/usr/bin/env bash +#!/usr/bin/env sh -# 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 is the initialization script for Alchemy. +# We can't rely on all systems being able to use 'make' etc. 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, +# Just to let the system know what we're doing... +ALCHEMY="initializing" + +# 'sourcing' a script is essentially running it to set up your system, # making sure that some basic values / variables are defined -source scripts/ingredients +source ingredients/lead + +clear +echo -e "${BLUE}" +echo -e " d8888 888 888 " +echo -e " d88888 888 888 " +echo -e " d88P888 888 888 " +echo -e " d88P 888 888 .d8888b 88888b. .d88b. 88888b.d88b. 888 888" +echo -e " d88P 888 888 d88P' 888 '88b d8P Y8b 888 '888 '88b 888 888" +echo -e " d88P 888 888 888 888 888 88888888 888 888 888 888 888" +echo -e " d8888888888 888 Y88b. 888 888 Y8b. 888 888 888 Y88b 888" +echo -e "d88P 888 888 'Y8888P 888 888 'Y8888 888 888 888 'Y88888" +echo -e " 888" +echo -e " ${BOLD}Initialization Script -- BMA${BLUE} Y8b d88P" +echo -e "${RESET}" -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 "No .env file found, let's initialize it" echo "ALCHEMY=true" > .env fi @@ -54,6 +71,7 @@ if [[ ! $DISTRO ]]; then echo "DISTRO=$DISTRO" >> .env fi +# TODO - Update intermittently (like if you haven't run it in a week? use date +%s and (($INT+$INT2)) if [[ ! $UPDATED ]]; then echo "" echo "Updating the repositories..." @@ -83,4 +101,7 @@ fi echo "" echo -e "${GREEN}${ULINE}Core Dependencies${RESET}" -install_if_needed git wget +install_if_needed git wget make + +echo "" +echo -e "${BOLD}You're good to go!${RESET} Go ${BLUE}make something cool${RESET} :)" diff --git a/scripts/ao.sh b/recipes/ao.sh similarity index 97% rename from scripts/ao.sh rename to recipes/ao.sh index dffe1bc..14d711a 100755 --- a/scripts/ao.sh +++ b/recipes/ao.sh @@ -3,7 +3,7 @@ # Script for installing the base dependencies of AO and getting it running # Bare Metal Alchemist, 2022 -source scripts/ingredients +source ingredients/lead clear echo '' @@ -17,12 +17,14 @@ echo ' d8888888888 Y88b. .d88P 888 888 888 X88 Y88b. 888 888 88 echo 'd88P 888 "Y88888P" 8888888 888 888 88888P" "Y888 "Y888888 888 888 "Y8888 888 ' echo '' - # ------------------- Step 1 - Baseline Setup ------------------- echo -e "${BOLD}Hiya!${RESET} We're going to get you set up with your very own Autonomous Engine." 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," +echo -e "while making it as easy as possible for you to get it going." +echo "" +echo -e "${BLUE}press enter to continue${RESET}" read if [ "$EUID" -eq 0 ]; then @@ -47,7 +49,7 @@ case $DISTRO in sudo pacman -S base-devel --noconfirm fi - install_if_needed wget python gmp sqlite3 \ + install_if_needed wget python gmp sqlite3 autoconf-archive pkgconf libev \ python-mako python-pip net-tools zlib libsodium gettext dnsutils nginx ;; "mac") @@ -140,17 +142,17 @@ if [ $AO = "3" ] || [ $AO = 'react' ]; then sudo make install popd - # TODO fix clboss - # echo 'Installing clboss' - # git clone https://github.com/ZmnSCPxj/clboss.git ~/clboss - # pushd ~/clboss - # git checkout 0.11B - # mkdir m4 - # autoreconf -i - # ./configure - # make - # sudo make install - # popd + TODO fix clboss + echo 'Installing clboss' + git clone https://github.com/ZmnSCPxj/clboss.git ~/clboss + pushd ~/clboss + git checkout 0.11B + mkdir m4 + autoreconf -fi + ./configure + make + sudo make install + popd echo "" echo -e "${BOLD}Bitcoin installed!${RESET} Let's make sure it's configured now." diff --git a/recipes/certify.sh b/recipes/certify.sh new file mode 100755 index 0000000..d07d9ed --- /dev/null +++ b/recipes/certify.sh @@ -0,0 +1,9 @@ +#!/bin/sh + +# Installs certbot and runs it +# -- Bare Metal Alchemist, 2022 + +source ingredients/lead + +install_if_needed certbot python3-certbot-nginx +sudo certbot --nginx diff --git a/scripts/get-image.sh b/recipes/get-image.sh similarity index 100% rename from scripts/get-image.sh rename to recipes/get-image.sh diff --git a/scripts/init.sh b/recipes/init.sh similarity index 100% rename from scripts/init.sh rename to recipes/init.sh diff --git a/scripts/prep-rpi-usb.sh b/recipes/prep-rpi-usb.sh similarity index 100% rename from scripts/prep-rpi-usb.sh rename to recipes/prep-rpi-usb.sh diff --git a/scripts/wordpress.sh b/recipes/wordpress.sh similarity index 100% rename from scripts/wordpress.sh rename to recipes/wordpress.sh diff --git a/scripts/write-image.sh b/recipes/write-image.sh similarity index 100% rename from scripts/write-image.sh rename to recipes/write-image.sh diff --git a/resources/bitcoin-service-template b/resources/bitcoin-service-template index 3985431..0acdb6b 100644 --- a/resources/bitcoin-service-template +++ b/resources/bitcoin-service-template @@ -5,15 +5,13 @@ After=network.target [Service] Type=notify NotifyAccess=all -ExecStart=BITCOIND --daemon --server --pid=HOME/.bitcoin/bitcoind.pid +ExecStart=BITCOIND --daemonwait --server --pid=HOME/.bitcoin/bitcoind.pid Type=forking PIDFile=HOME/.bitcoin/bitcoind.pid Restart=on-failure KillSignal=SIGINT -TimeoutSec=60 -WatchdogSec=60 LimitNOFILE=32768 User=USER Group=USER diff --git a/resources/lightning-service-template b/resources/lightning-service-template index 5d2a450..dc3c6f7 100644 --- a/resources/lightning-service-template +++ b/resources/lightning-service-template @@ -16,8 +16,6 @@ PIDFile=HOME/.lightning/lightningd.pid Restart=on-failure KillSignal=SIGINT -TimeoutSec=60 -WatchdogSec=60 LimitNOFILE=32768 # Hardening diff --git a/scripts/certify.sh b/scripts/certify.sh deleted file mode 100755 index 3700673..0000000 --- a/scripts/certify.sh +++ /dev/null @@ -1,48 +0,0 @@ -#!/bin/bash - -# Installs certbot and runs it -# ~ Zen, 2022 - -if [ -f "/etc/debian_version" ]; then - DISTRO="debian" - echo "Debian, Ubuntu, or Raspbian OS detected." -elif [ -f "/etc/arch-release" ]; then - DISTRO="arch" - echo "Arch- or Manjaro-based OS detected." -elif [ $(uname | grep -c "Darwin") -eq 1 ]; then - DISTRO="mac" - echo "MacOS detected." -else - echo "I don't know what OS you're running! Cancelling this operation." - exit 1 -fi - -echo "" - -install_if_needed() { - for package in "$@" - do - if [ -z $(which $package) ]; then - echo "installing" $package - - case $DISTRO in - "debian") - sudo apt install -y $package - ;; - "arch") - sudo pacman -S $package - ;; - "mac") - brew install $package - ;; - esac - - else - echo $package 'already installed!' - fi - done - -} - -install_if_needed certbot python3-certbot-nginx -sudo certbot --nginx diff --git a/scripts/ingredients b/scripts/ingredients deleted file mode 100644 index f7c5319..0000000 --- a/scripts/ingredients +++ /dev/null @@ -1,53 +0,0 @@ -#!/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 -e "${RED}Oops!${RESET} 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