-
Notifications
You must be signed in to change notification settings - Fork 0
/
archtrans.sh
executable file
·45 lines (34 loc) · 1.05 KB
/
archtrans.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
#!/bin/bash
if [ -z "$1" ];then
echo \$1
exit
fi
url=$1
date_now=`date +"%Y%m%d"`
url_arch="https://www.archlinux.org/feeds/news/"
url_archjp="https://www.archlinux.jp/feeds/news.xml"
xml=index.xml
xmljp=news.xml
curl -sL $url_arch -o $xml
curl -sLO $url_archjp
link=`xq a $xml|jq -r ".[0].link"`
link=${link%*/}
linkjp=`xq a $xmljp|jq -r ".[0].link"`
linkjp=${linkjp%*/}
if [ "${link##*/}" != "${linkjp##*/}" ];then
echo slack post webhook
exit
fi
date_xml=$date_now
if [ "$2" != "t" ];then
date_xml=`date --date="$(xq l $xml)" +"%Y%m%d"`
fi
if [ "$date_now" != "$date_xml" ];then
exit
fi
title=`xq a $xml|jq -r ".[0]|.title"`
body=`xq a $xml|jq -r ".[0]|.description"|tr -d '\n'|sed -e 's/<[^>]*>//g'`
echo $title, $body
title_ja=`curl -sL -d "{\"txt\":\"$title\"}" $url`
body_ja=`curl -sL -d "{\"txt\":\"$body\"}" $url|sed 's/'//g'`
curl -sL -X POST --data-urlencode "payload={\"channel\": \"@syui\" , \"username\": \"webhookbot\" , \"text\": \"${link}\n${title}\n${body}\n${title_ja}\n${body_ja}\" , \"icon_emoji\": \":arch:\"}" ${WEBHOOK_SLACK}