This repository has been archived by the owner on Jul 2, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpandocDownload2zip.sh
executable file
·135 lines (127 loc) · 3.47 KB
/
pandocDownload2zip.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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#!/usr/bin/env bash
# usage: VERSION=1.19.1 DEBUG=true source ./pandocDownload2zip.sh # source for running it in the current shell such that the variables can be obtained
# Notes:
# installing dependencies
## Linux: `sudo apt-get install p7zip-full msitools`, msitools requires ubuntu>=16.04
## macOS: `brew install msitools`
# debug msg
if [[ "$DEBUG" == "true" ]]; then
echo "Processing pandoc version $VERSION"
fi
# url to pandoc version
url="https://github.com/jgm/pandoc/releases/tag/$VERSION"
# debug msg
if [[ "$DEBUG" == "true" ]]; then
echo "Obtaining binaries from $url"
fi
# get url to pandoc binaries
html=$(curl -L --fail "$url")
if [[ $? != 0 ]]; then
echo "Cannot retrieve $url. Check if version $VERSION is valid."
exit 1
fi
debUrlPartial=$(printf '%s' "$html" | grep -o '/jgm/pandoc/releases/download/.*\.deb')
pkgUrlPartial=$(printf '%s' "$html" | grep -o '/jgm/pandoc/releases/download/.*\.pkg')
msiUrlPartial=$(printf '%s' "$html" | grep -o '/jgm/pandoc/releases/download/.*\.msi')
zipUrlPartial=$(printf '%s' "$html" | grep -o '/jgm/pandoc/archive/.*\.zip')
tarUrlPartial=$(printf '%s' "$html" | grep -o '/jgm/pandoc/archive/.*\.tar\.gz')
# debug msg
if [[ "$DEBUG" == "true" ]]; then
echo "URL to deb: $debUrlPartial"
echo "URL to pkg: $pkgUrlPartial"
echo "URL to msi: $msiUrlPartial"
echo "URL to source code in zip: $zipUrlPartial"
echo "URL to source code in tar.gz: $tarUrlPartial"
fi
# prepare dist folder
mkdir -p dist
# download and extract
## Linux
if [[ ! -z "$debUrlPartial" ]]; then
# variables
debUrl="https://github.com$debUrlPartial"
DEB="${debUrl##*/}"
debWoExt="${DEB%.*}"
debZip="$debWoExt.zip"
# download
wget "$debUrl"
# unpack
ar x "$DEB" data.tar.gz && mv data.tar.gz "$debWoExt.tar.gz"
tar -zxvf "$debWoExt.tar.gz" && mv usr "$debWoExt"
# zip
zip -r "$debZip" "$debWoExt"
# to dist/
mv "$DEB" dist/
mv "$debZip" dist/
mv "$debWoExt.tar.gz" dist/
else
echo "deb package not found"
fi
## macOS
if [[ ! -z "$pkgUrlPartial" ]]; then
# variables
pkgUrl="https://github.com$pkgUrlPartial"
PKG="${pkgUrl##*/}"
pkgWoExt="${PKG%.*}"
pkgZip="$pkgWoExt.zip"
# download
wget "$pkgUrl"
# unpack
if [[ `uname` == "Darwin" ]]; then
mkdir "$pkgWoExt-pkg" && xar -xf "$PKG" -C "$pkgWoExt-pkg"
else
7z x "$PKG" -o"$pkgWoExt-pkg"
fi
cat "$pkgWoExt-pkg/pandoc.pkg/Payload" | gunzip -dc |cpio -i && mv usr "$pkgWoExt"
# zip
zip -r "$pkgZip" "$pkgWoExt"
# to dist/
mv "$PKG" dist/
mv "$pkgZip" dist/
else
echo "pkg package not found"
fi
## Windows
if [[ ! -z "$msiUrlPartial" ]]; then
# variables
msiUrl="https://github.com$msiUrlPartial"
MSI="${msiUrl##*/}"
msiWoExt="${MSI%.*}"
msiZip="$msiWoExt.zip"
# download
wget "$msiUrl"
# unpack
msiextract "$MSI" && mv "Program Files/Pandoc" "$msiWoExt" && rm -rf "Program Files"
# zip
zip -r "$msiZip" "$msiWoExt"
# to dist/
mv "$MSI" dist/
mv "$msiZip" dist/
else
echo "msi package not found"
fi
## Source Code
### .zip
if [[ ! -z "$zipUrlPartial" ]]; then
# variables
zipUrl="https://github.com$zipUrlPartial"
ZIP="${zipUrl##*/}"
# download
wget "$zipUrl"
# rename & to dist/
mv "$ZIP" "dist/pandoc-source-code-$ZIP"
else
echo "source code not found in zip"
fi
### .tar.gz
if [[ ! -z "$tarUrlPartial" ]]; then
# variables
tarUrl="https://github.com$tarUrlPartial"
TAR="${tarUrl##*/}"
# download
wget "$tarUrl"
# rename & to dist/
mv "$TAR" "dist/pandoc-source-code-$TAR"
else
echo "source code not found in tag.gz"
fi