#!/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 # running them frm your server. Expect to use this one a lot if you're # writing alchemy recipes! # ------------------- NodeJS Ecosystem ------------------- if [ -d "$NVM_DIR" ]; then source $NVM_DIR/nvm.sh source $NVM_DIR/bash_completion fi set_node_to() { if check_for nvm; then if ! check_for node; then nvm install v16.14.0 fi if [ ! $(node -v) = $1 ]; then nvm install $1 nvm alias default $1 nvm use default fi else echo "nvm not available, something went wrong..." fi } install_nvm() { say "${BOLD}Installing Node Version Manager${RESET}" if [ -d "$NVM_DIR" ]; then echo "nvm already installed! skipping" else chmod +x scripts/nvm_install.sh scripts/nvm_install.sh &> /dev/null remember "NVM_DIR=$HOME/.nvm" fi } # ------------------- Systemd / Services ------------------- build_service_from_template() { SERVICE=$1 shift echo "" if [ -f resources/service-templates/${SERVICE} ]; then say "Creating $SERVICE.service..." SERVICE_FILE=/etc/systemd/system/${SERVICE}.service if [ -f "$SERVICE_FILE" ]; then say "Seems like you've already installed ${SERVICE} here!" ask_for reset "Would you like to recreate it? ${BLUE}(y/n)${RESET} " case $reset in "Y" | "y") sudo rm $SERVICE_FILE ;; "N" | "n") say "Okay, we'll leave it as is." ;; esac fi if [ ! -f "$SERVICE_FILE" ]; then sudo cp resources/service-templates/${SERVICE} $SERVICE_FILE # Common template values sudo sed -i "s#USER#${USER}#g" $SERVICE_FILE sudo sed -i "s#HOME#${HOME}#g" $SERVICE_FILE for keyval; do KEY=$(echo $keyval | cut -d'=' -f 1) VAL=$(echo $keyval | cut -d'=' -f 2) say "Substituting $KEY for $VAL" sudo sed -i "s#$KEY#$VAL#g" $SERVICE_FILE done fi else say "No service template available for $SERVICE" fi } activate_service() { SERVICE=$1 SERVICE_FILE=/etc/systemd/system/${SERVICE}.service if [ -f "$SERVICE_FILE" ]; then say "Enabling and starting ${GREEN}${SERVICE}${RESET}" sudo systemctl enable ${SERVICE} sudo systemctl start ${SERVICE} fi } IRON=1