You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
101 lines
3.5 KiB
101 lines
3.5 KiB
#!/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_exists nvm; then |
|
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() { |
|
echo -e "${BOLD}Installing Node Version Manager${RESET}" |
|
if [ -n $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 |
|
echo "Creating $SERVICE.service..." |
|
SERVICE_FILE=/etc/systemd/system/${SERVICE}.service |
|
if [ -f "$SERVICE_FILE" ]; then |
|
echo "Seems like you've already installed ${SERVICE} here!" |
|
echo -en "Would you like to recreate it? ${BLUE}(y/n)${RESET} " |
|
read reset |
|
case $reset in |
|
"Y" | "y") |
|
cat /etc/systemd/system/ |
|
sudo rm $SERVICE_FILE |
|
cat /etc/systemd/system/ |
|
;; |
|
"N" | "n") |
|
echo "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) |
|
|
|
echo "Substituting $KEY for $VAL" |
|
sudo sed -i "s#$KEY#$VAL#g" $SERVICE_FILE |
|
done |
|
fi |
|
else |
|
echo "No service template available for $SERVICE" |
|
fi |
|
} |
|
|
|
activate_service() { |
|
SERVICE=$1 |
|
SERVICE_FILE=/etc/systemd/system/${SERVICE}.service |
|
if [ -f "$SERVICE_FILE" ]; then |
|
echo -e "Enabling and starting ${GREEN}${SERVICE}${RESET}" |
|
sudo systemctl enable ${SERVICE} |
|
sudo systemctl start ${SERVICE} |
|
fi |
|
} |
|
|
|
IRON=1
|
|
|