Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- ##================================ xmr-mine ================================##
- # Launch script for xmr-stak-cpu: this script generates a config file from
- # command line arguments and the number of processors available.
- ##========================== DEFAULT SETTINGS ==========================##
- # wallet, pool:
- wallet_address=''
- pool_address=''
- pool_password=''
- # config:
- verbose_level=3
- daemon_mode='false'
- use_slow_memory='warn'
- ouput_file=''
- ##============================== HELP DOC ==============================##
- print_help() {
- cat <<'EODOC'
- SCRIPT:
- xmr-mine
- DESCRIPTION:
- Launch xmr-stak-cpu with user defined default settings that can be
- overridden by command line arguments. The thread count is calculated
- as half the number of processors unless specified.
- REQUIREMENTS:
- xmr-stak-cpu
- Monero pool cpu miner.
- USAGE:
- xmr-mine [ARGS]
- ARGUMENTS:
- -B|--background
- Launch in set verbose_level=0, launch in daemon mode, and
- fork to background.
- -F|--foreground
- Keep active. (default)
- -H|--help
- Print help.
- -l|--log [file]
- Save all output to file. No output logged if blank (default).
- -m|--memory [option]
- Options:
- always - Don't even try to use large pages.
- warn - Try large pages; fall back if necessary.
- nolock - Don't lock memory at all.
- never - Use large pages or fail and exit.
- -p|--pool [pool.domain.abc:12345]
- Pool address and port number. (default user specified in header)
- -S|--sudo
- Launch xmr-stak-cpu with sudo privileges. Users will be prompted
- for their password.
- -t|--threads
- Number of threads to mine with. (default = half number of processors)
- -v|--verbose_level [0-4]
- Verbosity level:
- 0 - Don't print anything.
- 1 - Intro + connection event + disconnect event
- 2 - (1) + new job event if difficulty is different
- 3 - (1) + all new job events + result submission event (default)
- 4 - (3) + hashrate every 60 seconds
- -V|--verbose
- Keep active, set verbose_level=4.
- -w|--wallet [wallet address]
- Public wallet address to mine to. (default set by user in header)
- SEE ALSO:
- https://github.com/fireice-uk/xmr-stak-cpu
- EODOC
- }
- ##============================= variables ==============================##
- sudoCmd=
- configTxt=
- fError=0
- fDryrun=0
- uThreads=
- red='\e[0;31m'
- Red='\e[0;38;5;196m'
- RedB='\e[1;38;5;196m'
- Yellow='\e[0;38;5;11m'
- YellowB='\e[1;33m'
- BlueB='\e[1;38;5;27m'
- Cyan='\e[0;38;5;14m'
- Gray='\e[0;37m'
- white='\e[0;38;5;15m'
- psError="$RedB!:$white"
- psWarn="$YellowB!:$white"
- psInfo="$BlueB::$white"
- ##============================= functions ==============================##
- printe() {
- printo "$psError" "$red" "$@"
- fError=1
- }
- printi() {
- printo "$psInfo" "$Cyan" "$@"
- }
- printo() {
- args=("$@")
- [ -n "${args[3]}" ] && args[3]=" ${args[3]}"
- [ -n "${args[4]}" ] && args[4]=" ${args[4]}"
- printf "${args[0]} ${args[2]}${args[1]}${args[3]}$white${args[4]}$Gray\n"
- }
- printw() {
- printo "$psWarn" "$Yellow" "$@"
- }
- ##============================= prechecks ==============================##
- if (ps aux | grep "xmr-stak-cpu" | grep -v grep &>/dev/null); then
- printw "xmr-stak-cpu is already running!"
- fError=1
- fi
- # check internet connection:
- if !(ping -q -c 1 -W 3 google.com &> /dev/null) &&
- !(ping -q -c 1 -W 3 archlinux.org &> /dev/null); then
- printe "No internet connection available."
- fi
- # exit if errors:
- [ $fError -eq 1 ] && exit 1
- ##============================= parse args =============================##
- for arg in "$@"; do case $arg in
- -B|--background) shift; daemon_mode='true' ;;
- -D|--dryrun) shift; fDryrun=1 ;;
- -F|--foreground) shift; daemon_mode='false' ;;
- -H|--help) print_help; exit 0 ;;
- -l|--log|-o|--output) shift; output_file="$1"; shift ;;
- -m|--memory) shift; use_slow_memory="$1"; shift ;;
- -p|--pool) shift; pool_address="$1"; shift ;;
- -S|--sudo) shift; sudoCmd='sudo ' ;;
- -t|--threads) shift; uThreads="$1"; shift ;;
- -v|--verbose_level) shift; verbose_level="$1"; shift ;;
- -V|--verbose) shift; verbose_level=4 ;;
- -w|--wallet) shift; wallet_address="$1"; shift ;;
- esac; done
- [ "$daemon_mode" = "true" ] && verbose_level=0
- ##============================ error checks ============================##
- # wallet:
- if [ -z "$wallet_address" ] || [ ${#wallet_address} -ne 95 ] ||
- [[ ! "$wallet_address" =~ ^[A-Za-z0-9]+$ ]]; then
- printe "Invalid wallet address:" "${wallet_address}"
- fi
- # pool address:
- if [ -z "$pool_address" ]; then
- printe "No pool address."
- elif [[ ! "$pool_address" =~ ^[A-Za-z]+.[A-Za-z0-9]+.[A-Za-z0-9]+:[0-9]+$ ]];
- then
- printe "Invalid pool address:" "${pool_address}"
- # pool status:
- elif !(ping -q -c 1 -W 3 "${pool_address%:*}" &> /dev/null); then
- printe "Unable to connect to pool:" "${pool_address%:*}"
- fi
- # EXIT if errors:
- [ $fError -eq 1 ] && exit 1
- ##============================== warnings ==============================##
- # verbose level:
- if [[ ! "${verbose_level}" =~ ^[0-4]$ ]]; then
- printw "Invalid verbose_level:" "${verbose_level}"
- verbose_level=3
- fi
- # memory setting:
- if [[ ! "$use_slow_memory" =~ ^always|warn|no_mlck|nolock|never$ ]]; then
- printw "Invalid memory setting:" "${use_slow_memory}"
- use_slow_memory='warn'
- elif [ "$use_slow_memory" = "nolock" ]; then
- use_slow_memory='no_mlck'
- fi
- # thread count:
- if [ -n "$uThreads" ] && [[ ! "$uThreads" =~ ^[1-9][0-9]*$ ]]; then
- printw "Invalid number of threads:" "$uThreads"
- uThreads=
- fi
- nProcessors=`nproc`
- if [ -z "$uThreads" ]; then
- mThreads=$(( $nProcessors / 2 ))
- elif [ $uThreads -ge $nProcessors ]; then
- printw "Using all processors:" "$nProcessors"
- mThreads=$nProcessors
- fi
- ##========================= build config text ==========================##
- # user settings:
- configTxt+="\"wallet_address\" : \"${wallet_address}\",\n"
- configTxt+="\"pool_address\" : \"${pool_address}\",\n"
- configTxt+="\"pool_password\" : \"${pool_password}\",\n"
- configTxt+="\"verbose_level\" : ${verbose_level},\n"
- configTxt+="\"daemon_mode\" : ${daemon_mode},\n"
- configTxt+="\"use_slow_memory\" : \"${use_slow_memory}\",\n"
- configTxt+="\"output_file\" : \"${output_file}\",\n"
- # threads:
- configTxt+="\"cpu_threads_conf\" :\n[\n"
- for ((n=1;n<=$mThreads;n++)); do
- configTxt+=" { \"low_power_mode\" : false, "
- configTxt+="\"no_prefetch\" : true, \"affine_to_cpu\" : $n },\n"
- done
- configTxt+="],\n"
- # template settings:
- configTxt+='"nicehash_nonce" : false,
- "aes_override" : null,
- "use_tls" : false,
- "tls_secure_algo" : true,
- "tls_fingerprint" : "",
- "call_timeout" : 10,
- "retry_time" : 10,
- "giveup_limit" : 0,
- "h_print_time" : 60,
- "httpd_port" : 0,
- "prefer_ipv4" : true'
- configTxt+="\n"
- ##============================ display info ============================##
- # print config and exit (dryrun):
- if [ $fDryrun -eq 1 ]; then
- printf "$configTxt"
- exit 0
- fi
- printi "Wallet:" "${wallet_address}"
- printi "Pool:" "${pool_address}"
- ##======================== launch xmr-stak-cpu =========================##
- printf "$psInfo Starting $Red$sudoCmd${Cyan}xmr-stak-cpu$white with "
- printf "$Cyan$mThreads$white threads...$Gray\n"
- printf "$configTxt" > /tmp/xmr-mine_config.txt
- if [ "$daemon_mode" = "false" ]; then
- $sudoCmd xmr-stak-cpu /tmp/xmr-mine_config.txt
- else
- $sudoCmd xmr-stak-cpu /tmp/xmr-mine_config.txt &
- sleep 4
- printf "$psInfo Forked to background PID: $!\n"
- fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement