-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate_flags.sh
More file actions
39 lines (29 loc) · 1.14 KB
/
create_flags.sh
File metadata and controls
39 lines (29 loc) · 1.14 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
#!/bin/bash
export LC_ALL=C
export LANG=C
# Your docker-compose.yml file path
compose_file="docker-compose.yml"
# Function to generate a random 16-character uppercase string
generate_random_string() {
tr -dc 'A-Z0-9' < /dev/urandom | head -c 16
}
# Create or clear the flags.env file
> flags.env
echo "Generating flags.env from $compose_file ..."
# Extract lines starting with environment entries that have FLAG_
grep "FLAG_" "$compose_file" | while read -r line; do
# Remove leading/trailing spaces and the '- ' or key: part
clean_line=$(echo "$line" | sed 's/^[[:space:]]*-[[:space:]]*//; s/^[[:space:]]*//')
# Extract variable name before '=' or ':-'
flag_name=$(echo "$clean_line" | sed 's/=.*//; s/:.*//')
# Generate random uppercase string
random_string=$(generate_random_string)
# New value is FLAGNAME_RANDOMSTRING (or keep your FLAG{...} style)
# Example: FLAG_FOO -> FLAG_FOO_RANDOMSTRING
new_flag_value="${flag_name}_${random_string}"
# Write to flags.env file
echo "${flag_name}=${new_flag_value}" >> flags.env
done
echo "Done! Generated flags.env:"
echo "=========================="
cat flags.env