forked from Onion-DAO/tornode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
oniondao.sh
146 lines (108 loc) · 2.89 KB
/
oniondao.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
142
143
144
145
146
#!/bin/bash
## ###############
## Variables
## ###############
oniondaofolder="$HOME/.oniondao/"
binfolder=/usr/local/sbin
visudo_path=/private/etc/sudoers.d/tordao
version='0.0.1'
# CLI help message
helpmessage="
OnionDAO CLI utility v$version.
Authors: @actuallymentor
Docs: https://github.com/Onion-DAO/tornode/
Usage:
oniondao help
output (this) oniondao help message
oniondao version
output the OnionDAO cli version
oniondao status
output your current configuration
oniondao install
set up and register a Tor exit node and notify the OnionDAO oracle
oniondao register
register an existing Tor node with the OnionDAO oracle
oniondao update
update your OnionDAO node to the lasest CLI and configuration
"
# Get parameters
action=$1
## ###############
## Helpers
## ###############
function log() {
echo -e "$(date +%T) - $1"
}
## ###############
## Actions
## ###############
# Help message
if [ -z "$action" ]; then
echo -e "$helpmessage"
exit 0
fi
if [[ "$action" == "help" ]]; then
echo -e "$helpmessage"
exit 0
fi
# Visudo message
if [[ "$action" == "version" ]]; then
echo "🧅 OnionDAO version v$version"
exit 0
fi
# Update script trigger
if [[ "$action" == "status" ]]; then
echo "🧅 OnionDAO version v$version"
echo -e "\n\n----------------------------------------"
echo -e "Your existing configurations:"
echo -e "----------------------------------------\n\n"
NODE_NICKNAME=$( grep -Po "(?<=Nickname )(.*)" /etc/tor/torrc 2> /dev/null )
NODE_BANDWIDTH=$( grep -Po "(?<=AccountingMax )(.*)(?= TB)" /etc/tor/torrc 2> /dev/null )
OPERATOR_EMAIL=$( grep -Po "(?<=ContactInfo )(.*)" /etc/tor/torrc 2> /dev/null )
OPERATOR_WALLET=$( grep -Po "(?<= address: )(.*)(?= -->)" /etc/tor/tor-exit-notice.html 2> /dev/null )
OPERATOR_TWITTER=$( grep -Po "(?<=OPERATOR_TWITTER=)(.*)" "$oniondaofolder/.oniondaorc" 2> /dev/null )
echo "POAP wallet: $OPERATOR_WALLET"
echo "Node nickname: $NODE_NICKNAME"
echo "Operator email: $OPERATOR_EMAIL"
echo "Operator twitter: $OPERATOR_TWITTER"
echo "Monthly bandwidth limit: $NODE_BANDWIDTH TB"
exit 0
fi
# Installation script trigger
if [[ "$action" == "install" ]]; then
cd "$oniondaofolder"
git pull &> /dev/null
sudo bash "./install-tornode.sh" "$HOME"
exit 0
fi
# Update script trigger
if [[ "$action" == "update" ]]; then
cd "$oniondaofolder"
git pull &> /dev/null
sudo bash "./install-tornode.sh" "$HOME"
exit 0
fi
# Update script trigger
if [[ "$action" == "register" ]]; then
cd "$oniondaofolder"
git pull &> /dev/null
sudo bash "./register-tornode.sh" "$HOME"
exit 0
fi
if [[ "$action" == "debug" ]]; then
log "\nSystem data:"
cat /etc/os-release
free -m
cat /proc/cpuinfo
log "\nOniondao status:"
oniondao status
log "\nTor status:"
service tor status
log "\nTor binary:"
which tor
log "\nPorts in use:"
sudo netstat -lp
log "\nTor config:"
cat /etc/tor/torrc
exit 0
fi