#!/bin/bash # to use run `source <(curl -s https://raw.githubusercontent.com/cynixx3/third-party-miner-installer-for-ethos/master/miner-manager) miner action` Where the miner is the branch in the repo and the actions are install, update, or revert # IE `source <(curl -s https://raw.githubusercontent.com/cynixx3/third-party-miner-installer-for-ethos/master/miner-manager) phoenixminer install` # Any setting changes to this should be made to the miner.settings file in the miners branch of this repo MINER_BRANCH="$1" CMD="$0" ACTION="$2" VERSION="$3" ALLOW="$(cat /opt/ethos/etc/allow.file)" # Github limits public api requests to 60 per hour, this script does 2 calls per install maxing out at 30 miner installs per hour # by adding a github user and password you can install up to 2,500 miners per hour # Either install the miner-manager and add a github.com user / pass here # or add the two lines to a file /home/ethos/.gituser and you can continue to use the source command or via install. #GITHUB_USERNAME="GitUser" #GITHUB_PASSWORD="GitPassword" # Default miner.settings TMP_DIR="/tmp/newminer" GIT_USER_REPO="cynixx3/third-party-miner-installer-for-ethos" #RELEASE_SHASUM="sha256sum of archive" #DEPENDS="URL URL" # Setting date for https sudo date -s "$(wget -qSO- --max-redirect=0 google.com 2>&1 | grep Date: | cut -d' ' -f5-8)Z" # Assemble API user login if [ -f /home/ethos/.gituser ] ; then source <(grep -m2 ^GITHUB_.*=".*"$ /home/ethos/.gituser) fi if [ "$GITHUB_PASSWORD" ] ; then GIT_LOGIN=" --user $GITHUB_USERNAME:$GITHUB_PASSWORD" elif [ "$GITHUB_USERNAME" ] ; then GIT_LOGIN=" --user $GITHUB_USERNAME" else GIT_LOGIN="" fi # Check Github API rate limit if [ "$(curl -iks $GIT_LOGIN https://api.github.com/rate_limit | grep -im1 ^x-ratelimit-remaining | cut -d ' ' -f 2 | sed 's/\r//')" -le 2 ] ; then echo "You have installed the maximum number of rigs github allows. You need to wait until $(date -d "@$(curl -is https://api.github.com/rate_limit | grep ^X-Ratelimit-Reset: | cut -d : -f 2)" +%r) or add GitHub authentication." exit 19 fi # Get miner files and setup temporary opt/ if [[ "$MINER_BRANCH" =~ "^ccminer$" ]] ; then DOWNLOAD_BRANCH="ccminer-tpruvot" else DOWNLOAD_BRANCH="$MINER_BRANCH" fi f.PREPMINER(){ if [ -z "$DOWNLOAD_URL" -a -n "$VERSION" ] ; then echo "Getting version $VERSION of $MINER_BRANCH" DOWNLOAD_URL=$(curl $GIT_LOGIN -s "https://api.github.com/repos/$GIT_USER_REPO/releases?per_page=100" \ | grep -i "browser_download_url.*$DOWNLOAD_BRANCH.*t.*z" \ | cut -d '"' -f 4 \ | grep -vE '(osx|txt|sha256|armhf)' \ | grep "$VERSION" \ | head -1 ) if [ -z "$DOWNLOAD_URL" ] ; then echo "WARNING: Unable to find $MINER_BRANCH version $VERSION. Defaulting to latest version" fi fi if [ -z "$DOWNLOAD_URL" ] ; then echo "Getting latest release of miner" DOWNLOAD_URL=$(curl $GIT_LOGIN -s "https://api.github.com/repos/$GIT_USER_REPO/releases?per_page=100" \ | grep -i "browser_download_url.*$DOWNLOAD_BRANCH.*t.*z" \ | cut -d '"' -f 4 \ | grep -vE '(osx|txt|sha256|cuda|armhf)' \ | head -1 ) fi COMPRESSION=$(echo "$DOWNLOAD_URL" | grep -oP 't[argxb.]{1,4}z2?$') case $COMPRESSION in tar.gz|tgz) CT="-z" ;; tar.xz) CT="-J" ;; tar.bz2) CT="-j" ;; *) CT="" ;; esac if [ -f "$MINER_BRANCH.$COMPRESSION" ] ; then rm -rf "/tmp/newminer/$MINER_BRANCH.$COMPRESSION" ; fi if ! wget -q "$DOWNLOAD_URL" -O "$MINER_BRANCH.$COMPRESSION" ; then echo "Download failed. Please check your firewall or git access and try again." exit 10 fi if [ "$RELEASE_SHASUM" ] ; then echo "Comparing download with checksum" if ! echo "$RELEASE_SHASUM $MINER_BRANCH.$COMPRESSION" | sha256sum -c ; then echo "Check of miner files failed, please check your access to git then try again or update miner.settings in repo" exit 11 fi fi echo "Unpacking miner" SUBDIR="" if tar "$CT" -tf "$MINER_BRANCH.$COMPRESSION" | grep -qv "^$(tar "$CT" -tf "$MINER_BRANCH.$COMPRESSION" | grep -oP '^.*\/' | sort | head -n1 )" ; then SUBDIR="--directory=$MINER_BRANCH" MINER_ARCHIVE_FOLDER="$MINER_BRANCH" mkdir "$MINER_BRANCH" echo "WARNING: tarbomb detected. Opening in subdirectory, $MINER_BRANCH." else MINER_ARCHIVE_FOLDER=$(tar "$CT" -tf "$MINER_BRANCH.$COMPRESSION" | grep -oP '^.*\/' | grep -vE '(kernel|plugin|log.|doc|web|licenses|scripts|lib)' | sort -u | tail -n1) || echo "failed to find archive folder" fi if ! tar "$CT" -xf "$MINER_BRANCH.$COMPRESSION" "$SUBDIR" ; then echo "Unable to extract files package. Please check your access to git then try again." exit 12 fi mkdir -p "$TMP_DIR/opt/miners" rsync -a --delete "$TMP_DIR/$MINER_ARCHIVE_FOLDER/" "$TMP_DIR/opt/miners/$MINER_BRANCH" sudo chown -R ethos.ethos "$TMP_DIR"/opt/miners/ if [ "$HOOK_PREP_MINER" ] ; then $HOOK_PREP_MINER ; fi echo "Temporary miner files ready" } # Prevent package lock when installing dependencies f.CHECKDPKG(){ DPKGLOCKED=$(lsof /var/lib/dpkg/lock 2>/dev/null | grep -c "/var/lib/dpkg/lock") WAITCOUNT="0" if [ "$DPKGLOCKED" -ge "1" ]; then until [ "$DPKGLOCKED" = "0" ] || [ "$WAITCOUNT" = "60" ]; do DPKGLOCKED=$(lsof /var/lib/dpkg/lock 2>/dev/null | grep -c "/var/lib/dpkg/lock") ((WAITCOUNT++)) done fi if [ "$WAITCOUNT" -ge "120" ]; then echo "Timed out waiting on dpkg lock to clear." echo "manually clearing dpkg lock" rm -f /var/lib/dpkg/lock fi } # Get Replacement ethos files that enable miner operation and install miner specific dependencies f.PREPETHOS(){ if [ "${VER//./}" -ne 133 ] ; then echo "Unable to install due to current ethOS version, try \"update\" instead to install just the miner or update ethOS." exit 14 fi echo "Download and unpack files needed by ethOS" if ! git clone https://github.com/cynixx3/third-party-miner-installer-for-ethos.git -b "$MINER_BRANCH" ; then echo "git clone download failed. Please check your firewall or git access and try again." exit 15 fi if [ -f "$TMP_DIR/third-party-miner-installer-for-ethos/opt/ethos/$MINER_BRANCH.stub.conf" ] ; then mkdir -p "$TMP_DIR/home/ethos/" mv "$TMP_DIR/third-party-miner-installer-for-ethos/opt/ethos/$MINER_BRANCH.stub.conf" "$TMP_DIR/home/ethos/" sudo chmod 644 "$TMP_DIR/home/ethos/$MINER_BRANCH.stub.conf" sudo chown -R ethos.ethos "$TMP_DIR/home/ethos/$MINER_BRANCH.stub.conf" fi mkdir -p $TMP_DIR/opt/ethos rsync -a --delete "$TMP_DIR/third-party-miner-installer-for-ethos/opt/ethos/" "$TMP_DIR/opt/ethos" chmod 775 "$TMP_DIR"/opt/ethos/bin/* "$TMP_DIR"/opt/ethos/sbin/* chmod 744 "$TMP_DIR"/opt/ethos/etc/* if [ -f "$TMP_DIR"/opt/ethos/lib/minerprocess.php ] ; then chmod 644 "$TMP_DIR"/opt/ethos/lib/minerprocess.php fi if [ -f "$TMP_DIR"/opt/ethos/lib/functions.php ] ; then chmod 755 "$TMP_DIR"/opt/ethos/lib/functions.php fi sudo chown -R root.root "$TMP_DIR"/opt/ethos/ sudo chown -R ethos.ethos "$TMP_DIR"/opt/ethos/etc/screenrc.* "$TMP_DIR/opt/ethos/bin/minestop" echo "Check for dependencies" if [ "$DEPENDS" ] ; then echo "Installing dependencies" mkdir "$TMP_DIR/depends" for URL in "${DEPENDS[@]}" ; do wget "$URL" -P depends sleep 5 done f.CHECKDPKG sudo dpkg --configure -a f.CHECKDPKG sudo dpkg -i "$TMP_DIR"/depends/*.deb fi if [ "$HOOK_PREP_ETHOS" ] ; then $HOOK_PREP_ETHOS ; fi echo "ethOS files ready" } # Gather stock ethOS files in temporary opt/ and install stock packages f.REVERT(){ if [ "${VER//./}" -lt 132 ] ; then echo "Unable to revert, stock files are not ready for your miner version. Please try \`sudo ethos-update reupdate\`" exit 16 fi if ! git clone https://github.com/cynixx3/third-party-miner-installer-for-ethos.git -b ethos ; then echo "git clone download failed. Please check your firewall or git access and try again." exit 17 fi mkdir -p "$TMP_DIR/opt/ethos" rsync -a --delete "$TMP_DIR/third-party-miner-installer-for-ethos/opt/ethos-$VER/" "$TMP_DIR/opt/ethos" chmod 775 "$TMP_DIR"/opt/ethos/bin/* "$TMP_DIR"/opt/ethos/sbin/* if [ -f "$TMP_DIR"/opt/ethos/lib/minerprocess.php ] ; then chmod 644 "$TMP_DIR"/opt/ethos/lib/minerprocess.php fi if [ -f "$TMP_DIR"/opt/ethos/lib/functions.php ] ; then chmod 755 "$TMP_DIR"/opt/ethos/lib/functions.php fi sudo chown -R root.root "$TMP_DIR"/opt/ethos/ sudo chown -R ethos.ethos "$TMP_DIR"/opt/ethos/bin/minestop # Reinstall stock dependencies mkdir "$TMP_DIR/depends" wget http://security.ubuntu.com/ubuntu/pool/main/g/gcc-4.8/gcc-4.8-base_4.8.4-2ubuntu1~14.04.4_amd64.deb -P depends wget https://launchpad.net/~ubuntu-toolchain-r/+archive/ubuntu/test/+build/14981774/+files/gcc-8-base_8.1.0-5ubuntu1~14.04_amd64.deb -P depends f.CHECKDPKG sudo dpkg --configure -a f.CHECKDPKG sudo dpkg -i "$TMP_DIR"/depends/*.deb if [ "$HOOK_REVERT" ] ; then $HOOK_REVERT ; fi } f.INSTALL(){ echo "Stopping the miner" /opt/ethos/bin/disallow MPID="$(ps uax | grep -E "avermore|ccminer|cgminer-skein|claymore|dstm-zcash|ethminer|ewbf-equihash|ewbf-zcash|lolminer|nevermore|optiminer-zcash|progpowminer|sgminer-gm|teamredminer|xmr-stak|xtl-stak|$MINER_BRANCH" | grep -Ev '(bash|source|curl|update-miner|miner-manager|develop|grep)' | awk '{print $2}' )" if [ "$MPID" ] ; then sudo kill -9 $MPID ; fi echo "Installing miner" sudo rsync -av "$TMP_DIR/opt/" /opt if [ -f "$TMP_DIR/home/ethos/$MINER_BRANCH.stub.conf" ] ; then sudo rsync -av "$TMP_DIR/home/ethos/" /home/ethos if [ "$HOOK_STUB" ] ; then $HOOK_STUB ; fi fi if [[ "$ACTION" == "install" ]] && [[ -d "$TMP_DIR/opt/ethos" ]] ; then sed "/#Installed/d" -i /home/ethos/remote.conf printf "\n#Installed $MINER_BRANCH ethOS files on %s" "$(date)" >> /home/ethos/remote.conf elif [[ "$ACTION" == "revert" ]] && [[ -d "$TMP_DIR/opt/ethos" ]] ; then sed "/#Installed/d" -i /home/ethos/remote.conf fi if [ "$HOOK_INSTALL" ] ; then ${HOOK_INSTALL[@]} ; fi echo "Restarting services and miner" sudo service ethos-miner-daemon restart sudo service ethos-stats-daemon restart sudo service ethos-gpu-stats-daemon restart if [ "$ALLOW" = "1" ] ; then /opt/ethos/bin/allow fi } f.CLEANUP(){ rm -rf "$TMP_DIR" echo "temporary files removed, all done." } f.HELP (){ echo "$1 Usage $CMD [ Miner ] ( install | update | revert ) Miners Available:" printf "%s\n" "${AVAILABLE_MINERS[@]//\"/}" } mapfile -t AVAILABLE_MINERS < <(curl $GIT_LOGIN -ks https://api.github.com/repos/cynixx3/third-party-miner-installer-for-ethos/branches?per_page=100 | grep name | grep -Ev '(ethos|master)' | sed -E 's/ +"name": ("[a-z0-9\-]+?"), ?/ \1/g') # TODO add logging if [ "$#" -lt "2" -o "$#" -gt "3" ] ; then f.HELP "Wrong number of arguments, must have 2 arguments, a miner and action, please refer to https://github.com/cynixx3/third-party-miner-installer-for-ethos" exit 1 elif ! [[ "${AVAILABLE_MINERS[@]}" == *"\"$MINER_BRANCH\""* ]] ; then f.HELP "Invalid miner selected, Please choose from the list below" exit 2 fi # Get miner settings if ! source <(curl $GIT_LOGIN -s "https://raw.githubusercontent.com/cynixx3/third-party-miner-installer-for-ethos/$MINER_BRANCH/miner.settings") ; then echo "You may have a security certificate issue." fi if [ -d "$TMP_DIR" ] ; then rm -rf "$TMP_DIR" ; fi echo "Move to a temporary work space" mkdir "$TMP_DIR" cd "$TMP_DIR" || exit 10 VER=$(grep -oE "[0-9]+\.[0-9]+\.[0-9]+" /opt/ethos/etc/version) case "$2" in install) f.PREPMINER f.PREPETHOS f.INSTALL f.CLEANUP ;; update) f.PREPMINER f.INSTALL f.CLEANUP ;; revert) f.REVERT rm -rf "/opt/miners/$MINER_BRANCH" f.INSTALL f.CLEANUP ;; *) f.HELP "Invalid instruction, options are install, update, or revert" exit 3 esac cd ~ || exit 20