Browse Source

modularized service templating

main
Zen 3 years ago
parent
commit
b410fa83bf
  1. 49
      ingredients/copper
  2. 112
      recipes/ao.sh
  3. 0
      resources/service-templates/ao
  4. 0
      resources/service-templates/bitcoin
  5. 0
      resources/service-templates/lightning
  6. 0
      resources/service-templates/tor

49
ingredients/copper

@ -95,6 +95,55 @@ get_domain_name() {
fi fi
} }
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 -n "Would you like to recreate it? ${BLUE}(y/n)${RESET} "
read reset
case reset in
"Y" | "y")
sudo rm $SERVICE_FILE
;;
"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_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
}
check_ports() { check_ports() {
install_if_needed nmap install_if_needed nmap
nmap -Pn $domain > nmap.txt nmap -Pn $domain > nmap.txt

112
recipes/ao.sh

@ -53,7 +53,7 @@ case $DISTRO in
fi fi
install_if_needed wget python gmp sqlite3 autoconf-archive pkgconf libev \ install_if_needed wget python gmp sqlite3 autoconf-archive pkgconf libev \
python-mako python-pip net-tools zlib libsodium gettext dnsutils nginx python-mako python-pip net-tools zlib libsodium gettext nginx
;; ;;
"mac") "mac")
# install_if_needed better-computer # install_if_needed better-computer
@ -257,25 +257,29 @@ esac
echo "Excellent! We've configured $AO_NGINX_CONF to serve your AO from $domain" echo "Excellent! We've configured $AO_NGINX_CONF to serve your AO from $domain"
echo "" echo ""
read -p "Would you like to enable SSL via Certbot? (y/n): " -n1 ssl if [ -z $anywhere ]; then
echo "" read -p "Would you like to enable SSL via Certbot? (y/n): " -n1 ssl
case $ssl in echo ""
y | Y) case $ssl in
echo "Alright, let's get Certbot in here!" y | Y)
install_if_needed python3 certbot python3-certbot-nginx echo "Alright, let's get Certbot in here!"
echo -e "${BOLD}Take it away, Certbot${NC}" install_if_needed python3 certbot python3-certbot-nginx
sudo certbot --nginx echo -e "${BOLD}Take it away, Certbot${NC}"
;; sudo certbot --nginx
*) ;;
echo "Yea, SSL is lame anyways..." *)
;; echo "Yea, SSL is lame anyways..."
esac ;;
esac
fi
echo "" echo ""
# ------------------- Step 7 - Systemd Setup ------------------- # ------------------- Step 7 - Systemd Setup -------------------
READY='' READY=''
echo -e "\n${BOLD}Alright, almost there!${RESET} Now we just need to set up the system daemons for Tor, Bitcoin, Lightning, and the AO so that everything opens on startup." echo -e "\n${BOLD}Alright, almost there!${RESET} Now we just need to \
set up the system daemons for Tor, Bitcoin, Lightning, and the AO\
so that everything opens on startup."
while [[ -z $READY ]]; do while [[ -z $READY ]]; do
echo -en "${BLUE}You ready? (y/n):${RESET} " echo -en "${BLUE}You ready? (y/n):${RESET} "
read -n1 ao_select read -n1 ao_select
@ -293,21 +297,7 @@ while [[ -z $READY ]]; do
esac esac
done done
echo "" build_service_from_template tor "TORRCPATH=$TORRCPATH" "TORPATH=`which tor`"
echo "Creating tor.service..."
TOR_SERVICE=/etc/systemd/system/tor.service
if [ -f "$TOR_SERVICE" ]; then
echo "Seems like you've already got tor here!"
else
sudo cp resources/tor-service-template $TOR_SERVICE
# Making sure all values have been de-templated
sudo sed -i "s#USER#${USER}#g" $TOR_SERVICE
sudo sed -i "s#HOME#${HOME}#g" $TOR_SERVICE
sudo sed -i "s#TORRCPATH#${TORRCPATH}#g" $TOR_SERVICE
sudo sed -i "s#TORPATH#$(which tor)#g" $TOR_SERVICE
fi
# Creating the .tor directory # Creating the .tor directory
sudo mkdir -p $HOME/.tor sudo mkdir -p $HOME/.tor
@ -315,67 +305,22 @@ sudo chown tor $HOME/.tor
sudo chgrp $USER $HOME/.tor sudo chgrp $USER $HOME/.tor
sudo chmod 770 $HOME/.tor sudo chmod 770 $HOME/.tor
echo "Enabling and starting Tor" activate_service tor
sudo systemctl enable tor
sudo systemctl start tor
echo "" echo ""
echo "Creating bitcoin.service..." build_service_from_template bitcoin "BITCOIND=`which bitcoind`"
BTC_SERVICE=/etc/systemd/system/bitcoin.service activate_service bitcoin
if [ -f "$BTC_SERVICE" ]; then
echo -e "Seems like you've already have a bitcoin service!"
else
sudo cp resources/bitcoin-service-template $BTC_SERVICE
# Making sure all values have been de-templated
sudo sed -i "s#USER#${USER}#g" $BTC_SERVICE
sudo sed -i "s#HOME#${HOME}#g" $BTC_SERVICE
sudo sed -i "s#BITCOIND#$(which bitcoind)#g" $BTC_SERVICE
fi
echo -e "Enabling and starting ${GREEN}Bitcoin${RESET}"
sudo systemctl enable bitcoin
sudo systemctl start bitcoin
echo "" echo ""
echo "Creating lightning.service..." build_service_from_template lightningd "LIGHTNINGD=`which lightningd`"
LN_SERVICE=/etc/systemd/system/lightning.service activate_service lightningd
if [ -f "$LN_SERVICE" ]; then
echo -e "Seems like you've already have a lightning service!"
else
sudo cp resources/lightning-service-template $LN_SERVICE
# Making sure all values have been de-templated
sudo sed -i "s#USER#${USER}#g" $LN_SERVICE
sudo sed -i "s#HOME#${HOME}#g" $LN_SERVICE
sudo sed -i "s#LIGHTNINGD#$(which lightningd)#g" $LN_SERVICE
fi
echo -e "Enabling and starting ${GREEN}lightning${RESET} "
sudo systemctl enable lightning
sudo systemctl start lightning
echo "" echo ""
echo "Creating ao.service..." build_service_from_template ao "NODE=`which node`" "AO=$AO" "NODE_PARAMS=$NODE_PARAMS"
AO_SERVICE=/etc/systemd/system/ao.service activate_service ao
if [ -f "$AO_SERVICE" ]; then
echo "Seems like you've already added one of these!"
else
sudo cp resources/ao-service-template $AO_SERVICE
# Making sure all values have been de-templated
sudo sed -i "s#USER#${USER}#g" $AO_SERVICE
sudo sed -i "s#HOME#${HOME}#g" $AO_SERVICE
sudo sed -i "s#NODE#$(which node)#g" $AO_SERVICE
sudo sed -i "s#AO#${AO}#g" $AO_SERVICE
sudo sed -i "s#NODE_PARAMS#${NODE_PARAMS}#g" $AO_SERVICE
fi
echo -e "Enabling and starting the ${GREEN}AO${RESET}'s backend"
sudo systemctl enable ao
sudo systemctl start ao
echo "" echo ""
echo -e "Enabling and starting ${GREEN}NGINX${RESET} as the webserver" activate_service nginx
sudo systemctl enable nginx
sudo systemctl start nginx
# ------------------- Step 8 - Port Testing ------------------- # ------------------- Step 8 - Port Testing -------------------
@ -384,6 +329,7 @@ echo -e "${BOLD}One more thing!${RESET} We need to make sure that your ports are
check_ports check_ports
# ------------------- Step 9 - Health Check ------------------- # ------------------- Step 9 - Health Check -------------------
echo '*********************************************************' echo '*********************************************************'
echo -e "* ${BOLD}Version Information${RESET} *" echo -e "* ${BOLD}Version Information${RESET} *"
echo '*********************************************************' echo '*********************************************************'

0
resources/ao-service-template → resources/service-templates/ao

0
resources/bitcoin-service-template → resources/service-templates/bitcoin

0
resources/lightning-service-template → resources/service-templates/lightning

0
resources/tor-service-template → resources/service-templates/tor

Loading…
Cancel
Save