-
Notifications
You must be signed in to change notification settings - Fork 0
/
ddns-start
executable file
·39 lines (36 loc) · 1.31 KB
/
ddns-start
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
#!/bin/bash
IP=$1
source .config
echo "start ddns" > ddns.log
echo "the new ip is $IP" >> ddns.log
if [ -z $IP ]; then
echo "can not get ip, quit" >> ddns.log
exit 1
fi
SHA=`curl -s -k github.pem -u $GITHUB_U:$GITHUB_P https://api.github.com/repos/Apache9/IP/contents/R6300V2 | grep '"sha":' | awk '{print $2}' | awk -F\" '{print $2}'`
if [ ${#SHA} != 40 ]; then
echo "can not get sha of the file, quit" >> ddns.log
exit 1
fi
BASE64_IP=`echo $IP | openssl enc -base64`
DATE=`LC_ALL=en_US.utf8 date`
sed "s/{date}/$DATE/g; s/{content}/$BASE64_IP/g; s/{sha}/$SHA/g;" template.json > request.json
SC=`curl -s -k github.pem -u $GITHUB_U:$GITHUB_P -X PUT -H "Content-Type: application/json" -d '@request.json' -w "%{http_code}" "https://api.github.com/repos/Apache9/IP/contents/R6300V2"`
LEN=`echo ${#SC}`
let START=LEN-3
SC=`echo ${SC:$START:3}`
if [ "$SC" != "200" ]; then
echo "failed to update ip to github, quit" >> ddns.log
exit 1
fi
echo "successfully update ip to github" >> ddns.log
SC=`curl -s -X GET -w "%{http_code}" 'http://$NOIP_U:[email protected]/nic/update?hostname=$NOIP_H&myip=$IP'`
LEN=`echo ${#SC}`
let START=LEN-3
SC=`echo ${SC:$START:3}`
if [ "$SC" != "200" ]; then
echo "failed to update ip to no-ip, quit" >> ddns.log
exit 1
fi
echo "successfully update ip to no-ip" >> ddns.log
exit 0