forked from gzinck/uw-ethics
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ethics
executable file
·142 lines (110 loc) · 4.69 KB
/
ethics
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
#!/bin/bash
# Pull in the variables from the external file. This should define $FORM_VALUES and $METHOD.
source "$(dirname "$0")/uw-ethics-vars"
CONVERSION_OPTIONS=()
# FIX FOR M1 MACS:
# If you are running on an M1 Mac, you may need to specify the Chromium executable
# in order to convert markdown files to PDF.
if [[ $(uname -m) == 'arm64' ]]; then
CONVERSION_OPTIONS=( --launch-options '{"executablePath": "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome"}' )
fi
# Get the CSS file first
CSS=`which gdoc2pdf | sed 's/bin\/gdoc2pdf/lib\/node_modules\/gdoc2pdf\/src\/styles\/no-h3\.css/'`
CSS_HEADERS=`which gdoc2pdf | sed 's/bin\/gdoc2pdf/lib\/node_modules\/gdoc2pdf\/src\/styles\/with-highlights\.css/'`
# Figure out where pwdiff is for our diffs
PWDIFF="$(dirname "$0")/pwdiff"
PROJTEXT= ""
if [ "$PROJECT_NAME" != "" ]; then
PROJTEXT="$PROJECT_NAME-"
fi
# Create a folder with (optional) project name and date.
FOLDER="output-$PROJTEXT$(date +'%Y-%m-%d-%Hh%M')"
mkdir $FOLDER
echo 'Form values'
gdoc2pdf -f $FORM_VALUES -v none -o "$FOLDER/0-formvals.md"
# If old file exists, use the diff for the PDF generation
if [ -f "$1/0-formvals.md" ]; then
$PWDIFF "$1/0-formvals.md" "$FOLDER/0-formvals.md" > "$FOLDER/0-formvals-final.md"
else
cp "$FOLDER/0-formvals.md" "$FOLDER/0-formvals-final.md"
fi
md-to-pdf --stylesheet $CSS "${CONVERSION_OPTIONS[@]}" "$FOLDER/0-formvals-final.md"
echo 'Method'
gdoc2pdf -f $METHOD -t $TEMPLATE -o "$FOLDER/1-method.md"
if [ -f "$1/1-method.md" ]; then
$PWDIFF "$1/1-method.md" "$FOLDER/1-method.md" > "$FOLDER/1-method-final.md"
else
cp "$FOLDER/1-method.md" "$FOLDER/1-method-final.md"
fi
npx md-to-pdf --stylesheet $CSS "${CONVERSION_OPTIONS[@]}" "$FOLDER/1-method-final.md"
echo 'Consent form'
CONSENT='https://docs.google.com/document/d/1EffPq6GcAEmVJo29hvets215AY3NDxFcM8OahDiTwjk/edit'
gdoc2pdf -f $CONSENT -v $FORM_VALUES -o "$FOLDER/2-consent.md" -c $CSS
if [ -f "$1/2-consent.md" ]; then
$PWDIFF "$1/2-consent.md" "$FOLDER/2-consent.md" > "$FOLDER/2-consent-final.md"
else
cp "$FOLDER/2-consent.md" "$FOLDER/2-consent-final.md"
fi
npx md-to-pdf --stylesheet $CSS "${CONVERSION_OPTIONS[@]}" "$FOLDER/2-consent-final.md"
echo 'Recruitment text'
RECRUIT='https://docs.google.com/document/d/1n45fYI1TSWuzMsQdnvw5j_R3MxF9e2JG_m44yYU1R_o/edit'
gdoc2pdf -f $RECRUIT -v $FORM_VALUES -o "$FOLDER/3-recruit.md" -c $CSS
if [ -f "$1/3-recruit.md" ]; then
$PWDIFF "$1/3-recruit.md" "$FOLDER/3-recruit.md" > "$FOLDER/3-recruit-final.md"
else
cp "$FOLDER/3-recruit.md" "$FOLDER/3-recruit-final.md"
fi
npx md-to-pdf --stylesheet $CSS "${CONVERSION_OPTIONS[@]}" "$FOLDER/3-recruit-final.md"
echo 'Feedback text'
FEEDBACK='https://docs.google.com/document/d/1atErn8uSQ9JH-3T6JevJTOF4VwzSAmmIvVJfV6ucz4o/edit'
gdoc2pdf -f $FEEDBACK -v $FORM_VALUES -o "$FOLDER/4-feedback.md" -c $CSS
if [ -f "$1/4-feedback.md" ]; then
$PWDIFF "$1/4-feedback.md" "$FOLDER/4-feedback.md" > "$FOLDER/4-feedback-final.md"
else
cp "$FOLDER/4-feedback.md" "$FOLDER/4-feedback-final.md"
fi
npx md-to-pdf --stylesheet $CSS "${CONVERSION_OPTIONS[@]}" "$FOLDER/4-feedback-final.md"
if [ "$ADDITIONAL_FILES" != "CHANGEME" ]; then
echo 'Appending file(s) at path' $ADDITIONAL_FILES
# If the filepath specified exists...
if [ -e "$ADDITIONAL_FILES" ]; then
# If it's a directory...
if [ -d "$ADDITIONAL_FILES" ]; then
echo "Path is a folder, appending PDFs inside."
# Save old working directory
OLDWD=$PWD
cd "$ADDITIONAL_FILES"
# Add all PDFs in the directory to the working folder
COUNT=0
for FILE in *; do
if [ $(head -c 4 "$FILE") = "%PDF" ]; then
echo "Appending" $FILE
cp -f "$FILE" "$OLDWD/$FOLDER/$(($COUNT+5))-additional-file-$COUNT.pdf"
let "COUNT += 1"
fi
done
cd $OLDWD
#If it's a single PDF...
elif [ $(head -c 4 "$ADDITIONAL_FILES") = "%PDF" ]; then
echo "File at path is a PDF. Appending."
cp "$ADDITIONAL_FILES" "$FOLDER/5-additional-file.pdf"
# If it's not a PDF...
else
ERROR_RED='\033[0;31m'
NC='\033[0m' # No Color
echo -e "${ERROR_RED}File at path is not a PDF. Not appending.${NC}"
fi
# Bad filepath
else
ERROR_RED='\033[0;31m'
NC='\033[0m' # No Color
echo -e "${ERROR_RED}Nothing at path exists. Check your ADDITIONAL_FILES variable.${NC}"
fi
fi
echo 'Combine'
cd $FOLDER
if [ -f 'all.pdf' ]; then
echo 'Deleting old all.pdf...'
rm 'all.pdf'
fi
echo 'all.pdf' | npx pdfmerge-cli@latest -a