-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcreate_environment_file.sh
More file actions
executable file
·65 lines (50 loc) · 1.67 KB
/
create_environment_file.sh
File metadata and controls
executable file
·65 lines (50 loc) · 1.67 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
#!/bin/bash
if [ $# -ne 3 ]; then
echo "Error: this script requires three arguments: bench_name, deployment_dir, custom_image_details"
exit 1
fi
bench_name="$1"
deployment_dir="$2"
custom_image_details="${3:-}"
template_env_file="example.env"
output_env_file="$deployment_dir/$bench_name.env"
validate_env_template() {
if [ ! -f "$template_env_file" ]; then
echo "Error: Template environment file $template_env_file not found."
return 1
fi
return 0
}
sanitize_name() {
local name="$1"
# Replace dots with underscores
echo "$name" | sed 's/\./_/g'
}
main() {
if ! validate_env_template; then
exit 1
fi
cp "$template_env_file" "$output_env_file"
sanitized_bench_name=$(sanitize_name "$bench_name")
sed -i "s/^ROUTER=.*/ROUTER=$sanitized_bench_name/" "$output_env_file"
sed -i "s/^BENCH_NETWORK=.*/BENCH_NETWORK=$sanitized_bench_name/" "$output_env_file"
if [ -n "$custom_image_details" ]; then
IFS=':' read -r custom_image custom_tag <<< "$custom_image_details"
if [ -n "$custom_image" ] && [ -n "$custom_tag" ]; then
sed -i "s/^CUSTOM_IMAGE=.*/CUSTOM_IMAGE=$custom_image/" "$output_env_file"
sed -i "s/^CUSTOM_TAG=.*/CUSTOM_TAG=$custom_tag/" "$output_env_file"
fi
fi
echo "Environment file template copied to: $output_env_file"
read -p "Press enter to continue with editing the file... "
nano "$output_env_file"
if [ -s "$output_env_file" ]; then
echo -e "\nEnvironment file was updated."
echo "Final environment file contents:"
cat $output_env_file
else
echo "Warning: Environment file is empty. Reverting to template."
cp "$template_env_file" "$output_env_file"
fi
}
main