forked from NclRSE-Training/WorkshopAdmin
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbash.sh
More file actions
executable file
·255 lines (232 loc) · 8.33 KB
/
Copy pathbash.sh
File metadata and controls
executable file
·255 lines (232 loc) · 8.33 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
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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
#!/bin/bash
## syntax: bash.sh [spreadsheet.csv]
# READ CONFIGURATION FILE
source includes/db_config.inc
echo "Data source: ${DATA}"
echo "DB Client: ${DB_CLIENT}"
echo "DB_Host: ${DB_HOST}"
echo "Database name: ${DB_NAME}"
echo "Connection string: ${DB_STRING}"
# function to make a python style list from comma separated values
# e.g. input is John Doe, Jane Doe and the output is [ "John Doe", "Jane Doe" ]
make_list() {
count=$[`echo $1 | awk -F, '{print NF-1}'`+1]
LIST="[ "
for i in `seq 1 $count`
do
ITEM=`echo $1 | cut -d, -f$i`
if [ "$i" = "1" ]
then
LIST=$LIST' "'$ITEM'"'
else
LIST=$LIST', "'$ITEM'"'
fi
done
LIST=$LIST' ]'
echo $LIST
}
# LOG INTO GITHUB
if [ -f ~/.ssh/gh_token ]
then
cat ~/.ssh/gh_token
export GH_TOKEN=`cat ~/.ssh/gh_token`
else
GH_TOKEN=`gh auth token`
fi
if [ $? != "0" ]
then
echo -e "Please login to github command line by running:\n\t gh auth login\n"
exit 1
fi
##### SQL OPTION TO STORING DATA #####
if [[ ${DATA} == "sql" ]]
then
if [[ -z ${1} ]]
then
echo "Syntax: bash.sh [slug]"
exit 1
fi
SCRIPT0="select organisation, venue from settings;"
SCRIPT0A="select value from settings where keyvalue='organisation'"
SCRIPT0B="select value from settings where keyvalue='venue'"
SCRIPT0C="select value from settings where keyvalue='collabdoc'"
SCRIPT1="select slug, w.title, humandate, humantime, startdate, enddate, r.description, r.longitude, r.latitude, language, country, online, pilot, inc_lesson_site, pre_survey, post_survey, carpentry_code, curriculum_code, flavour_id, eventbrite, inc_lesson_site, pre_survey, post_survey, r.what_three_words, schedule \
from workshops as w \
join room as r on w.room_id=r.room_id \
where w.slug=\"${1}\";"
SCRIPT2="select p.title, p.firstname, p.lastname from instructors as i
join people as p on i.person_id=p.person_id \
where slug=\"${1}\""
SCRIPT3="select p.title, p.firstname, p.lastname from helpers as h
join people as p on h.person_id=p.person_id \
where slug=\"${1}\""
SCRIPT4="select p.email from emails as e
join people as p on e.person_id=p.person_id \
where slug=\"${1}\""
echo $SCRIPT0A
echo $SCRIPT0A > script0a.sql
echo $SCRIPT0B > script0b.sql
echo $SCRIPT0C > script0c.sql
echo $SCRIPT1 > script1.sql
echo $SCRIPT2 > script2.sql
echo $SCRIPT3 > script3.sql
echo $SCRIPT4 > script4.sql
# RESULT0A="$(${DB_CLIENT} --host=${DB_HOST} --skip-column-names --user=${DB_USER} --password=${DB_PASSWD} workshopadmin < script0a.sql)"
echo "Script0a: ${DB_STRING}< script0a.sql"
RESULT0A="$(${DB_STRING}< script0a.sql)"
echo "Result of script0a: ${RESULT0A}"
RESULT0B="$(${DB_STRING}< script0b.sql)"
RESULT0C="$(${DB_STRING}< script0c.sql)"
RESULT1="$(${DB_STRING}< script1.sql)"
RESULT2="$(${DB_STRING}< script2.sql)"
RESULT3="$(${DB_STRING}< script3.sql)"
RESULT4="$(${DB_STRING}< script4.sql)"
ORGANISATION=`echo "$RESULT0A"`
VENUE=`echo "$RESULT0B"`
SLUG=`echo "$RESULT1"|cut -f1`
TITLE=`echo "$RESULT1"|cut -f2`
ADDRESS=`echo "$RESULT1"|cut -f7`
COUNTRY=`echo "$RESULT1"|cut -f11`
LANGUAGE=`echo "$RESULT1"|cut -f10`
LATITUDE=`echo "$RESULT1"|cut -f9`
LONGITUDE=`echo "$RESULT1"|cut -f8`
HUMANDATE=`echo "$RESULT1"|cut -f3`
HUMANTIME=`echo "$RESULT1"|cut -f4`
STARTDATE=`echo "$RESULT1"|cut -f5`
ENDDATE=`echo "$RESULT1"|cut -f6`
INSTRUCTORS=`echo "$RESULT2"`
EVENTBRITE=`echo "$RESULT1"|cut -f20`
PILOT=`echo "$RESULT1"|cut -f13`
CARPENTRY=`echo "$RESULT1"|cut -f17`
CURRICULUM=`echo "$RESULT1"|cut -f18`
FLAVOUR=`echo "$RESULT1"|cut -f19`
TITLE=`echo "$RESULT1"|cut -f2`
INC_LESSON_SITE=`echo "$RESULT1"|cut -f21`
PRE_SURVEY=`echo "$RESULT1"|cut -f22`
POST_SURVEY=`echo "$RESULT1"|cut -f23`
WHATTHREEWORDS=`echo "$RESULT1"|cut -f24`
SCHEDULE=`echo "$RESULT1"|cut -f25`
INSTRUCTOR_LIST=[`echo -e "$RESULT2"|sed "s/\t/ /g"|sed -e "s/^[ \t]*//g"|sed -e "s/^/\"/g"|sed -e "s/$/\"/g"|sed ':a;N;$!ba;s/\n/, /g'|sed -e "s/^[ ]*//g"`]
HELPER_LIST=[`echo -e "$RESULT3"|sed "s/\t/ /g"|sed -e "s/^[ \t]*//g"|sed -e "s/^/\"/g"|sed -e "s/$/\"/g"|sed ':a;N;$!ba;s/\n/, /g'|sed -e "s/^[ ]*//g"`]
EMAIL_LIST=[`echo -e "$RESULT4"|sed "s/\t/ /g"|sed -e "s/^[ \t]*//g"|sed -e "s/^/\"/g"|sed -e "s/$/\"/g"|sed ':a;N;$!ba;s/\n/, /g'|sed -e "s/^[ ]*//g"`]
else
##### CSV (semi-colon) OPTION TO STORING DATA #####
if [[ -z "${1}" ]]
then
echo "Syntax: bash.sh [spreadsheet.csv]"
else
RESULT=`tail -1 $1`
echo $RESULT
fi
ORGANISATION=`echo "$RESULT"|cut -d';' -f1`
VENUE=`echo "$RESULT"|cut -d';' -f2`
SLUG=`echo "$RESULT"|cut -d';' -f3`
TITLE=`echo "$RESULT"|cut -d';' -f4`
ADDRESS=`echo "$RESULT"|cut -d';' -f5`
COUNTRY=`echo "$RESULT"|cut -d';' -f6`
LANGUAGE=`echo "$RESULT"|cut -d';' -f7`
LATITUDE=`echo "$RESULT"|cut -d';' -f8`
LONGITUDE=`echo "$RESULT"|cut -d';' -f9`
HUMANDATE=`echo "$RESULT"|cut -d';' -f10`
HUMANTIME=`echo "$RESULT"|cut -d';' -f11`
STARTDATE=`echo "$RESULT"|cut -d';' -f12`
ENDDATE=`echo "$RESULT"|cut -d';' -f13`
INSTRUCTORS=`echo "$RESULT" | cut -d';' -f14`
EVENTBRITE=`echo "$RESULT"|cut -d';' -f15`
PILOT=`echo "$RESULT"|cut -d';' -f16`
CARPENTRY=`echo "$RESULT"|cut -d';' -f17`
CURRICULUM=`echo "$RESULT"|cut -d';' -f18`
FLAVOUR=`echo "$RESULT"|cut -d';' -f19`
INC_LESSON_SITE=`echo "$RESULT"|cut -d';' -f20`
PRE_SURVEY=`echo "$RESULT"|cut -d';' -f21`
POST_SURVEY=`echo "$RESULT"|cut -d';' -f22`
WHATTHREEWORDS=`echo "$RESULT"|cut -d';' -f23`
SCHEDULE=`echo "$RESULT"|cut -d';' -f24`
HELPERS=`echo "$RESULT"|cut -d';' -f25`
EMAIL=`echo "$RESULT"|cut -d';' -f26`
HELPER_LIST=$(make_list "$HELPERS")
INSTRUCTOR_LIST=$(make_list "$INSTRUCTORS")
EMAIL_LIST=$(make_list "$EMAIL")
fi
export COLLABDOC=`echo $RESULT0C|sed "s/<slug>/${SLUG}/"`
echo "Collaborative doc ${COLLABDOC}"
cat <<EOM >index.inc
venue: "${VENUE}"
address: "${ADDRESS}"
country: "${COUNTRY}"
language: "${LANGUAGE}"
latitude: "${LATITUDE}"
longitude: "${LONGITUDE}"
humandate: "${HUMANDATE}"
humantime: "${HUMANTIME}"
startdate: ${STARTDATE}
enddate: ${ENDDATE}
instructor: ${INSTRUCTOR_LIST}
helper: ${HELPER_LIST}
email: ${EMAIL_LIST}
collaborative_notes: ${COLLABDOC}
eventbrite: ${EVENTBRITE}
what3words: ${WHATTHREEWORDS}
EOM
P="false"
if [ "$PILOT" = "yes" -o "$PILOT" = "true" -o "$PILOT" = "1" -o "$PILOT" = "True" ]
then
P="true"
else
P="false"
fi
cat <<EOM >config.inc
carpentry: "${CARPENTRY}"
curriculum: "${CURRICULUM}"
flavor: "${FLAVOUR}"
pilot: ${P}
title: "${TITLE}"
EOM
if [ "$P" = "true" ]
then
cat <<EOM >>config.inc
incubator_lesson_site: "${INC_LESSON_SITE}"
incubator_pre_survey: "${PRE_SURVEY}"
incubator_post_survey: "${POST_SURVEY}"
EOM
fi
echo Create website from template
echo gh repo create ${ORGANISATION}/${SLUG} --template carpentries/workshop-template --public --description "${TITLE}"
gh repo create ${ORGANISATION}/${SLUG} --template carpentries/workshop-template --public --description "${TITLE}"
echo Edit the URL for GitHub Pages
echo Organisation: ${ORGANISATION}
echo Slug: ${SLUG}
echo gh repo edit ${ORGANISATION}/${SLUG} --homepage "${ORGANISATION}.github.io/${SLUG}"
gh repo edit ${ORGANISATION}/${SLUG} --homepage "${ORGANISATION}.github.io/${SLUG}"
echo Wait for 10 seconds for repo creating to finish
sleep 10
echo Clone the repo
echo gh repo clone git@github.com:${ORGANISATION}/${SLUG}.git ../${SLUG}
gh repo clone git@github.com:${ORGANISATION}/${SLUG}.git ../${SLUG}
echo Wait 10 seconds for cloning to finish
sleep 10
echo Delete lines 213 to 264
sed -i '213,264d' ../${SLUG}/index.md
echo Insert requirements.inc after line 213 of index.md
sed -i '213r requirements.inc' ../${SLUG}/index.md
echo Delete lines 37 to 61
sed -i '37,61d' ../${SLUG}/index.md
echo Delete lines 6 to 21
sed -i '6,21d' ../${SLUG}/index.md
echo Insert index.inc after line 6 of index.md
sed -i '5r index.inc' ../${SLUG}/index.md
echo Delete lines 8 to 72 in _config.yml
sed -i '8,57d' ../${SLUG}/_config.yml
echo Insert config.inc after line 8 of _config.yml
sed -i '8r config.inc' ../${SLUG}/_config.yml
echo Copy schedule ${SCHEDULE}
echo Copy schedule: ${SCHEDULE}
if [ ${SCHEDULE} != "na" ]
then
cp schedules/${SCHEDULE}.html ../${SLUG}/_includes/${CARPENTRY}/schedule.html
fi
echo Commit changes to repository
cd ../${SLUG}
git add .
git commit -m "Update"
git push