diff --git a/ingredients/copper b/ingredients/copper index e7bfdf2..b3fb4b8 100644 --- a/ingredients/copper +++ b/ingredients/copper @@ -246,7 +246,7 @@ check_ports() { ADDR=$DOMAIN fi - echo -e "Querying this computer from ${BLUE}${ADDR}${RESET}" + echo -e "Querying this computer's network from ${BLUE}${ADDR}${RESET}" echo "" install_if_needed nmap nmap -Pn $EXTERNAL_IP > nmap.txt diff --git a/ingredients/gold b/ingredients/gold index 59cd2ff..552f1cd 100644 --- a/ingredients/gold +++ b/ingredients/gold @@ -13,7 +13,7 @@ # the Bitcoin ecosystem install_bitcoin() { - echo -e "${BOLD}Installing Bitcoin Core${RESET}" + say "${BOLD}Installing Bitcoin Core${RESET}" # We're building bitcoin from source here. It might be slower than # downloading the pre-built binaries but this is more reliable @@ -36,7 +36,7 @@ install_bitcoin() { } install_lightning() { - echo -e "${BOLD}Installing lightningd${RESET}" + say "${BOLD}Installing lightningd${RESET}" git clone https://github.com/ElementsProject/lightning.git ./lightning pushd ./lightning git checkout v0.10.2 @@ -53,7 +53,7 @@ install_lightning() { } install_clboss() { - echo -e "${BOLD}Installing clboss${RESET}" + say "${BOLD}Installing clboss${RESET}" git clone https://github.com/ZmnSCPxj/clboss.git ./clboss pushd ./clboss git checkout 0.11B @@ -70,43 +70,49 @@ configure_bitcoin() { mkdir -p ~/.bitcoin AUTHDEETS=$(python3 scripts/rpcauth.py ao) - AUTHLINE=$(echo $AUTHDEETS | grep -o rpcauth=ao:[^[:space:]]*[[:space:]]) - PASSLINE=$(echo $AUTHDEETS | grep -o [^[:space:]]*\$) + AUTHLINE=$(say "$AUTHDEETS" | sed '2q;d' ) + PASSLINE=$(say "$AUTHDEETS" | sed '4q;d' ) + + remember "BTC_PASS=${PASSLINE}" if [ -f $HOME/.bitcoin/bitcoin.conf ]; then - echo -e "Looks like you already have a ${BLUE}bitcoin.conf${RESET} file!" - echo "" + say "Looks like you already have a ${BLUE}bitcoin.conf${RESET} file!" + say "" cat $HOME/.bitcoin/bitcoin.conf - echo "" - echo -en "Would you like to reset it? ${BLUE}(y/n)${RESET}: " - read btc_reconf + say "" + ask_for btc_reconf "Would you like to reset it? ${BLUE}(y/n)${RESET}: " case $btc_reconf in "y" | "Y") cp resources/sample_bitcoin.conf $HOME/.bitcoin/bitcoin.conf - echo 'Reset bitcoin configuration file' + say 'Reset bitcoin configuration file' ;; "n" | "N") - echo "Cool, we'll leave it as is then". + say "Cool, we'll leave it as is then". ;; esac else cp resources/sample_bitcoin.conf $HOME/.bitcoin/bitcoin.conf - echo 'Created default bitcoin config' + say 'Created default bitcoin config' fi sed -i "s/BTC_LOGIN/${AUTHLINE}/" $HOME/.bitcoin/bitcoin.conf - echo "" + say "" - echo -en "Next question - do you have 500GB of open memory on this device? ${BLUE}(y/n)${RESET}: " - read prune - echo "" + ask_for prune "Next question - would you like to operate bitcoin in pruned mode? \ +This reduces its file size from ~500GB to something more portable ${BLUE}(y/n)${RESET}: " + say "" case $prune in y | Y) - echo "Okay great! We'll leave the bitcoin config it as it is." + say "Let's ${GREEN}enable pruning${RESET} to keep the file size down, then." + prune_size=0 + while [ "$prune_size" -lt 550 ]; do + ask_for prune_size "How many Mb are you willing to put towards btc? Min 550: " + done + + sed -i "s/txindex=1/prune=${prune_size}/" $HOME/.bitcoin/bitcoin.conf ;; *) - 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 + say "Okay great! We'll leave the bitcoin config it as it is." ;; esac } @@ -115,29 +121,27 @@ configure_lightning() { mkdir -p $HOME/.lightning if [ -f $HOME/.lightning/config ]; then - echo -e "Looks like you already have a ${BLUE}lightning config${RESET} file!" - echo "" + say "Looks like you already have a ${BLUE}lightning config${RESET} file!" + say "" cat $HOME/.lightning/config - echo "" - echo -en "Would you like to reset it? ${BLUE}(y/n)${RESET}: " - read ln_reconf + say "" + ask_for ln_reconf "Would you like to reset it? ${BLUE}(y/n)${RESET}: " case $ln_reconf in "y" | "Y") cp resources/sample_lightning_config $HOME/.lightning/config - echo -e "${GREEN}Reset lightning configuration file${RESET}" + say "${GREEN}Reset lightning configuration file${RESET}" ;; "n" | "N") - echo "Cool, we'll leave it as is then". + say "Cool, we'll leave it as is then". ;; esac else cp resources/sample_lightning_config $HOME/.lightning/config - echo -e "${GREEN}Created default lightning config${RESET}" + say "${GREEN}Created default lightning config${RESET}" fi - echo "" - echo -en "Would you like to use clboss to automatically open lightning channels? ${BLUE}(y/n)${RESET}: " - read clboss_enable + say "" + ask_for clboss_enable "Would you like to use clboss to automatically open lightning channels? ${BLUE}(y/n)${RESET}: " case $clboss_enable in "y" | "Y") if ! check_for clboss; then @@ -146,13 +150,32 @@ configure_lightning() { sed -i "s/#plugin/plugin/" $HOME/.lightning/config sed -i "s/#log/log/" $HOME/.lightning/config echo "" - echo -e "${GREEN}clboss successfully configured!${RESET}" + say "${GREEN}clboss successfully configured!${RESET}" ;; "n" | "N") - echo "" - echo "Sounds good. You might want to open some channels manually to participate in the network!". + say "" + say "Sounds good. You might want to open some channels manually to participate in the network!". ;; esac } +bitcoin_is_synced() { + if [ -f "$HOME/.bitcoin/debug.log" ]; then + progress=$(tac ~/.bitcoin/debug.log | grep -m1 UpdateTip | awk '{print $10}') + case $progress in + *"=1"*) + say "Bitcoin is synced!" + return 0 + ;; + *) + say "Bitcoin is not synced yet" + return 1 + ;; + esac + else + say "Not sure where your bitcoin log is!" + return 2 + fi +} + GOLD=1 diff --git a/ingredients/lead b/ingredients/lead index 7ec1159..0089ad4 100644 --- a/ingredients/lead +++ b/ingredients/lead @@ -195,6 +195,13 @@ forget() { } remember() { + # Optionally choose to output somewhere other than Alchemy/ + if [ "${2}" = "to" ]; then + ENV_LOCATION=${3} + else + ENV_LOCATION="$ALCHEMY/.env" + fi + KEY=$(say ${1} | cut -d'=' -f 1) VALUE=$(say ${1} | cut -d'=' -f 2) @@ -202,39 +209,46 @@ remember() { say "Keys must consist only of capital letters and underscores" fi - if [[ ! $VALUE =~ ^[A-Za-z0-9/_.:-]+$ ]]; then + VALID_CHARS='A-Za-z0-9/_.:=-' + + if [[ ! $VALUE =~ ^[$VALID_CHARS]+$ ]]; then + say "illegal VALUE: $VALUE" + say "for key $KEY" 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_]+\=[$VALID_CHARS]+$ ]]; then - DOTENV_ENTRY=$(cat .env | grep ${KEY}) + DOTENV_ENTRY=$(cat $ENV_LOCATION | grep "^${KEY}" ) # If something already exists and we're trying to set it to something new if [ -n "$DOTENV_ENTRY" ] && [ "$DOTENV_ENTRY" != "$1" ]; then say "I'm trying to remember ${BLUE}${1}${RESET}, but..." say "" say "${BLUE}${DOTENV_ENTRY}${RESET}" - say "This has already been defined in the .env file!" + say "This has already been defined in the $ENV_LOCATION file!" say "" ask_for overwrite "would you like to overwrite it? ${BLUE}(y/n)${RESET} " case $overwrite in "y" | "Y") unset ${KEY} - sed -i "/^${KEY}.*$/d" .env - echo "${1}" >> .env + sed -i "/^${KEY}.*$/d" $ENV_LOCATION + echo "${1}" >> $ENV_LOCATION export ${1} ;; esac elif [ -z "$DOTENV_ENTRY" ]; then unset ${KEY} - echo "${1}" >> .env + echo "${1}" >> $ENV_LOCATION export ${1} fi fi - # Once we've made changes, we need to make sure we're up to date - source_env + # Once we've made changes to the Alchemy .env, + # we need to make sure we're up to date + if [ -z "$2" ]; then + source_env + fi } LEAD=1 diff --git a/recipes/ao.sh b/recipes/ao.sh index 42132d2..199b535 100755 --- a/recipes/ao.sh +++ b/recipes/ao.sh @@ -98,11 +98,11 @@ while [[ -z $AO ]]; do case $ao_select in "1") echo -e "Minimalism, I like it! Proceeding with ${BLUE}ao-3${RESET} installation" - AO=3 + AO='3' ;; "2") echo -e "It's got community! Proceeding with ${BLUE}ao-react${RESET} installation" - AO=react + AO='react' ;; *) echo "that aint no AO i ever heard of, try again" @@ -169,7 +169,22 @@ echo "" # TODO this is really janky/fragile, it would be better to store this in ~/.ao CONFIG_FILE=$HOME/ao-$AO/configuration.js +UNIFIED_CONFIG=$HOME/.ao/env +if [ ! -f "$UNIFIED_CONFIG" ]; then + touch $UNIFIED_CONFIG +fi + +remember "SQLITE_DATABASE=${HOME}/.ao/database.sqlite3" to "$UNIFIED_CONFIG" +remember "PASSLINE=${BTC_PASS}" to "$UNIFIED_CONFIG" +remember "PRIVATEKEY=${HOME}/.ao/key" to "$UNIFIED_CONFIG" +remember "CLIGHTNING_DIR=${HOME}/.lightning/bitcoin" to "$UNIFIED_CONFIG" +remember "MEMES_DIR=${HOME}/.ao/memes" to "$UNIFIED_CONFIG" +remember "RENT=0" to "$UNIFIED_CONFIG" +remember "LIGHTNINGDIR=0" to "$UNIFIED_CONFIG" +say "!!!!!!! WARNING !!!!!! I'm exaggerating but this is not going to \ +configure AO properly. It's time that we build out the unified config" +read case $AO in "3") if [ ! -d ~/ao-3 ]; then @@ -181,7 +196,7 @@ case $AO in 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#PASSLINE#${BTC_PASS}#" $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 @@ -206,7 +221,7 @@ case $AO in 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#PASSLINE#${BTC_PASS}#" $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 diff --git a/resources/sample_bitcoin.conf b/resources/sample_bitcoin.conf index 3454285..a7f16f8 100644 --- a/resources/sample_bitcoin.conf +++ b/resources/sample_bitcoin.conf @@ -1,8 +1,8 @@ proxy=127.0.0.1:9050 txindex=1 -#prune=550 listen=1 bind=127.0.0.1 disablewallet=1 zmqpubrawblock=tcp://127.0.0.1:28332 zmqpubrawtx=tcp://127.0.0.1:28333 +BTC_LOGIN