-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathoxen-multi-sn-create
executable file
·105 lines (92 loc) · 3.07 KB
/
oxen-multi-sn-create
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
#!/bin/bash
set -e
if [ "$#" -ne 1 ] || [[ ! $1 =~ ^[0-9][0-9]$ ]]; then
echo "Usage: oxen-multi-sn-create XX where XX is a two-digit number."
exit 1
fi
if [ "$UID" -ne 0 ]; then
echo "This script must be run as root (e.g. via sudo)."
exit 1
fi
PT=$1
oxend_conf=/etc/oxen/node-$PT.conf
ss_conf=/etc/oxen/storage-$PT.conf
lokinet_conf=/etc/loki/lokinet-router-$PT.ini
if ! [ -d /etc/loki ]; then mkdir /etc/loki; fi
if [ -z "$OVERWRITE" ]; then
for x in $oxend_conf $ss_conf $lokinet_conf /var/lib/oxen/node-$PT /var/lib/lokinet/router-$PT /var/lib/oxen/storage-$PT; do
if [ -e $x ]; then
echo "$x already exists, refusing to overwrite."
exit 1
fi
done
fi
ip=$(curl -sS http://api.ipify.org)
if [ -z "$ip" ]; then
echo "Failed to figure out your public IP via ipify.org"
exit 2
fi
echo "Creating $oxend_conf"
cat <<EOF >$oxend_conf
service-node=1
service-node-public-ip=$ip
storage-server-port=221$PT
p2p-bind-port=222$PT
rpc-admin=127.0.0.1:223$PT
quorumnet-port=225$PT
data-dir=/var/lib/oxen/node-$PT
EOF
mkdir -p /var/lib/oxen/node-$PT
chown _loki:_loki /var/lib/oxen/node-$PT
echo "Creating $ss_conf"
cat <<EOF >$ss_conf
ip=0.0.0.0
port=221$PT
lmq-port=202$PT
oxend-rpc=ipc:///var/lib/oxen/node-$PT/oxend.sock
data-dir=/var/lib/oxen/storage-$PT
EOF
mkdir -p /var/lib/oxen/storage-$PT
chown _loki:_loki /var/lib/oxen/storage-$PT
echo "Creating $lokinet_conf"
tmpdir=$(mktemp --tmpdir -d lokinet.XXXXXXXXXX)
/usr/bin/lokinet -r -g $tmpdir/lokinet.ini
perl -pi -e "
s#$tmpdir#/var/lib/lokinet/router-$PT#;
if (/^\[lokid/ ... /^\[/) {
s{^#?rpc=.*}{rpc=ipc:///var/lib/oxen/node-$PT/oxend.sock};
}
if (/^\[router/ ... /^\[/) {
s{#?public-ip=.*}{public-ip=$ip};
s{#?public-port=.*}{public-port=109$PT};
}
if (/^\[bind/ ... /^\[/) {
\$_ = qq{0.0.0.0=109$PT\n\n} if /^$/ and not \$added_bind++;
}
if (/^\[dns/ ... /^\[/) {
s{^#?bind=(?:.*):53}{bind=127.1$PT.0.0:53};
}
if (/^\[api/ ... /^\[/) {
s{^#?bind=127.0.0.1:1190}{bind=127.1$PT.0.0:1190};
}
if (/^\[network\]/) {
s{^#?ifname=.*}{ifname=lokitun$PT};
s{^#?ifaddr=.*}{ifaddr=10.1$PT.0.1/16}
}
" $tmpdir/lokinet.ini
chmod 640 $tmpdir/lokinet.ini
chgrp _loki $tmpdir/lokinet.ini
mv $tmpdir/lokinet.ini $lokinet_conf
mkdir -p /var/lib/lokinet/router-$PT
ln -snf $lokinet_conf /var/lib/lokinet/router-$PT/lokinet.ini
chown -R _lokinet:_loki /var/lib/lokinet/router-$PT
echo -e "\n\n\nDone with configuration setup. Enabling services..."
systemctl enable {oxen-node,oxen-storage-server,lokinet-router}@$PT.service
echo -e "\n\nServices configured to auto-start. Press enter to actually start services now,"
echo -e "or Ctrl-C if you want to look around first before launching them. Note that if"
echo -e "you hit Ctrl-C here you will have to start them yourself using:\n"
echo -e " systemctl start oxen-node@$PT oxen-storage-server@$PT lokinet-router@$PT\n"
read
echo "Starting services..."
systemctl start {oxen-node,oxen-storage-server,lokinet-router}@$PT.service
echo "All done!\n"