Browse Source

Finished v1 of flask installer

main
Zen 3 years ago
parent
commit
5bd66308ab
  1. 1
      .gitignore
  2. 290
      recipes/flask.sh
  3. 2
      resources/flask/demo.html
  4. 12
      resources/service-templates/flask

1
.gitignore vendored

@ -1,3 +1,4 @@
images/ images/
.env .env
bitcoin-22.0/ bitcoin-22.0/
nmap.txt

290
recipes/flask.sh

@ -49,7 +49,7 @@ case $DISTRO in
;; ;;
"arch") "arch")
install_if_needed python python-pip install_if_needed python python-pip
pip install --upgrade pip python -m pip install --upgrade pip
;; ;;
"mac") "mac")
say "HEY I HAVEN'T TESTED THIS BY THE WAY" say "HEY I HAVEN'T TESTED THIS BY THE WAY"
@ -103,290 +103,38 @@ say ""
# ------------------- Step 3 - Build Flask ------------------- # ------------------- Step 3 - Build Flask -------------------
say "${BOLD}We've got everything!${RESET} I'm going to set you up with \ 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} mkdir -p ${FLASK_DIR}/{templates,static}
cp resources/flask/app.py ${FLASK_DIR} cp resources/flask/app.py ${FLASK_DIR}
cp resources/flask/demo.css ${FLASK_DIR}/static cp resources/flask/demo.css ${FLASK_DIR}/static
cp resources/flask/demo.html ${FLASK_DIR}/templates cp resources/flask/demo.html ${FLASK_DIR}/templates
say "Flask directory initialized, setting up reverse proxy\n"
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 ------------------- # ------------------- Step 4 - NGINX Setup -------------------
echo ""
echo -en "You still there? I might need your input here! \n\n${BLUE}(enter)${RESET}"
read
initialize_nginx initialize_nginx
make_site ao "FILE_ROOT=${HOME}/ao-${AO}/dist" make_site flask "FILE_ROOT=${FLASK_DIR}"
echo "" say ""
configure_domain_for_site ao configure_domain_for_site flask
enable_ssl enable_ssl
echo -e "Excellent! We've configured this computer to serve your AO from ${BLUE}${ACCESS_POINT}${RESET}" say "Excellent! We've configured this computer to serve this Flask\
server from ${BLUE}${ACCESS_POINT}:5000${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 # ------------------- Step 5 - Service Configuration -------------------
sudo mkdir -p $HOME/.tor
sudo chown tor $HOME/.tor
sudo chgrp $USER $HOME/.tor
sudo chmod 770 $HOME/.tor
activate_service tor build_service_from_template flask "GUNICORN=`which gunicorn`" \
"FLASK_DIR=${FLASK_DIR}" "PORT=5000"
echo "" say ""
build_service_from_template bitcoin "BITCOIND=`which bitcoind`" activate_service flask
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 ' ' say "${BOLD}\nAaaand, we're done!${RESET}\nAs long as everything \
echo 'lightningd Version' worked properly, you should be able to visit your flask server at \
echo '*********************************************************' ${BLUE}${ACCESS_POINT}:5000${RESET}"
lightningd --version 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 exit 0

2
resources/flask/demo.html

@ -6,7 +6,7 @@
<link rel="stylesheet" href="{{ url_for('static', filename='demo.css') }}"> <link rel="stylesheet" href="{{ url_for('static', filename='demo.css') }}">
</head> </head>
<body> <body>
<header>This server is running via the <tt>flask_demo.py</tt> <header>This server is running via the <tt>app.py</tt>
file in <tt>{{ wd }}</tt></header> file in <tt>{{ wd }}</tt></header>
<main> <main>
{% if name %} {% if name %}

12
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
Loading…
Cancel
Save