-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathubuntu18.04_amd64_install_wkhtmltopdf.sh
executable file
·54 lines (43 loc) · 1.73 KB
/
ubuntu18.04_amd64_install_wkhtmltopdf.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
#!/bin/bash
# 遇到錯誤就中止
set -e
# 避免有舊版本存在
if ls wkhtmltox_*.bionic_amd64.deb 1> /dev/null 2>&1; then
echo -e "Find order version deb! This shell will remove all of them.\n"
rm wkhtmltox_*.bionic_amd64.deb
fi
# Get deb info from Github api
read -p "Input specific version or leave empty to download latest: " version
if [ -z "$version" ] ; then
# Call Github api to download the latest version deb
url=$(curl -s https://api.github.com/repos/wkhtmltopdf/packaging/releases/latest | sed -r -n 's/.*"browser_download_url": *"(.*\.bionic_amd64\.deb)".*/\1/p')
else
# download specific version which user designates
url=$(curl -s https://api.github.com/repos/wkhtmltopdf/packaging/releases/tags/$version | sed -r -n 's/.*"browser_download_url": *"(.*\.bionic_amd64\.deb)".*/\1/p')
# Older version binary file store in other repo
if [ -z "$url" ] ; then
url=$(curl -s https://api.github.com/repos/wkhtmltopdf/wkhtmltopdf/releases/tags/$version | sed -r -n 's/.*"browser_download_url": *"(.*\.bionic_amd64\.deb)".*/\1/p')
fi
fi
# Check binary file of this version exist or not
if [ -z "$url" ] ; then
echo "Not found! Please check release tag."
exit 1
fi
# download
wget $url
# Let's install it!
sudo dpkg -i wkhtmltox_*.bionic_amd64.deb
# check the default path
echo -e "\n"
if ls /usr/local/bin/wkhtmltopdf 1> /dev/null 2>&1; then
echo -e "The latest wkhtmltopdf now is installed and path is /usr/local/bin/wkhtmltopdf \n\n"
else
echo -e "The latest wkhtmltopdf now is installed. You can use the following command to locate path: \n"
echo -e "\t whereis wkhtmltopdf \n"
echo -e "\n"
fi
# remove the deb file
rm wkhtmltox_*.bionic_amd64.deb
# See you~
echo -e "==========This is the end of this shell script.==========\n\n"