Browse Source

Modularization and further polishing complete

main
Zen 3 years ago
parent
commit
8548ee7721
  1. 2
      README.md
  2. 80
      ingredients/copper
  3. 10
      ingredients/gold
  4. 57
      ingredients/iron
  5. 6
      ingredients/lead
  6. 43
      recipes/ao.sh

2
README.md

@ -39,7 +39,7 @@ It provides infrastructure that makes development in Alchemy more accessible.
`tin` corresponds to hardware and interaction with physical systems. `tin` corresponds to hardware and interaction with physical systems.
`iron` forms the core of web development in the ecosystem. `iron` forms the core of web development and system operation
`copper` corresponds to connectivity to other systems on the network. `copper` corresponds to connectivity to other systems on the network.

80
ingredients/copper

@ -41,7 +41,7 @@ configure_tor() {
echo "" echo ""
cat $TORRCPATH | grep '^[^#]' cat $TORRCPATH | grep '^[^#]'
echo "" echo ""
echo -en "Would you like to reset them?: ${BLUE}(y/n)${RESET} " echo -en "Would you like to reset it?: ${BLUE}(y/n)${RESET} "
read torrc_reset read torrc_reset
case $torrc_reset in case $torrc_reset in
"Y" | "y") "Y" | "y")
@ -77,6 +77,8 @@ get_external_ip() {
} }
initialize_nginx() { initialize_nginx() {
echo -e "${BOLD}Installing and configuring NGINX${RESET}"
echo ""
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
@ -95,10 +97,8 @@ 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 -en "You already have a site available for ${SITE}, \ echo -e "You already have a site available for ${BLUE}${SITE}${RESET}, what would you like to do?"
what would you like to do? ${BOLD}R${RESET}eset it,\ echo -en "${BOLD}R${RESET}eset it, ${BOLD}A${RESET}ctivate it, or do ${BOLD}N${RESET}othing? (r/a/n): "
${BOLD}A${RESET}ctivate it, or do ${BOLD}N${RESET}\
othing? ( r / a / n ): "
read whatdo read whatdo
case $whatdo in case $whatdo in
"R" | "r") "R" | "r")
@ -118,6 +118,7 @@ make_site() {
echo "Instructions unclear, accidentally an choice" echo "Instructions unclear, accidentally an choice"
;; ;;
esac esac
echo ""
fi fi
if [ ! -f $NGINX_SITE_LOCATION ]; then if [ ! -f $NGINX_SITE_LOCATION ]; then
@ -239,58 +240,19 @@ enable_ssl() {
remember "ACCESS_POINT=${ACCESS_POINT}" remember "ACCESS_POINT=${ACCESS_POINT}"
} }
build_service_from_template() { check_ports() {
SERVICE=$1 echo -e "${BOLD}Checking Port Accessibility${RESET}"
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" if [ -z $DOMAIN ]; then
sudo sed -i "s#$KEY#$VAL#g" $SERVICE_FILE ADDR=$EXTERNAL_IP
done
fi
else else
echo "No service template available for $SERVICE" ADDR=$DOMAIN
fi fi
}
activate_service() { echo -e "Querying this computer from ${BLUE}${ADDR}${RESET}"
SERVICE_FILE=/etc/systemd/system/${SERVICE}.service echo ""
if [ -f "$SERVICE_FILE" ]; then
echo -e "Enabling and starting ${GREEN}${SERVICE}${RESET}"
sudo systemctl enable ${SERVICE}
sudo systemctl start ${SERVICE}
fi
}
check_ports() {
install_if_needed nmap install_if_needed nmap
nmap -Pn $domain > 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}!" echo -e "I can see port ${GREEN}80${RESET}!"
@ -307,19 +269,19 @@ check_ports() {
fi fi
rm nmap.txt rm nmap.txt
echo "" echo ""
# TODO I changed default to src on the line below - impact?
LOCAL_IP=$(ip route | grep src | grep -oP "(?<=src )[^ ]+")
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." 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."
echo "Port forwarding is relatively simple, but as it stands it is beyond the scope of this script to be able to automate it." echo "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}$(ip route | grep default | grep -oP "(?<=src )[^ ]+")${RESET})." 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})."
echo -e "You can log into your router at this IP address: ${BOLD}$(route -n | grep ^0.0.0.0 | awk '{print $2}')${RESET}" echo -e "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!" echo "That's all the help I can give you regarding port forwarding. Good luck!"
echo "" echo ""
fi fi
} }
# internet connections? copper wires etc.
# using yggdrasil could maybe fit in here # using yggdrasil could maybe fit in here
# nginx setup
# port checking

10
ingredients/gold

@ -78,7 +78,7 @@ configure_bitcoin() {
echo "" echo ""
cat $HOME/.bitcoin/bitcoin.conf cat $HOME/.bitcoin/bitcoin.conf
echo "" echo ""
echo -n "Would you like to reset it? (y/n): " echo -en "Would you like to reset it? ${BLUE}(y/n)${RESET}: "
read btc_reconf read btc_reconf
case $btc_reconf in case $btc_reconf in
"y" | "Y") "y" | "Y")
@ -97,7 +97,7 @@ configure_bitcoin() {
sed -i "s/BTC_LOGIN/${AUTHLINE}/" $HOME/.bitcoin/bitcoin.conf sed -i "s/BTC_LOGIN/${AUTHLINE}/" $HOME/.bitcoin/bitcoin.conf
echo "" echo ""
echo -n "Next question - do you have 500GB of open memory on this device? (y/n): " echo -en "Next question - do you have 500GB of open memory on this device? ${BLUE}(y/n)${RESET}: "
read prune read prune
echo "" echo ""
case $prune in case $prune in
@ -105,7 +105,7 @@ configure_bitcoin() {
echo "Okay great! We'll leave the bitcoin config it as it is." echo "Okay great! We'll leave the bitcoin config it as it is."
;; ;;
*) *)
echo "Let's enable pruning to keep the file size down, then." echo -e "Let's ${GREEN}enable pruning${RESET} to keep the file size down, then."
sed -i "s/txindex=1/prune=550/" $HOME/.bitcoin/bitcoin.conf sed -i "s/txindex=1/prune=550/" $HOME/.bitcoin/bitcoin.conf
;; ;;
esac esac
@ -119,7 +119,7 @@ configure_lightning() {
echo "" echo ""
cat $HOME/.lightning/config cat $HOME/.lightning/config
echo "" echo ""
echo -n "Would you like to reset it? (y/n): " echo -en "Would you like to reset it? ${BLUE}(y/n)${RESET}: "
read ln_reconf read ln_reconf
case $ln_reconf in case $ln_reconf in
"y" | "Y") "y" | "Y")
@ -136,7 +136,7 @@ configure_lightning() {
fi fi
echo "" echo ""
echo -n "Would you like to use clboss to automatically open lightning channels? (y/n): " echo -en "Would you like to use clboss to automatically open lightning channels? ${BLUE}(y/n)${RESET}: "
read clboss_enable read clboss_enable
case $clboss_enable in case $clboss_enable in
"y" | "Y") "y" | "Y")

57
ingredients/iron

@ -10,10 +10,9 @@
# our society as a whole. # our society as a whole.
# This ingredient contains functions for building web applications and # This ingredient contains functions for building web applications and
# installing common frameworks. Expect to use this one a lot if you're # running them frm your server. Expect to use this one a lot if you're
# writing alchemy recipes! # writing alchemy recipes!
# ------------------- NodeJS Ecosystem ------------------- # ------------------- NodeJS Ecosystem -------------------
if [ -d $NVM_DIR ]; then if [ -d $NVM_DIR ]; then
@ -23,9 +22,11 @@ fi
set_node_to() { set_node_to() {
if check_exists nvm; then if check_exists nvm; then
if [ ! $(node -v) = $1 ]; then
nvm install $1 nvm install $1
nvm alias default $1 nvm alias default $1
nvm use default nvm use default
fi
else else
echo "nvm not available, something went wrong..." echo "nvm not available, something went wrong..."
fi fi
@ -43,4 +44,56 @@ install_nvm() {
fi 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")
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=$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 IRON=1

6
ingredients/lead

@ -115,12 +115,12 @@ remember() {
echo "Keys must consist only of capital letters and underscores" echo "Keys must consist only of capital letters and underscores"
fi fi
if [[ ! $VALUE =~ ^[A-Za-z0-9/_.]+$ ]]; then if [[ ! $VALUE =~ ^[A-Za-z0-9/_.:]+$ ]]; then
echo "Valid characters for env values: letters, numbers, \".\",\"/\",\"_\"" echo "Valid characters for env values: letters, numbers, \".\",\"/\",\"_\"",\":\"
fi fi
# If we're setting a valid key/value pair # If we're setting a valid key/value pair
if [[ ${1} =~ ^[A-Z_]+\=[A-Za-z0-9/._]*$ ]]; then if [[ ${1} =~ ^[A-Z_]+\=[A-Za-z0-9/._:]*$ ]]; then
# If we're trying to set the value to something new # If we're trying to set the value to something new
if [[ ! $(env | grep ${KEY}) = $1 ]]; then if [[ ! $(env | grep ${KEY}) = $1 ]]; then

43
recipes/ao.sh

@ -67,6 +67,21 @@ echo ""
# ------------------- Step 2 - AO Environment Setup ------------------- # ------------------- Step 2 - AO Environment Setup -------------------
if [ ! -z $AO ]; then
echo "You're currently using ao-$AO"
echo -en "Would you like to re-install? ${BLUE}(y/n): ${RESET}"
read reinstall_ao
echo ""
case $reinstall_ao in
"Y" | "y")
forget AO
;;
*)
echo "Okay, we'll keep using this version of AO"
;;
esac
fi
if [ -z $AO ]; then if [ -z $AO ]; then
AO='' AO=''
echo -e "${BOLD}Hey!${RESET} I was wondering which ${BLUE}version of AO${RESET} you wanted to install. \n" echo -e "${BOLD}Hey!${RESET} I was wondering which ${BLUE}version of AO${RESET} you wanted to install. \n"
@ -102,11 +117,10 @@ if [ $AO = "3" ] || [ $AO = 'react' ]; then
install_nvm install_nvm
source ingredients/iron source ingredients/iron
else else
echo -e "${BLUE}Node${RESET} already installed" echo -e "${BLUE}Node${RESET} already installed!"
echo ""
fi fi
echo "Setting Node to ${BLUE}v16.13.0${RESET} for compatibility" echo -e "Setting Node to ${BLUE}v16.13.0${RESET} for compatibility"
set_node_to v16.13.0 set_node_to v16.13.0
echo "" echo ""
echo -e "${GREEN}Done!${RESET}" echo -e "${GREEN}Done!${RESET}"
@ -136,6 +150,7 @@ if [ $AO = "3" ] || [ $AO = 'react' ]; then
echo -e "${BOLD}Installing and configuring Tor${RESET}\n" echo -e "${BOLD}Installing and configuring Tor${RESET}\n"
install_if_needed tor install_if_needed tor
configure_tor configure_tor
echo ""
fi fi
# ------------------- Step 3 - AO Installation ------------------- # ------------------- Step 3 - AO Installation -------------------
@ -157,8 +172,10 @@ CONFIG_FILE=$HOME/ao-$AO/configuration.js
case $AO in case $AO in
"3") "3")
if [ ! -d ~/ao-3 ]; then
echo -e "Installing ${BLUE}ao-3${RESET}" echo -e "Installing ${BLUE}ao-3${RESET}"
git clone 'https://github.com/AutonomousOrganization/ao-3.git' ~/ao-3 git clone 'https://github.com/AutonomousOrganization/ao-3.git' ~/ao-3
fi
if [ -f "$CONFIG_FILE" ]; then if [ -f "$CONFIG_FILE" ]; then
echo configuration.js already exists echo configuration.js already exists
else else
@ -181,7 +198,9 @@ case $AO in
;; ;;
"react") "react")
echo -e "Installing ${BLUE}ao-react${RESET}" echo -e "Installing ${BLUE}ao-react${RESET}"
if [ ! -d ~/ao-react ]; then
git clone 'https://github.com/coalition-of-invisible-colleges/ao-react.git' ~/ao-react git clone 'https://github.com/coalition-of-invisible-colleges/ao-react.git' ~/ao-react
fi
if [ -f "$CONFIG_FILE" ]; then if [ -f "$CONFIG_FILE" ]; then
echo configuration.js already exists echo configuration.js already exists
else else
@ -196,8 +215,8 @@ case $AO in
echo "" echo ""
pushd ~/ao-react pushd ~/ao-react
npm install #npm install
npm run webpack #npm run webpack
popd popd
NODE_PARAMS='--experimental-specifier-resolution=node -r dotenv/config' NODE_PARAMS='--experimental-specifier-resolution=node -r dotenv/config'
@ -207,11 +226,12 @@ esac
# ------------------- Step 4 - NGINX Setup ------------------- # ------------------- Step 4 - NGINX Setup -------------------
echo "" echo ""
echo -e "You still there? I need to ask you some questions! \n\n${BLUE}(enter)${RESET}" echo -en "You still there? I might need your input here! \n\n${BLUE}(enter)${RESET}"
read read
initialize_nginx initialize_nginx
make_site ao "FILE_ROOT=${HOME}/ao-${AO}/dist" make_site ao "FILE_ROOT=${HOME}/ao-${AO}/dist"
echo ""
configure_domain_for_site ao configure_domain_for_site ao
enable_ssl enable_ssl
@ -220,9 +240,7 @@ esac
# ------------------- Step 7 - Systemd Setup ------------------- # ------------------- Step 7 - Systemd Setup -------------------
READY='' READY=''
echo -e "\n${BOLD}Alright, almost there!${RESET} Now we just need to \ 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."
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
@ -255,20 +273,21 @@ build_service_from_template bitcoin "BITCOIND=`which bitcoind`"
activate_service bitcoin activate_service bitcoin
echo "" echo ""
build_service_from_template lightningd "LIGHTNINGD=`which lightningd`" build_service_from_template lightning "LIGHTNINGD=`which lightningd`"
activate_service lightningd activate_service lightning
echo "" echo ""
build_service_from_template ao "NODE=`which node`" "AO=$AO" "NODE_PARAMS=$NODE_PARAMS" build_service_from_template ao "NODE=`which node`" "AO=$AO" "NODE_PARAMS=$NODE_PARAMS"
activate_service ao activate_service ao
echo "" echo "this should be nginx"
activate_service nginx activate_service nginx
# ------------------- Step 8 - Port Testing ------------------- # ------------------- Step 8 - Port Testing -------------------
echo "" echo ""
echo -e "${BOLD}One more thing!${RESET} We need to make sure that your ports are open." echo -e "${BOLD}One more thing!${RESET} We need to make sure that your ports are open."
echo ""
check_ports check_ports
# ------------------- Step 9 - Health Check ------------------- # ------------------- Step 9 - Health Check -------------------

Loading…
Cancel
Save