├── VERSION ├── AUTHOR ├── ziesha ├── LICENSE ├── ziesha-installer.sh ├── .gitignore ├── ziesha-service.sh ├── README.md ├── ziesha-summary.sh ├── ziesha-common.sh ├── ziesha-usage.sh └── ziesha-helper.sh /VERSION: -------------------------------------------------------------------------------- 1 | version = 0.1 -------------------------------------------------------------------------------- /AUTHOR: -------------------------------------------------------------------------------- 1 | author = pentafenolin 2 | twitter = @pentafenolin 3 | discord = pentafenolin#9413 4 | github = https://github.com/isezen -------------------------------------------------------------------------------- /ziesha: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # shellcheck disable=1090 3 | # Ziesha Runner 4 | # 5 | # To Install Ziesha, run: 6 | # $ curl -s https://raw.githubusercontent.com/isezen/ziesha-helper/main/ziesha | bash && . ~/.profile 7 | # 8 | file="$HOME/.local/ziesha/ziesha-helper/ziesha-helper.sh" 9 | [ -f "$file" ] && source "$file" || { 10 | bash <(curl --proto '=https' --tlsv1.2 -sSf https://raw.githubusercontent.com/isezen/ziesha-helper/main/ziesha-helper.sh) install me 11 | echo "Ziesha-helper was installed" 12 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 Ismail SEZEN 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /ziesha-installer.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # This is an easy installer script for Ziesha Helper to a computer/server. 4 | # 5 | 6 | header=$(cat <> "$LOG_FILE" 2>&1 70 | systemctl --user daemon-reload >> "$LOG_FILE" 2>&1 71 | ;; 72 | disable) 73 | systemctl --user "$status" --now ziesha@"$a" >> "$LOG_FILE" 2>&1 74 | systemctl --user daemon-reload >> "$LOG_FILE" 2>&1 75 | ;; 76 | *) 77 | _unknown_option "$status"; exit 1 ;; 78 | esac 79 | } 80 | 81 | # Start a Ziesha service 82 | start () { service start "$1"; } 83 | 84 | # Stop a Ziesha service 85 | stop () { service stop "$1"; } 86 | 87 | # Restart a Ziesha service 88 | restart () { service restart "$1"; } 89 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Ziesha-Helper 2 | _Ziesha Helper_ is a tool to install and manage your Ziesha infrastructure. You can 3 | 4 | * install bazuka, uzi-miner, zoro and uzi-pool 5 | * start/stop/restart Ziesha tools 6 | * get summary reports about your tools 7 | * and your tool can be restarted if an error happens. 8 | 9 | # How to install? 10 | 11 | To install _Ziesha Helper_, just copy&paste following command in your terminal window. It will make required adjustments and install _Ziesha Helper_ on your system. 12 | 13 | ```sh 14 | curl -s https://raw.githubusercontent.com/isezen/ziesha-helper/main/ziesha | bash && . ~/.profile 15 | ``` 16 | 17 | # How to use? 18 | 19 | After installation, type `ziesha` (and press `ENTER`) on your command line to see _Ziesha Helper_ command parameters. You can get detailed usage information about each command by typing `ziesha COMMAND -h`. For instance, to get informationm how to install a Ziesha tool, type `ziesha install -h`. 20 | 21 | ``` 22 | ℤiesha Helper v0.1 23 | 24 | Made with ❤️ by pentafenolin (2022) 25 | ● Discord: pentafenolin#9413 26 | ● Twitter: @pentafenolin (Follow me! ^_^) 27 | ● Github : https://github.com/isezen 28 | 29 | DESCRIPTION: 30 | Manage Ziesha-network infrastructure. 31 | For more info, type 'ziesha COMMAND -h' 32 | 33 | OPTIONS: 34 | -h | --help : Shows this message 35 | -v | --version : Show Ziesha Helper version 36 | 37 | COMMANDS: 38 | install : Install a Ziesha tool 39 | update : Update a Ziesha tool 40 | remove : Remove/uninstall a Ziesha tool 41 | list : List installed tools 42 | log : Show log of a Ziesha tool 43 | set : Set a variable 44 | get : Get a variable 45 | download : Download zoro dat files 46 | init : Initialize bazuka 47 | run : Run selected tool 48 | reset : Reset bazuka and wallet 49 | start : Start a service 50 | stop : Stop a service 51 | restart : Restart a service 52 | status : Show status 53 | summary : Show summary 54 | 55 | USAGE EXAMPLES: 56 | $ ziesha install bazuka 57 | $ ziesha remove zoro 58 | $ ziesha set discord-handle MYHANDLE 59 | $ ziesha start uzi-pool 60 | ``` 61 | 62 | # How to install? 63 | 64 | ## Install Rust 65 | 66 | It is easier to install rust after installing _Ziesha Helper_. You just need to type following command to install rust. 67 | 68 | ```sh 69 | ziesha install rust 70 | ``` 71 | 72 | # Install Bazuka 73 | 74 | Just type `ziesha install bazuka`. This command will download required source files from github, save them under `.local/ziesha/bazuka` folder and compile using rust toolchain. Installing other tools are easy as installing Bazuka. To install uzi-miner, just type `ziesha install uzi-miner`. 75 | 76 | # Start Bazuka 77 | 78 | Before starting Bazuka, we need to set some settings to be able to join testnet phase of Ziesha Network. Following command will set your discord handle to track your Bazuka node status. 79 | 80 | ```sh 81 | ziesha set --discord-handle pentafenolin#1234 82 | ``` 83 | 84 | Then, you need to `init` your bazuka environment before starting bazuka. This command is completely same as `bazuka init ...` command. 85 | 86 | ```sh 87 | ziesha init --network NETWORK_NAME --bootstrap X.X.X.X:8765 --mnemonic "YOUR MNEMONIC WORDS" 88 | ``` 89 | 90 | where `NETWORK_NAME` is your testnet network name, `X.X.X.X` is your bootstrap IP and `YOUR MNEMONIC WORDS` are your previous mnemonics. If you are first time setting up a bazuka node, you won't have any mnemonics, bazuka will give your mnemonics after initialization. Don't forget to save them somewhere safe. 91 | 92 | Through out testnet phase, you might be required to change the network name. You can change it by the command below: 93 | 94 | ```sh 95 | ziesha set --network NEW_NETWORK_NAME 96 | ``` 97 | 98 | After setting up, you can start bazuka just by typing: 99 | 100 | ```sh 101 | ziesha start bazuka 102 | ``` 103 | 104 | This command will start bazuka in the background. You can see the log output just by typing; 105 | 106 | ```sh 107 | ziesha log bazuka 108 | ``` 109 | 110 | You need to press `CTRL+C` to quit the log output screen. 111 | 112 | Also, you can watch a summary report of your bazuka node by typing: 113 | 114 | ```sh 115 | watch -c "ziesha summary" 116 | ``` 117 | 118 | # Start Uzi-Miner 119 | 120 | Uzi-Miner is a required tool to start mining in Ziesha Network. You can install uzi-miner just by typing the command below: 121 | 122 | ```sh 123 | ziesha install uzi-miner 124 | ``` 125 | 126 | After installation, we need to set up some variables for uzi-miner. You can define number of CPU threads by `nthreads` option and access token required by the pool `pool-token` option. 127 | 128 | ```sh 129 | ziesha set --nthreads 1 130 | ziesha set --pool-token MUsYPsZiLnpKqM1ykc6bTZypv3KX5i 131 | ``` 132 | 133 | After setting up those options, you can start mining by typing `ziesha start uzi-miner` and see the log output by typing `ziesha log uzi-miner`. You will need to press `CTRL+C` to quit the log output screen. -------------------------------------------------------------------------------- /ziesha-summary.sh: -------------------------------------------------------------------------------- 1 | # shellcheck disable=1090,1091,2015,2034,2059,2155 2 | # Health of running service 3 | # return Good if service is active and running normally 4 | # otherwise return Bad 5 | # Args: 6 | # $1: Name of service 7 | # $2: If set to '-q', it will return True/False quietly. 8 | health () { 9 | local since="10min ago" 10 | local ret="inactive" 11 | local a=${1:-bazuka}; shift 12 | local quiet=$1 13 | if service_is_active "$a"; then 14 | local content 15 | content=$(journalctl -q -o short-iso-precise --since \ 16 | "$since" --user-unit=ziesha@"$a") 17 | is_in () { echo "$content" | grep -q "$1"; } 18 | case $a in 19 | "bazuka") 20 | ret=$(echo "$content" | grep "Height" | grep "Outdated" | \ 21 | awk -F ' ' '{print $5}' | sort -n | uniq) 22 | [ -n "$ret" ] && { [[ $(echo "$ret" | wc -l) -eq 1 ]] && 23 | { echo "$content" | grep -q "Height advanced to" && 24 | ret="Good" || ret="Moderate"; } || ret="Good" ;} || 25 | ret="Bad" 26 | ;; 27 | "zoro") 28 | is_in "Proving took:" && ret="Good" || ret="Bad" ;; 29 | "uzi-pool") 30 | is_in "Share found by:" && ret="Good" || ret="Bad" ;; 31 | "uzi-miner") 32 | is_in "Solution found" && ret="Good" || ret="Bad" ;; 33 | -*) 34 | _unknown_option "$1" ;; 35 | *) 36 | esac 37 | fi 38 | [ -z "$quiet" ] && echo "$ret" || [ "$ret" = "Good" ] 39 | } 40 | 41 | # Return date part of systemctl status command 42 | get_since () { 43 | local a=${1:-bazuka} 44 | local content 45 | content=$(systemctl --user --timestamp=utc status ziesha@"$a" | grep "Active:") 46 | content="${content#*since }" 47 | echo "${content%%;*}" 48 | } 49 | 50 | # Return run-time part of systemctl status command 51 | get_runtime () { 52 | local a=${1:-bazuka} 53 | local content 54 | content=$(systemctl --user status ziesha@"$a" | grep "Active:") 55 | content="${content##*; }" 56 | echo "${content:0:$#-4}" 57 | } 58 | 59 | # crawle currnet height from log content 60 | # $1 : log content 61 | get_current_height () { 62 | h1=$(echo "$content" | grep "Outdated states" | \ 63 | tail -n 1 | awk -F ' ' '{print $5}') 64 | h2=$(echo "$content" | grep "Height advanced to" | \ 65 | tail -n 1 | awk -F ' ' '{print $7}') 66 | [ -n "$h2" ] && { [ -z "$h1" ] && h1="${h2::-1}" || 67 | { h2="${h2::-1}"; [ "$h1" -lt "$h2" ] && h1="$h2"; }; } 68 | echo "$h1" 69 | } 70 | 71 | # crawle currnet height from log content 72 | # $1 : log content 73 | get_active_nodes () { 74 | echo "$content" | grep "Outdated states" | \ 75 | tail -n 1 | awk -F ' ' '{print $13}' 76 | } 77 | 78 | status () { 79 | local a=${1:-all} 80 | if ! check_a status "$a"; then 81 | ! service_is_active "$a" && { return; } 82 | local heal; heal=$(health "$a") 83 | local col="${ER}" 84 | local sign="${CROSS}" 85 | case "$heal" in 86 | "Good") 87 | col="${EG}" 88 | sign="${CHECK}" 89 | ;; 90 | "Moderate") 91 | col="${EY}" 92 | sign="\U23F3" 93 | ;; 94 | *) 95 | esac 96 | printf "${C}%-9s" "$a"; ylw ": "; echo -e "${col}$heal${sign}${NONE}" 97 | fi 98 | } 99 | 100 | summary () { 101 | local a=${*:-"all"} 102 | local time="10m" 103 | check_a summary "$a" && return 104 | ! service_is_active "$a" && { return; } 105 | 106 | local heal; heal=$(health "$a") 107 | local since; since=$(get_since "$a") 108 | local runtime; runtime=$(get_runtime "$a") 109 | local col="${ER}" 110 | local sign="\U26D4" 111 | local col="${ER}" 112 | 113 | case "$heal" in 114 | "Good") 115 | col="${EG}" 116 | sign="${CHECK}" 117 | ;; 118 | "Moderate") 119 | col="${EY}" 120 | sign="\U23F3" 121 | ;; 122 | *) 123 | esac 124 | 125 | vl=$(version local "$a"); vr=$(version remote "$a") 126 | cyn "$a v$vl:" 127 | need_update "$a" && echo -ne " ${EY}(New version v$vr)${NONE}" 128 | echo 129 | echo -e " Status : ${col}$heal${sign}${NONE}" 130 | echo -e " Started at : ${M}$since${NONE}" 131 | echo -e " Running for : ${EW}$runtime${NONE}" 132 | if [ "$heal" == "Good" ]; then 133 | sign= 134 | col="${G}" 135 | else 136 | sign=" \U203c" 137 | fi 138 | local content 139 | content=$(journalctl -q -o short-iso-precise --since \ 140 | "$time ago" --user-unit=ziesha@"$a") 141 | nhashes () { 142 | echo "$content" | grep "Got new puzzle! Approximately" | \ 143 | tail -n 1 | awk -F ' ' '{print $8}' 144 | } 145 | nl () { echo "$content" | grep "$1" | wc -l; } 146 | found () { 147 | printf "%-18s" " Found $1s"; echo -n ": " 148 | printf "${col}%s${NONE}" "$(nl "${2-$1} found")"; 149 | echo -e " (in last ${time})"; 150 | } 151 | case $a in 152 | "bazuka") 153 | height="$(get_current_height)" 154 | echo -ne " Current Height : ${col}$height${sign}${NONE}" 155 | echo "$content" | grep -q "Height advanced to" && 156 | echo -ne "${Y} (Syncing)${NONE}" 157 | echo -ne "\n Active Nodes : ${col}$(get_active_nodes)${NONE}" 158 | balance=$(bazuka wallet info | grep "Ziesha:" | \ 159 | awk -F ' ' '{print $3}') 160 | [ -z "$balance" ] && balance="0.0\U2124" 161 | echo -e "\n Balance : ${col}$balance${NONE}" 162 | ;; 163 | "zoro") 164 | ret=$(echo "$content" | grep "Proving took:" | \ 165 | awk -F ' ' '{print $NF}' | sed 's/ms//g') 166 | avg=$(echo "$ret" | awk '{ total += $1 } END { print total/NR }' \ 167 | | sed 's/,/\./g') 168 | echo -e " Avg. Prov. time : ${col}$avg${NONE} ms" 169 | ;; 170 | "uzi-pool") 171 | found "Share" 172 | found "Solution" 173 | ns="$(nl "Share")" 174 | nh="$(nhashes)" 175 | if [ -n "$nh" ]; then 176 | local sp=$(echo "scale=3 ; $(nhashes) / $SHARE_EASINESS" | bc) 177 | local hr=$(echo "scale=3 ; $ns * $sp / (600 * 1000)" | bc) 178 | echo -e " Hashrate : ${col}$hr${NONE} KH/s" 179 | fi 180 | ;; 181 | "uzi-miner") 182 | ns="$(nl "Solution")" 183 | nh="$(nhashes)" 184 | echo -e " Threads : ${col}$NTHREADS${NONE}" 185 | echo -e " Pool IP : ${Y}$POOL_IP${NONE}" 186 | found "Share" "Solution" 187 | if [ -n "$SHARE_EASINESS" ] && [ -n "$nh" ]; then 188 | local sp=$(echo "scale=3 ; $(nhashes) / $SHARE_EASINESS" | bc) 189 | local hr=$(echo "scale=3 ; $ns * $sp / (600)" | bc | \ 190 | awk '{printf "%01.3f" ,$1}') 191 | echo -e " Hashrate : ${col}$hr${NONE} H/s" 192 | fi 193 | ;; 194 | -*) 195 | _unknown_option "$1" 196 | exit 1 197 | ;; 198 | *) 199 | esac 200 | } 201 | -------------------------------------------------------------------------------- /ziesha-common.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # shellcheck disable=1090,1091,2015,2034,2059 3 | # 4 | # Common functions to use in other installation scripts. 5 | # 6 | # 7 | 8 | # PATHS 9 | PROFILE=$HOME/.profile 10 | 11 | # COLOR CODES 12 | # ------------------------------------------------------------- 13 | NONE="\033[0m" # unsets color to term's fg color 14 | 15 | # regular colors 16 | K="\033[0;30m" # black 17 | R="\033[0;31m" # red 18 | G="\033[0;32m" # green 19 | Y="\033[0;33m" # yellow 20 | B="\033[0;34m" # blue 21 | M="\033[0;35m" # magenta 22 | C="\033[0;49;96m" # cyan 23 | W="\033[0;37m" # white 24 | 25 | # emphasized (bolded) colors 26 | EK="\033[1;30m" 27 | ER="\033[1;31m" 28 | EG="\033[1;32m" 29 | EY="\033[1;33m" 30 | EB="\033[1;34m" 31 | EM="\033[1;35m" 32 | EC="\033[1;49;96m" 33 | EW="\033[1;37m" 34 | 35 | # background colors 36 | BGK="\033[40m" 37 | BGR="\033[41m" 38 | BGG="\033[42m" 39 | BGY="\033[43m" 40 | BGB="\033[44m" 41 | BGM="\033[45m" 42 | BGC="\033[46m" 43 | BGW="\033[47m" 44 | 45 | # UNICODE CODES 46 | # ------------------------------------------------------------- 47 | CHECK='\U02714'; WARN='\U026A1'; CROSS='\U274c'; NOTE='\U1F4D3' 48 | PACK='\U1F4E6' 49 | # ------------------------------------------------------------- 50 | # FUNCTIONS: 51 | col () { echo -ne "$1"; shift; echo -ne "$@"; echo -ne "${NONE}"; } 52 | red () { col "$R" "$@"; } 53 | grn () { col "$G" "$@"; } 54 | ylw () { col "$Y" "$@"; } 55 | blu () { col "$B" "$@"; } 56 | mgt () { col "$M" "$@"; } 57 | cyn () { col "$C" "$@"; } 58 | wht () { col "$W" "$@"; } 59 | 60 | msg_info () { grn "$CHECK $*"; } 61 | msg_warn () { ylw "$WARN $*"; } 62 | msg_err () { red "$CROSS $*"; } 63 | msg_note () { wht "$NOTE $*"; } 64 | 65 | rep () { eval "printf -- '${1:-'-'}%.0s' {1.."${2:-65}"}"; } 66 | line () { col ${2:-$M} $(rep ${1:-'-'}); } 67 | line1 () { line; } 68 | line2 () { line '=' ${1:-$M}; } 69 | 70 | # Check if current user has sudo access 71 | is_sudo () { groups | grep -q sudo; } 72 | 73 | # Check if $1 contains $2 74 | contains () { [[ $1 =~ (^|[[:space:]])"$2"($|[[:space:]]) ]]; } 75 | 76 | # Return file path if exist 77 | get_file_if_exist () { [ -f "$1" ] && echo "$1"; } 78 | 79 | # Return public IP address 80 | get_ip () { echo $(curl -s -4 ifconfig.co); } 81 | 82 | # If set up, return IP6 address from inet6 83 | get_ip6 () { ip addr | grep inet6 | grep "scope global" | awk '{$1=$1};1' | \ 84 | awk '{print $2}' | awk -F'/' '{print $1}'; } 85 | 86 | # Return OS name 87 | get_os () { 88 | local un=$(uname | awk '{print tolower($0)}') 89 | [ "$un" = "darwin" ] && echo 'macos' || echo $un 90 | } 91 | 92 | # Return architecture name 93 | get_arch () { 94 | local arc=$(arch) 95 | [ "$arc" = "aarch64" ] && echo 'arm64' || \ 96 | ([ "$arc" = "x86_64" ] && echo 'amd64' || echo $arc) 97 | } 98 | 99 | # Return joined OS and architecture names 100 | get_os_arch () { 101 | local un=$(get_os) 102 | local arc=$(get_arch) 103 | [[ $un == 'linux' && $arc == 'amd64' ]] && echo $un || echo $un'_'$arc 104 | } 105 | 106 | # A modified lsb_release wrapper. 107 | lsb_releasef () { 108 | echo "$(lsb_release "$1" | \ 109 | awk 'BEGIN{FS=":"} {print $2}' | \ 110 | awk '{$1=$1};1')" 111 | } 112 | 113 | # Return name of linux distribution 114 | get_linux_dist () { 115 | [ "$(get_os)" = "linux" ] && echo "$(lsb_releasef -i)" || echo "$(get_os)" 116 | } 117 | 118 | # Return version if dist is Ubuntu 119 | get_ubuntu_ver () { 120 | [ "$(get_linux_dist)" = "Ubuntu" ] && echo "$(lsb_releasef -r)" 121 | } 122 | 123 | # String to lowercase 124 | tolower () { echo "$1" | awk '{print tolower($0)}'; } 125 | 126 | # String to uppercase 127 | toupper () { echo "$1" | awk '{print toupper($0)}'; } 128 | 129 | # Add a text to a specified file 130 | a2f () { 131 | local exp=$1; local f=$2 132 | local exist; exist=$(grep "$exp" "$f") 133 | [ -z "$exist" ] && echo -e "$exp" >> "$f" 134 | source "$f" 135 | } 136 | 137 | # Remove text from specified file 138 | rff () { 139 | grep -q "^$1*" "$2" && 140 | grep -v "^$1*" "$2" > "$2.tmp" && 141 | mv "$2.tmp" "$2" 142 | } 143 | 144 | # Add a text to bash profile file if it does not exist 145 | # Default text is $HOME/.local/bin 146 | a2p () { a2f ${1:-'PATH="$HOME/.local/bin:$PATH"'} "$PROFILE"; } 147 | 148 | # Remove variable from bash profile file 149 | rfp () { rff "export $1" "$PROFILE"; } 150 | 151 | # Get a password from $USER 152 | get_pass () { 153 | local pass= 154 | local prompt=${1:-"Enter a password: "} 155 | stty -echo 156 | while [ -z "${pass}" ]; do 157 | echo -e "" 158 | read -p "$prompt" pass 159 | done 160 | stty echo 161 | echo "$pass" 162 | } 163 | 164 | # Ask yes/no question. 165 | # Args: 166 | # $1: Question prompt 167 | is_yes () { 168 | prompt=${1:-""} 169 | default=${2:-"n"} 170 | prompt+=$([ "$default" == "y" ] && echo " ([y]/n) " || echo " (y/[n]) ") 171 | while true; do 172 | read -p "$prompt" yn 173 | yn=${yn:-n} 174 | case $yn in 175 | [yY] ) break;; 176 | [nN] ) break;; 177 | * ) echo [y]es or [n]o?; 178 | esac 179 | done 180 | [ "$yn" = "y" ] 181 | } 182 | 183 | # Check a package is already installed or not 184 | # Args: 185 | # $1: Name of package 186 | is_pkg_exist () { 187 | local dist=$(get_linux_dist) 188 | if [ "$dist" == "Ubuntu" ]; then 189 | [ -z "$(dpkg -l | grep "$1")" ] 190 | elif [ "$dist" == "macos" ]; then 191 | if [ -f "$(which port)" ]; then 192 | ret=$(port installed "$1") 193 | [ "$ret" != "None of the specified ports are installed." ] 194 | fi 195 | fi 196 | } 197 | 198 | # Check package(s) need to install 199 | # $1: Name of packages to install 200 | to_install () { 201 | local to_install= 202 | for p in $1 203 | do 204 | if is_pkg_exist "$p"; then 205 | to_install+=" $p" 206 | fi 207 | 208 | done 209 | echo "$to_install" 210 | } 211 | 212 | # Multiple Install function 213 | # Currently only supports Ubuntu/debian and Macports 214 | # 215 | # Args: 216 | # $1: Name of packages to install 217 | install_pkg () { 218 | local dist=$(get_linux_dist) 219 | if [ "$dist" == "Ubuntu" ]; then 220 | sudo apt update > /dev/null 2>&1 221 | sudo apt install "$1" -y > /dev/null 2>&1 222 | elif [ "$dist" == "macos" ]; then 223 | if [ -f "$(which port)" ]; then 224 | sudo port install "$1" > /dev/null 2>&1 225 | fi 226 | else 227 | col "$BGR" "Installing dependencies on $dist is not supported." 228 | col "$BGR" "You need to make sure install dependencies manually." 229 | fi 230 | } 231 | 232 | # Install given packages if not installed 233 | # Currently only supports Ubuntu and Macports 234 | # 235 | # Args: 236 | # $1: Name of packages to install 237 | # $2: Installing Message Text 238 | # Default: "Installing dependencies" 239 | # $3: End of Installing Message Text 240 | # Default: "Dependencies installed" 241 | install () { 242 | local to_install=$(to_install "$1") 243 | local header="${2:-"Installing dependencies"}" 244 | local footer="${3:-"Dependencies installed"}" 245 | local installed=false 246 | if test -n "$to_install"; then 247 | if ! is_sudo; then 248 | msg_warn "You don't have sudo priviliges."; echo 249 | ylw " Install required packages manually:"; echo 250 | col "$EW" " sudo apt install$to_install"; echo 251 | return; 252 | fi 253 | installed=true 254 | ylw "$header"; echo -e '' 255 | install_pkg "$to_install" 256 | fi 257 | [ "$installed" = true ] && ylw "$footer" 258 | } 259 | 260 | # Install given packages if not installed. 261 | # Currently only supports Ubuntu and Macports. 262 | # Created for pre-dependencies. 263 | # 264 | # Args: 265 | # $1: Name of packages to install 266 | install_pre_deps () { 267 | install "$1" \ 268 | "Installing pre-dependencies to run the script..." \ 269 | "Pre-dependencies installed" 270 | } 271 | 272 | # Save embedded content in script files 273 | # Args: 274 | # $1: Starting pattern of variables 275 | save_embedded_content () { 276 | pattern=${1:-script} 277 | echo -e ${YLW}'Generating '$pattern's...'${NC} 278 | vars="$(set | grep "^"$pattern"\_" | grep -v '_file' | 279 | awk -F= '{print $1}' | uniq)" 280 | pat="^# Path:" 281 | for v in $vars 282 | do 283 | content=$(eval echo \"\${$v}\") 284 | file_path=$(echo "$content" | grep "$pat" | awk '{print $3}') 285 | dir_path="$(dirname "${file_path}")" 286 | mkdir -p "$dir_path" 287 | content=$(echo "$content" | grep -v "$pat") 288 | sd= 289 | if [[ $file_path != $HOME* ]]; then 290 | sd="sudo" 291 | fi 292 | if test -n "$file_path"; then 293 | eval 'echo "$content" | '$sd' tee $file_path > /dev/null' 294 | if [[ "$content" == "#!"* ]]; then 295 | eval $sd' chmod +x "$file_path"' 296 | fi 297 | echo -e ${YLW}' '${CHK}' '$file_path${NC} 298 | fi 299 | done 300 | } 301 | 302 | get_emb_cont_var_names () { 303 | pattern=${1:-script} 304 | vars="$(set | grep "^"$pattern"\_" | grep -v '_file' | 305 | awk -F= '{print $1}' | uniq)" 306 | echo "$vars" 307 | } 308 | 309 | get_emb_cont_file_paths () { 310 | pattern=${1:-script} 311 | vars="$(get_emb_cont_var_names "$pattern")" 312 | pat="^# Path:" 313 | paths= 314 | for v in $vars 315 | do 316 | content=$(eval echo \"\${$v}\") 317 | paths+=$(echo "$content" | grep "$pat" | awk '{print $3}')" " 318 | done 319 | echo $paths 320 | } 321 | -------------------------------------------------------------------------------- /ziesha-usage.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # 3 | # Usage printing functions for Ziesha Helper 4 | # 5 | # 6 | 7 | DESCRIPTION="DESCRIPTION:" 8 | OPTIONS="OPTIONS:" 9 | COMMANDS="COMMANDS:" 10 | USAGE="USAGE EXAMPLES:" 11 | 12 | # Print version 13 | function _version () { 14 | cat< "$file" 150 | else 151 | ret=$(grep -i "^version = " "$file") 152 | fi 153 | else 154 | ret=$(remote "$a" | grep -i "^version = ") 155 | echo "$ret" > "$file" 156 | fi 157 | fi 158 | echo "$ret" | tail -n 1 | awk '{print $NF}' | tr -d '"' 159 | } 160 | VERSION=$(version local ziesha) 161 | 162 | # Get/search binary path 163 | get_bin_loc () { which "${1:-bazuka}"; } 164 | 165 | # Check if app is installed 166 | is_installed () { [[ -n "$(get_bin_loc "${1:-bazuka}")" ]]; } 167 | 168 | # Get installed tools 169 | get_installed_tools () { 170 | local ret= 171 | for a in $APPS; do is_installed "$a" && ret+=" $a"; done; 172 | echo "$ret" 173 | } 174 | 175 | # Check if rust is installed 176 | rust_is_installed () { is_installed "cargo"; } 177 | 178 | # Check if rust is installed and exit if it it is not. 179 | check_rust_installed () { 180 | if ! rust_is_installed; then 181 | msg_err "Rust is not installed. Run 'ziesha install rust'."; echo 182 | exit 0 183 | fi 184 | } 185 | 186 | # Install dependencies 187 | install_deps () { 188 | local pkgs="cmake build-essential libssl-dev ocl-icd-opencl-dev" 189 | install "$pkgs" "Installing dependencies" "Dependencies installed" 190 | } 191 | 192 | # Install Rust 193 | install_rust () { 194 | if ! is_installed "$a"; then 195 | msg_warn "Installing Rust..."; echo -e '' 196 | bash <(curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs) -y 197 | else 198 | msg_info "Rust is ready." 199 | fi 200 | } 201 | 202 | # Check variable if it is a Ziesha tool or not 203 | # if so, run specified function 204 | check_a () { 205 | local func=$1; shift 206 | local a=${@:-bazuka} 207 | [ "$a" = "all" ] && a=$APPS 208 | if [[ "$a" = *" "* ]]; then 209 | for i in $a; do 210 | ! contains "$APPS" "$i" && 211 | { msg_err "$i is not a Ziesha tool. ('$APPS')"; return 1; } 212 | $func "$i" 213 | done 214 | return 0 215 | else 216 | ! contains "$APPS" "$a" && 217 | { msg_err "$a is not a Ziesha tool. ('$APPS')"; return 0; } 218 | fi 219 | return 1 220 | } 221 | 222 | # Install/update ziesha-helper 223 | install_me () { 224 | loginctl enable-linger "$USER" 225 | install_deps 226 | mkdir -p "$HOME/.local/bin" && a2p 227 | mkdir -p "$ZIESHA_HELPER_PATH" && { 228 | for f in ziesha-helper.sh ziesha-common.sh ziesha-usage.sh \ 229 | ziesha-service.sh ziesha-summary.sh VERSION AUTHOR; do 230 | curl -s -o "$ZIESHA_HELPER_PATH/$f" "$ZIESHA_URL/$f" 231 | done 232 | curl -s -o "$HOME/.local/bin/ziesha" "$ZIESHA_URL/ziesha" 233 | chmod +x "$HOME/.local/bin/ziesha" 234 | } 235 | } 236 | 237 | # Install given Ziesha app 238 | install_app () { 239 | local a=$* 240 | if [ -z "$a" ]; then 241 | is_yes "Are you sure to install all Ziesha tools?" && a="all" || return 0 242 | fi 243 | if [ "$a" = "rust" ]; then 244 | rust_is_installed && msg_warn "$a is already installed." || install_rust 245 | echo -e '' 246 | return 247 | fi 248 | if [ "$a" = "me" ]; then 249 | install_me 250 | return 251 | fi 252 | check_rust_installed 253 | if ! check_a install_app "$a"; then 254 | if ! is_installed "$a"; then 255 | source "$CARGO_ENV" 256 | if [ -d "$ZIESHA_PATH/$a" ]; then 257 | msg_warn "$a is exist. Try to update!" 258 | fi 259 | mkdir -p "$ZIESHA_PATH" && cd "$ZIESHA_PATH" || return 260 | msg_warn "Building $a..."; echo -e '' 261 | git clone "$(printf $GITURL "$a")" >> "$LOG_FILE" 2>&1 262 | cd "$a" && cargo update >> "$LOG_FILE" 2>&1 263 | cargo install --path . >> "$LOG_FILE" 2>&1 264 | cd "$HOME" || return 265 | msg_info "$a installed to '$ZIESHA_PATH/$a'" 266 | else 267 | msg_warn "$a is already installed." 268 | fi 269 | fi 270 | echo -e '' 271 | } 272 | 273 | # check update is needed for a tool 274 | need_update () { [ "$(version local "$1")" != "$(version remote "$1")" ]; } 275 | 276 | # Update given Ziesha app or rust 277 | update_app () { 278 | local vc; local vr; 279 | local a=${*:-bazuka} 280 | [ "$a" = "me" ] && { install_me; return; } 281 | [ "$a" = "rust" ] && { rustup self update; return; } 282 | check_rust_installed 283 | if ! check_a update_app "$a"; then 284 | if is_installed "$a"; then 285 | now=$(date) 286 | if need_update "$a"; then 287 | cd "$ZIESHA_PATH/$a" || return 288 | vc="$(version local "$a")" 289 | vl="$(version remote "$a")" 290 | msg_warn "Updating $a $vc to $vr" 291 | git pull origin >> "$LOG_FILE" 2>&1 292 | source "$CARGO_ENV" 293 | cargo update >> "$LOG_FILE" 2>&1 294 | cargo install --path . >> "$LOG_FILE" 2>&1 295 | cd "$HOME" || return 296 | msg_info "$a was updated to v$(version local "$a")." 297 | echo "$now: $a was updated to v$(version local "$a")." >> "$HOME/.ziesha-update.log" 298 | if service_is_active "$a"; then 299 | service "restart" "$a" 300 | fi 301 | else 302 | msg_warn "$a is up-to-date." 303 | echo "$now: $a is up-to-date." >> "$HOME/.ziesha-update.log" 304 | fi 305 | else 306 | msg_err "$a is NOT installed." 307 | fi 308 | echo -e '' 309 | fi 310 | } 311 | 312 | # Remove Ziesha-helper from system 313 | remove_me () { 314 | msg_warn "This operation will stop running services\n and remove Ziesha-helper."; echo 315 | if is_yes "Are you sure to remove Ziesha-helper?"; then 316 | for s in $(get_running_services); do 317 | service_is_active "$s" && service disable "$s" 318 | done 319 | [ -f "$SYSTEMD_PATH/ziesha@.service" ] && rm "$SYSTEMD_PATH/ziesha@.service" 320 | for f in ziesha-helper.sh ziesha-common.sh ziesha-usage.sh \ 321 | VERSION AUTHOR; do 322 | rm "$ZIESHA_HELPER_PATH/$f" 323 | done 324 | [ ! "$(ls -A "$ZIESHA_HELPER_PATH")" ] && rm -rf "$ZIESHA_HELPER_PATH" 325 | # rm -rf "$ZIESHA_HELPER_PATH" 326 | rm "$HOME/.local/bin/ziesha" 327 | msg_info "Ziesha removed from your system! :("; echo 328 | fi 329 | } 330 | 331 | # Remove/uninstall given Ziesha app or rust 332 | remove_app () { 333 | local a=${@:-bazuka} 334 | if [ "$a" = "rust" ]; then 335 | if is_yes "Are you sure to remove rust?"; then 336 | rustup self uninstall -y 337 | msg_info "$a removed from your system :("; echo 338 | return 339 | fi 340 | fi 341 | if [ "$a" = "me" ]; then 342 | remove_me; return 343 | fi 344 | check_a remove_app "$a" 345 | if is_installed "$a"; then 346 | service_is_active "$a" && service disable "$a" 347 | rm "$(get_bin_loc "$a")" 348 | rm -rf "${ZIESHA_PATH:?}/$a" 349 | if [ "$a" = "bazuka" ]; then 350 | rm -rf "$HOME/.bazuka" >> "$LOG_FILE" 2>&1 351 | rm "$HOME/.bazuka.yaml" >> "$LOG_FILE" 2>&1 352 | rm "$HOME/.bazuka-wallet" >> "$LOG_FILE" 2>&1 353 | fi 354 | msg_info "$a removed from your system :(" 355 | else 356 | msg_err "$a is NOT installed." 357 | fi 358 | echo -e '' 359 | } 360 | 361 | # Show log of selected tool 362 | show_log () { 363 | local color=true 364 | local nlines=30 365 | local short=true 366 | local timestamp=false 367 | local a=${1:-bazuka}; shift 368 | ! contains "$APPS" "$a" && 369 | { msg_err "$a is not a Ziesha tool. ('$APPS')"; echo -e ''; exit 1; } 370 | 371 | if ([ "$a" = "auto-update" ] || is_installed "$a"); then 372 | while [[ $# -gt 0 ]]; do 373 | case $1 in 374 | -n|--nlines) 375 | shift 376 | nlines=$1 377 | shift 378 | ;; 379 | -c|--no-color) 380 | color=false 381 | shift 382 | ;; 383 | -s|--short) 384 | short=false 385 | shift 386 | ;; 387 | -t|--timestamp) 388 | timestamp=true 389 | shift 390 | ;; 391 | *) 392 | _unknown_option "$1"; exit 1 ;; 393 | esac 394 | done 395 | # cmd="journalctl -q -f -o short-iso-precise -n \"$nlines\" _COMM=\"$a\"" 396 | cmd="journalctl -q -f -o short-iso-precise -n \"$nlines\" --user-unit=ziesha@$a" 397 | # echo "$cmd" 398 | cmd+=" | stdbuf -oL cut --complement -d' ' -f2,3" 399 | cmd+=" | sed -u 's/\(:[0-9][0-9]\)\.[0-9]\{6\}/\1/g'" 400 | cmd+=" | sed -u 's/\+0000//'" 401 | if [[ "$a" == "bazuka" ]]; then 402 | if [[ "${short}" == "true" ]]; then 403 | cmd+=" | sed -u -e 's/Height/H/' -e 's/Outdated states/ODs/'" 404 | cmd+=" -e 's/Timestamp/TS/' -e 's/Active nodes/AcN/'" 405 | cmd+=" -e 's/Chain Pool/CHp/' -e 's/MPN Pool/MPNp/'" 406 | fi 407 | elif [[ "$a" == "uzi-pool" ]]; then 408 | cmd+="| sed -ur 's/[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{5} \+[0-9]{2}:[0-9]{2} -> //g'" 409 | fi 410 | [[ "${color}" == "true" && $(which ccze) ]] && cmd+=" | ccze -Ar" 411 | if [[ "${timestamp}" == "true" ]]; then 412 | cmd+=' | sed -u '\''s/^/echo "/; s/\([0-9]\{10\}\)/$(date +"%Y-%m-%dT%T" -ud @\1)/; s/$/"/'\'' | bash' 413 | fi 414 | # echo "$cmd" 415 | eval "$cmd" 416 | else 417 | msg_err "$a is NOT installed." 418 | fi 419 | echo -e '' 420 | } 421 | 422 | # Set variable in .profile or .bazuka.yaml 423 | set_var () { 424 | declare -A vars 425 | tool=() 426 | while [[ $# -gt 0 ]]; do 427 | case $1 in 428 | -d|--discord-handle) 429 | local k=$1; shift 430 | if [ -z "$1" ]; then 431 | msg_err "You have to give a value for $k" 432 | exit 1 433 | fi 434 | if ! [[ "$1" =~ ^.{3,32}#[0-9]{4}$ ]]; then 435 | msg_err "Wrong discord handle 'pentafenolin#9413'" 436 | exit 1 437 | fi 438 | vars["DISCORD_HANDLE"]="$1" 439 | tool+=(bazuka) 440 | shift 441 | ;; 442 | -z|--zoro-seed) 443 | local k=$1; shift 444 | if [ -z "$1" ]; then 445 | msg_err "You have to give a value for $k" 446 | exit 1 447 | fi 448 | vars["ZORO_SEED"]="$1" 449 | tool+=(zoro) 450 | shift 451 | ;; 452 | -t|--update-dat) 453 | local k=$1; shift 454 | [[ -z "$1" ]] && v="$UPDATE_DAT" || v=$1 455 | vars["UPDATE_DAT"]="$v" 456 | tool+=(zoro) 457 | shift 458 | ;; 459 | -p|--deposit-dat) 460 | local k=$1; shift 461 | [[ -z "$1" ]] && v="$DEPOSIT_DAT" || v=$1 462 | vars["DEPOSIT_DAT"]="$v" 463 | tool+=(zoro) 464 | shift 465 | ;; 466 | -w|--withdraw-dat) 467 | local k=$1; shift 468 | [[ -z "$1" ]] && v="$WITHDRAW_DAT" || v=$1 469 | vars["WITHDRAW_DAT"]="$v" 470 | tool+=(zoro) 471 | shift 472 | ;; 473 | -c|--share-capacity) 474 | local k=$1; shift 475 | [[ -z "$1" ]] && v="$SHARE_CAPACITY" || v=$1 476 | vars["SHARE_CAPACITY"]="$v" 477 | tool+=(uzi-pool) 478 | shift 479 | ;; 480 | -e|--share-easiness) 481 | local k=$1; shift 482 | [[ -z "$1" ]] && v="$SHARE_EASINESS" || v=$1 483 | vars["SHARE_EASINESS"]="$v" 484 | tool+=(uzi-pool) 485 | shift 486 | ;; 487 | -o|--reward-ratio) 488 | local k=$1; shift 489 | [[ -z "$1" ]] && v="$REWARD_RATIO" || v=$1 490 | vars["REWARD_RATIO"]="$v" 491 | tool+=(uzi-pool) 492 | shift 493 | ;; 494 | -y|--reward-delay) 495 | [[ -z "$1" ]] && v="$REWARD_DELAY" || v=$1 496 | vars["REWARD_DELAY"]="$v" 497 | tool+=(uzi-pool) 498 | shift 499 | ;; 500 | -n|--network) 501 | local k=$1; shift 502 | if [ -z "$1" ]; then 503 | msg_err "You have to give a value for $k" 504 | exit 1 505 | fi 506 | vars["NETWORK"]="$1" 507 | tool+=(bazuka) 508 | shift 509 | ;; 510 | -i|--pool-ip) 511 | local k=$1; shift 512 | if [ -z "$1" ]; then 513 | msg_err "You have to give a value for $k" 514 | exit 1 515 | fi 516 | vars["POOL_IP"]="$1" 517 | tool+=(uzi-miner) 518 | shift 519 | ;; 520 | -k|--pool-token) 521 | local k=$1; shift 522 | if [ -z "$1" ]; then 523 | msg_err "You have to give a value for $k" 524 | exit 1 525 | fi 526 | vars["POOL_TOKEN"]="$1" 527 | tool+=(uzi-miner) 528 | shift 529 | ;; 530 | -m|--nthreads) 531 | local k=$1; shift 532 | if [ -z "$1" ]; then 533 | msg_err "You have to give a value for $k" 534 | exit 1 535 | fi 536 | vars["NTHREADS"]="$1" 537 | tool+=(uzi-miner) 538 | shift 539 | ;; 540 | *) 541 | _unknown_option "$1" 542 | exit 1 543 | ;; 544 | esac 545 | done 546 | for k in "${!vars[@]}"; do 547 | [ "$k" = "NETWORK" ] && 548 | sed -i "s/network:.*/network: ${vars[$k]}/g" "$HOME/.bazuka.yaml" || 549 | { a2set "$k" "${vars[$k]}"; } 550 | msg_info "$k is set to ${vars[$k]}"; echo -e '' 551 | done 552 | source "$ZIESHA_SETTINGS" 553 | tool=( "$(printf "%s\n" "${tool[@]}" | sort | uniq)" ) 554 | for t in "${tool[@]}"; do 555 | msg_warn "$(printf "You must restart %s for the changes to take effect." "$t")" 556 | echo -e '' 557 | done 558 | } 559 | 560 | # Get variable from .profile 561 | get_var () { 562 | local k; k=$(toupper "$1" | tr - _) 563 | if [ "$k" = "NETWORK" ]; then 564 | v=$(grep "network" "$HOME/.bazuka.yaml") 565 | v="${v##*: }" 566 | else 567 | [ -z ${k+x} ] && v="NOT SET" || v="${!k}" 568 | fi 569 | echo "\"$v\"" 570 | } 571 | 572 | # Set-up initialization parameters for bazuka. 573 | init_bazuka () { 574 | if is_installed "bazuka"; then 575 | local rem="$@" 576 | rem+=" $BOOTSTRAP" 577 | $(get_bin_loc bazuka) init "$@" 578 | else 579 | msg_err "bazuka is NOT installed."; echo -e '' 580 | fi 581 | } 582 | 583 | # Reset bazuka initialization parameters and wallet. 584 | reset_bazuka () { 585 | case $1 in 586 | bazuka) 587 | rm -f "$HOME/.bazuka.yaml" 588 | msg_info "Bazuka was reset. Run 'bazuka init PARAMS'" 589 | ;; 590 | wallet) 591 | rm -f "$HOME/.bazuka-wallet" 592 | msg_info "Wallet was reset. Run 'bazuka init PARAMS'" 593 | ;; 594 | db) 595 | rm -rf "$HOME/.bazuka" 596 | msg_info "Bazuka database was reset.Run 'ziesha restart bazuka'" 597 | ;; 598 | all) 599 | rm -f "$HOME/.bazuka.yaml" 600 | rm -f "$HOME/.bazuka-wallet" 601 | rm -rf "$HOME/.bazuka" 602 | msg_info "Bazuka, wallet and database were reset. " \ 603 | "Run 'bazuka init PARAMS' and 'ziesha restart bazuka'" 604 | ;; 605 | *) 606 | _unknown_option "$1" 607 | exit 1 608 | ;; 609 | esac 610 | echo -e '' 611 | } 612 | 613 | # Run given Ziesha app 614 | run () { 615 | local bin 616 | local installed_apps 617 | local a=${1:-bazuka}; shift 618 | # APPS+=" auto-update" 619 | if [ "$a" != "auto-update" ]; then 620 | if ! contains "$APPS" "$a"; then 621 | msg_err "$a is not a Ziesha tool. ('$APPS')"; echo -e '' 622 | exit 1 623 | fi 624 | local rem="$*" 625 | if ! is_installed "$a"; then 626 | msg_err "$a is NOT installed. Run 'ziesha install $a'."; echo -e '' 627 | exit 0 628 | fi 629 | # shellcheck source=$HOME/.cargo/env 630 | source "$CARGO_ENV" 631 | bin=$(get_bin_loc "$a") 632 | fi 633 | case $a in 634 | "bazuka") 635 | [[ -z "$DISCORD_HANDLE" ]] && { msg_err "discord-handle " \ 636 | "is not set. Run 'ziesha set discord-handle MYHANDLE'"; exit 0; } 637 | { ret="$( { $bin node start --discord-handle "$DISCORD_HANDLE"; } 2>&1 1>&3 3>&- )"; } 3>&1; 638 | echo "RUST_BACKTRACE: $RUST_BACKTRACE" 639 | echo "$HOME" 640 | if echo "$ret" | grep -q "LOCK: Resource temporarily unavailable"; then 641 | ylw "------------------------------"; echo -e "" 642 | msg_info "bazuka is already running..." 643 | echo -e "" 644 | exit 0 645 | elif echo "$ret" | grep -q "Bazuka is not initialized!"; then 646 | ylw "------------------------------"; echo -e "" 647 | msg_info "Bazuka is not initialized." 648 | echo -e "" 649 | exit 0 650 | else 651 | echo "ERROR:" 652 | echo "$ret" 653 | fi 654 | ;; 655 | "zoro") 656 | [[ -z "$ZORO_SEED" ]] && { msg_err "zoro-seed is not set" \ 657 | "Run 'ziesha set zoro-seed MYSEED'"; exit 0; } 658 | $bin start --node 127.0.0.1:8765 --seed "$ZORO_SEED" \ 659 | --update-circuit-params "$UPDATE_DAT" \ 660 | --deposit-circuit-params "$DEPOSIT_DAT" \ 661 | --withdraw-circuit-params "$WITHDRAW_DAT" \ 662 | --db "$DB_PATH" --gpu 663 | ;; 664 | "uzi-pool") 665 | $bin --node 127.0.0.1:8765 --share-capacity $SHARE_CAPACITY \ 666 | --share-easiness $SHARE_EASINESS \ 667 | --owner-reward-ratio $REWARD_RATIO --reward-delay $REWARD_DELAY 668 | ;; 669 | "uzi-miner") 670 | [[ -z "$POOL_TOKEN" ]] && { msg_err "pool-token is not set" \ 671 | "Run 'ziesha set --pool-token MYPOOLTOKEN'"; exit 0; } 672 | ylw "\U25AA Pool IP : $POOL_IP"; echo 673 | grn "\U25AA Pool token : $POOL_TOKEN"; echo 674 | red "\U25AA Number of threads : $NTHREADS"; echo 675 | line2; echo 676 | $bin --pool --node "$POOL_IP:8766" --miner-token "$POOL_TOKEN" \ 677 | --threads "$NTHREADS" 678 | ;; 679 | "auto-update") 680 | msg_info "Auto-update is started."; echo 681 | while true; do 682 | installed_apps=$(get_installed_tools) 683 | update_app "$installed_apps" 684 | sleep $UPDATE_INTERVAL 685 | done 686 | echo "Auto-update is stopped." 687 | ;; 688 | -*) 689 | _unknown_option "$1" 690 | exit 1 691 | ;; 692 | *) 693 | esac 694 | echo -e '' 695 | } 696 | 697 | # Download zoro dat files 698 | download () { 699 | local file= 700 | local a=${1:-all} 701 | case "$a" in 702 | update-dat) 703 | file=$UPDATE_DAT 704 | url="https://api.rues.info/update.dat" ;; 705 | deposit-dat) 706 | file=$DEPOSIT_DAT 707 | url="https://api.rues.info/deposit.dat" ;; 708 | withdraw-dat) 709 | file=$WITHDRAW_DAT 710 | url="https://api.rues.info/withdraw.dat" ;; 711 | all) 712 | ylw "This process may take a long time."; echo 713 | ylw "Are you sure to download all dat files?" 714 | ! is_yes && return 0 715 | download update-dat 716 | download deposit-dat 717 | download withdraw-dat 718 | ;; 719 | *) 720 | _unknown_option "$1"; exit 1 ;; 721 | esac 722 | mkdir -p "$ZORO_PATH" && cd "$ZORO_PATH" || return 723 | curl -o "$file" "$url" 724 | } 725 | 726 | list () { 727 | local t; t=$(get_installed_tools) 728 | for i in $t; do 729 | vl=$(version local "$i") 730 | msg_info "$i v$vl" 731 | service_is_active "$i" && { echo -ne " - "; ylw "Running"; } 732 | echo; 733 | done 734 | } 735 | 736 | # ------------------------------------------------------------- 737 | # MAIN 738 | 739 | function _unknown_option () { echo -n "Unknown option "; red "$1"; echo -e ''; } 740 | 741 | function show_help () { 742 | case $1 in 743 | -h|--help) 744 | _usage_main ;; 745 | log) 746 | _usage_log ;; 747 | set) 748 | _usage_set ;; 749 | get) 750 | _usage_get ;; 751 | init) 752 | _usage_init ;; 753 | download) 754 | _usage_download ;; 755 | run) 756 | _usage_run ;; 757 | reset) 758 | _usage_reset ;; 759 | start|stop|restart) 760 | _usage_service "$1" ;; 761 | status|summary) 762 | _usage_status "$1" ;; 763 | list) 764 | _usage_list ;; 765 | -*) 766 | _unknown_option "$1"; exit 1 ;; 767 | *) 768 | _usage "$1" 769 | esac 770 | } 771 | 772 | cd "$HOME" || exit 1 773 | 774 | OPTS=( "-i|install|install_app" 775 | "-u|update|update_app" 776 | "-r|remove|remove_app" 777 | "-l|log|show_log" 778 | "-s|set|set_var" 779 | "-g|get|get_var" 780 | "|list|list" 781 | "|download|download" 782 | "|init|init_bazuka" 783 | "|run|run" 784 | "|reset|reset_bazuka" 785 | "|start|start" 786 | "|stop|stop" 787 | "|restart|restart" 788 | "|status|status" 789 | "|summary|summary" ) 790 | 791 | 792 | get_func () { 793 | local ret= 794 | if [ -n "$1" ]; then 795 | for opt in "${OPTS[@]}" ; do 796 | short_opt="${opt%%|*}"; rem="${opt#*|}" 797 | long_opt="${rem%%|*}"; rem="${rem#*|}" 798 | func="${rem%%|*}"; rem="${rem#*|}" 799 | if [ "$1" = "$short_opt" ]; then 800 | ret="$func" 801 | break 802 | elif [ "$1" = "$long_opt" ]; then 803 | ret="$func" 804 | break 805 | fi 806 | done 807 | fi 808 | echo "$ret" 809 | } 810 | 811 | get_long_opt () { 812 | local ret= 813 | if [ -n "$1" ]; then 814 | for opt in "${OPTS[@]}" ; do 815 | short_opt="${opt%%|*}"; rem="${opt#*|}" 816 | long_opt="${rem%%|*}"; rem="${rem#*|}" 817 | if [ "$1" = "$short_opt" ]; then 818 | ret="$long_opt" 819 | break 820 | elif [ "$1" = "$long_opt" ]; then 821 | ret="$long_opt" 822 | break 823 | fi 824 | done 825 | fi 826 | echo "$ret" 827 | } 828 | 829 | func= 830 | long_opt="--help" 831 | POSITIONAL_ARGS=() 832 | while [[ $# -gt 0 ]]; do 833 | case $1 in 834 | -v|--version) 835 | _version; exit 0 ;; 836 | -h|--help) 837 | [[ -z ${POSITIONAL_ARGS[*]} ]] && { show_help "$long_opt"; exit 0; } 838 | shift ;; 839 | *) 840 | if [ -z "$func" ]; then 841 | long_opt=$(get_long_opt "$1") 842 | func=$(get_func "$1") 843 | if [ -z "$func" ]; then 844 | _unknown_option "$1" 845 | exit 1 846 | fi 847 | else 848 | POSITIONAL_ARGS+=("$1") 849 | fi 850 | shift ;; 851 | esac 852 | done 853 | 854 | set -- "${POSITIONAL_ARGS[@]}" 855 | [ -n "$func" ] && { $func "${POSITIONAL_ARGS[@]}"; } || 856 | { [[ -z "${1+x}" ]] && { show_help "$long_opt"; exit 0; } } --------------------------------------------------------------------------------