-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathconfigure
More file actions
executable file
·126 lines (96 loc) · 3.18 KB
/
configure
File metadata and controls
executable file
·126 lines (96 loc) · 3.18 KB
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
#!/usr/bin/env bash
#set -x
. /etc/lotus/docker/bash-config
repeat() { while :; sleep 3; do $@ && return; done }
# Handle INFRA_CLEAR_RESTART variable
function run_clear_restart {
echo "I'll remove ALL LOTUS DATA from $LOTUS_PATH/";
echo " -------> Removing ... <---------";
repeat rm -rf "$LOTUS_PATH/*";
}
# Handle INFRA_SECRETVOLUME variable
function handle_persist_node_id {
if [[ $INFRA_PERSISTNODEID = true ]]; then
cp $NODE_ID_SOURCE_PATH $NODE_ID_TARGET_PATH;
return 0;
fi
rm -f $NODE_ID_TARGET_PATH;
}
function copy_secrets {
mkdir -p $KEYSTORE_TARGET_DIR;
handle_persist_node_id;
cp $TOKEN_SOURCE_PATH $TOKEN_TARGET_PATH;
cp $PRIVATE_KEY_SOURCE_PATH $PRIVATE_KEY_TARGET_PATH;
}
# Set filesystem permissions on the copied secrets
function set_secrets_permissions {
# Set permissions in the keystore directory to 600
if [ -d "$KEYSTORE_TARGET_DIR" ]; then
find "$KEYSTORE_TARGET_DIR/" -type f -exec chmod 600 {} \;
fi
# Set permissions to the token file to 600
if [ -f "$TOKEN_TARGET_PATH" ]; then
chmod -f 600 "$TOKEN_TARGET_PATH"
fi
}
# Copy config.toml if needed
function copy_config {
# If config.toml doesn't exist,
# print out error message and exit.
if [ ! -f "$LOTUS_CONFIG_SOURCE_PATH" ]; then
echo "$LOTUS_CONFIG_SOURCE_PATH not found";
return 0;
fi
# If the .lotus directory doesn't exist, create it.
if [ ! -d "$LOTUS_PATH" ]; then
mkdir "$LOTUS_PATH"
fi
# Copy config.toml to the .lotus directory
cp $LOTUS_CONFIG_SOURCE_PATH $LOTUS_CONFIG_TARGET_PATH
}
# Handle INFRA_IMPORT variable
function run_import {
echo "Starting import...";
if [ -f "$SNAPSHOT_DEFAULT_PATH" ] && [ ! -e "$DATASTORE_TARGET_PATH" ]; then
lotus daemon --halt-after-import --import-chain "$SNAPSHOT_DEFAULT_PATH";
touch "$IMPORT_COMPLETE_PATH";
fi
}
function run_import_from_ipfs {
echo "Fetching IPFS CID...";
local CID=$(curl $SNAPSHOT_CID);
echo "Fetched. CID is $CID";
SNAPSHOTURL="$IPFS_GW/$CID";
echo "Full URL to snapshot is $SNAPSHOTURL";
INFRA_IMPORT_SNAPSHOT=true;
}
function run_import_snapshot {
echo "Starting import...";
if [ -e "$DATASTORE_TARGET_PATH" ]; then
echo "Removing all chain data...";
rm -rf "$DATASTORE_TARGET_PATH/chain/*";
fi
lotus daemon --halt-after-import --remove-existing-chain --import-snapshot $SNAPSHOTURL;
touch "$IMPORT_COMPLETE_PATH";
}
function is_import_completed {
# If there's a file at IMPORT_COMPLETE_PATH, exit.
if [ -f "$IMPORT_COMPLETE_PATH" ]; then
return 0;
fi
return 1;
}
function run_sync {
echo "Starting sync wait...";
( repeat lotus sync wait && touch "$INFRA_LOTUS_HOME/.lotus/sync-complete" &);
}
# Exit if INFRA_LOTUS_HOME is not defined
validate_env_hard INFRA_LOTUS_HOME;
validate_env_soft INFRA_CLEAR_RESTART && run_clear_restart;
validate_env_soft INFRA_SECRETVOLUME && copy_secrets;
set_secrets_permissions;
copy_config;
validate_env_soft INFRA_IMPORT && run_import;
validate_env_soft INFRA_IMPORT_SNAPSHOT_FROM_IPFS && run_import_from_ipfs;
is_import_completed || (validate_env_soft INFRA_IMPORT_SNAPSHOT && run_import_snapshot || echo "Do not run import");
validate_env_soft INFRA_SYNC && run_sync || echo "Do not run sync";