-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpdf.sh
113 lines (72 loc) · 1.66 KB
/
pdf.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
set -e
STDIN=$(cat -)
URL=$1
source config.sh
if [ $# -lt 1 ] ; then
cat << EOF
Provide at least one argument (url), like:
/bin/bash $0 \"http://google.com\"
You can also specify output file name:
/bin/bash $0 \"http://google.com\" pdf.pdf
default is "$TMPFILE"
Full examples:
/bin/bash pdf.sh "https://www.google.com/search?ncr=&q=puppeteer"
/bin/bash pdf.sh "https://www.google.com/search?ncr=&q=puppeteer" pdf.pdf
EOF
exit 1;
fi
if [ ! $# -lt 2 ] ; then
TMPFILE="$2"
fi
URLMATCH="^https?://.*"
if [[ $URL =~ $URLMATCH ]]; then
true
else
echo "$URL is not valid url";
exit 1;
fi
# export SCRIPT=$(cat <<END
# docker build -t $DOCKERIMAGE . 2>&1
# END
# );
# set +e
# OUTPUT=$(eval $SCRIPT 2>&1);
# STATUS="$?"
# set -e
# if [ "$STATUS" != "0" ]; then
#
# echo -e "for url: 'build process failed code:$STATUS\nstdout:>>>>$OUTPUT<<<\n\n"
#
# exit 1
# fi
rm -rf $TMPFILE;
export SCRIPT=$(cat <<END
docker run \
--env P_URL="$URL" \
--env P_TMPFILE="$TMPFILE" \
--env P_JSON="$STDIN" \
-t \
--rm \
--cap-add=SYS_ADMIN \
-v $(pwd):/app/app \
$DOCKERIMAGE \
node -e "\$(cat script.js)" 2>&1
END
);
printf "\n"
echo $SCRIPT;
printf "\n"
set +e
OUTPUT=$(eval $SCRIPT 2>&1);
STATUS="$?"
set -e
if [ "$STATUS" != "0" ]; then
echo -e "for url: '$URL' receive process code != 0\nprocess code:$STATUS\nstdout:>>>>$OUTPUT<<<\n\n"
exit 1
fi
if [ ! -f $TMPFILE ]; then
echo "file '$TMPFILE' was not created for url '$URL'"
echo "OUTPUT: >>>$OUTPUT<<<"
exit 1
fi
echo -e "$(date +"%Y-%m-%d %H:%M:%S"): file '$TMPFILE' generated for url '$URL' - script didn't crashed";