Browse Source

Modularization and further polishing complete

main
Zen 3 years ago
parent
commit
8548ee7721
  1. 2
      README.md
  2. 84
      ingredients/copper
  3. 10
      ingredients/gold
  4. 63
      ingredients/iron
  5. 6
      ingredients/lead
  6. 49
      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.
`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.

84
ingredients/copper

@ -41,7 +41,7 @@ configure_tor() {
echo ""
cat $TORRCPATH | grep '^[^#]'
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
case $torrc_reset in
"Y" | "y")
@ -77,6 +77,8 @@ get_external_ip() {
}
initialize_nginx() {
echo -e "${BOLD}Installing and configuring NGINX${RESET}"
echo ""
install_if_needed nginx
# Making sure this version of NGINX supports sites-enabled
@ -95,10 +97,8 @@ make_site() {
if [ -f resources/nginx/${SITE}.nginx.conf ]; then
NGINX_SITE_LOCATION=/etc/nginx/sites-available/${SITE}
if [ -f $NGINX_SITE_LOCATION ]; then
echo -en "You already have a site available for ${SITE}, \
what would you like to do? ${BOLD}R${RESET}eset it,\
${BOLD}A${RESET}ctivate it, or do ${BOLD}N${RESET}\
othing? ( r / a / n ): "
echo -e "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): "
read whatdo
case $whatdo in
"R" | "r")
@ -118,6 +118,7 @@ make_site() {
echo "Instructions unclear, accidentally an choice"
;;
esac
echo ""
fi
if [ ! -f $NGINX_SITE_LOCATION ]; then
@ -231,66 +232,27 @@ enable_ssl() {
ACCESS_POINT=http://localhost
else
if [ -z $SSL ]; then
ACCESS_POINT=http://$DOMAIN
ACCESS_POINT=http://$DOMAIN
else
ACCESS_POINT=https://$DOMAIN
ACCESS_POINT=https://$DOMAIN
fi
fi
remember "ACCESS_POINT=${ACCESS_POINT}"
}
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)
check_ports() {
echo -e "${BOLD}Checking Port Accessibility${RESET}"
echo "Substituting $KEY for $VAL"
sudo sed -i "s#$KEY#$VAL#g" $SERVICE_FILE
done
fi
if [ -z $DOMAIN ]; then
ADDR=$EXTERNAL_IP
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}
ADDR=$DOMAIN
fi
}
check_ports() {
echo -e "Querying this computer from ${BLUE}${ADDR}${RESET}"
echo ""
install_if_needed nmap
nmap -Pn $domain > nmap.txt
nmap -Pn $EXTERNAL_IP > nmap.txt
OPEN=1
if grep -qE "^80/.*(open|filtered)" nmap.txt; then
echo -e "I can see port ${GREEN}80${RESET}!"
@ -307,19 +269,19 @@ check_ports() {
fi
rm nmap.txt
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
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 -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 can log into your router at this IP address: ${BOLD}$(route -n | grep ^0.0.0.0 | awk '{print $2}')${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}${ROUTER_IP}${RESET}"
echo "That's all the help I can give you regarding port forwarding. Good luck!"
echo ""
fi
}
# internet connections? copper wires etc.
# using yggdrasil could maybe fit in here
# nginx setup
# port checking

10
ingredients/gold

@ -78,7 +78,7 @@ configure_bitcoin() {
echo ""
cat $HOME/.bitcoin/bitcoin.conf
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
case $btc_reconf in
"y" | "Y")
@ -97,7 +97,7 @@ configure_bitcoin() {
sed -i "s/BTC_LOGIN/${AUTHLINE}/" $HOME/.bitcoin/bitcoin.conf
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
echo ""
case $prune in
@ -105,7 +105,7 @@ configure_bitcoin() {
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
;;
esac
@ -119,7 +119,7 @@ configure_lightning() {
echo ""
cat $HOME/.lightning/config
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
case $ln_reconf in
"y" | "Y")
@ -136,7 +136,7 @@ configure_lightning() {
fi
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
case $clboss_enable in
"y" | "Y")

63
ingredients/iron

@ -10,10 +10,9 @@
# our society as a whole.
# 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!
# ------------------- NodeJS Ecosystem -------------------
if [ -d $NVM_DIR ]; then
@ -23,9 +22,11 @@ fi
set_node_to() {
if check_exists nvm; then
nvm install $1
nvm alias default $1
nvm use default
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
@ -43,4 +44,56 @@ install_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")
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

6
ingredients/lead

@ -115,12 +115,12 @@ remember() {
echo "Keys must consist only of capital letters and underscores"
fi
if [[ ! $VALUE =~ ^[A-Za-z0-9/_.]+$ ]]; then
echo "Valid characters for env values: letters, numbers, \".\",\"/\",\"_\""
if [[ ! $VALUE =~ ^[A-Za-z0-9/_.:]+$ ]]; then
echo "Valid characters for env values: letters, numbers, \".\",\"/\",\"_\"",\":\"
fi
# 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 [[ ! $(env | grep ${KEY}) = $1 ]]; then

49
recipes/ao.sh

@ -67,6 +67,21 @@ echo ""
# ------------------- 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
AO=''
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
source ingredients/iron
else
echo -e "${BLUE}Node${RESET} already installed"
echo ""
echo -e "${BLUE}Node${RESET} already installed!"
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
echo ""
echo -e "${GREEN}Done!${RESET}"
@ -136,6 +150,7 @@ if [ $AO = "3" ] || [ $AO = 'react' ]; then
echo -e "${BOLD}Installing and configuring Tor${RESET}\n"
install_if_needed tor
configure_tor
echo ""
fi
# ------------------- Step 3 - AO Installation -------------------
@ -157,8 +172,10 @@ CONFIG_FILE=$HOME/ao-$AO/configuration.js
case $AO in
"3")
echo -e "Installing ${BLUE}ao-3${RESET}"
git clone 'https://github.com/AutonomousOrganization/ao-3.git' ~/ao-3
if [ ! -d ~/ao-3 ]; then
echo -e "Installing ${BLUE}ao-3${RESET}"
git clone 'https://github.com/AutonomousOrganization/ao-3.git' ~/ao-3
fi
if [ -f "$CONFIG_FILE" ]; then
echo configuration.js already exists
else
@ -181,7 +198,9 @@ case $AO in
;;
"react")
echo -e "Installing ${BLUE}ao-react${RESET}"
git clone 'https://github.com/coalition-of-invisible-colleges/ao-react.git' ~/ao-react
if [ ! -d ~/ao-react ]; then
git clone 'https://github.com/coalition-of-invisible-colleges/ao-react.git' ~/ao-react
fi
if [ -f "$CONFIG_FILE" ]; then
echo configuration.js already exists
else
@ -196,8 +215,8 @@ case $AO in
echo ""
pushd ~/ao-react
npm install
npm run webpack
#npm install
#npm run webpack
popd
NODE_PARAMS='--experimental-specifier-resolution=node -r dotenv/config'
@ -207,11 +226,12 @@ esac
# ------------------- Step 4 - NGINX Setup -------------------
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
initialize_nginx
make_site ao "FILE_ROOT=${HOME}/ao-${AO}/dist"
echo ""
configure_domain_for_site ao
enable_ssl
@ -220,9 +240,7 @@ esac
# ------------------- Step 7 - Systemd Setup -------------------
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
echo -en "${BLUE}You ready? (y/n):${RESET} "
read -n1 ao_select
@ -255,20 +273,21 @@ build_service_from_template bitcoin "BITCOIND=`which bitcoind`"
activate_service bitcoin
echo ""
build_service_from_template lightningd "LIGHTNINGD=`which lightningd`"
activate_service lightningd
build_service_from_template lightning "LIGHTNINGD=`which lightningd`"
activate_service lightning
echo ""
build_service_from_template ao "NODE=`which node`" "AO=$AO" "NODE_PARAMS=$NODE_PARAMS"
activate_service ao
echo ""
echo "this should be nginx"
activate_service nginx
# ------------------- Step 8 - Port Testing -------------------
echo ""
echo -e "${BOLD}One more thing!${RESET} We need to make sure that your ports are open."
echo ""
check_ports
# ------------------- Step 9 - Health Check -------------------

Loading…
Cancel
Save