generated from RedHatQuickCourses/course-starter
-
Notifications
You must be signed in to change notification settings - Fork 1
/
course-init.sh
117 lines (105 loc) · 2.23 KB
/
course-init.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
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
print_usage()
{
echo -e """
USAGE: $0 --type [hol|bfx] --lab [demo|role|other]
"""
return
}
exit_script()
{
#cleanup
echo -e "\nPlease replace the FIXME line in the antora.yml and antora-playbook.yml files with the title for this course. \nCommit the changes before proceeding with the course development."
grep FIXME antora.yml antora-playbook.yml
}
handle_lab()
{
cp -f modules/LABENV/pages/index-lab-$LAB.adoc modules/LABENV/pages/index.adoc
}
handle_type()
{
case "$TYPE" in
"hol" )
rm -rf modules.bfx
;;
"bfx" )
rm -rf modules
mv modules.bfx modules
;;
* )
echo -e "ERROR: you should never land here"
print_usage
exit 1
;;
esac
}
execute_init()
{
## Get the training repository name and replace it with the placeholder string in different files
handle_type
handle_lab
REPONAME=$(basename `git rev-parse --show-toplevel`)
echo -ne "Initializing $REPONAME . . . "
sed -i "s/REPLACEREPONAME/${REPONAME}/g" *.* > /dev/null 2>&1
sed -i "s/REPLACEREPONAME/${REPONAME}/g" supplemental-ui/partials/header-content.hbs > /dev/null 2>&1
echo -e "done"
mv -f README-TRAINING.md README.md
}
validate_args()
{
case "$LAB" in
"demo"|"role"|"other" )
;;
* )
echo -e "ERROR: Invalid lab type: $LAB"
print_usage
exit 1
;;
esac
case "$TYPE" in
"hol"|"bfx" )
;;
* )
echo -e "ERROR: Invalid course type: $TYPE"
print_usage
exit 1
;;
esac
execute_init
echo -e "Initialized type to $TYPE and lab to $LAB "
exit_script
}
cleanup()
{
# Clean unused files for lab type
rm -f modules/LABENV/pages/index-*.adoc
# Clean unused files for course type
# Remove this script
rm -f $0
}
## Start by validating provided options and initializing variables for arguments
if [ $# -lt 4 ]
then
echo -e "ERROR: Insufficient arguments"
print_usage
exit 1
fi
for arg in "$@"
do
case ${arg} in
"--lab" )
shift
LAB=$(echo $1)
shift
;;
"--type" )
shift
TYPE=$(echo $1)
shift
;;
"--help" )
print_usage
exit 0
;;
esac
done
validate_args