forked from emacs-china/elpa
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmake-total-dowloads-badge
executable file
·31 lines (23 loc) · 1.33 KB
/
make-total-dowloads-badge
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
#!/bin/bash
#
# 计算下载量,制作 JSON 和 SVG badge,放到
# https://elpa.zilongshanren.com/downloads
# https://elpa.zilongshanren.com/downloads-badge.svg
#
# 用到 grep, jq, wget, numfmt (part of coreutils)
set -e # Exit immediately if error occurs
cd /tmp
cp -v /var/log/nginx/emacs-china-elpa/access.log elpa-access.log
test -f downloads && downloads_last=$( jq '.downloads' downloads )
downloads=$( grep 'URL/Emacs' elpa-access.log | grep -E 'GET /[^ ]*.(tar|el) ' -c )
test -v downloads_last && downloads_yesterday=$(( $downloads - $downloads_last ))
echo -n "{\"downloads\": $downloads, \"last-update\": \"$( date +"%z %F %T" )\", \"update-period\": \"24 hours\"}" > downloads
downloads_hunman_readable=$( numfmt --to=si $downloads )
test -v downloads_yesterday && downloads_yesterday_human_readable=$( numfmt --to=si $downloads_yesterday )
if test -v downloads_yesterday_human_readable; then
wget --retry-connrefused "https://img.shields.io/badge/downloads-${downloads_hunman_readable}%20total%2C%20${downloads_yesterday_human_readable}%20yesterday-brightgreen.svg" -O downloads-badge.svg
else
wget --retry-connrefused "https://img.shields.io/badge/downloads-${downloads_hunman_readable}%20total-brightgreen.svg" -O downloads-badge.svg
fi
cp -v downloads /var/elpa
cp -v downloads-badge.svg /var/elpa