forked from CarpentriesMagic/WorkshopAdmin
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbash.sh
More file actions
executable file
·159 lines (138 loc) · 5.29 KB
/
bash.sh
File metadata and controls
executable file
·159 lines (138 loc) · 5.29 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
#!/bin/bash
## syntax: bash.sh [slug] [organisation] [username] [password]
## [slug] in the format of YYYY-MM-DD-Org
## [organisation] is the GitHub organisation in which the repository is
if [[ -z "${1}" || -z "${2}" || -z "${3}" || -z "${4}" ]]
then
echo "Syntax: bash.sh [slug] [organisation]"
echo "[slug] in the format of YYYY-MM-DD-Org"
echo "[organisation] is the GitHub organisation in which the repository is"
echo "[username] is the username of the database"
echo "[password] is the password for the database"
else
export GH_TOKEN=`cat gh_token`
# ORGANISATION=NclRSE-Training
ORGANISATION=$2
DB_CLIENT='mysql'
DB_USER=${3}
DB_PASSWD=${4}
VENUE="Newcastle University"
# sql:
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 $SCRIPT1 > script1.sql
echo $SCRIPT2 > script2.sql
echo $SCRIPT3 > script3.sql
echo $SCRIPT4 > script4.sql
RESULT1="$(${DB_CLIENT} --host=localhost --skip-column-names --user=${DB_USER} --password=${DB_PASSWD} workshopadmin < script1.sql)"
RESULT2="$(${DB_CLIENT} --host=localhost --skip-column-names --user=${DB_USER} --password=${DB_PASSWD} workshopadmin < script2.sql)"
RESULT3="$(${DB_CLIENT} --host=localhost --skip-column-names --user=${DB_USER} --password=${DB_PASSWD} workshopadmin < script3.sql)"
RESULT4="$(${DB_CLIENT} --host=localhost --skip-column-names --user=${DB_USER} --password=${DB_PASSWD} workshopadmin < script4.sql)"
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`
cat <<EOM >index.inc
venue: "${VENUE}, ${ADDRESS}"
address: "${ADDRESS}"
country: "${COUNTRY}"
language: "${LANGUAGE}"
latitude: "${LATITUDE}"
longitude: "${LONGITUDE}"
humandate: "${HUMANDATE}"
humantime: "${HUMANTIME}"
startdate: ${STARTDATE}
enddate: ${ENDDATE}
instructor: [`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: [`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: [`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"`]
collaborative_notes: https://hackmd.io/@rseteam/${SLUG}
eventbrite: ${EVENTBRITE}
what3words: ${WHATTHREEWORDS}
EOM
if [ $PILOT == 1 ]
then
P="true"
else
P="false"
fi
cat <<EOM >config.inc
carpentry: "${CARPENTRY}"
curriculum: "${CURRICULUM}"
flavor: "${FLAVOUR}"
pilot: ${P}
title: "${TITLE}"
EOM
if [ $PILOT == 1 ]
then
cat <<EOM >>config.inc
incubator_lesson_site: "${INC_LESSON_SITE}"
incubator_pre_survey: "${PRE_SURVEY}"
incubator_post_survey: "${POST_SURVEY}"
EOM
fi
echo Log into GitHub
gh auth login
echo Create website from template
gh repo create ${ORGANISATION}/${SLUG} --template carpentries/workshop-template --public --description "${TITLE}"
echo Edit the URL for GitHub Pages
gh repo edit ${ORGANISATION}/${SLUG} --homepage "${ORGANISATION}.github.io/${SLUG}"
echo Clone the repo
gh repo clone git@github.com:${ORGANISATION}/${SLUG}.git ../${SLUG}
echo Delete lines 213 to 263
sed -i '213,263d' ../${SLUG}/index.md
echo Insert requirements.inc after line 213 of index.md
sed -i '213r requirements.inc' ../${SLUG}/index.md
echo Delete lines 38 to 58
sed -i '38,58d' ../${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
if [ ${SCHEDULE} != "na" ]
then
cp schedules/${SCHEDULE}.html ../${SLUG}/_includes/${CARPENTRY}/schedule.html
fi
echo Delete temporary files
rm script?.sql
echo Commit changes to repository
cd ../${SLUG}
git add .
git commit -m "Update"
git push
fi