-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconversion.sh
executable file
·162 lines (132 loc) · 4.3 KB
/
conversion.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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
#!/bin/bash
#=========================================================================
# Copyright 2019 Crunchy Data Solutions, Inc.
#=========================================================================
#==============
# 0) Sources
#==============
if [[ $(pwd) == *"priv-all-portal-docs"* ]]; then
export ETL_PATH=$(echo $(pwd))
else
echo "Error-- $0 must be called from inside the priv-all-portal-docs directory"
exit 1
fi
source etl/common/common.sh
#==============
# 1) Functions
#==============
function usage {
echo ""
echo "Usage: $ ./conversion.sh [project_name] [project_version] [flags] (baseURL)"
echo ""
echo "Example of a command:"
echo ""
echo "./conversion.sh pgaudit 1.3.0 --all /examplesite/project"
echo ""
echo "Available project names:"
echo ""
echo " amcheck_next"
echo " backrest"
echo " crunchy_postgresql_for_pcf"
echo " patroni"
echo " pgadmin4"
echo " pgaudit"
echo " pgaudit_analyze"
echo " pgbadger"
echo " pgbouncer"
echo " pg_partman"
echo " pgjdbc"
echo " pgmonitor"
echo " pgpool"
echo " pgrouting"
echo " pgstigcheck-inspec"
echo " plr"
echo " postgis"
echo " postgres_operator"
echo " postgresql"
echo " psycopg2"
echo " sec_install_n_config"
echo " set_user"
echo ""
echo "Available project versions:"
echo ""
echo " All project versions available to be converted."
echo " Ensure the version number takes the format X.X.X, using periods as separators."
echo ""
echo "Available flags: "
echo ""
echo " --pdf"
echo " --epub"
echo " --html"
echo " --all"
echo ""
echo "If baseURL is not specified, the default of \$PROJECT_NAME/\$PROJECT_VERSION is used."
echo ""
exit 1
}
function remove_project {
# Clean up any and all leftover build artifacts from incomplete builds
if [[ -d ${ETL}/${1}/build ]] || [[ -d ${ETL}/${1}/dst ]]
then
rm -rf ${ETL}/${1}/build ${ETL}/${1}/dst && echo_info "Deleted the build artifacts from the data directory." || echo_err "The build artifacts were not successfully deleted from the data directory."
fi
}
function extract_transform {
# Check if baseURL is specified; if so, set it in load.sh for that project
if [ "$#" -eq 3 ]; then
export PROJECT_BASEURL=$(echo ${2^^}\_BASEURL)
export PROJECT_NAME=$2
export PROJECT_DOCS=$(echo ${PROJECT_NAME} | sed 's/_/-/g')
export PROJECT_VERSION=$3
export ${PROJECT_BASEURL}=${1}/${PROJECT_DOCS}/${PROJECT_VERSION}
elif [ "$#" -eq 2 ]; then
export PROJECT_BASEURL=$(echo ${1^^}\_BASEURL)
export PROJECT_NAME=$1
export PROJECT_DOCS=$(echo ${PROJECT_NAME} | sed 's/_/-/g')
export PROJECT_VERSION=$2
export ${PROJECT_BASEURL}=${ETL_PATH}/docs/${PROJECT_DOCS}/${PROJECT_VERSION}
fi
# Run the conversion script
SET_PROJECT_VERSION=${PROJECT_NAME^^}_VERSION
export ${SET_PROJECT_VERSION}=$(echo $PROJECT_VERSION | sed 's/\./_/g')
mkdir -p ${ETL_PATH}/docs
cd ${ETL}/${PROJECT_NAME} && ./run.sh
}
function load {
# Run load.sh for that project and pass in the flag
cd ${ETL}/${PROJECT_NAME} && ./load.sh ${1}
}
function etl {
# Parameter setup
export PROJECT_NAME=$1
export PROJECT_VERSION=$2
# Clean up build artifacts
remove_project ${PROJECT_NAME} ${PROJECT_VERSION}
# Run the extract and transform scripts
extract_transform ${4} ${PROJECT_NAME} ${PROJECT_VERSION}
# Generate the documentation, choosing whether HTML, PDF, EPUB, or all should be generated
load ${3}
exit
}
#====================
# 2) Install projects
#====================
# A user needs a minimum of 3 flags and shouldn't have more than 4
if [[ "$#" -lt 3 && "$#" -gt 4 ]]; then
echo_err "Invalid number of flags."
usage
fi
# Find all project directories under /etl
# If it exists, run the script; if not, run command guide
AllProjects=( $( find etl -maxdepth 1 -type d ! -name 'common' ! -name 'template' ! -name 'etl' | cut -d "/" -f 2 ) )
for project in "${AllProjects[@]}"; do
if [[ " ${AllProjects[@]} " =~ " ${1} " ]]; then
etl $1 $2 $3 $4
else
usage
fi
done
#====================
# 3) Closing remarks
#====================
echo_info "Done!"