This repository has been archived by the owner on May 7, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparasnaps.sh
executable file
·162 lines (143 loc) · 4.16 KB
/
parasnaps.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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
#!/bin/bash
paradir="$HOME/.parasnaps"
paraurl="https://github.com/amforc/s3get/releases/latest/download/"
bucketrooturl="parasnaps.io"
RED='\033[0;31m'
GREEN='\033[1;32m'
BLUE='\033[1;34m'
YELLOW='\033[1;33m'
NC='\033[0m'
echo -e "\n${GREEN}Create working directory: $paradir\n"
mkdir -p $paradir && cd $paradir
echo -e "${GREEN}Download s3get"
curl --silent -o "${paradir}/s3get.sha256" "${paraurl}/s3get.sha256"
curl --silent -o "${paradir}/s3get" "${paraurl}/s3get"
chmod +x "${paradir}/s3get"
echo -e "Verify checksum\n"
if ! sha256sum --quiet -c "${paradir}/s3get.sha256"; then
echo -e "${RED}Checksum failed" >&2
exit 1
fi
#-- Select Download location
echo -e "${BLUE}Select the Download source for the snapshot (closest to the host):"
PS3='Please enter your choice: '
options=("(Europe) Ireland" "(Europe) Frankfurt" "(US East) N. Virginia" "(US West) Oregon" "(Asia Pacific) Singapore" "Quit")
select opt in "${options[@]}"
do
case $opt in
"(Europe) Ireland")
echo -e "${GREEN}you chose $opt\n"
bucketurl="euw1.${bucketrooturl}"
break
;;
"(Europe) Frankfurt")
echo -e "${GREEN}you chose $opt\n"
bucketurl="euc1.${bucketrooturl}"
break
;;
"(US East) N. Virginia")
echo -e "${GREEN}you chose $opt\n"
bucketurl="use1.${bucketrooturl}"
break
;;
"(US West) Oregon")
echo -e "${GREEN}you chose $opt\n"
bucketurl="usw2.${bucketrooturl}"
break
;;
"(Asia Pacific) Singapore")
echo -e "${GREEN}you chose $opt\n"
bucketurl="apse1.${bucketrooturl}"
break
;;
"Quit")
echo -e "${RED}exiting exiting script\n"
exit 1
;;
*) echo -e "${RED}invalid option $REPLY${BLUE}";;
esac
done
#++ Select Download location
#-- Select chain
echo -e "${BLUE}Select the chain:"
PS3='Please enter your choice: '
options=("polkadot" "kusama" "Quit")
select opt in "${options[@]}"
do
case $opt in
"polkadot")
echo -e "${GREEN}you chose $opt\n"
chainselection=$opt
break
;;
"kusama")
echo -e "${GREEN}you chose $opt\n"
chainselection=$opt
break
;;
"Quit")
echo -e "${RED}exiting exiting script\n"
exit 1
;;
*) echo -e "${RED}invalid option $REPLY${BLUE}";;
esac
done
#++ Select chain
#-- Select database format
echo -e "${BLUE}Select the chain:"
PS3='Please enter your choice: '
options=("rocksdb" "paritydb" "Quit")
select opt in "${options[@]}"
do
case $opt in
"rocksdb")
echo -e "${GREEN}you chose $opt\n${BLUE}"
dbformat=$opt
break
;;
"paritydb")
echo -e "${GREEN}you chose $opt\n${BLUE}"
dbformat=$opt
break
;;
"Quit")
echo -e "${RED}exiting exiting script\n"
exit 1
;;
*) echo -e "${RED}invalid option $REPLY${BLUE}";;
esac
done
#++ Select database format
#-- Select Directory
if [ "$chainselection" == "kusama" ]; then
chain_dir_name="ksmcc3"
else
chain_dir_name="polkadot"
fi
default_dir="$HOME/.local/share/polkadot/chains/${chain_dir_name}/"
read -p "Enter download directory [$default_dir]:" download_dir
: ${download_dir:=$default_dir}
if [ ! -d "$download_dir" ]; then
echo -e "${RED}Directory does not exist\n"
exit 1
fi
echo -e "${GREEN}you chose $download_dir\n${BLUE}"
#++ Select Directory
# --Download file
file_name="${chainselection}_${dbformat}.tar"
echo -e "${BLUE}Downloading:"
${paradir}/s3get "s3://${bucketurl}/${file_name}" | tar -xf - -C $download_dir &
PID=$!
sleep 1
while [ -d /proc/$PID ]
do
current_size=$(du -sh ${download_dir})
echo -ne "${GREEN}$current_size\r"
sleep 1
done
# ++ Downlaod file
echo -e "\n"
echo -e "${GREEN}SCRIPT FINISHED.\n"
# -- User part
echo -e "${BLUE}#Run the polkadot node with:\n${YELLOW}polkadot --chain=${chainselection} --database=${dbformat} --state-pruning=1000"
# ++ User part