Browse Source

increasing POSIX compliance

main
zen 3 years ago
parent
commit
eb35ff8290
  1. 107
      ingredients/copper
  2. 2
      ingredients/gold
  3. 23
      ingredients/iron
  4. 4
      recipes/ao.sh
  5. 12
      recipes/flask.sh
  6. 33
      recipes/init.sh

107
ingredients/copper

@ -34,12 +34,11 @@ locate_torrc() {
configure_tor() { configure_tor() {
locate_torrc locate_torrc
echo -e "Your existing torrc file has the following settings: " say "Your existing torrc file has the following settings: "
echo "" say ""
cat $TORRCPATH | grep '^[^#]' cat $TORRCPATH | grep '^[^#]'
echo "" say ""
echo -en "Would you like to reset it?: ${BLUE}(y/n)${RESET} " ask_for torrc_reset "Would you like to reset it?: ${BLUE}(y/n)${RESET} "
read torrc_reset
case $torrc_reset in case $torrc_reset in
"Y" | "y") "Y" | "y")
cp resources/torrc-template . cp resources/torrc-template .
@ -74,12 +73,12 @@ get_external_ip() {
} }
initialize_nginx() { initialize_nginx() {
echo -e "${BOLD}Installing and configuring NGINX${RESET}" say "${BOLD}Installing and configuring NGINX${RESET}"
echo "" say ""
install_if_needed nginx install_if_needed nginx
# Making sure this version of NGINX supports sites-enabled # Making sure this version of NGINX supports sites-enabled
if [[ -z $(sudo cat /etc/nginx/nginx.conf | grep sites-enabled) ]]; then if [ -z $(sudo cat /etc/nginx/nginx.conf | grep sites-enabled) ]; then
sudo mkdir -p /etc/nginx/sites-available sudo mkdir -p /etc/nginx/sites-available
sudo mkdir -p /etc/nginx/sites-enabled sudo mkdir -p /etc/nginx/sites-enabled
sudo cp resources/nginx/base.nginx.conf /etc/nginx/nginx.conf sudo cp resources/nginx/base.nginx.conf /etc/nginx/nginx.conf
@ -94,28 +93,27 @@ make_site() {
if [ -f resources/nginx/${SITE}.nginx.conf ]; then if [ -f resources/nginx/${SITE}.nginx.conf ]; then
NGINX_SITE_LOCATION=/etc/nginx/sites-available/${SITE} NGINX_SITE_LOCATION=/etc/nginx/sites-available/${SITE}
if [ -f $NGINX_SITE_LOCATION ]; then if [ -f $NGINX_SITE_LOCATION ]; then
echo -e "You already have a site available for ${BLUE}${SITE}${RESET}, what would you like to do?" say "You already have a site available for ${BLUE}${SITE}${RESET}, what would you like to do?"
echo -en "${BOLD}R${RESET}eset it, ${BOLD}A${RESET}ctivate it, or do ${BOLD}N${RESET}othing? (r/a/n): " ask_for whatdo "${BOLD}R${RESET}eset it, ${BOLD}A${RESET}ctivate it, or do ${BOLD}N${RESET}othing? (r/a/n): "
read whatdo
case $whatdo in case $whatdo in
"R" | "r") "R" | "r")
echo "Resetting sites-available/${SITE}" say "Resetting sites-available/${SITE}"
sudo rm /etc/nginx/sites-available/${SITE} sudo rm /etc/nginx/sites-available/${SITE}
;; ;;
"A" | "a") "A" | "a")
echo "Activating sites-available/${SITE}" say "Activating sites-available/${SITE}"
if [ ! -e /etc/nginx/sites-enabled/${SITE} ]; then if [ ! -e /etc/nginx/sites-enabled/${SITE} ]; then
sudo ln -s /etc/nginx/sites-available/${SITE} /etc/nginx/sites-enabled/ sudo ln -s /etc/nginx/sites-available/${SITE} /etc/nginx/sites-enabled/
fi fi
;; ;;
"N" | "n") "N" | "n")
echo "Okay, we'll leave it be." say "Okay, we'll leave it be."
;; ;;
*) *)
echo "Instructions unclear, accidentally an choice" say "Instructions unclear, accidentally an choice"
;; ;;
esac esac
echo "" say ""
fi fi
if [ ! -f $NGINX_SITE_LOCATION ]; then if [ ! -f $NGINX_SITE_LOCATION ]; then
@ -125,7 +123,7 @@ make_site() {
KEY=$(echo $keyval | cut -d'=' -f 1) KEY=$(echo $keyval | cut -d'=' -f 1)
VAL=$(echo $keyval | cut -d'=' -f 2) VAL=$(echo $keyval | cut -d'=' -f 2)
echo "Substituting $KEY for $VAL" say "Substituting $KEY for $VAL"
sudo sed -i "s#$KEY#$VAL#g" $NGINX_SITE_LOCATION sudo sed -i "s#$KEY#$VAL#g" $NGINX_SITE_LOCATION
done done
@ -134,18 +132,17 @@ make_site() {
fi fi
fi fi
else else
echo "" say ""
echo -e "${RED}Sorry${RESET}, ${SITE} isn't available as an nginx template" say "${RED}Sorry${RESET}, ${SITE} isn't available as an nginx template"
echo "We have..." say "We have..."
echo `ls resources/nginx` echo `ls resources/nginx`
fi fi
} }
get_domain() { get_domain() {
if [ ! -z $DOMAIN ]; then if [ ! -z $DOMAIN ]; then
echo -e "Your domain name is currently set to ${BLUE}${DOMAIN}${RESET}" say "Your domain name is currently set to ${BLUE}${DOMAIN}${RESET}"
echo -ne "would you like to change it? ${BLUE}(y/n): ${RESET}" ask_for newdns "would you like to change it? ${BLUE}(y/n): ${RESET}"
read newdns
case $newdns in case $newdns in
y | Y) y | Y)
forget "DOMAIN" forget "DOMAIN"
@ -155,33 +152,30 @@ get_domain() {
fi fi
if [ -z $DOMAIN ]; then if [ -z $DOMAIN ]; then
echo -en "Do you have a domain name pointing to this computer? ${BLUE}(y/n)${RESET}: " ask_for dns "Do you have a domain name pointing to this computer? ${BLUE}(y/n)${RESET}: "
read dns say ""
echo ""
case $dns in case $dns in
y | Y) y | Y)
echo "Good to hear! What is it?" say "Good to hear! What is it?"
OKAY=0 OKAY=0
while [ $OKAY -eq 0 ]; do while [ $OKAY -eq 0 ]; do
echo -n "http://" ask_for DOMAIN "http://"
read DOMAIN say ""
echo "" ask_for correct "is ${BLUE}http://${DOMAIN}${RESET} correct? ${BLUE}(y/n): ${RESET}"
echo -ne "is ${BLUE}http://${DOMAIN}${RESET} correct? ${BLUE}(y/n): ${RESET}"
read correct
case $correct in case $correct in
y | Y) y | Y)
OKAY=1 OKAY=1
;; ;;
*) *)
echo "Okay, let's try again! What is your domain name?" say "Okay, let's try again! What is your domain name?"
;; ;;
esac esac
done done
echo -e "${BLUE}${DOMAIN}${RESET}, got it." say "${BLUE}${DOMAIN}${RESET}, got it."
remember "DOMAIN=${DOMAIN}" remember "DOMAIN=${DOMAIN}"
;; ;;
*) *)
echo "Okay, let's just leave it open for now." say "Okay, let's just leave it open for now."
;; ;;
esac esac
fi fi
@ -206,22 +200,23 @@ enable_ssl() {
echo "We've already gone through the SSL enabling process! Skipping" echo "We've already gone through the SSL enabling process! Skipping"
else else
if [ ! -z $DOMAIN ]; then if [ ! -z $DOMAIN ]; then
read -p "Would you like to enable SSL via Certbot? (y/n): " -n1 ssl ask_for ssl "Would you like to enable SSL via Certbot? (y/n): "
echo "" say ""
case $ssl in case $ssl in
y | Y) y | Y)
echo "Alright, let's get Certbot in here!" say "Alright, let's get Certbot in here!"
install_if_needed python3 certbot python3-certbot-nginx install_if_needed python3 certbot python3-certbot-nginx
echo -e "${BOLD}Take it away, Certbot${NC}" say "${BOLD}Take it away, Certbot${RESET}"
SSL=$(sudo certbot --nginx) sudo certbot --nginx
SSL=$?
remember "SSL=$SSL" remember "SSL=$SSL"
;; ;;
*) *)
echo "Yea, SSL is like, totally whatever anyways..." say "Yea, SSL is like, totally whatever anyways..."
;; ;;
esac esac
else else
echo "We can't configure SSL without a domain! Skipping" say "We can't configure SSL without a domain! Skipping"
fi fi
fi fi
@ -238,7 +233,7 @@ enable_ssl() {
} }
check_ports() { check_ports() {
echo -e "${BOLD}Checking Port Accessibility${RESET}" say "${BOLD}Checking Port Accessibility${RESET}"
if [ -z $DOMAIN ]; then if [ -z $DOMAIN ]; then
ADDR=$EXTERNAL_IP ADDR=$EXTERNAL_IP
@ -246,38 +241,38 @@ check_ports() {
ADDR=$DOMAIN ADDR=$DOMAIN
fi fi
echo -e "Querying this computer's network from ${BLUE}${ADDR}${RESET}" say "Querying this computer's network from ${BLUE}${ADDR}${RESET}"
echo "" echo ""
install_if_needed nmap install_if_needed nmap
nmap -Pn $EXTERNAL_IP > nmap.txt nmap -Pn $EXTERNAL_IP > nmap.txt
OPEN=1 OPEN=1
if grep -qE "^80/.*(open|filtered)" nmap.txt; then if grep -qE "^80/.*(open|filtered)" nmap.txt; then
echo -e "I can see port ${GREEN}80${RESET}!" say "I can see port ${GREEN}80${RESET}!"
else else
echo -e "Uh oh, port ${RED}80${RESET} isn't showing up..." say "Uh oh, port ${RED}80${RESET} isn't showing up..."
OPEN=0 OPEN=0
fi fi
if grep -qE "^443/.*(open|filtered)" nmap.txt; then if grep -qE "^443/.*(open|filtered)" nmap.txt; then
echo -e "I can see port ${GREEN}443${RESET} as well!" say "I can see port ${GREEN}443${RESET} as well!"
else else
echo -e "Uh oh, port ${RED}443${RESET} isn't showing up..." say "Uh oh, port ${RED}443${RESET} isn't showing up..."
OPEN=0 OPEN=0
fi fi
rm nmap.txt rm nmap.txt
echo "" say ""
# TODO I changed default to src on the line below - impact? # TODO I changed default to src on the line below - impact?
LOCAL_IP=$(ip route | grep src | grep -oP "(?<=src )[^ ]+") LOCAL_IP=$(ip route | grep src | grep -oP "(?<=src )[^ ]+")
ROUTER_IP=$(route -n | grep ^0.0.0.0 | awk '{print $2}') ROUTER_IP=$(route -n | grep ^0.0.0.0 | awk '{print $2}')
if [[ $OPEN -eq 0 ]]; then if [ "$OPEN" -eq 0 ]; then
echo -e "${RED}Port configuration needed.${RESET} Something (probably your wireless router) is blocking us from serving this page to the rest of the internet." say "${RED}Port configuration needed.${RESET} Something (probably your wireless router) is blocking us from serving this page to the rest of the internet."
echo "Port forwarding is relatively simple, but as it stands it is beyond the scope of this script to be able to automate it." say "Port forwarding is relatively simple, but as it stands it is beyond the scope of this script to be able to automate it."
echo -e "You'll probably need to look up the login information for your specific router and forward the red ports to the local IP of this computer (${BOLD}${LOCAL_IP}${RESET})." say "You'll probably need to look up the login information for your specific router and forward the red ports to the local IP of this computer (${BOLD}${LOCAL_IP}${RESET})."
echo -e "You can log into your router at this IP address: ${BOLD}${ROUTER_IP}${RESET}" say "You can log into your router at this IP address: ${BOLD}${ROUTER_IP}${RESET}"
echo "That's all the help I can give you regarding port forwarding. Good luck!" say "That's all the help I can give you regarding port forwarding. Good luck!"
echo "" say ""
fi fi
} }

2
ingredients/gold

@ -22,7 +22,7 @@ install_bitcoin() {
fi fi
# This still relies on package management though # This still relies on package management though
install_if_needed boost install_if_needed boost autoconf
tar -xvf 🜍/bitcoin-22.0.tar.gz tar -xvf 🜍/bitcoin-22.0.tar.gz
sleep 1 sleep 1

23
ingredients/iron

@ -22,6 +22,10 @@ fi
set_node_to() { set_node_to() {
if check_for nvm; then if check_for nvm; then
if ! check_for node; then
nvm install v16.14.0
fi
if [ ! $(node -v) = $1 ]; then if [ ! $(node -v) = $1 ]; then
nvm install $1 nvm install $1
nvm alias default $1 nvm alias default $1
@ -33,8 +37,8 @@ set_node_to() {
} }
install_nvm() { install_nvm() {
echo -e "${BOLD}Installing Node Version Manager${RESET}" say "${BOLD}Installing Node Version Manager${RESET}"
if [ -n $NVM_DIR ]; then if [ -d "$NVM_DIR" ]; then
echo "nvm already installed! skipping" echo "nvm already installed! skipping"
else else
chmod +x scripts/nvm_install.sh chmod +x scripts/nvm_install.sh
@ -51,18 +55,17 @@ build_service_from_template() {
shift shift
echo "" echo ""
if [ -f resources/service-templates/${SERVICE} ]; then if [ -f resources/service-templates/${SERVICE} ]; then
echo "Creating $SERVICE.service..." say "Creating $SERVICE.service..."
SERVICE_FILE=/etc/systemd/system/${SERVICE}.service SERVICE_FILE=/etc/systemd/system/${SERVICE}.service
if [ -f "$SERVICE_FILE" ]; then if [ -f "$SERVICE_FILE" ]; then
echo "Seems like you've already installed ${SERVICE} here!" say "Seems like you've already installed ${SERVICE} here!"
echo -en "Would you like to recreate it? ${BLUE}(y/n)${RESET} " ask_for reset "Would you like to recreate it? ${BLUE}(y/n)${RESET} "
read reset
case $reset in case $reset in
"Y" | "y") "Y" | "y")
sudo rm $SERVICE_FILE sudo rm $SERVICE_FILE
;; ;;
"N" | "n") "N" | "n")
echo "Okay, we'll leave it as is." say "Okay, we'll leave it as is."
;; ;;
esac esac
fi fi
@ -77,12 +80,12 @@ build_service_from_template() {
KEY=$(echo $keyval | cut -d'=' -f 1) KEY=$(echo $keyval | cut -d'=' -f 1)
VAL=$(echo $keyval | cut -d'=' -f 2) VAL=$(echo $keyval | cut -d'=' -f 2)
echo "Substituting $KEY for $VAL" say "Substituting $KEY for $VAL"
sudo sed -i "s#$KEY#$VAL#g" $SERVICE_FILE sudo sed -i "s#$KEY#$VAL#g" $SERVICE_FILE
done done
fi fi
else else
echo "No service template available for $SERVICE" say "No service template available for $SERVICE"
fi fi
} }
@ -90,7 +93,7 @@ activate_service() {
SERVICE=$1 SERVICE=$1
SERVICE_FILE=/etc/systemd/system/${SERVICE}.service SERVICE_FILE=/etc/systemd/system/${SERVICE}.service
if [ -f "$SERVICE_FILE" ]; then if [ -f "$SERVICE_FILE" ]; then
echo -e "Enabling and starting ${GREEN}${SERVICE}${RESET}" say "Enabling and starting ${GREEN}${SERVICE}${RESET}"
sudo systemctl enable ${SERVICE} sudo systemctl enable ${SERVICE}
sudo systemctl start ${SERVICE} sudo systemctl start ${SERVICE}
fi fi

4
recipes/ao.sh

@ -3,7 +3,7 @@
# Script for installing the base dependencies of AO and getting it running # Script for installing the base dependencies of AO and getting it running
# Bare Metal Alchemist, 2022 # Bare Metal Alchemist, 2022
source ingredients/lead . ingredients/lead
source ingredients/copper source ingredients/copper
source ingredients/iron source ingredients/iron
source ingredients/gold source ingredients/gold
@ -38,6 +38,8 @@ if [ "$EUID" -eq 0 ]; then
exit 1 exit 1
fi fi
# TODO: dependencies should not be frontloaded, they should be installed as needed
echo -e "Making sure we've got the basics..." echo -e "Making sure we've got the basics..."
echo -e "(you'll probably need to input ${BLUE}your 'sudo' password${RESET} here)" echo -e "(you'll probably need to input ${BLUE}your 'sudo' password${RESET} here)"
case $DISTRO in case $DISTRO in

12
recipes/flask.sh

@ -3,7 +3,7 @@
# Script for installing a simple Flask server and deploying it # Script for installing a simple Flask server and deploying it
# Bare Metal Alchemist, 2022 # Bare Metal Alchemist, 2022
source ingredients/lead . ingredients/lead
source ingredients/iron source ingredients/iron
source ingredients/copper source ingredients/copper
@ -31,7 +31,7 @@ say "Well, as an alchemy-themed toolkit, I must say: ${GREEN}good decision :)${R
say "" say ""
# Make sure this script isn't being run with sudo in front # Make sure this script isn't being run with sudo in front
if [ "$EUID" -eq 0 ]; then if [ "$(id -u)" -eq 0 ]; then
say "${RED}${BOLD}Woah there!${RESET} Seems you're running this script as a superuser." say "${RED}${BOLD}Woah there!${RESET} Seems you're running this script as a superuser."
say "" say ""
say "That might cause some issues with permissions and whatnot. Run this script as your default user (without sudo) and I'll ask you when I need superuser permissions" say "That might cause some issues with permissions and whatnot. Run this script as your default user (without sudo) and I'll ask you when I need superuser permissions"
@ -40,11 +40,10 @@ if [ "$EUID" -eq 0 ]; then
fi fi
say "${ULINE}Making sure we've got the basics...${RESET}" say "${ULINE}Making sure we've got the basics...${RESET}"
echo -e "(you'll probably need to input ${BLUE}your 'sudo' password${RESET} here)" say "(you'll probably need to input ${BLUE}your 'sudo' password${RESET} here)"
case $DISTRO in case $DISTRO in
"debian") "debian")
say "HEY I HAVEN'T TESTED THIS BY THE WAY" install_if_needed python python3-pip python-is-python3 python3-venv
install_if_needed python python-pip
pip install --upgrade pip pip install --upgrade pip
;; ;;
"arch") "arch")
@ -105,7 +104,8 @@ say ""
say "${BOLD}We've got everything!${RESET} I'm going to set you up with \ say "${BOLD}We've got everything!${RESET} I'm going to set you up with \
a basic Flask page now\n" a basic Flask page now\n"
mkdir -p ${FLASK_DIR}/{templates,static} mkdir -p ${FLASK_DIR}/templates
mkdir -p ${FLASK_DIR}/static
cp resources/flask/app.py ${FLASK_DIR} cp resources/flask/app.py ${FLASK_DIR}
cp resources/flask/demo.css ${FLASK_DIR}/static cp resources/flask/demo.css ${FLASK_DIR}/static
cp resources/flask/demo.html ${FLASK_DIR}/templates cp resources/flask/demo.html ${FLASK_DIR}/templates

33
recipes/init.sh

@ -3,24 +3,7 @@
# This is a script to be run on a fresh installation of Raspbian in order to make it suitable (to me) for CLI development # This is a script to be run on a fresh installation of Raspbian in order to make it suitable (to me) for CLI development
# ~ Zen, 2022 # ~ Zen, 2022
source ingredients/lead . ingredients/lead
echo "Updating the repositories..."
case $DISTRO in
"debian")
sudo apt update
sudo apt autoremove
sudo apt upgrade
;;
"arch")
sudo pacman -Syu
;;
"mac")
install
sudo brew update
;;
esac
echo ""
echo "Making sure we've got the basics..." echo "Making sure we've got the basics..."
case $DISTRO in case $DISTRO in
@ -36,10 +19,12 @@ case $DISTRO in
esac esac
echo "" echo ""
echo "Getting tmux-powerline" if [ ! -d "$HOME/.tmux/tmux-powerline" ]; then
mkdir -p $HOME/.tmux echo "Getting tmux-powerline"
git clone https://github.com/erikw/tmux-powerline.git $HOME/.tmux/tmux-powerline mkdir -p $HOME/.tmux
echo "" git clone https://github.com/erikw/tmux-powerline.git $HOME/.tmux/tmux-powerline
echo ""
fi
echo "Copying configuration files" echo "Copying configuration files"
mkdir -p $HOME/.vim/colors mkdir -p $HOME/.vim/colors
@ -50,8 +35,8 @@ cp resources/tmux-powerline-theme.sh $HOME/.tmux/tmux-powerline/themes/default.s
echo "" echo ""
# TODO is this needed? can we install p10k on base zsh? # TODO is this needed? can we install p10k on base zsh?
#echo "Installing Oh My Zsh for theming - this could take a moment" echo "Installing Oh My Zsh for theming - this could take a moment"
#sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
cat resources/zshrc-extras >> $HOME/.zshrc cat resources/zshrc-extras >> $HOME/.zshrc
echo "" echo ""

Loading…
Cancel
Save