Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
galaxyproject
GitHub Repository: galaxyproject/training-material
Path: blob/main/bin/knit-automated.sh
1677 views
1
#!/bin/bash
2
DIR=/tmp/git-gat
3
op="$1"
4
5
declare -a tutorials
6
tutorials=(admin/ansible-galaxy admin/backup-cleanup admin/customization admin/tus admin/cvmfs admin/apptainer admin/tool-management admin/data-library admin/connect-to-compute-cluster admin/job-destinations admin/pulsar admin/celery admin/reports admin/monitoring admin/tiaas admin/sentry admin/ftp admin/beacon)
7
#tutorials=(admin/wireguard-headscale)
8
#tutorials=(admin/wireguard)
9
10
#echo "${tutorials[0]}"
11
#exit 1;
12
if [[ "$op" == "export" ]]; then
13
rm -rf "${DIR}"
14
mkdir -p "${DIR}"
15
mkdir -p "${DIR}/.scripts"
16
17
# Setup readme as the root commit
18
19
cat > ${DIR}/0-commit-0000-root-commit.patch <<-EOF
20
From: The Galaxy Training Network <[email protected]>
21
Date: Mon, 15 Feb 2021 14:06:56 +0100
22
Subject: admin/init/0000: Root commit
23
24
25
--- /dev/null
26
+++ b/readme.md
27
@@ -0,0 +1,11 @@
28
+# GIT-GAT
29
+
30
+This is a git repository with the current <abbr title="Galaxy Admin Training">GAT</abbr> history. See the current [GAT schedule](https://gxy.io/gat).
31
+
32
+This is built from [the GTN's library of admin training](https://training.galaxyproject.org/training-material/topics/admin/)
33
+
34
+Extra | Data
35
+--- | ---
36
+Date | $(date --rfc-3339=seconds)
37
+Github Run ID | [$GITHUB_RUN_ID](https://github.com/galaxyproject/training-material/actions/runs/$GITHUB_RUN_ID)
38
+GTN Commit | [$GITHUB_SHA](https://github.com/galaxyproject/training-material/tree/$GITHUB_SHA)
39
--
40
2.25.1
41
EOF
42
43
44
# Then do the rest
45
for idx in "${!tutorials[@]}"; do
46
echo "Processing ${tutorials[$idx]}"
47
folder=$(echo "${tutorials[$idx]}" | cut -d / -f 1)
48
tuto=$(echo "${tutorials[$idx]}" | cut -d / -f 2)
49
50
python3 bin/knit-frog.py \
51
topics/${folder}/tutorials/${tuto}/tutorial.md \
52
${DIR}/$(( idx + 10 ))-${tuto};
53
done
54
elif [[ "$op" == "import" ]]; then
55
if [[ ! -d "${DIR}" ]]; then
56
echo "Error, ${DIR} is missing"
57
exit 1
58
fi
59
60
# Store current dir
61
CURRENT_DIR=$(pwd)
62
cd "${DIR}" || exit
63
64
# Export root commit
65
root_commit=$(git log --pretty=oneline | tail -n 1 | cut -f1 -d' ')
66
# Export everything BUT the root commit
67
git format-patch "${root_commit}..HEAD"
68
69
# Go back
70
cd "${CURRENT_DIR}" || exit
71
72
# Import all of the patches
73
for idx in "${!tutorials[@]}"; do
74
folder=$(echo "${tutorials[$idx]}" | cut -d / -f 1)
75
tuto=$(echo "${tutorials[$idx]}" | cut -d / -f 2)
76
77
python3 bin/knit.py \
78
topics/${folder}/tutorials/${tuto}/tutorial.md \
79
--patches ${DIR}/*${folder}-${tuto}*.patch
80
done
81
elif [[ "$op" == "deploy" ]]; then
82
if [[ ! -d "${DIR}" ]]; then
83
echo "Error, ${DIR} is missing"
84
exit 1
85
fi
86
87
cd ${DIR} || exit
88
git init && \
89
git add .scripts/
90
git commit -a -m 'Add scripts directory'
91
git am -3 -- *.patch && \
92
git remote add origin [email protected]:hexylena/git-gat.git && \
93
git push -f origin
94
elif [[ "$op" == "roundtrip" ]]; then
95
rm -rf ${DIR}
96
bash $0 export
97
cd ${DIR} || exit
98
git init && git config --local --add commit.gpgsign false && \
99
git am -3 -C2 -- *.patch
100
cd -
101
bash $0 import
102
elif [[ "$op" == "check-offsets" ]]; then
103
for idx in "${!tutorials[@]}"; do
104
folder=$(echo "${tutorials[$idx]}" | cut -d / -f 1)
105
tuto=$(echo "${tutorials[$idx]}" | cut -d / -f 2)
106
n2=$(( idx + 1 ))
107
echo $idx $folder $tuto = $n2
108
grep "snippet topics/admin/faqs/missed-something.md step=$n2" topics/${folder}/tutorials/${tuto}/tutorial.md -q
109
if (( $? != 0 )); then
110
echo "Error, topics/${folder}/tutorials/${tuto}/tutorial.md is missing a snippet for step $n2"
111
#exit 1
112
fi
113
#vim topics/${folder}/tutorials/${tuto}/tutorial.md
114
done
115
elif [[ "$op" == "fix-offsets" ]]; then
116
for idx in "${!tutorials[@]}"; do
117
folder=$(echo "${tutorials[$idx]}" | cut -d / -f 1)
118
tuto=$(echo "${tutorials[$idx]}" | cut -d / -f 2)
119
n2=$(( idx + 1 ))
120
echo -n "$folder/$tuto should be $n2 "
121
grep "snippet topics/admin/faqs/missed-something.md step=$n2" topics/${folder}/tutorials/${tuto}/tutorial.md -q
122
if (( $? != 0 )); then
123
echo "Fixed!"
124
sed -i -r 's|topics/admin/faqs/missed-something.md step=[0-9]+|topics/admin/faqs/missed-something.md step='$n2'|' topics/${folder}/tutorials/${tuto}/tutorial.md
125
else
126
echo "Already correct"
127
fi
128
#vim topics/${folder}/tutorials/${tuto}/tutorial.md
129
done
130
elif [[ "$op" == "edit" ]]; then
131
files=""
132
for idx in "${!tutorials[@]}"; do
133
folder=$(echo "${tutorials[$idx]}" | cut -d / -f 1)
134
tuto=$(echo "${tutorials[$idx]}" | cut -d / -f 2)
135
files="$files topics/${folder}/tutorials/${tuto}/tutorial.md"
136
done
137
$EDITOR $files
138
else
139
echo "$0 <import|export|deploy|roundtrip|check-offsets|fix-offsets|edit>"
140
exit 1;
141
fi
142
143
144
145