-
Notifications
You must be signed in to change notification settings - Fork 2
/
entrypoint.sh
executable file
·88 lines (84 loc) · 2.33 KB
/
entrypoint.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/bin/sh
# e is for exiting the script automatically if a command fails, u is for exiting if a variable is not set
# x would be for showing the commands before they are executed
set -eu
# Function for setting up git env in the docker container (copied from https://github.com/stefanzweifel/git-auto-commit-action/blob/master/entrypoint.sh)
_git_setup ( ) {
cat <<- EOF > $HOME/.netrc
machine github.com
login $GITHUB_ACTOR
password ${{ secrets.GITHUB_TOKEN }}
machine api.github.com
login $GITHUB_ACTOR
password ${{ secrets.GITHUB_TOKEN }}
EOF
chmod 600 $HOME/.netrc
git config --global user.email "[email protected]"
git config --global user.name "GitHub Action"
}
while test $# -gt 0; do
case "$1" in
-h|--help)
echo "options:"
echo "-h, --help show brief help"
echo "-i, --input-dir=DIR specify a directory to take input from"
echo "-o, --output-dir=DIR specify a directory to store output in"
echo "-t, --template=DIR specify a template for Pandoc to use"
exit 0
;;
-i)
shift
if test $# -gt 0; then
export INPUT_DIRECTORY=$1
else
echo "no input dir specified"
exit 1
fi
shift
;;
--input-dir*)
export INPUT_DIRECTORY=`echo $1 | sed -e 's/^[^=]*=//g'`
shift
;;
-o)
shift
if test $# -gt 0; then
export OUTPUT_DIRECTORY=$1
else
echo "no output dir specified"
exit 1
fi
shift
;;
--output-dir*)
export OUTPUT_DIRECTORY=`echo $1 | sed -e 's/^[^=]*=//g'`
shift
;;
-t)
shift
if test $# -gt 0; then
export TEMPLATE_FILE=$1
fi
shift
;;
--template*)
export TEMPLATE_FILE=`echo $1 | sed -e 's/^[^=]*=//g'`
shift
;;
*)
break
;;
esac
done
mkdir -p $OUTPUT_DIRECTORY
if ls $INPUT_DIRECTORY/*.md ; then
find $INPUT_DIRECTORY -type f -name '*.md' -print0 | xargs -0 -n1 basename | xargs -P2 -I{} pandoc "$INPUT_DIRECTORY/{}" --template="$TEMPLATE_FILE" -o "$OUTPUT_DIRECTORY/{}.pdf"
_git_setup
echo "Committing and pushing changes..."
git add $OUTPUT_DIRECTORY
git commit -m "Compiled PDFs"
git push origin
echo "Changes pushed successfully."
else
echo "No files in input directory."
fi