-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathfunctions
More file actions
167 lines (145 loc) · 3.91 KB
/
functions
File metadata and controls
167 lines (145 loc) · 3.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
#!/bin/bash
# functions file for nntools
#
# @author webworker01
#
#31 = red (default)
#32 = green
#33 = yellow
#34 = blue
# @param category string
# @param message string
# @param color (red|green|yellow|blue)
# @param mode (echo|file) echo = echo only, file = logfile only
log()
{
local category=$1
local message=$2
local color=$3
local mode=$4
local datetime=$(date '+%Y-%m-%d %H:%M:%S')
case $color in
red)
colorcode=31
;;
green)
colorcode=32
;;
yellow)
colorcode=33
;;
blue)
colorcode=34
;;
*)
colorcode=32
;;
esac
if [[ $mode != "echo" ]] && [[ ! -z $nntoolslogfile ]]; then
echo "${datetime} [${category}] ${message}" >> $nntoolslogfile
fi
if [[ $mode != "file" ]]; then
printf "\033[0;${colorcode}m${datetime} [${category}] ${message}\033[0m\n"
fi
}
# @return (1|0)
isSapling()
{
local coin=${1^^}
if [[ ! ${sproutcoins[*]} =~ ${coin} ]]; then
echo 1
else
echo 0
fi
}
isValidCoin()
{
local coin=${1^^}
if [[ ! -z $1 ]] && [[ $1 != "KMD" ]]; then
#check it exists in coinlist
if [[ ! " ${coinlist[@]} " =~ " ${1^^} " ]] && [[ ${1^^} != "VRSC" ]]; then
log "isValidCoin" "${1^^} does not exist in coinlist!" "red" "echo"
echo 0
else
echo 1
fi
else
echo
fi
}
timeSince ()
{
local currentimestamp=$(date +%s)
local timecompare=$1
if [ ! -z $timecompare ] && [[ $timecompare != "null" ]]; then
local t=$((currentimestamp-timecompare))
local d=$((t/60/60/24))
local h=$((t/60/60%24))
local m=$((t/60%60))
local s=$((t%60))
if (( d > 0 )); then
echo -n "${d}D"
fi
if (( d < 2 && h > 0 )); then
echo -n "${h}h"
fi
if (( d == 0 && h < 4 && m > 0 )); then
echo -n "${m}m"
fi
if (( d == 0 && h == 0 && m == 0 )); then
echo -n "${s}s"
fi
fi
}
# Setup commonly needed variables for working with a coin daemon
# Pass in the coin name or it will assume kmd
setupCoinVars ()
{
coin=${1^^}
logfrom=${2}
if [[ ! -z $coin ]] && [[ $coin != "KMD" ]]; then
#check it exists in coinlist
if [[ ! " ${coinlist[@]} " =~ " ${coin} " ]] && [[ ! " ${komodolike[@]} " =~ " ${coin} " ]]; then
log $logfrom "${coin} does not exist in coinlist!" "red" "echo"
exit 0
fi
asset=" -ac_name=${coin}"
feepkb=$sctxfeeperkb
datadir=""
coinexec=""
if (( $thirdpartycoins < 1 )); then
searchlist="coinsfirst[@]"
else
searchlist="coinsthird[@]"
fi
#search for alt komodods
altkmd=('kmd' 'zimport')
for coins in "${!searchlist}"; do
searchcoin=($coins)
if [[ "${coin}" == "${searchcoin[0]}" ]] && [[ ${altkmd[*]} =~ ${searchcoin[4]} ]]; then
eval $(echo coinexec=${searchcoin[2]})
datadir="${HOME}/${searchcoin[3]}"
fi
done
coinexec=${coinexec:=$komodod}
datadir=${datadir:="$HOME/.komodo/$coin"}
else
coin="KMD"
asset=""
datadir="$HOME/.komodo"
feepkb=$txfeeperkb
coinexec=$komodod
fi
nntpath="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
if [[ -f "${datadir}/komodod.pid" ]]; then
pidfile="${datadir}/komodod.pid"
processid=$(<${pidfile})
elif [[ -f "${nntpath}/pid/${coin}" ]]; then
pidfile="${nntpath}/pid/${coin}"
processid=$(<${pidfile})
log $logfrom "komodod.pid does not exist, pid=${processid} from ${nntpath}/pid/${coin}!" "red"
else
log $logfrom "no pid files found!" "red"
processid=""
fi
}