Browse Source

Still working on moving AO script bits to copper

main
Zen 3 years ago
parent
commit
4f4d43d6d8
  1. 71
      ingredients/copper
  2. 40
      ingredients/iron
  3. 11
      ingredients/lead
  4. 2
      recipes/alchemy.sh
  5. 90
      recipes/ao.sh
  6. 1
      recipes/init.sh

71
ingredients/copper

@ -27,7 +27,7 @@ locate_torrc() {
fi fi
echo -e "Your torrc is located at ${BLUE}${TORRCPATH}${RESET}" echo -e "Your torrc is located at ${BLUE}${TORRCPATH}${RESET}"
echo "TORRCPATH=${TORRCPATH}" > .env remember "TORRCPATH=${TORRCPATH}"
} }
configure_tor() { configure_tor() {
@ -56,6 +56,75 @@ configure_tor() {
echo -e "Tor configuration ${GREEN}complete!${RESET}" echo -e "Tor configuration ${GREEN}complete!${RESET}"
} }
get_external_ip() {
case $DISTRO in
"arch")
install_if_needed dnsutils
;;
"*")
#install_if_needed dig
echo "Not yet supported! Feel free to help out here :)"
;;
esac
EXTERNAL_IP=$(dig @resolver4.opendns.com myip.opendns.com +short)
echo "Your external IP is $EXTERNAL_IP"
remember "EXTERNAL_IP=$EXTERNAL_IP"
}
get_domain_name() {
read -p "Do you have a domain name pointing to this computer? (y/n): " dns
echo ""
case $dns in
y | Y)
echo "Good to hear! What is it?"
read -p "http://" domain
;;
*)
echo "Okay, let's just leave it open for now."
domain=$(dig @resolver4.opendns.com myip.opendns.com +short)
anywhere=1
echo "Try accessing this AO from either localhost, 127.0.0.1, or ${domain}"
;;
esac
if [ "$anywhere" -eq 1 ]; then
ACCESS_POINT=http://localhost
else
ACCESS_POINT=https://$domain
fi
}
check_ports() {
install_if_needed nmap
nmap -Pn $domain > nmap.txt
OPEN=1
if grep -qE "^80/.*(open|filtered)" nmap.txt; then
echo -e "I can see port ${GREEN}80${RESET}!"
else
echo -e "Uh oh, port ${RED}80${RESET} isn't showing up..."
OPEN=0
fi
if grep -qE "^443/.*(open|filtered)" nmap.txt; then
echo -e "I can see port ${GREEN}443${RESET} as well!"
else
echo -e "Uh oh, port ${RED}443${RESET} isn't showing up..."
OPEN=0
fi
rm nmap.txt
echo ""
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 "That's all the help I can give you regarding port forwarding. Good luck!"
echo ""
fi
}
# internet connections? copper wires etc. # internet connections? copper wires etc.
# using yggdrasil could maybe fit in here # using yggdrasil could maybe fit in here

40
ingredients/iron

@ -13,27 +13,33 @@
# installing common frameworks. Expect to use this one a lot if you're # installing common frameworks. Expect to use this one a lot if you're
# writing alchemy recipes! # writing alchemy recipes!
install_nodejs() { set_node_to() {
echo -e "${BOLD}Installing Node.js${RESET}" if check_exists nvm; then
nvm install v16.13.0
nvm alias default v16.13.0
nvm use default
else
echo "nvm not available, something went wrong..."
fi
}
install_nvm() {
echo -e "${BOLD}Installing Node Version Manager${RESET}"
chmod +x scripts/nvm_install.sh chmod +x scripts/nvm_install.sh
scripts/nvm_install.sh scripts/nvm_install.sh &> /dev/null
export NVM_DIR="$HOME/.nvm" remember "NVM_DIR=$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion [ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
# if [ "$SHELL" = '/bin/zsh' ]; then case $SHELL in
# echo 'sourcing zshrc' "/bin/zsh")
# source ~/.zshrc source ~/.zshrc
# else ;;
# source ~/.bashrc "/bin/bashrc")
# fi source ~/.bashrc
;;
esac
} }
set_node_to() { IRON=1
nvm install v16.13.0
nvm alias default v16.13.0
nvm use default
}

11
ingredients/lead

@ -29,16 +29,13 @@ if [[ $SHLVL -gt 1 ]]; then
# Make sure that ctrl+C consistently exits the script # Make sure that ctrl+C consistently exits the script
trap "exit" INT trap "exit" INT
# Give informative error messages when we receive ERR # Give informative error messages when we receive ERR
trap 'echo -e "${RED}Oops!${RESET} Something went wrong on line $LINENO of this script. Exit code was $?" >&2' ERR trap 'echo -e "${RED}Oops...${RESET} Something went wrong on line $LINENO of this script. Exit code was $?" >&2' ERR
fi fi
# --------------- Environment Setup --------------- # --------------- Environment Setup ---------------
if [ -d $ALCHEMY ]; then # If there's an env file, export it's contents to the environment
cd $ALCHEMY
fi
if [ -f .env ]; then if [ -f .env ]; then
export $(grep -v '^#' .env | xargs) export $(grep -v '^#' .env | xargs)
else else
@ -103,9 +100,11 @@ install_if_needed() {
done done
} }
# This one looks like gibberish because we're using regex, don't worry.
# It takes values and stores them away in the env for later reference
remember() { remember() {
KEY=$(echo ${1} | cut -d'=' -f 1) KEY=$(echo ${1} | cut -d'=' -f 1)
if [[ ${1} =~ ^[A-Z]+\=[a-z_0-9]*$ ]] && [[ -z $(env | grep ${KEY}) ]]; then if [[ ${1} =~ ^[A-Z_]+\=[A-Za-z0-9/._]*$ ]] && [[ -z $(env | grep ${KEY}) ]]; then
echo "${1}" >> .env echo "${1}" >> .env
export ${1} export ${1}
fi fi

2
recipes/alchemy.sh

@ -32,7 +32,7 @@ if [ -f .env ]; then
export $(grep -v '^#' .env | xargs) export $(grep -v '^#' .env | xargs)
else else
echo "No .env file found, let's initialize it" echo "No .env file found, let's initialize it"
echo "ALCHEMY=`pwd`" >> .env remember "ALCHEMY=$(pwd)"
fi fi
echo "" echo ""

90
recipes/ao.sh

@ -1,4 +1,4 @@
#!/bin/bash #!/bin/sh
# 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
@ -64,13 +64,16 @@ case $DISTRO in
;; ;;
esac esac
echo "" echo ""
#
## ------------------- Step 2 - AO Environment Setup ------------------- # ------------------- Step 2 - AO Environment Setup -------------------
#
AO='' if [ -z $AO ]; then
echo -e "${BOLD}Hey!${RESET} I was wondering which ${BLUE}version of AO${RESET} you wanted to install. \n" AO=''
echo -e "${BOLD}1.${RESET} ao-3 (Vue)" echo -e "${BOLD}Hey!${RESET} I was wondering which ${BLUE}version of AO${RESET} you wanted to install. \n"
echo -e "${BOLD}2.${RESET} ao-react (React)" echo -e "${BOLD}1.${RESET} ao-3 (Vue)"
echo -e "${BOLD}2.${RESET} ao-react (React)"
fi
while [[ -z $AO ]]; do while [[ -z $AO ]]; do
echo -en "${BLUE}(number):${RESET} " echo -en "${BLUE}(number):${RESET} "
read -n1 ao_select read -n1 ao_select
@ -79,11 +82,11 @@ while [[ -z $AO ]]; do
case $ao_select in case $ao_select in
"1") "1")
echo "Minimalism, I like it! Proceeding with ao-3 installation" echo "Minimalism, I like it! Proceeding with ${BLUE}ao-3${RESET} installation"
AO=3 AO=3
;; ;;
"2") "2")
echo "It's got community! Proceeding with ao-react installation" echo -e "It's got community! Proceeding with ${BLUE}ao-react${RESET} installation"
AO=react AO=react
;; ;;
*) *)
@ -91,27 +94,20 @@ while [[ -z $AO ]]; do
;; ;;
esac esac
done; done;
echo "AO=${AO}" >> .env remember "AO=${AO}"
echo ""
echo ""
if [ $AO = "3" ] || [ $AO = 'react' ]; then if [ $AO = "3" ] || [ $AO = 'react' ]; then
echo -e "${BOLD}Installing Node.js${RESET}" if ! check_exists nvm; then
chmod +x scripts/nvm_install.sh install_nvm
scripts/nvm_install.sh
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
if [ "$SHELL" = '/bin/zsh' ]; then
echo 'sourcing zshrc'
source ~/.zshrc
else else
source ~/.bashrc echo -e "${BLUE}Node${RESET} already installed"
echo ""
fi fi
nvm install v16.13.0
nvm alias default v16.13.0 echo "Setting Node to v16.13.0 for compatibility"
nvm use default set_node_to v16.13.0
echo -e "${GREEN}Done!${RESET}"
fi fi
if [ $AO = "3" ] || [ $AO = 'react' ]; then if [ $AO = "3" ] || [ $AO = 'react' ]; then
@ -151,6 +147,7 @@ else
node scripts/createPrivateKey.js >> $HOME/.ao/key node scripts/createPrivateKey.js >> $HOME/.ao/key
echo -e "Just made a fresh private key and put it in ${GREEN}~/.ao${RESET}" echo -e "Just made a fresh private key and put it in ${GREEN}~/.ao${RESET}"
fi fi
echo ""
# TODO this is really janky/fragile, it would be better to store this in ~/.ao # TODO this is really janky/fragile, it would be better to store this in ~/.ao
CONFIG_FILE=$HOME/ao-$AO/configuration.js CONFIG_FILE=$HOME/ao-$AO/configuration.js
@ -264,14 +261,14 @@ esac
echo "" echo ""
case $ssl in case $ssl in
y | Y) y | Y)
echo "Alright, let's get Certbot in here!" echo "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}" echo -e "${BOLD}Take it away, Certbot${NC}"
sudo certbot --nginx sudo certbot --nginx
;; ;;
*) *)
echo "Yea, SSL is lame anyways..." echo "Yea, SSL is lame anyways..."
;; ;;
esac esac
echo "" echo ""
@ -384,32 +381,7 @@ sudo systemctl start nginx
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."
install_if_needed nmap check_ports
nmap -Pn $domain > nmap.txt
OPEN=1
if grep -qE "^80/.*(open|filtered)" nmap.txt; then
echo -e "I can see port ${GREEN}80${RESET}!"
else
echo -e "Uh oh, port ${RED}80${RESET} isn't showing up..."
OPEN=0
fi
if grep -qE "^443/.*(open|filtered)" nmap.txt; then
echo -e "I can see port ${GREEN}443${RESET} as well!"
else
echo -e "Uh oh, port ${RED}443${RESET} isn't showing up..."
OPEN=0
fi
rm nmap.txt
echo ""
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 "That's all the help I can give you regarding port forwarding. Good luck!"
echo ""
fi
# ------------------- Step 9 - Health Check ------------------- # ------------------- Step 9 - Health Check -------------------
echo '*********************************************************' echo '*********************************************************'

1
recipes/init.sh

@ -90,6 +90,7 @@ cp resources/tmux.conf $HOME/.tmux.conf
cp resources/tmux-powerline-theme.sh $HOME/.tmux/tmux-powerline/themes/default.sh cp resources/tmux-powerline-theme.sh $HOME/.tmux/tmux-powerline/themes/default.sh
echo "" echo ""
# TODO is this neededd? 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

Loading…
Cancel
Save