-
Notifications
You must be signed in to change notification settings - Fork 0
/
_helper.sh
111 lines (87 loc) · 2.72 KB
/
_helper.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
#!/bin/sh
# I assume a DPKG based system
# I expect these on the command line and I expect to be called by
# a deployment script - see values for $1, ... below
# it has already checked for a snapshot.
OS=debian-12
PKGSITE=https://pkgbeta.tzinit.org
SNAPREG=eu
MODE=rolling
NETWORK=mainnet
TEZTNETS=https://teztnets.com
ARCH=amd64
VER="19.0-1"
NODEHOME=/var/tezos/.tezos-node # XXX in later packages this will change
[ ! -z "$8" ] && VER="$8"
[ ! -z "$7" ] && ARCH="$7"
[ ! -z "$6" ] && OS="$6"
[ ! -z "$5" ] && PKGSITE="$5"
[ ! -z "$4" ] && SNAPREG="$4"
[ ! -z "$3" ] && RPC="$3"
[ ! -z "$2" ] && MODE="$2"
[ ! -z "$1" ] && NETWORK="$1"
CLIENTPKG="octez-client_${VER}_${ARCH}.deb"
NODEPKG="octez-node_${VER}_${ARCH}.deb"
# Snapshot service
#
SNAPSHOTURL="https://snapshot.$SNAPREG.tzinit.org/$NETWORK/$MODE"
[ "$MODE" = "archive" ] && \
SNAPSHOTURL="https://snapshot.$SNAPREG.tzinit.org/$NETWORK/archive.tar.lz4"
# Network URL
#
NETWORKURL="$NETWORK"
if [ "$NETWORK" != "mainnet" ] && [ "$NETWORK" != "ghostnet" ]; then
# Test network
#
NETWORKURL="$TEZTNETS/$NETWORK"
fi
date
echo "===> Setting up node"
echo "Network URL: $NETWORKURL"
echo "Mode: $MODE"
echo "Snapshot: $SNAPSHOTURL"
echo "===> Upgrading OS"
apt update
apt upgrade -y
apt install -y lz4 tmux
echo "===> Fetching Octez"
wget $PKGSITE/$OS/$CLIENTPKG
wget $PKGSITE/$OS/$NODEPKG
echo "===> Installing Octez"
apt install -y ./$CLIENTPKG
apt install -y ./$NODEPKG
rm -f $CLIENTPKG $NODEPKG
mkdir -p $NODEHOME
chown tezos:tezos $NODEHOME
if [ $MODE = "archive" ]; then
echo "===> Fetching and decompressing archive"
cd $NODEHOME
wget -nv -O - ${SNAPSHOTURL} | lz4cat | tar xvf -
chown tezos:tezos -R $NODEHOME
cd
fi
RPCOPTIONS="--rpc-addr='127.0.0.1:8732'"
if [ "$RPC" = "yes" ]; then
RPCOPTIONS="--rpc-addr='0.0.0.0:8732' --allow-all-rpc='0.0.0.0:8732'" # Assumed to be firewalled - could be better
fi
echo "===> Configuring node"
su - tezos -c "octez-node config init --data-dir ${NODEHOME} \
--network=${NETWORKURL} \
--history-mode=${MODE} \
--net-addr='[::]:9732' \
${RPCOPTIONS}"
if [ $MODE != "archive" ] ; then
echo "===> Fetching Snapshot"
wget -nv ${SNAPSHOTURL} -O /var/tezos/__snapshot
su - tezos -c "octez-node snapshot import /var/tezos/__snapshot --data-dir $NODEHOME"
rm -f /var/tezos/__snapshot
if [ ! -d $NODEHOME/context ]; then
echo "Warning: Snapshot import has failed."
echo "We will attempt to start the node anyway..."
fi
fi
echo "===> Enabling and starting services"
systemctl enable octez-node
systemctl start octez-node
#echo "===> Rebooting to clean and start"
#shutdown -r now