-
Notifications
You must be signed in to change notification settings - Fork 0
/
update_telegram_cli.sh
61 lines (56 loc) · 1.34 KB
/
update_telegram_cli.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
#!/bin/bash
SendMessage() {
cd /opt/tg
(echo "contact_list" ; echo "msg Jaehyun_Jang $1 $2"; echo "safe_quit") | ./bin/telegram-cli -k ./tg-server.pub -W
}
#Notification for each repo
InitialNoti() {
GITFILE="/.git"
sudo git --git-dir=$1$GITFILE fetch origin
RESLOG=$(sudo git --git-dir=$1$GITFILE log HEAD..origin/master --oneline)
if [[ "${RESLOG}" != "" ]]; then
echo $RESLOG
else
RESLOG=""
echo ""
fi
}
Notification() {
GITFILE="/.git"
sudo git --git-dir=$1$GITFILE fetch origin
RESLOG=$(sudo git --git-dir=$1$GITFILE log HEAD..origin/master --oneline)
if [[ $RESLOG=$2 ]]; then
echo $RESLOG
else
if [[ "${RESLOG}" != "" ]]; then
echo $RESLOG
else
RESLOG=""
echo $RESLOG
fi
fi
}
while read folder; do
i=0
if [ -a "$folder/.hashes" ]; then
while read -r repo && read -r hash <&3; do
RETVAL=$(Notification $folder$repo $hash)
hashes[$i]=$RETVAL
if [[ "${RETVAL}" != "" && "${RETVAL}" != "$hash" ]]; then
SendMessage $folder$repo "${RETVAL}"
fi
i=$(($i+1))
done < "$folder/.repos" 3<"$folder/.hashes"
else
while read -r repo; do
RETVAL=$(InitialNoti $folder$repo)
hashes[$i]=$RETVAL
if [[ "${RETVAL}" != "" ]]; then
SendMessage $folder$repo "${RETVAL}"
fi
i=$(($i+1))
done < "$folder/.repos"
fi
sudo printf "%s\n" "${hashes[@]}" > "$folder/.hashes"
unset hashes
done < "./.folders"