From 993595e46cca0f94113a1dca51464e80169b9510 Mon Sep 17 00:00:00 2001 From: Zen Date: Fri, 25 Feb 2022 12:14:13 -0600 Subject: [PATCH] added remember util to lead --- ingredients/copper | 3 ++- ingredients/iron | 39 +++++++++++++++++++++++++++++++++++++++ ingredients/lead | 24 +++++++++++++++++++----- recipes/alchemy.sh | 8 ++++---- recipes/ao.sh | 2 ++ 5 files changed, 66 insertions(+), 10 deletions(-) create mode 100644 ingredients/iron diff --git a/ingredients/copper b/ingredients/copper index 8a13d3c..5c53bbb 100644 --- a/ingredients/copper +++ b/ingredients/copper @@ -20,7 +20,8 @@ locate_torrc() { elif [ -e $HOME/.tor/torrc ]; then TORRCPATH="${HOME}/.tor/torrc" else - echo -e "${RED}Uh oh...${RESET} I couldn't figure out where your torrc file is. That might cause some issues" + echo -e "${RED}Uh oh...${RESET} I couldn't figure out\ + where your torrc file is. That might cause some issues" exit 1 fi fi diff --git a/ingredients/iron b/ingredients/iron new file mode 100644 index 0000000..04b9e10 --- /dev/null +++ b/ingredients/iron @@ -0,0 +1,39 @@ +#!/bin/sh +# Bare Metal Alchemist, 2022 + +############################################# +# Iron - ♂ # +############################################# + +# Iron is the most common element found on our planet, and an element +# that we, as a species, frequently rely on to build our tools and +# our society as a whole. + +# This ingredient contains functions for building web applications and +# installing common frameworks. Expect to use this one a lot if you're +# writing alchemy recipes! + +install_nodejs() { + 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 + # else + # source ~/.bashrc + # fi +} + +set_node_to() { + nvm install v16.13.0 + nvm alias default v16.13.0 + nvm use default +} + + diff --git a/ingredients/lead b/ingredients/lead index c342227..81649bf 100644 --- a/ingredients/lead +++ b/ingredients/lead @@ -24,15 +24,21 @@ RESET="\e[0m" # 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 +# We only want these to activate if we're running a recipe +if [[ $SHLVL -gt 1 ]]; then + # 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 +fi # --------------- Environment Setup --------------- +if [ -d $ALCHEMY ]; then + cd $ALCHEMY +fi + if [ -f .env ]; then export $(grep -v '^#' .env | xargs) else @@ -97,4 +103,12 @@ install_if_needed() { done } +remember() { + KEY=$(echo ${1} | cut -d'=' -f 1) + if [[ ${1} =~ ^[A-Z]+\=[a-z_0-9]*$ ]] && [[ -z $(env | grep ${KEY}) ]]; then + echo "${1}" >> .env + export ${1} + fi +} + LEAD=1 diff --git a/recipes/alchemy.sh b/recipes/alchemy.sh index 8772843..c337f56 100755 --- a/recipes/alchemy.sh +++ b/recipes/alchemy.sh @@ -32,7 +32,7 @@ if [ -f .env ]; then export $(grep -v '^#' .env | xargs) else echo "No .env file found, let's initialize it" - echo "ALCHEMY=true" > .env + echo "ALCHEMY=`pwd`" >> .env fi echo "" @@ -48,7 +48,7 @@ if [[ ! $ISA ]]; then elif [ $ISA == 'armv7l' ]; then echo -e "I see you rockin an ${GREEN}ARM${RESET} processor, neato" fi - echo "ISA=$ISA" >> .env + remember "ISA=$ISA" fi if [[ ! $DISTRO ]]; then @@ -68,7 +68,7 @@ if [[ ! $DISTRO ]]; then echo -e "I don't know ${RED}what OS you're running${RESET}! Cancelling this operation." exit 1 fi - echo "DISTRO=$DISTRO" >> .env + remember "DISTRO=$DISTRO" fi # TODO - Update intermittently (like if you haven't run it in a week? use date +%s and (($INT+$INT2)) @@ -96,7 +96,7 @@ if [[ ! $UPDATED ]]; then sudo brew update ;; esac - echo "UPDATED=true" >> .env + remember "UPDATED=true" fi echo "" diff --git a/recipes/ao.sh b/recipes/ao.sh index db20f15..826d128 100755 --- a/recipes/ao.sh +++ b/recipes/ao.sh @@ -5,6 +5,7 @@ source ingredients/lead source ingredients/copper +source ingredients/iron source ingredients/gold clear @@ -90,6 +91,7 @@ while [[ -z $AO ]]; do ;; esac done; +echo "AO=${AO}" >> .env echo "" if [ $AO = "3" ] || [ $AO = 'react' ]; then