forked from AgentJ-WR/prysmatic_bazel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.sh
executable file
·129 lines (93 loc) · 4.97 KB
/
setup.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
#!/bin/bash
#2019-06-06 based on https://github.com/prysmaticlabs/prysm
#2020-01-25 considering it mostly done, now is fully automated install and launch of goerli geth, beacon chain, validator, and eth2stats.
if [ $EUID != 0 ]; then
sudo "$0" "$@"
exit $?
fi
#Adding to the docker group is necessary for eth2stats to run. Do this as early as possible so the user can step away.
groups `id -un -- 1000`| grep docker
RESULT=$?
if [ $RESULT -eq 0 ]; then
echo You are in the docker group, cool beans.
else
#Add the user to docker
sudo groupadd docker
sudo usermod -aG docker `id -un -- 1000`
#give a notice then terminate the script beacuse they're not ready
echo "You are NOT in the docker group I'm adding you, but you MUST exit and log back in and restart this script. (Sorry, it has to be this way)"
echo "REBOOT and relaunch setup.sh"
echo "REBOOT and relaunch setup.sh"
echo "REBOOT and relaunch setup.sh"
exit 1
fi
#update the system
sudo apt update && sudo apt dist-upgrade -y
#install dependencies for bazel, expect is to add the unbuffer command to allow colorful text piping
sudo apt install -y pkg-config zip g++ zlib1g-dev unzip python expect git curl screen
#check for docker and install it if necessary
which docker
RESULT=$?
if [ $RESULT -eq 0 ]; then
echo docker is installed
else
echo docker is not installed
#download the docker installer
curl -fsSL https://get.docker.com -o get-docker.sh
#install docker
sudo sh get-docker.sh
fi
#launch the stats monitor
$HOME/prysmatic_bazel/eth2stats.sh
#user 1000 (main user) needs to reboot without password:
sudo sh -c "echo \"`id -un -- 1000` ALL=NOPASSWD: /sbin/halt, /sbin/reboot, /sbin/poweroff\" >> /etc/sudoers"
#add ethereum repository for geth
#sudo add-apt-repository -y ppa:ethereum/ethereum
#install geth
#sudo apt install -y geth
#download bazel (this could be updated to pull the latest release!)
wget https://github.com/bazelbuild/bazel/releases/download/2.0.0/bazel-2.0.0-installer-linux-x86_64.sh
chmod +x bazel-2.0.0-installer-linux-x86_64.sh
./bazel-2.0.0-installer-linux-x86_64.sh --user
#bazel needs this path - this appears to be redundant because it is sourced later in this file.
export PATH="$PATH:$HOME/bin"
#addingthe path to bashrc for later boots
echo 'export PATH="$PATH:$HOME/bin"' >> $HOME/.bashrc
#colorful prompts are nice
echo 'force_color_prompt=yes' >> $HOME/.bashrc
#bazel command completion
echo "source $HOME/.bazel/bin/bazel-complete.bash" >> $HOME/.bashrc
#sourcing all of this now so it goes into effect immediately.
source $HOME/.bashrc
#remove the prysm directory on the off chance it already exists (user re-runs script)
rm -rf $HOME/prysm
#cloning the prysmatic client
cd $HOME && git clone https://github.com/prysmaticlabs/prysm
#adding screen start jobs at boot
sudo cp $HOME/prysmatic_bazel/rc.local /etc/
#create a key pair just to get things started.
cd $HOME && $HOME/prysmatic_bazel/create_wallet.sh
#permissions got jacked for the git repo, won't hurt to set all home permissions
sudo chown -R `id -un -- 1000`:`id -un -- 1000` ~/
sudo chown -R `id -un -- 1000`:`id -un -- 1000` ~/.*
sudo chown -R root:root /home/`id -un -- 1000`/.cache/bazel/_bazel_root
sudo chown -R `id -un -- 1000`:`id -un -- 1000` /home/`id -un -- 1000`/.cache/bazel
#starting screen jobs now
/bin/su `id -un -- 1000` -c "/usr/bin/screen -dmS beacon-screen bash -c '/home/`id -un -- 1000`/prysmatic_bazel/beacon_chain_restarter.sh; exec bash'"
/bin/su `id -un -- 1000` -c "/usr/bin/screen -dmS validator-screen bash -c '/home/`id -un -- 1000`/prysmatic_bazel/validator_restarter.sh; exec bash'"
#/bin/su `id -un -- 1000` -c "/usr/bin/screen -dmS geth bash -c '/home/`id -un -- 1000`/prysmatic_bazel/launch_geth.sh; exec bash'"
#still encountering a permission bug, just throwing potential solutions at it.
#FATAL: mkdir('/home/superphiz/.cache/bazel/_bazel_superphiz'): (error: 13): Permission denied
sudo mkdir -p $HOME/.cache/bazel/_bazel_`id -un -- 1000`
sudo chown -R `id -un -- 1000`:`id -un -- 1000` $HOME
sudo chown -R `id -un -- 1000`:`id -un -- 1000` $HOME/.*
sudo chown -R root:root $HOME/.cache/bazel/_bazel_root
sudo chown -R `id -un -- 1000`:`id -un -- 1000` /home/`id -un -- 1000`/.cache/bazel
RED='\033[0;31m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
printf "${RED}READ THE FOLLOWING TEXT FOR SHURE LEGIT PLZ.\n${NC}"
printf "${YELLOW}\n\nThe basic setup is done. It looks like nothing is happening, but everything is currently syncing in the background. \n\nCopy the message and use it to send the transaction from https://prylabs.net/participate. \n\nYou can now access the screen sessions with 'screen -ls' that will show 'beacon-screen' and 'validator-screen'.\n\n${NC}"
#show running screens
/bin/su `id -un -- 1000` -c "screen -ls"
printf "${YELLOW}\nYou can enter any of the screens above by typing something like \"screen -x beacon-screen\". To EXIT that screen session, hold [CTRL] and press A, then D.\n\n When you reboot this computer those tools will run in the background with screen.\n\n"