-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sh
executable file
·64 lines (53 loc) · 1.87 KB
/
build.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
#!/usr/bin/env bash
###Functions
die () {
#Reedirect stdout to stderr
echo "$@" 1>&2
#exit in an error state, which will cause Jenkins to report the error
exit 1
}
copy_to_target () {
echo "cp $WORKSPACE/$1 $webdirectory/$1"
cp $WORKSPACE/$1 $webdirectory/$1
}
###Variables
#a list containing the output formats
filetypelist="pdf docx epub"
#web-directory
webdirectory="/var/www/html/"
###Initial Tests and corrections
#If we are not running on Jenkins, then $BUILD_NUMBER will not be populated. It is probably on a dev machine for some reason.
if [[ -z $BUILD_NUMBER ]]; then
BUILD_NUMBER=1
fi
#Check for pandoc
pandoc_location=`which pandoc`
if [[ ! -e $pandoc_location ]]; then
die "pandoc does not seem to exist"
fi
###Program
#change the filename because pandoc chokes on special characters.
mv Will_Albenzi*.md Albenzi.md
#Version the files
cat Albenzi.md | sed -e s/JENKINS_BUILD_NUMBER/$BUILD_NUMBER/ > Albenzi.md.new
mv Albenzi.md.new Albenzi.md
#TODO: Add link to where each of the files will be after the build
#Do the conversions. This requires pandoc and a bunch of latex libraries.
pandoc Albenzi.md -o index.html
for filetype in $filetypelist; do
echo "pandoc Albenzi.md -o Albenzi.$filetype"
pandoc Albenzi.md -o Albenzi.$filetype || die "There were errors building Albenzi.$filetype"
done
#Testing.
#If the Linux Systems Architect position is not listed, do not copy to live website.
if ! grep "<p><strong>Linux Systems Architect" index.html; then
die "We are missing an element that is required in index.html The whole thing is suspect. Do nothing more."
fi
if grep "JENKINS_BUILD_NUMBER" index.html; then
die "We failed to substitute the build number properly in the file. No copying"
fi
#Copy the files to a location they can be used.
copy_to_target "index.html"
for filetype in $filetypelist; do
copy_to_target "Albenzi.$filetype"
done