forked from Noretreat/smOS-unsupported-miners
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
executable file
·141 lines (127 loc) · 5.38 KB
/
install.sh
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
#!/bin/bash
# =======================================================================================
# Run as root
# =======================================================================================
if [ "$(id -nu)" != "root" ]; then
sudo -k
PASSWORD=$(whiptail --backtitle "$PROJECT_NAME Masternode Installer" --title "Authentication required" --passwordbox "Installing $PROJECT_NAME requires root privilege. Please authenticate to begin the installation.\n\n[sudo] Password for user $USER:" 12 50 )
exec sudo -E -S -p '' "$0" "$@" <<< "$PASSWORD"
exit 1
fi
# ---------------------------------------------------------------------------------------
# =======================================================================================
# Helper functions
# =======================================================================================
# infobox TEXT
infobox() {
BASE_LINES=10
WT_HEIGHT=$(echo -e "$@" | wc -l)
(( WT_HEIGHT=WT_HEIGHT+BASE_LINES ))
WT_WIDTH=78
WT_SIZE="$WT_HEIGHT $WT_WIDTH"
TERM=ansi whiptail \
--infobox "$@" \
--backtitle "$WT_BACKTITLE" \
--title "$WT_TITLE" \
$WT_SIZE
}
# msgbox TEXT
msgbox() {
BASE_LINES=10
WT_HEIGHT=$(echo -e "$@" | wc -l)
(( WT_HEIGHT=WT_HEIGHT+BASE_LINES ))
WT_WIDTH=78
WT_SIZE="$WT_HEIGHT $WT_WIDTH"
TERM=ansi whiptail \
--msgbox "$@" \
--backtitle "$WT_BACKTITLE" \
--title "$WT_TITLE" \
$WT_SIZE
}
# inputbox "TEXT" "DEFAULT"
inputbox() {
BASE_LINES=10
WT_HEIGHT=$(echo -e "$@" | wc -l)
(( WT_HEIGHT=WT_HEIGHT+BASE_LINES ))
WT_WIDTH=78
WT_SIZE="$WT_HEIGHT $WT_WIDTH"
TERM=ansi whiptail \
--inputbox "$1" \
--backtitle "$WT_BACKTITLE" \
--title "$WT_TITLE" \
3>&1 1>&2 2>&3 \
$WT_SIZE \
"$2"
}
# yesnobox TEXT
yesnobox() {
BASE_LINES=8
WT_HEIGHT=$(echo -e "$@" | wc -l)
(( WT_HEIGHT=WT_HEIGHT+BASE_LINES ))
WT_WIDTH=78
WT_SIZE="$WT_HEIGHT $WT_WIDTH"
TERM=ansi whiptail \
--yesno "$@" \
--backtitle "$WT_BACKTITLE" \
--title "$WT_TITLE" \
$WT_SIZE
}
# ---------------------------------------------------------------------------------------
# =======================================================================================
# Set Variables
# =======================================================================================
# Location of smOS miners
minerRoot="/root/miner_org/"
smosMiners=($(ls $minerRoot))
URL="https://api.github.com/repos/greerso/smOS-unsupported-miners/contents/miners"
declare -A githubJSON="($(
curl -fsSL "${URL}" \
| jq '.[] | "[" + .name + "]=\"" +.download_url + "\""' -r
))"
IFS=$'\n' read -r -d '' -a githubMiners < <(set -o pipefail; curl --fail -kfsSL "https://api.github.com/repos/greerso/smOS-unsupported-miners/contents/miners" | jq -r '.[].name' && printf '\0')
clear
# ---------------------------------------------------------------------------------------
# =======================================================================================
# Which smOS miner to replace?
# =======================================================================================
printf "Please select the miner to replace:\n"
select smosMiner in ${smosMiners[@]}; do test -n "$smosMiner" && break; echo ">>> Invalid Selection"; done
smosMinerBin="$(find $minerRoot$smosMiner/ -maxdepth 1 -type f -size +512k -executable -printf "%f\n" -quit)"
clear
# ---------------------------------------------------------------------------------------
# =======================================================================================
# Which miner to replace $smosMiner with?
# =======================================================================================
printf "Please select the miner to replace $smosMiner with:\n"
select newMiner in ${githubMiners[@]%.gz}; do test -n "$newMiner" && break; echo ">>> Invalid Selection"; done
clear
echo "You're replacing $smosMiner with $newMiner"
# ---------------------------------------------------------------------------------------
# =======================================================================================
# Download miner
# =======================================================================================
newMinerURL=${githubJSON[$newMiner.gz]}
# ---------------------------------------------------------------------------------------
# =======================================================================================
# Switch out miner and create masquerade symlink
# =======================================================================================
mv $minerRoot$smosMiner/$smosMinerBin $minerRoot$smosMiner/$smosMiner.backup
curl -fsSL $newMinerURL | gunzip > $minerRoot$smosMiner/$newMiner
chmod +x $minerRoot$smosMiner/$newMiner
chown miner:miner $minerRoot$smosMiner/$newMiner
ln -s $minerRoot$smosMiner/$newMiner $minerRoot$smosMiner/$smosMinerBin
clear
# ---------------------------------------------------------------------------------------
# =======================================================================================
# Done.
# =======================================================================================
echo "###"
echo "$smosMiner is now $newMiner!"
echo "###"
echo ""
# $minerRoot$smosMiner/$smosMinerBin --version
echo ""
echo "###"
echo "You should now configure your Rig Group for $smosMiner remembering that it is $newMiner"
echo "###"
# ---------------------------------------------------------------------------------------