-
Notifications
You must be signed in to change notification settings - Fork 37
/
Copy pathupdate_generated_time.sh
executable file
·72 lines (65 loc) · 1.67 KB
/
update_generated_time.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
#!/usr/bin/env bash
# Default values
section=""
file=""
# Print help message
print_help() {
echo "Usage: $0 --section SECTION --file FILE"
echo
echo Updates the timestamp for the automatically generated docs for the section SECTION in the file FILE
echo
echo "Valid sections:"
echo " available_software -> Updates 'generated_time (available software)' field in FILE"
echo " testsuite_api -> Updates 'generated_time (EESSI testsuite API docs)' field in FILE"
echo
exit 0
}
# Parse named options
while [[ $# -gt 0 ]]; do
case "$1" in
--section)
section="$2"
shift 2
;;
--file)
file="$2"
shift 2
;;
--help)
print_help
;;
*)
echo "Unknown option: $1"
print_help
exit 1
;;
esac
done
# Validate section
if [[ -z "$section" ]]; then
echo "ERROR: --section argument is required."
print_help
exit 1
fi
# Validate file
if [[ -z "$file" ]]; then
echo "ERROR: --file argument is required."
print_help
exit 1
fi
# Get the new date
NEW_DATE="$(date '+%a, %d %b %Y at %H:%M:%S %Z')"
# Replace date for requested section
case "$section" in
available_software)
sed -E -i 's/(generated_time \(available software\): ")[^"]*(".*)/\1'"${NEW_DATE}"'\2/' $file
;;
testsuite_api)
sed -E -i 's/(generated_time \(testsuite API\): ")[^"]*(".*)/\1'"${NEW_DATE}"'\2/' $file
;;
*)
echo "ERROR: Unknown section '$section'"
echo "Valid sections are: available_software, testsuite_api"
exit 1
;;
esac