-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtezd-update-scripts.sh
99 lines (98 loc) · 2.82 KB
/
tezd-update-scripts.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
#!/bin/bash
if [ "$EUID" -ne 0 ]
then echo "Please run as root or using sudo!"
exit
fi
HPATH=/usr/lib/tezd
echo "Updating scripts..."
rm -rf $HPATH/scripts
rm -f /bin/tezd
mkdir $HPATH/scripts
cd $HPATH/scripts
cat > start.sh << EOF
#!/bin/bash
echo "Starting tezd...\n"
if [ ! -f "$HPATH/.tezos-node/config.json" ]; then
echo "Creating config..."
PEERS=\$(curl -s 'http://api5.tzscan.io/v1/network?state=running&p=0&number=50' | grep -Po '::ffff:([0-9.:]+)' | sed ':a;N;\$!ba;s/\n/ /g' | sed 's/::ffff:/--peer=/g')
su tezd -c "$HPATH/tezos/tezos-node config init --data-dir $HPATH/.tezos-node --rpc-addr 127.0.0.1:8732 \$PEERS"
fi
if [ ! -f "$HPATH/.tezos-node/identity.json" ]; then
su tezd -c "$HPATH/tezos/tezos-node identity generate 26. --data-dir $HPATH/.tezos-node";
fi
echo "Starting node..."
su tezd -c "nohup $HPATH/tezos/tezos-node run > $HPATH/node.log &"
exit
EOF
cat > stop.sh << EOF
#!/bin/bash
echo "Stopping tezd...\n"
pkill -9 tezos-node
EOF
cat > restart.sh << EOF
#!/bin/bash
sh $HPATH/scripts/stop.sh
sh $HPATH/scripts/start.sh
EOF
cat > update.sh << EOF
#!/bin/bash
sh $HPATH/scripts/stop.sh
su tezd -c "cd $HPATH/tezos && git fetch && git rebase && eval \\\$(opam env) && make && cd $HPATH"
sh $HPATH/scripts/start.sh
EOF
cat > rebuild.sh << EOF
#!/bin/bash
sh $HPATH/scripts/stop.sh
cd $HPATH/tezos
su tezd -c 'sh -c "\$(curl -sL https://raw.githubusercontent.com/TezTech/tezd-install/master/tezd-rebuild.sh)"'
su tezd -c "make build-deps && eval \\\$(opam env) && make"
if [ ! -d "$HPATH/.tezos-node" ]; then
su tezd -c 'sh -c "\$(curl -sL https://raw.githubusercontent.com/TezTech/tezd-install/master/tezd-quicksync.sh)"'
else
su tezd -c "$HPATH/tezos/tezos-node upgrade storage"
fi
sh $HPATH/scripts/setup.sh
EOF
cat > setup.sh << EOF
#!/bin/bash
sh $HPATH/scripts/stop.sh
if [ -f "$HPATH/.tezos-node/config.json" ]; then rm -f "$HPATH/.tezos-node/config.json"; fi
if [ -f "$HPATH/.tezos-node/identity.json" ]; then rm -f "$HPATH/.tezos-node/identity.json"; fi
sh $HPATH/scripts/start.sh
EOF
cat > update_scripts.sh << EOF
#!/bin/bash
sh $HPATH/scripts/stop.sh
sh -c "\$(curl -sL https://raw.githubusercontent.com/TezTech/tezd-install/master/tezd-update-scripts.sh)"
sh $HPATH/scripts/start.sh
EOF
cd $HPATH
cat > /bin/tezd << EOF
#!/bin/bash
if test "\$1" = 'stop'; then
sh $HPATH/scripts/stop.sh
fi
if test "\$1" = 'start'; then
sh $HPATH/scripts/start.sh
fi
if test "\$1" = 'restart'; then
sh $HPATH/scripts/restart.sh
fi
if test "\$1" = 'update'; then
sh $HPATH/scripts/update.sh
fi
if test "\$1" = 'update_scripts'; then
sh $HPATH/scripts/update_scripts.sh
fi
if test "\$1" = 'rebuild'; then
sh $HPATH/scripts/rebuild.sh
fi
if test "\$1" = 'setup'; then
sh $HPATH/scripts/setup.sh
fi
if test "\$1" = 'client'; then
su tezd -c "$HPATH/tezos/tezos-\$@";
fi
EOF
chmod a+rwx,g-w,o-w /bin/tezd
chown -Rf tezd:tezd $HPATH/scripts