-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaeamerge
More file actions
executable file
·157 lines (125 loc) · 4.1 KB
/
aeamerge
File metadata and controls
executable file
·157 lines (125 loc) · 4.1 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
#!/bin/bash
os=$(uname)
apperror=0
#set -e
CSSURL=https://gist.githubusercontent.com/dashed/6714393/raw/ae966d9d0806eb1e24462d88082a0264438adc50/github-pandoc.css
CSSLOCAL=.local.css
WKHTMLOPTS="-V margin-top=1in -V margin-left=1in -V margin-right=1in -V margin-bottom=1in"
ICPSRMSG="Details in the full report, which you will receive via ScholarOne shortly. Please provide your response to the items listed above via the openICPSR Project Communication log, specifying AEAREP-xxx. Other items in the report may need to be addressed via ScholarOne."
# print help
cat << EOF
$0 (name of extra file)
This script will take 'REPLICATION.md', transform it into a PDF,
save it as REPLICATION.raw.pdf, then merge it with the second
argument to create REPLICATION.pdf.
You will need to then run 'aeaready' with the 'nopdf' option.
EOF
exit_on_error() {
exit_code=$1
exit_message=${@:2}
if [ $exit_code -ne 0 ]; then
>&2 echo "${exit_message}, exit code ${exit_code}."
exit $exit_code
fi
}
# rest of the stuff
case $os in
Linux)
echo "OK"
;;
*)
echo "This script only works on Linux"
;;
esac
nopdf=0
if [[ "$1" == "nopdf" ]]
then
nopdf=1
shift
fi
extrafile="$1"
if [[ ! -f "$extrafile" ]]
then
#echo "Need a second argument that is a file"
exit_on_error 2 "Need a second argument that is a file"
fi
set -o history -o histexpand
case $os in
Linux)
pandoc=$(which pandoc)
[[ -f $pandoc ]] || apperror=1
wkhtmltopdf=$(which wkhtmltopdf)
[[ -f $wkhtmltopdf ]] || apperror=1
pdfengine="--pdf-engine wkhtmltopdf"
export QT_STYLE_OVERRIDE=fusion
# get the CSS
curl $CSSURL > $CSSLOCAL && PANDOCXTRA="$WKHTMLOPTS -c $CSSLOCAL"
qpdf=$(which qpdf)
[[ -f $qpdf ]] || apperror=1
;;
Darwin)
# for MacOS, might want to install Rstudio (comes with pandoc) and replace the line above with the outcome of
# find /Applications -name pandoc -type f
pandoc=/Applications/RStudio.app/Contents/MacOS/pandoc/pandoc
# later versions have it bundled in the quarto directory
[[ ! -f $pandoc ]] && pandoc=/Applications/RStudio.app/Contents/MacOS/quarto/bin/pandoc
[[ ! -f $pandoc ]] && pandoc=/Applications/RStudio.app/Contents/MacOS/quarto/bin/tools/pandoc
# let's see if its there
if [[ ! -f $pandoc ]]
then
echo "We suggest using pandoc from the RStudio install. Searching for a different one..."
pandoc=$(find /Applications -name pandoc -type f)
fi
echo "Found pandoc at $pandoc"
# get the CSS
curl $CSSURL > $CSSLOCAL && PANDOCXTRA="$WKHTMLOPTS -c $CSSLOCAL"
;;
*)
echo "Please review the script to define your OS"
apperror=1
;;
esac
# other stuff
if [[ "$apperror" == "1" ]]
then
echo "We need pandoc, wkhtmltopdf, qpdf"
echo "One or the other not found"
case $os in
Darwin)
echo "Install Rstudio to get pandoc"
echo "Try: brew cask install wkhtmltopdf"
;;
*)
echo "Please install"
;;
esac
exit_on_error 2 pandoc wkhtmltopdf or qpdf missing
fi
# update the CSS
if [[ -f $CSSLOCAL ]]
then
echo 'pre, code { white-space: pre-wrap !important; } ' >> $CSSLOCAL
fi
## Test if we are where we think we should be
if [[ ! -d ".git" ]]
then
exit_on_error 2 Not in right directory
fi
if [[ ! -f "REPLICATION.md" ]]
then
exit_on_error 2 Missing REPLICATION.md -required-
fi
# convert to PDF, just in case
# requires: wkhtmltopdf and pandoc
if [[ "$nopdf" == "0" ]]
then
$pandoc $pdfengine REPLICATION.md -f gfm -t html5 -o REPLICATION.raw.pdf --metadata pagetitle="Report for AEAREP-$num" $PANDOCXTRA
else
echo "Skipping PDF generation as requested"
fi
rm $CSSLOCAL
# Merge files
qpdf --empty --pages "REPLICATION.raw.pdf" "$extrafile" -- "REPLICATION.pdf"
[[ -f REPLICATION.pdf ]] || exit_on_error 2 Missing PDF -something went wrong-
echo "-------- Current git status -----------"
git status