2018-11-05 04:42:35 +01:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
2018-11-06 22:26:26 +01:00
|
|
|
## TODO: Be Polite and ask for confirmation.
|
2018-11-05 04:42:35 +01:00
|
|
|
function QandA() {
|
|
|
|
read -r -p "Continue with $1 [y/N] " response
|
|
|
|
response=${response,,} # tolower
|
|
|
|
if [[ "$response" =~ ^(yes|y)$ ]]; then
|
|
|
|
echo "Continuing with this."
|
|
|
|
eval $1
|
|
|
|
else
|
|
|
|
echo "Skipping the $1."
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
## Check your $PATH for required dependencies.
|
|
|
|
## Stop and complain for now, later automagically install them.
|
2018-11-06 22:26:26 +01:00
|
|
|
## TODO: Add dependency checker.
|
2018-11-05 04:42:35 +01:00
|
|
|
function test_for_deps() {
|
|
|
|
## Test for Command
|
|
|
|
if ! [ -x "$(command -v $1)" ]; then
|
|
|
|
echo "Error: $1 is not installed." >&2
|
|
|
|
echo "You must have $1 installed."
|
|
|
|
else
|
|
|
|
echo "Info: $1 is installed."
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
## Declare Linux app dependencies to check for.
|
|
|
|
DEPENDENCIES=(
|
|
|
|
docker
|
|
|
|
docker-compose
|
|
|
|
)
|
|
|
|
|
2018-11-06 23:36:18 +01:00
|
|
|
## TODO: Check for docker and docker-compose
|
2018-11-05 04:42:35 +01:00
|
|
|
function check_deps() {
|
|
|
|
for i in "${!DEPENDENCIES[@]}"; do
|
|
|
|
echo ${DEPENDENCIES[$i]}"_KEY"
|
|
|
|
## Indirect references http://tldp.org/LDP/abs/html/ivr.html
|
|
|
|
eval TESTDEP=\$"${DEPENDENCIES[$i]}"
|
|
|
|
test_for_deps $TESTDEP
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
## Add ways to get into and out of a bind here.
|
|
|
|
case $1 in
|
|
|
|
getdata )
|
|
|
|
## Get DB Checkpoint data.
|
2018-11-06 23:01:07 +01:00
|
|
|
echo Asked to get the latest checkpoint data from
|
2018-11-06 23:26:57 +01:00
|
|
|
docker run -v $(pwd)/:/download --rm leopere/axel-docker http://chainquery-data.s3.amazonaws.com/chainquery-data.zip -o ./chainquery.zip
|
2018-11-05 04:42:35 +01:00
|
|
|
;;
|
|
|
|
extract )
|
|
|
|
## Unpack the data again if need be.
|
2018-11-06 23:01:07 +01:00
|
|
|
echo Asked to unpack chainquery.zip if downloaded.
|
|
|
|
# TODO: add some magic here which will check for the presence of chainquery.zip and notify if its already gone.
|
2018-11-06 23:26:57 +01:00
|
|
|
docker run -v $(pwd)/:/data --rm leopere/unzip-docker ./chainquery.zip
|
2018-11-05 04:42:35 +01:00
|
|
|
;;
|
|
|
|
cleanup )
|
|
|
|
## Remove any junk here.
|
2018-11-06 23:01:07 +01:00
|
|
|
echo Asked to clean up leftover chainquery.zip to save on disk space.
|
2018-11-05 04:42:35 +01:00
|
|
|
rm chainquery.zip
|
|
|
|
;;
|
|
|
|
reset )
|
|
|
|
## Give up on everything and try again.
|
2018-11-06 23:01:07 +01:00
|
|
|
docker-compose kill
|
|
|
|
docker-compose rm -f
|
|
|
|
rm -Rf ./data
|
|
|
|
rm -f ./chainquery.zip
|
|
|
|
## TODO: Consider moving this somewhere as a function.
|
|
|
|
# docker-compose up -d mysql
|
|
|
|
# sleep 30
|
|
|
|
# docker-compose up -d chainquery
|
|
|
|
;;
|
|
|
|
start )
|
|
|
|
## Unsupported start command to start containers.
|
|
|
|
## You can use this if you want to start this thing gracefully.
|
|
|
|
## Ideally you would not use this in production.
|
|
|
|
echo "Asked to start chainquery gracefully for you."
|
|
|
|
docker-compose up -d mysql
|
|
|
|
echo "giving mysql some time to establish schema, crypto, users, permissions, and tables"
|
|
|
|
sleep 30
|
|
|
|
echo "Starting Chainquery"
|
|
|
|
docker-compose up -d chainquery
|
2018-11-05 04:42:35 +01:00
|
|
|
;;
|
2018-11-06 21:32:38 +01:00
|
|
|
compress-latest-checkpoint-data )
|
|
|
|
## This is not intended for public use.
|
2018-11-06 21:11:20 +01:00
|
|
|
docker-compose stop chainquery
|
|
|
|
docker-compose stop mysql
|
2018-11-06 21:32:38 +01:00
|
|
|
sudo zip -r chainquery-data.zip data
|
|
|
|
docker-compose up -d mysql
|
|
|
|
sleep 30
|
|
|
|
docker-compose up -d chainquery
|
|
|
|
;;
|
|
|
|
upload-latest-checkpoint-data )
|
|
|
|
## This is not intended for public use.
|
2018-11-06 21:11:20 +01:00
|
|
|
aws s3 cp ./chainquery-data.zip s3://chainquery-data/chainquery-data.new
|
|
|
|
aws s3 rm s3://chainquery-data/chainquery-data.zip
|
|
|
|
aws s3 mv s3://chainquery-data/chainquery-data.new s3://chainquery-data/chainquery-data.zip
|
2018-11-06 21:19:50 +01:00
|
|
|
;;
|
2018-11-05 04:42:35 +01:00
|
|
|
* )
|
|
|
|
echo "=================================================="
|
|
|
|
echo "You look like you need usage examples let me help."
|
|
|
|
echo "=================================================="
|
2018-11-06 22:00:34 +01:00
|
|
|
echo "./quick-boostrap.sh {Parameter}"
|
|
|
|
echo "Example: ./quick-bootstrap.sh getdata # Downloads the latest Chainquery checkpoint data from a LBRYio official aws instance."
|
|
|
|
echo ""
|
|
|
|
echo ""
|
|
|
|
echo "=================================================="
|
|
|
|
echo "Usage example and available parameters"
|
|
|
|
echo "=================================================="
|
|
|
|
echo ""
|
|
|
|
echo "getdata # This function grabs the latest Chainquery checkpoint data."
|
|
|
|
echo "extract # Unpacks the chainquery data into the correct directory. ./data/"
|
|
|
|
echo "cleanup # Removes chainquery.zip"
|
|
|
|
echo "reset # Reset the state of these containers entirely, use if all else fails."
|
|
|
|
echo ""
|
|
|
|
echo ""
|
|
|
|
echo "=================================================="
|
|
|
|
echo "=================================================="
|
|
|
|
echo "Any other functions that are not documented here are not intended for public use."
|
|
|
|
echo " These functions are included in this repository to keep things in one place."
|
2018-11-05 04:42:35 +01:00
|
|
|
;;
|
|
|
|
esac
|