Browse Source

refactored code for aesthetic

main
Zen 3 years ago
parent
commit
6e6bef0553
  1. 85
      Makefile
  2. 95
      ingredients/lead
  3. 35
      recipes/alchemy.sh
  4. 32
      recipes/ao.sh
  5. 9
      recipes/certify.sh
  6. 0
      recipes/get-image.sh
  7. 0
      recipes/init.sh
  8. 0
      recipes/prep-rpi-usb.sh
  9. 0
      recipes/wordpress.sh
  10. 0
      recipes/write-image.sh
  11. 4
      resources/bitcoin-service-template
  12. 2
      resources/lightning-service-template
  13. 48
      scripts/certify.sh
  14. 53
      scripts/ingredients

85
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?"

95
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
}

35
init.sh → 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} :)"

32
scripts/ao.sh → 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."

9
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

0
scripts/get-image.sh → recipes/get-image.sh

0
scripts/init.sh → recipes/init.sh

0
scripts/prep-rpi-usb.sh → recipes/prep-rpi-usb.sh

0
scripts/wordpress.sh → recipes/wordpress.sh

0
scripts/write-image.sh → recipes/write-image.sh

4
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

2
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

48
scripts/certify.sh

@ -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

53
scripts/ingredients

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