-
Notifications
You must be signed in to change notification settings - Fork 2
/
entrypoint.sh
executable file
·74 lines (59 loc) · 1.52 KB
/
entrypoint.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
#!/bin/bash
set -e
unarchive_7z() {
echo "Unarchiving (7zip)..."
7z x "$1" -o$2
}
unarchive_zstd() {
echo "Unarchiving (zstd)..."
tar xv --zstd -f "$1" -C "$2"
}
unarchive_gzip() {
echo "Unarchiving (gzip)..."
tar xvzf "$1" -C "$2"
}
if [ -z "$ARCHIVE_URL" ]; then
echo "No archive download url specified, exiting"
exit 0
fi
CHAIN_DB_PATH=$CHAIN_DIR/db
if [ "$(ls -A "$CHAIN_DB_PATH" 2>/dev/null)" ]; then
echo "Chain database $CHAIN_DB_PATH already exists, exiting"
exit 0
else
echo "No chain database files in $CHAIN_DB_PATH, initializing..."
fi
if [[ "$ARCHIVE_URL" == *.7z ]]; then
unarchive_func=unarchive_7z
elif [[ "$ARCHIVE_URL" == *.tar.zst ]]; then
unarchive_func=unarchive_zstd
elif [[ "$ARCHIVE_URL" == *.tar.gz ]]; then
unarchive_func=unarchive_gzip
else
echo "Unsupported archive file type $ARCHIVE_URL"
exit 1
fi
if [ -z "$CHAIN_DIR" ]; then
echo 'Environment variable $CHAIN_DIR should not be empty'
exit 1
#
# With the chain node CLI option --base=/data, $CHAIN_DIR examples:
#
fi
echo "Downloading $ARCHIVE_URL..."
mkdir -p /snapshot
wget -c --progress dot:giga -O /snapshot/archive.tmp "$ARCHIVE_URL"
mkdir -p "$CHAIN_DB_PATH"
$unarchive_func /snapshot/archive.tmp "$CHAIN_DIR"
if [ -n "$CHOWN" ]; then
echo "Chown to $CHOWN..."
chown -R "$CHOWN" "$CHAIN_DIR"
fi
if [ -n "$CHMOD" ]; then
echo "Chmod to $CHMOD..."
chmod -R "$CHMOD" "$CHAIN_DIR"
fi
echo "Cleaning up..."
rm -v /snapshot/archive.tmp
echo
ls -la $CHAIN_DB_PATH