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.
138 lines
4.3 KiB
138 lines
4.3 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 from your server. Expect to use this one a lot if you're |
|
# writing alchemy recipes! |
|
|
|
# ------------------- Databases ------------------- |
|
|
|
install_database() { |
|
if [ -n "$ALCHEMY_DB" ]; then |
|
say "Alchemy has already installed ${ALCHEMY_DB} as the database" |
|
fi |
|
|
|
if [ -z "${1}" ]; then |
|
say "Okay, let's get you set up with a database" |
|
say "But I'm too tired of this to write this atm" |
|
fi |
|
|
|
case ${1} in |
|
"postgres" | "postgresql") |
|
install_if_needed postgresql |
|
;; |
|
"mysql" | "mariadb") |
|
install_if_needed mariadb-server |
|
;; |
|
esac |
|
} |
|
|
|
|
|
# ------------------- 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 |
|
sudo systemctl status ${SERVICE} &> /dev/null |
|
return_code=$? |
|
|
|
case $return_code in |
|
0) |
|
say "${BLUE}${SERVICE}${RESET} is already running" |
|
;; |
|
3) |
|
say "Enabling and starting ${GREEN}${SERVICE}${RESET}" |
|
sudo systemctl enable ${SERVICE} |
|
sudo systemctl start ${SERVICE} |
|
;; |
|
4) |
|
say "Hmm, I don't see a service for ${SERVICE}" |
|
;; |
|
*) |
|
say "whoa what the heck is $return_code" |
|
;; |
|
esac |
|
} |
|
|
|
IRON=1
|
|
|