Last active
September 14, 2016 21:21
-
-
Save Someguy123/100dbc0e40d343886e2aa014317f586f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# Someguy123's Price Feed installer script | |
# https://github.com/someguy123 - https://someguy123.com | |
# https://steemit.com/@someguy123 | |
# Released under the GNU GPL 3 license | |
# | |
# Update environment file | |
setup_env() { | |
if [[ ! -f .env ]]; then | |
echo "Creating config file..." | |
cp .example.env .env | |
fi | |
echo "If you make a mistake, just press CTRL-C to exit without saving." | |
read -p "Your STEEM username (no @ sign): " STMUSER | |
read -p "Your active private key (begins with 5): " STMKEY | |
sed -i 's/^feed_account=.*/feed_account='$STMUSER'/' .env | |
sed -i 's/^feed_wif=.*/feed_wif='$STMKEY'/' .env | |
echo "- - - - - - - - - - - - - - - - - - - - - -" | |
echo "Successfully saved config" | |
} | |
setup_env_question() { | |
read -p "Automatically configure the price feed? (Y/n) " SETUP_ENV | |
case "$SETUP_ENV" in | |
[yY] | [yY][Ee][Ss] | "" ) | |
setup_env | |
;; | |
[nN] | [nN][oO] ) | |
echo "Skipping environment setup" | |
;; | |
*) | |
echo "Invalid option" | |
setup_env_question | |
;; | |
esac | |
} | |
# Install the price feed in the current directory | |
install() { | |
echo "Installing Python3, git, and Python3-PIP..." | |
echo "- - - - - - - - - - - - - - - - - - - - - -" | |
echo | |
case "$OSTYPE" in | |
darwin*) | |
echo "Detected OSX. Trying to install via Homebrew" | |
command -v brew >/dev/null 2>&1 || { echo "Homebrew not found. Please install Homebrew from http://brew.sh" >&2; exit 1; } | |
brew update | |
brew install git | |
brew install python3 | |
brew install screen | |
;; | |
linux*) | |
command -v apt-get >/dev/null 2>&1 || { echo "Couldn't find apt-get. This script only supports debian-based and OSX systems" >&2; exit 1; } | |
apt-get update > /dev/null | |
apt-get install -y python3 python3-dev git screen libssl-dev libffi-dev python3-pip > /dev/null | |
;; | |
*) echo "Your OS is NOT supported. You'll have to do it manually." && exit ;; | |
esac | |
echo "- - - - - - - - - - - - - - - - - - - - - -" | |
echo | |
echo "Updating PIP to avoid problems..." | |
pip3 install --upgrade pip > /dev/null | |
echo "- - - - - - - - - - - - - - - - - - - - - -" | |
echo | |
echo "Cloning @jesta's Steem Feed..." | |
echo "- - - - - - - - - - - - - - - - - - - - - -" | |
echo | |
git clone https://github.com/aaroncox/steemfeed.git > /dev/null | |
cd steemfeed | |
echo | |
echo "Installing dependencies..." | |
echo "- - - - - - - - - - - - - - - - - - - - - -" | |
echo | |
pip3 install {python-dateutil,websocket-client,steem-piston,steem} > /dev/null | |
setup_env_question | |
echo "- - - - - - - - - - - - - - - - - - - - - -" | |
echo | |
echo "Price feed has been installed. Start with '$0 restart'" | |
echo | |
} | |
if [[ $# -lt 1 ]]; then | |
echo "Welcome to the price feed script by @SOMEGUY123" | |
echo "What would you like to do?" | |
echo | |
echo "install -> Install price feed into current directory" | |
echo "config -> Re-configure username and key used" | |
echo "status -> Check if the feed is running" | |
echo "restart -> (Re)start the price feed" | |
echo "stop -> Stop the price feed" | |
read -p "Your choice: " CHOICE | |
else | |
CHOICE=$1 | |
fi | |
stop() { | |
echo "Killing any existing price feed" | |
pkill -9 -f "steemfeed.py" | |
} | |
case "$CHOICE" in | |
install) | |
install | |
;; | |
config) | |
if [[ ! -d "steemfeed" ]]; then | |
echo "Please install using the install command first!" | |
exit | |
fi | |
cd steemfeed | |
setup_env | |
;; | |
status) | |
IS_RUNNING=$(ps aux | grep "steemfeed.py" | grep -v "grep" | wc -l) | |
if [[ $IS_RUNNING -gt 0 ]]; then | |
echo "The price feed is currently running" | |
echo "View it by typing:" | |
echo "screen -x pricefeed" | |
else | |
echo "The price feed is NOT running" | |
fi | |
;; | |
stop) | |
stop | |
;; | |
start | restart) | |
if [[ ! -d "steemfeed" ]]; then | |
echo "Please install using the install command first!" | |
exit | |
fi | |
stop | |
echo "Loading environment settings" | |
cd steemfeed | |
export $(grep -o '^[^#]*' .env) | |
# clear old error log | |
if [[ -f error.log ]]; then | |
rm error.log | |
fi | |
echo "Starting steemfeed in screen 'pricefeed'" | |
screen -L -dmS pricefeed sh -c 'python3 steemfeed.py 2> error.log' | |
echo "Pricefeed started! Check on it with 'screen -x pricefeed'" | |
echo "Problems? Check steemfeed/error.log" | |
if [[ -f error.log ]]; then | |
cat error.log | |
fi | |
;; | |
*) | |
echo "Invalid command." | |
echo "Usage: $0 install|config|status|restart|stop" | |
;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment