-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.sh
142 lines (129 loc) · 5.17 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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#!/bin/bash
# Define color codes
GREEN='\033[0;32m'
GRAY='\033[1;30m'
WHITE='\033[1;37m'
RED='\033[0;31m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
ITALIC='\033[3m'
RENAMED_SNAPSHOT_FILE_NAME='geth.tar.gz'
# Ask if the user wants to fetch the latest snapshot
read -p "Do you want to fetch the latest snapshot? [y/N]: " fetch_snapshot
echo ""
if [[ "$fetch_snapshot" == "y" || "$fetch_snapshot" == "Y" ]]; then
SNAPSHOT_FILE_PATH=$(curl -s https://storage.googleapis.com/raas-op-geth-snapshots-d2a56/datadir-archive/latest)
SNAPSHOT_FILE_NAME=${SNAPSHOT_FILE_PATH##*/}
echo -e "${GRAY}Fetching the latest snapshot... ${ITALIC}(will take a few minutes...) ${NC}"
wget https://storage.googleapis.com/raas-op-geth-snapshots-d2a56/datadir-archive/$SNAPSHOT_FILE_PATH
if [ $? -eq 0 ]; then
echo -e "${GREEN}↳ Snapshot successfully fetched as $SNAPSHOT_FILE_NAME.${NC}\n"
else
echo -e "${RED}↳ Error fetching the snapshot.${NC}\n"
exit 1
fi
echo -e "${GRAY}Fetching the snapshot checksum...${NC}"
wget https://storage.googleapis.com/raas-op-geth-snapshots-d2a56/datadir-archive/$SNAPSHOT_FILE_PATH.sha256
if [ $? -eq 0 ]; then
echo -e "${GREEN}↳ Checksum successfully fetched as $SNAPSHOT_FILE_NAME.sha256${NC}\n"
else
echo -e "${RED}↳ Error fetching the checksum.${NC}\n"
exit 1
fi
echo -e "${GRAY}Verifying the snapshot checksum... ${ITALIC}(can take a few minutes...)${NC}"
shasum -a 256 -c $SNAPSHOT_FILE_NAME.sha256
if [ $? -eq 0 ]; then
echo -e "${GREEN}↳ Checksum verification passed.${NC}\n"
else
echo -e "${RED}↳ Checksum verification failed.${NC}\n"
exit 1
fi
echo -e "${GRAY}Renaming the snapshot to $RENAMED_SNAPSHOT_FILE_NAME${NC}"
mv $SNAPSHOT_FILE_NAME $RENAMED_SNAPSHOT_FILE_NAME
if [ $? -eq 0 ]; then
echo -e "${GREEN}↳ Snapshot renamed properly to $RENAMED_SNAPSHOT_FILE_NAME.${NC}\n"
else
echo -e "${RED}↳ Failed to rename the snapshot.${NC}\n"
exit 1
fi
else
echo -e "${BLUE}Skipping snapshot fetch.${NC}\n"
fi
# Create the `var` directory structure with proper permissions
echo -e "${GRAY}Creating var/secrets directory structure...${NC}"
mkdir -p var/secrets
if [ $? -eq 0 ]; then
# Set directory permissions
chmod 777 var
chmod 777 var/secrets
echo -e "${GREEN}↳ Directory structure created with proper permissions.${NC}\n"
else
echo -e "${RED}↳ Error creating directory structure.${NC}\n"
exit 1
fi
# Generate the secret for the engine API secure communication
echo -e "${GRAY}Generating secret for the engine API secure communication...${NC}"
openssl rand -hex 32 > var/secrets/jwt.txt
if [ $? -eq 0 ]; then
# Set jwt.txt permissions
chmod 666 var/secrets/jwt.txt
echo -e "${GREEN}↳ Secret generated and saved to var/secrets/jwt.txt with proper permissions.${NC}\n"
else
echo -e "${RED}↳ Error generating secret.${NC}\n"
exit 1
fi
# Check if RENAMED_SNAPSHOT_FILE_NAME and geth exist and handle accordingly
if [ -f $RENAMED_SNAPSHOT_FILE_NAME ]; then
if [ -d geth ]; then
echo -e "${WHITE}$RENAMED_SNAPSHOT_FILE_NAME snapshot detected at the root, but geth already exists.${NC}"
read -p "Do you want to wipe the existing geth and reset from snapshot? [y/N] " response
if [[ "$response" == "y" || "$response" == "Y" ]]; then
echo -e "${GRAY}Removing existing geth directory...${NC}"
rm -rf ./geth
if [ $? -eq 0 ]; then
echo -e "${GREEN}↳ Existing geth directory removed.${NC}\n"
else
echo -e "${RED}↳ Error removing existing geth directory.${NC}\n"
exit 1
fi
echo -e "${GRAY}Decompressing and extracting $RENAMED_SNAPSHOT_FILE_NAME... ${ITALIC}(will take a few minutes...)${NC}"
tar -xzf $RENAMED_SNAPSHOT_FILE_NAME
if [ $? -eq 0 ]; then
# Set permissions for geth directory
chmod -R 777 geth
echo -e "${GREEN}↳ Decompression and extraction complete with proper permissions.${NC}\n"
else
echo -e "${RED}↳ Error during decompression and extraction.${NC}\n"
exit 1
fi
else
echo -e "Preserving existing geth directory.${NC}\n"
# Set permissions for existing geth directory
chmod -R 777 geth
fi
else
echo -e "${GRAY}geth directory not found. Decompressing and extracting $RENAMED_SNAPSHOT_FILE_NAME...${NC}"
tar -xzf $RENAMED_SNAPSHOT_FILE_NAME
if [ $? -eq 0 ]; then
# Set permissions for new geth directory
chmod -R 777 geth
echo -e "${GREEN}Decompression and extraction complete with proper permissions.${NC}\n"
else
echo -e "${RED}Error during decompression and extraction.${NC}\n"
exit 1
fi
fi
else
echo -e "${RED}$RENAMED_SNAPSHOT_FILE_NAME not found. Skipping decompression.${NC}\n"
# Ensure geth directory exists with proper permissions if it was created manually
if [ -d geth ]; then
chmod -R 777 geth
fi
fi
# Final permission check
echo -e "${GRAY}Performing final permission check...${NC}"
chmod -R 777 geth 2>/dev/null || true
chmod -R 777 var
chmod 666 var/secrets/jwt.txt
echo -e "${GREEN}↳ Permissions verified.${NC}\n"
echo -e "${WHITE}The Ink Node is ready to be started. Run it with:${NC}\n${BLUE} docker compose up${GRAY} # --build to force rebuild the images ${NC}"