From 84cdf7bc0ad15148fa60ee7c47868934a8666928 Mon Sep 17 00:00:00 2001 From: Zen Date: Sun, 6 Mar 2022 13:22:12 -0600 Subject: [PATCH 1/3] make flask is working up to debug mode --- Makefile | 4 ++++ ingredients/copper | 2 ++ ingredients/iron | 2 -- ingredients/lead | 16 ++++++++++--- recipes/init.sh | 57 +++++++--------------------------------------- 5 files changed, 27 insertions(+), 54 deletions(-) diff --git a/Makefile b/Makefile index 3aa3af6..d174a15 100644 --- a/Makefile +++ b/Makefile @@ -31,6 +31,10 @@ prosperity: free: @echo "This will install freespace, once it exists" + +flask: + @chmod +x recipes/flask.sh + @recipes/flask.sh manifest: @chmod +x recipes/wordpress.sh diff --git a/ingredients/copper b/ingredients/copper index d4a517d..e7bfdf2 100644 --- a/ingredients/copper +++ b/ingredients/copper @@ -281,4 +281,6 @@ check_ports() { fi } +# TODO Expose ports via firewalld + # using yggdrasil could maybe fit in here diff --git a/ingredients/iron b/ingredients/iron index 891ac14..33fcab5 100644 --- a/ingredients/iron +++ b/ingredients/iron @@ -59,9 +59,7 @@ build_service_from_template() { read reset case $reset in "Y" | "y") - cat /etc/systemd/system/ sudo rm $SERVICE_FILE - cat /etc/systemd/system/ ;; "N" | "n") echo "Okay, we'll leave it as is." diff --git a/ingredients/lead b/ingredients/lead index 336b6ca..7ec1159 100644 --- a/ingredients/lead +++ b/ingredients/lead @@ -121,6 +121,14 @@ source_env check_for() { command -v "$1" >/dev/null } +if [ "$EUID" -eq 0 ]; then + echo -e "${RED}Woah there!${RESET} Seems you're running this script as a superuser." + echo "" + echo "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" + echo "" + exit 1 +fi + # This one installs utilities to your OS (If you need them!) install_if_needed() { @@ -194,12 +202,12 @@ remember() { say "Keys must consist only of capital letters and underscores" fi - if [[ ! $VALUE =~ ^[A-Za-z0-9/_.:]+$ ]]; then - say "Valid characters for env values: letters, numbers, \".\",\"/\",\"_\"",\":\" + if [[ ! $VALUE =~ ^[A-Za-z0-9/_.:-]+$ ]]; then + say "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 DOTENV_ENTRY=$(cat .env | grep ${KEY}) # If something already exists and we're trying to set it to something new @@ -230,3 +238,5 @@ remember() { } LEAD=1 + +# Confirm? Something to automate the y/n dialog diff --git a/recipes/init.sh b/recipes/init.sh index 101caf4..d233ba8 100755 --- a/recipes/init.sh +++ b/recipes/init.sh @@ -3,48 +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 # ~ Zen, 2022 -if [ -f "/etc/debian_version" ]; then - DISTRO="debian" - echo "Debian, Ubuntu, or Raspbian OS detected." -elif [ -f "/etc/arch-release" ]; then - DISTRO="arch" - echo "Arch- or Manjaro-based OS detected." -elif [ $(uname | grep -c "Darwin") -eq 1 ]; then - DISTRO="mac" - echo "MacOS detected." -else - echo "I don't know what OS you're running! Cancelling this operation." - exit 1 -fi - -echo "" - -# This makes sure that ctrl+C exits the entire script -trap "exit" INT - -install_if_needed() { - for package in "$@" - do - if [ -z $(which $package) ]; then - echo "installing" $package - - case $DISTRO in - "debian") - sudo apt install -y $package - ;; - "arch") - sudo pacman -S $package --noconfirm - ;; - "mac") - brew install $package - ;; - esac - - else - echo $package 'already installed!' - fi - done -} +source ingredients/lead echo "Updating the repositories..." case $DISTRO in @@ -66,13 +25,13 @@ echo "" echo "Making sure we've got the basics..." case $DISTRO in "debian") - install_if_needed make vim tmux zsh git silversearcher-ag + install_if_needed vim tmux zsh git silversearcher-ag ;; "arch") - install_if_needed make vim tmux zsh git the_silver_searcher + install_if_needed vim tmux zsh git the_silver_searcher ;; "mac") - install_if_needed make vim tmux zsh git the_silver_searcher + install_if_needed vim tmux zsh git the_silver_searcher ;; esac echo "" @@ -90,9 +49,9 @@ cp resources/tmux.conf $HOME/.tmux.conf cp resources/tmux-powerline-theme.sh $HOME/.tmux/tmux-powerline/themes/default.sh echo "" -# TODO is this neededd? can we install p10k on base zsh? -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)" +# TODO is this needed? can we install p10k on base zsh? +#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)" cat resources/zshrc-extras >> $HOME/.zshrc echo "" @@ -101,4 +60,4 @@ git clone --depth=1 https://github.com/romkatv/powerlevel10k.git ${ZSH_CUSTOM:-$ sed -i 's/^ZSH_THEME.*/ZSH_THEME="powerlevel10k\/powerlevel10k"/' $HOME/.zshrc echo "" -echo "...and we're back! Now that you've installed everything you need, try closing your connection to the terminal and re-opening." +$SHELL From becad986db0cb6b20d1f287a3c434f0c5e5e7a36 Mon Sep 17 00:00:00 2001 From: Zen Date: Sun, 6 Mar 2022 13:22:39 -0600 Subject: [PATCH 2/3] added new files --- recipes/flask.sh | 392 +++++++++++++++++++++++++++++++ resources/flask/app.py | 10 + resources/flask/demo.css | 12 + resources/flask/demo.html | 32 +++ resources/flask/requirements.txt | 7 + resources/nginx/flask.nginx.conf | 17 ++ 6 files changed, 470 insertions(+) create mode 100755 recipes/flask.sh create mode 100644 resources/flask/app.py create mode 100644 resources/flask/demo.css create mode 100644 resources/flask/demo.html create mode 100644 resources/flask/requirements.txt create mode 100644 resources/nginx/flask.nginx.conf diff --git a/recipes/flask.sh b/recipes/flask.sh new file mode 100755 index 0000000..744fe31 --- /dev/null +++ b/recipes/flask.sh @@ -0,0 +1,392 @@ +#!/bin/sh + +# Script for installing a simple Flask server and deploying it +# Bare Metal Alchemist, 2022 + +source ingredients/lead +source ingredients/iron +source ingredients/copper + +clear +say "${BLUE}" +say " ${AAAAAAAAAAAA} &&&&&&&&&&& " +say " ${AAAAAAAAAAAA} &@ && " +say " ${AAAAAAAAAAAA} &@ && " +say " ${AAAAAAAAAAAA} &@ && " +say "${RESET} 8888888888 888 888 ${BLUE} /&& @& " +say "${RESET} 8888888888 888 888 ${BLUE} @&# &&&&&, " +say "${RESET} 888 888 888 ${BLUE} #&. /&/ " +say "${RESET} 888 888 888 ${BLUE} && *&@ " +say "${RESET} 8888888 888 8888b. .d8888b 888 888${BLUE} && &&&&&@ " +say "${RESET} 888 888 '88b 88K 888 .88P${BLUE} && && " +say "${RESET} 888 888 .d888888 'Y8888b. 888888K ${BLUE} &@ && " +say "${RESET} 888 888 888 888 X88 888 '88b${BLUE} && .&@ " +say "${RESET} 888 888 'Y888888 88888P' 888 888${BLUE} (&&&&&&&&&&&&&&&&&&&&&. " +say "${RESET}" + +# ------------------- Step 1 - Baseline Setup ------------------- + +say "${BOLD}Hi again!${RESET} Looks like you want to get ${BLUE}Flask${RESET} up and running." +say "Well, as an alchemy-themed toolkit, I must say: ${GREEN}good decision :)${RESET}" +say "" + +# Make sure this script isn't being run with sudo in front +if [ "$EUID" -eq 0 ]; then + say "${RED}${BOLD}Woah there!${RESET} Seems you're running this script as a superuser." + 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 "" + exit 1 +fi + +say "${ULINE}Making sure we've got the basics...${RESET}" +echo -e "(you'll probably need to input ${BLUE}your 'sudo' password${RESET} here)" +case $DISTRO in + "debian") + say "HEY I HAVEN'T TESTED THIS BY THE WAY" + install_if_needed python python-pip + pip install --upgrade pip + ;; + "arch") + install_if_needed python python-pip + pip install --upgrade pip + ;; + "mac") + say "HEY I HAVEN'T TESTED THIS BY THE WAY" + install_if_needed python python-pip + pip install --upgrade pip + ;; + "fedora") + say "HEY I HAVEN'T TESTED THIS BY THE WAY" + install_if_needed python python-pip + pip install --upgrade pip + ;; +esac +echo "" + +while [ ! -d "$FLASK_DIR" ]; do + ask_for FLASK_DIR "Please enter the path you would like to install \ +Flask to (or enter nothing for ${BLUE}~/flask${RESET}): " + if [ -z "$FLASK_DIR" ]; then + remember "FLASK_DIR=$HOME/flask" + fi + say "" + ask_for CONFIRM "Okay, should we install to \ +${BLUE}${FLASK_DIR}${RESET}? ${BLUE}(y/n)${RESET} " + + case $CONFIRM in + "Y" | "y") + mkdir -p $FLASK_DIR + ;; + esac +done + +# ------------------- Step 2 - Create venv ------------------- + +if [ -d "$FLASK_VENV" ]; then + say "We already have a virtualenv folder for Flask here: ${BLUE}$FLASK_VENV${RESET}" +else + say "Creating virtual environment for Flask" + python -m venv $FLASK_DIR/venv + remember FLASK_VENV=$FLASK_DIR/venv +fi + +if [ "$VIRTUAL_ENV" != "$FLASK_VENV" ]; then + say "Sourcing the virtual environment" + source ${FLASK_VENV}/bin/activate +fi + +say "Making sure we've got all the python packages we need!" +pip install -r resources/flask/requirements.txt +say "" + +# ------------------- Step 3 - Build Flask ------------------- + +say "${BOLD}We've got everything!${RESET} I'm going to set you up with \ +a basic Flask page now" + +mkdir -p ${FLASK_DIR}/{templates,static} +cp resources/flask/app.py ${FLASK_DIR} +cp resources/flask/demo.css ${FLASK_DIR}/static +cp resources/flask/demo.html ${FLASK_DIR}/templates + +cd ${FLASK_DIR} +flask run + +exit 0 + + + + + + + +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" + echo -e "${BOLD}1.${RESET} ao-3 (Vue)" + echo -e "${BOLD}2.${RESET} ao-react (React)" +fi + +while [[ -z $AO ]]; do + echo -en "${BLUE}(number):${RESET} " + read -n1 ao_select + echo "" + echo "" + + case $ao_select in + "1") + echo -e "Minimalism, I like it! Proceeding with ${BLUE}ao-3${RESET} installation" + AO=3 + ;; + "2") + echo -e "It's got community! Proceeding with ${BLUE}ao-react${RESET} installation" + AO=react + ;; + *) + echo "that aint no AO i ever heard of, try again" + ;; + esac +done; +remember "AO=${AO}" + +echo "" +if [ $AO = "3" ] || [ $AO = 'react' ]; then + if [ -z $NVM_DIR ]; then + install_nvm + source ingredients/iron + else + echo -e "${BLUE}Node${RESET} already installed!" + fi + + echo -e "Setting Node to ${BLUE}v16.13.0${RESET} for compatibility" + set_node_to v16.13.0 + echo "" + echo -e "${GREEN}Done!${RESET}" + echo "" +fi + +if [ $AO = "3" ] || [ $AO = 'react' ]; then + echo -e "${BOLD}Installing Bitcoin Ecosystem${RESET}" + echo "" + + if ! check_for bitcoind; then + echo -e "Building bitcoind from source... might take a while!" + install_bitcoin + fi + + if ! check_for lightningd; then + echo -e "Building lightningd from source... here we go again" + install_lightning + fi + + configure_bitcoin + configure_lightning +fi +echo '' + +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 ------------------- + +echo -e "${BOLD}Configuring AO Core${RESET}\n" + +mkdir -p $HOME/.ao + +if [ -f $HOME/.ao/key ]; then + echo 'We already have a private key for this AO, sweet!' +else + node scripts/createPrivateKey.js >> $HOME/.ao/key + echo -e "Just made a fresh private key and put it in ${GREEN}~/.ao${RESET}" +fi +echo "" + +# TODO this is really janky/fragile, it would be better to store this in ~/.ao +CONFIG_FILE=$HOME/ao-$AO/configuration.js + +case $AO in + "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 + cp resources/ao-config $CONFIG_FILE + sed -i "s#SQLITE_DATABASE#${HOME}/.ao/database.sqlite3#" $CONFIG_FILE + sed -i "s#PASSLINE#${PASSLINE}#" $CONFIG_FILE + sed -i "s#PRIVATEKEY#${HOME}/.ao/key#" $CONFIG_FILE + sed -i "s#CLIGHTNING_DIR#${HOME}/.lightning/bitcoin#" $CONFIG_FILE + sed -i "s#MEMES_DIR#${HOME}/.ao/memes#" $CONFIG_FILE + fi + + echo "" + pushd ~/ao-3 + npm install + npm run build + npm run checkconfig + popd + + NODE_PARAMS='' + ;; + "react") + 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 + fi + if [ -f "$CONFIG_FILE" ]; then + echo configuration.js already exists + else + cp resources/ao-config $CONFIG_FILE + sed -i "s#SQLITE_DATABASE#${HOME}/.ao/database.sqlite3#" $CONFIG_FILE + sed -i "s#PASSLINE#${PASSLINE}#" $CONFIG_FILE + sed -i "s#PRIVATEKEY#${HOME}/.ao/key#" $CONFIG_FILE + sed -i "s#CLIGHTNING_DIR#${HOME}/.lightning/bitcoin#" $CONFIG_FILE + sed -i "s#MEMES_DIR#${HOME}/.ao/memes#" $CONFIG_FILE + fi + + echo "" + + pushd ~/ao-react + npm install + npm run webpack + popd + + NODE_PARAMS='--experimental-specifier-resolution=node -r dotenv/config' + ;; +esac + +# ------------------- Step 4 - NGINX Setup ------------------- + + echo "" + 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 + + echo -e "Excellent! We've configured this computer to serve your AO from ${BLUE}${ACCESS_POINT}${RESET}" + +# ------------------- 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." +while [[ -z $READY ]]; do + echo -en "${BLUE}You ready? (y/n):${RESET} " + read -n1 ao_select + echo "" + echo "" + + case $ao_select in + "y" | "Y") + echo -e "Nice, let's do it.\n" + READY=1 + ;; + *) + echo -e "wrong answer, fren\n" + ;; + esac +done + +build_service_from_template tor "TORRCPATH=$TORRCPATH" "TORPATH=`which tor`" + +# Creating the .tor directory +sudo mkdir -p $HOME/.tor +sudo chown tor $HOME/.tor +sudo chgrp $USER $HOME/.tor +sudo chmod 770 $HOME/.tor + +activate_service tor + +echo "" +build_service_from_template bitcoin "BITCOIND=`which bitcoind`" +activate_service bitcoin + +echo "" +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 "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 ------------------- + + echo '*********************************************************' + echo -e "* ${BOLD}Version Information${RESET} *" + echo '*********************************************************' + + echo ' ' + echo 'make Version' + echo '*********************************************************' + make --version + + echo ' ' + echo 'node Version' + echo '*********************************************************' + node --version + + echo ' ' + echo 'sqlite3 Version' + echo '*********************************************************' + sqlite3 --version + + echo ' ' + echo 'tor Version' + echo '*********************************************************' + tor --version + + echo ' ' + echo 'bitcoind Version' + echo '*********************************************************' + bitcoind --version + + echo ' ' + echo 'lightningd Version' + echo '*********************************************************' + lightningd --version + + echo ' ' + echo 'clboss Version' + echo '*********************************************************' + clboss --version +echo "" +echo -e "$BOLD\nOkay, well that's everything!${RESET}\n\nAs long as everything worked properly, \ +you should be ready to continue your journey\ntowards autonomy by opening ${BLUE}$ACCESS_POINT${RESET} in your browser." +echo -e "The default login is ${BLUE}dctrl/dctrl${RESET}, have fun!" + +exit 0 diff --git a/resources/flask/app.py b/resources/flask/app.py new file mode 100644 index 0000000..dbe31f5 --- /dev/null +++ b/resources/flask/app.py @@ -0,0 +1,10 @@ +from flask import Flask, render_template +import os + +app = Flask(__name__) + +@app.route("/") +@app.route("/") +def demo(name=None): + wd = os.popen('pwd').readline() + return render_template('demo.html', name=name, wd=wd) diff --git a/resources/flask/demo.css b/resources/flask/demo.css new file mode 100644 index 0000000..d570aa5 --- /dev/null +++ b/resources/flask/demo.css @@ -0,0 +1,12 @@ +html { + font-family: sans-serif; +} + +body { + margin: 40px auto; + max-width: 650px; + line-height: 1.6; + font-size: 18px; + color: #444; + padding: 0 10px; +} diff --git a/resources/flask/demo.html b/resources/flask/demo.html new file mode 100644 index 0000000..cb343a4 --- /dev/null +++ b/resources/flask/demo.html @@ -0,0 +1,32 @@ + + + + + Flask Boilerplate + + + +
This server is running via the flask_demo.py + file in {{ wd }}
+
+ {% if name %} +

Hello, {{ name }}!

+

You provided me a name through the URL of this webpage.

+

Flask parsed it and passed it as a parameter to the + render_template function in flask_demo.py, + which is located in the directory where you installed Flask

+

It also imports the css as a file in the static/ + directory. This is the standard used for images etc.

+
+

There's plenty to learn about Flask! Hopefully this gives you + some of the information you need to dive deeper

+ {% else %} +

Hello!

+

This is a page served up by Flask. Try adding a / followed by + your first name in the URL, or click here + for a demonstration of URL parsing.

+ {% endif %} +
+
courtesy of Bare Metal Alchemist, March 2022
+ + diff --git a/resources/flask/requirements.txt b/resources/flask/requirements.txt new file mode 100644 index 0000000..6fa9321 --- /dev/null +++ b/resources/flask/requirements.txt @@ -0,0 +1,7 @@ +click==8.0.4 +Flask==2.0.3 +gunicorn==20.1.0 +itsdangerous==2.1.0 +Jinja2==3.0.3 +MarkupSafe==2.1.0 +Werkzeug==2.0.3 diff --git a/resources/nginx/flask.nginx.conf b/resources/nginx/flask.nginx.conf new file mode 100644 index 0000000..c1b43a1 --- /dev/null +++ b/resources/nginx/flask.nginx.conf @@ -0,0 +1,17 @@ +server { + listen 5000 default_server; + listen [::]:5000 default_server; + + server_name _; + root FILE_ROOT; + index index.html; + + location = /favicon.ico { + log_not_found off; + access_log off; + } + + location / { + proxy_pass http://localhost:5000; + } +} From 5bd66308ab220700312fc76c8f2c65838480d272 Mon Sep 17 00:00:00 2001 From: Zen Date: Sun, 6 Mar 2022 19:21:37 -0600 Subject: [PATCH 3/3] Finished v1 of flask installer --- .gitignore | 1 + recipes/flask.sh | 290 ++---------------------------- resources/flask/demo.html | 2 +- resources/service-templates/flask | 12 ++ 4 files changed, 33 insertions(+), 272 deletions(-) create mode 100644 resources/service-templates/flask diff --git a/.gitignore b/.gitignore index 137ebe9..97e9f72 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ images/ .env bitcoin-22.0/ +nmap.txt diff --git a/recipes/flask.sh b/recipes/flask.sh index 744fe31..cf35357 100755 --- a/recipes/flask.sh +++ b/recipes/flask.sh @@ -49,7 +49,7 @@ case $DISTRO in ;; "arch") install_if_needed python python-pip - pip install --upgrade pip + python -m pip install --upgrade pip ;; "mac") say "HEY I HAVEN'T TESTED THIS BY THE WAY" @@ -103,290 +103,38 @@ say "" # ------------------- Step 3 - Build Flask ------------------- say "${BOLD}We've got everything!${RESET} I'm going to set you up with \ -a basic Flask page now" +a basic Flask page now\n" mkdir -p ${FLASK_DIR}/{templates,static} cp resources/flask/app.py ${FLASK_DIR} cp resources/flask/demo.css ${FLASK_DIR}/static cp resources/flask/demo.html ${FLASK_DIR}/templates - -cd ${FLASK_DIR} -flask run - -exit 0 - - - - - - - -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" - echo -e "${BOLD}1.${RESET} ao-3 (Vue)" - echo -e "${BOLD}2.${RESET} ao-react (React)" -fi - -while [[ -z $AO ]]; do - echo -en "${BLUE}(number):${RESET} " - read -n1 ao_select - echo "" - echo "" - - case $ao_select in - "1") - echo -e "Minimalism, I like it! Proceeding with ${BLUE}ao-3${RESET} installation" - AO=3 - ;; - "2") - echo -e "It's got community! Proceeding with ${BLUE}ao-react${RESET} installation" - AO=react - ;; - *) - echo "that aint no AO i ever heard of, try again" - ;; - esac -done; -remember "AO=${AO}" - -echo "" -if [ $AO = "3" ] || [ $AO = 'react' ]; then - if [ -z $NVM_DIR ]; then - install_nvm - source ingredients/iron - else - echo -e "${BLUE}Node${RESET} already installed!" - fi - - echo -e "Setting Node to ${BLUE}v16.13.0${RESET} for compatibility" - set_node_to v16.13.0 - echo "" - echo -e "${GREEN}Done!${RESET}" - echo "" -fi - -if [ $AO = "3" ] || [ $AO = 'react' ]; then - echo -e "${BOLD}Installing Bitcoin Ecosystem${RESET}" - echo "" - - if ! check_for bitcoind; then - echo -e "Building bitcoind from source... might take a while!" - install_bitcoin - fi - - if ! check_for lightningd; then - echo -e "Building lightningd from source... here we go again" - install_lightning - fi - - configure_bitcoin - configure_lightning -fi -echo '' - -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 ------------------- - -echo -e "${BOLD}Configuring AO Core${RESET}\n" - -mkdir -p $HOME/.ao - -if [ -f $HOME/.ao/key ]; then - echo 'We already have a private key for this AO, sweet!' -else - node scripts/createPrivateKey.js >> $HOME/.ao/key - echo -e "Just made a fresh private key and put it in ${GREEN}~/.ao${RESET}" -fi -echo "" - -# TODO this is really janky/fragile, it would be better to store this in ~/.ao -CONFIG_FILE=$HOME/ao-$AO/configuration.js - -case $AO in - "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 - cp resources/ao-config $CONFIG_FILE - sed -i "s#SQLITE_DATABASE#${HOME}/.ao/database.sqlite3#" $CONFIG_FILE - sed -i "s#PASSLINE#${PASSLINE}#" $CONFIG_FILE - sed -i "s#PRIVATEKEY#${HOME}/.ao/key#" $CONFIG_FILE - sed -i "s#CLIGHTNING_DIR#${HOME}/.lightning/bitcoin#" $CONFIG_FILE - sed -i "s#MEMES_DIR#${HOME}/.ao/memes#" $CONFIG_FILE - fi - - echo "" - pushd ~/ao-3 - npm install - npm run build - npm run checkconfig - popd - - NODE_PARAMS='' - ;; - "react") - 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 - fi - if [ -f "$CONFIG_FILE" ]; then - echo configuration.js already exists - else - cp resources/ao-config $CONFIG_FILE - sed -i "s#SQLITE_DATABASE#${HOME}/.ao/database.sqlite3#" $CONFIG_FILE - sed -i "s#PASSLINE#${PASSLINE}#" $CONFIG_FILE - sed -i "s#PRIVATEKEY#${HOME}/.ao/key#" $CONFIG_FILE - sed -i "s#CLIGHTNING_DIR#${HOME}/.lightning/bitcoin#" $CONFIG_FILE - sed -i "s#MEMES_DIR#${HOME}/.ao/memes#" $CONFIG_FILE - fi - - echo "" - - pushd ~/ao-react - npm install - npm run webpack - popd - - NODE_PARAMS='--experimental-specifier-resolution=node -r dotenv/config' - ;; -esac +say "Flask directory initialized, setting up reverse proxy\n" # ------------------- Step 4 - NGINX Setup ------------------- - echo "" - 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 + make_site flask "FILE_ROOT=${FLASK_DIR}" + say "" + configure_domain_for_site flask enable_ssl - echo -e "Excellent! We've configured this computer to serve your AO from ${BLUE}${ACCESS_POINT}${RESET}" - -# ------------------- 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." -while [[ -z $READY ]]; do - echo -en "${BLUE}You ready? (y/n):${RESET} " - read -n1 ao_select - echo "" - echo "" - - case $ao_select in - "y" | "Y") - echo -e "Nice, let's do it.\n" - READY=1 - ;; - *) - echo -e "wrong answer, fren\n" - ;; - esac -done - -build_service_from_template tor "TORRCPATH=$TORRCPATH" "TORPATH=`which tor`" + say "Excellent! We've configured this computer to serve this Flask\ + server from ${BLUE}${ACCESS_POINT}:5000${RESET}" -# Creating the .tor directory -sudo mkdir -p $HOME/.tor -sudo chown tor $HOME/.tor -sudo chgrp $USER $HOME/.tor -sudo chmod 770 $HOME/.tor +# ------------------- Step 5 - Service Configuration ------------------- -activate_service tor - -echo "" -build_service_from_template bitcoin "BITCOIND=`which bitcoind`" -activate_service bitcoin - -echo "" -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 "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 ------------------- - - echo '*********************************************************' - echo -e "* ${BOLD}Version Information${RESET} *" - echo '*********************************************************' - - echo ' ' - echo 'make Version' - echo '*********************************************************' - make --version - - echo ' ' - echo 'node Version' - echo '*********************************************************' - node --version - - echo ' ' - echo 'sqlite3 Version' - echo '*********************************************************' - sqlite3 --version - - echo ' ' - echo 'tor Version' - echo '*********************************************************' - tor --version - - echo ' ' - echo 'bitcoind Version' - echo '*********************************************************' - bitcoind --version +build_service_from_template flask "GUNICORN=`which gunicorn`" \ +"FLASK_DIR=${FLASK_DIR}" "PORT=5000" +say "" +activate_service flask - echo ' ' - echo 'lightningd Version' - echo '*********************************************************' - lightningd --version +say "${BOLD}\nAaaand, we're done!${RESET}\nAs long as everything \ +worked properly, you should be able to visit your flask server at \ +${BLUE}${ACCESS_POINT}:5000${RESET}" +say "\nThe main file is located in ${BLUE}${FLASK_DIR}${RESET}, other recipes may rely \ +on making further modifications to this application. Take a look, and \ +don't forget to experiment!" - echo ' ' - echo 'clboss Version' - echo '*********************************************************' - clboss --version -echo "" -echo -e "$BOLD\nOkay, well that's everything!${RESET}\n\nAs long as everything worked properly, \ -you should be ready to continue your journey\ntowards autonomy by opening ${BLUE}$ACCESS_POINT${RESET} in your browser." -echo -e "The default login is ${BLUE}dctrl/dctrl${RESET}, have fun!" exit 0 diff --git a/resources/flask/demo.html b/resources/flask/demo.html index cb343a4..7422744 100644 --- a/resources/flask/demo.html +++ b/resources/flask/demo.html @@ -6,7 +6,7 @@ -
This server is running via the flask_demo.py +
This server is running via the app.py file in {{ wd }}
{% if name %} diff --git a/resources/service-templates/flask b/resources/service-templates/flask new file mode 100644 index 0000000..58a9a99 --- /dev/null +++ b/resources/service-templates/flask @@ -0,0 +1,12 @@ +[Unit] +Description=Service File for a Flask application or API +After=network.target + +[Service] +User=USER +WorkingDirectory=FLASK_DIR +ExecStart=GUNICORN -b localhost:PORT app:app +Restart=always + +[Install] +WantedBy=multi-user.target