18/03/21 Notes
Bash Tooling and Automation
### Enhanced this script with additional options ###
#!/bin/bash

mining_function () {
  # Top scope variables	
  VERSION='0.19.0'
  WORKER='goldmine'
  USERNAME=$(whoami)

  # Introduction
  echo "This script processes two arguments."
  echo "Argument 1, 'etc' or 'eth'."
  echo "Argument 2, 'ssl' or 'stratum'."
  echo "$# arguments supplied."

  # Validate number of arguments
  if [ $# -ne 2 ]; then
    echo "Please supply two arguments".
    exit 0
  fi

  # Validate argument 1
  if [ $1 != 'eth' -a $1 != 'ETH' -a $1 != 'etc' -a $1 != 'ETC' ]; then
    echo "You entered ${1}. You must enter eth or etc."
    exit 0
  fi
  
  # Validate argument 2
  if [ $2 != 'ssl' -a $2 != 'SSL' -a $2 != 'stratum' -a $2 != 'STRATUM' ]; then
    echo "You entered ${2}. You must enter ssl or stratum."
    exit 0
  fi

  # Set ETH address
  if [ $1 == 'eth' -o $1 == 'ETH' ]; then
    echo "Enter a wallet to mine to, coinjar or exodus?"
    read WALLET
    if [ $WALLET == 'exodus' -o $WALLET == 'EXODUS' ]; then 
      ADDRESS='abcde'
    elif [ $WALLET == 'coinjar' -o $WALLET == 'COINJAR' ]; then
      ADDRESS='12345'
    else 
      echo "You entered ${WALLET}. You must enter coinjar or exodus."
      exit 0
    fi
    SERVER='asia1.ethermine.org'
  fi

  # Set ETC address
  if [ $1 == 'etc' -o $1 == 'ETC' ]; then
    ADDRESS='67891'
    SERVER='asia1-etc.ethermine.org'
    WALLET='exodus'
  fi

  # Set stratum(s)
  if [ $2 == 'ssl' -o $2 == 'SSL' ]; then
    PORT='5555'
    PROTOCOL='stratums'
  elif [ $2 == 'stratum' -o $2 == 'STRATUM' ]; then
    PORT='4444'
    PROTOCOL='stratum'
  fi

  # Begin Mining. The same server is repeated to continuously attempt reconnection if connectivity is lost.
  echo "You will be mining ${1} over ${2} to ${ADDRESS} (${WALLET})."
  /home/${USERNAME}/linux-ethminer-${VERSION}/bin/ethminer -P ${PROTOCOL}://${ADDRESS}.${WORKER}@${SERVER}:${PORT} -P ${PROTOCOL}://${ADDRESS}.${WORKER}@${SERVER}:${PORT}
}

mining_function $1 $2

### Setup Ruby on devbox script ###
#!/bin/bash
# Install ruby
set -x
sudo yum install -y centos-release-scl
sudo yum install -y gcc gcc-c++ openssl openssl-devel rh-ruby26 rh-ruby26-ruby-devel git
echo -e '#enable ruby on login\nsource scl_source enable rh-ruby26' | sudo tee -a /etc/bashrc
source scl_source enable rh-ruby26
gem install beaker
gem install bundler

### Prototype for devbox installation tool ###
#!/bin/bash
devbox_function () {
  echo "Welcome to the devbox configuration tool"
  while true; do
  echo "Enter 1 to configure Python to perform OpenStack Orchestration (HEAT)."
  echo "Enter 2 to configure Ruby to perform Puppet Spec/Acceptance testing."
  echo "Enter 3 to configure base settings such as a Graphical Desktop and Remote Desktop Server."
  echo "Enter 4 to update your devbox and reboot (exits program)."
  echo "Enter exit to end program"
    read selection
    case $selection in
    1)  bash python.sh
        ;;
    2)  bash ruby.sh
        ;;
    3)  bash base.sh
        ;;
    4)  bash update.sh
        ;;
    exit) break
        ;;
    *)  echo "Invalid response"
        ;;
  esac
done
}

devbox_function

### Alias for python venv ###
echo -e 'alias venv="source $HOME/.venv/bin/activate" | tee -a ~/.bashrc