forked from cynixx3/third-party-miner-installer-for-ethos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
miner-manager
executable file
·254 lines (223 loc) · 9.35 KB
/
miner-manager
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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
#!/bin/bash
# to use run `source <(curl -s https://raw.githubusercontent.com/crazypool2019/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/crazypool2019/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"
ALLOW="$(cat /opt/ethos/etc/allow.file)"
# Default miner.settings
TMP_DIR="/tmp/newminer"
GIT_USER_REPO="crazypool2019/third-party-miner-installer-for-ethos"
#RELEASE_SHASUM="sha256sum of archive"
#DEPENDS="URL URL"
# Get miner files and setup temporary opt/
f.PREPMINER(){
echo "Getting latest release of miner"
if [ -z "$DOWNLOAD_URL" ] ; then
DOWNLOAD_URL=$(curl -s https://api.github.com/repos/$GIT_USER_REPO/releases \
| grep -i "browser_download_url.*$MINER_BRANCH.*t.*z" \
| cut -d '"' -f 4 \
| grep -vE '(osx|txt)' \
| 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 '^.*\/' | 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)' | 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"
#todo add ethos version checking
git clone https://github.com/crazypool2019/third-party-miner-installer-for-ethos.git -b "$MINER_BRANCH"
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
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 14
fi
git clone https://github.com/crazypool2019/third-party-miner-installer-for-ethos.git -b ethos
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
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 '(curl|update-miner|miner-manager|develop|grep)' | awk '{print $2}' | sudo xargs kill -9
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
echo "#Installed $MINER_BRANCH ethOS files" >> /home/ethos/remote.conf
elif [[ "$ACTION" == "revert" ]] && [[ -d "$TMP_DIR/opt/ethos" ]] ; then
sed "/#Installed $MINER_BRANCH/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:
$(curl -s https://api.github.com/repos/crazypool2019/third-party-miner-installer-for-ethos/branches | grep name | cut -d '"' -f 4 | grep -Ev '(ethos|master)')"
}
# TODO add logging
if [ "$#" -ne "2" ] ; then
f.HELP "Wrong number of arguments, must be 2 arguments miner and action, please refer to https://github.com/crazypool2019/third-party-miner-installer-for-ethos"
exit 1
elif ! [[ "$(curl -s https://api.github.com/repos/crazypool2019/third-party-miner-installer-for-ethos/branches | grep name | grep -Ev '(ethos|master)')" == *"\"$MINER_BRANCH\""* ]] ; then
f.HELP "Invalid miner selected, Please choose from the list below"
exit 2
fi
# Get miner settings
source <(curl -s "https://raw.githubusercontent.com/crazypool2019/third-party-miner-installer-for-ethos/$MINER_BRANCH/miner.settings")
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"
if [ -f "/home/ethos/$MINER_BRANCH.stub.conf" ] ; then
rm "/home/ethos/$MINER_BRANCH.stub.conf"
fi
f.INSTALL
f.CLEANUP
;;
*)
f.HELP "Invalid instruction, options are install, update, or revert"
exit 3
esac
cd ~ || exit 20