Update Notification Example - XIYO/asuswrt-merlin.ng-kr GitHub Wiki

์•„๋ž˜๋Š” ํ‘ธ์‹œ๋ถˆ๋ฆฟ(Pushbullet), ํ‘ธ์‹œ์˜ค๋ฒ„(Pushover), ๋ฉ”์ผ ์•Œ๋ฆผ ๊ธฐ๋Šฅ์ด ํฌํ•จ๋œ ์—…๋ฐ์ดํŠธ ์•Œ๋ฆผ ์Šคํฌ๋ฆฝํŠธ์˜ ํ•œ๊ตญ์–ด ๋ฒˆ์—ญ๋ณธ์ž…๋‹ˆ๋‹ค. ์Šคํฌ๋ฆฝํŠธ๋Š” ์•„๋ž˜ ์œ„์น˜์— ์ €์žฅํ•˜๊ณ  ์‹คํ–‰ ๊ฐ€๋Šฅํ•˜๊ฒŒ ์„ค์ •ํ•œ ๋‹ค์Œ, ์›นUI์˜ "๋„๊ตฌ > ๊ธฐํƒ€ ์„ค์ •" ๋ฉ”๋‰ด์—์„œ "์ƒˆ ํŽŒ์›จ์–ด ๋ฒ„์ „ ํ™•์ธ"์„ "์˜ˆ"๋กœ ์„ค์ •ํ•˜๋ฉด ๋ฉ๋‹ˆ๋‹ค. ์ด ์Šคํฌ๋ฆฝํŠธ๋Š” 48์‹œ๊ฐ„๋งˆ๋‹ค ํ™•์ธ์„ ์ง„ํ–‰ํ•ฉ๋‹ˆ๋‹ค.

/jffs/scripts/update-notification

chmod +x /jffs/scripts/update-notification

#!/bin/sh
use_email="disabled"                                    # ํ™œ์„ฑํ™” / ๋น„ํ™œ์„ฑํ™” (๊ธฐ๋ณธ๊ฐ’: ๋น„ํ™œ์„ฑํ™”)
use_pushbullet="disabled"                               # ํ™œ์„ฑํ™” / ๋น„ํ™œ์„ฑํ™” (๊ธฐ๋ณธ๊ฐ’: ๋น„ํ™œ์„ฑํ™”)
use_pushover="disabled"                                 # ํ™œ์„ฑํ™” / ๋น„ํ™œ์„ฑํ™” (๊ธฐ๋ณธ๊ฐ’: ๋น„ํ™œ์„ฑํ™”)

# ํ‘ธ์‹œ๋ถˆ๋ฆฟ/ํ‘ธ์‹œ์˜ค๋ฒ„ ์„ค์ •
pushbullet_token=""                                     # ์—ฌ๊ธฐ์— ์ ‘๊ทผ ํ† ํฐ ์ž…๋ ฅ (https://docs.pushbullet.com/)
pushover_token=""                                       # ์—ฌ๊ธฐ์— ์ ‘๊ทผ ํ† ํฐ ์ž…๋ ฅ (https://pushover.net/api)
pushover_username=""                                    # ํ‘ธ์‹œ์˜ค๋ฒ„ ์‚ฌ์šฉ์ž ID (์ด๋ฉ”์ผ ์ฃผ์†Œ๊ฐ€ ์•„๋‹Œ ์‚ฌ์šฉ์ž/๊ทธ๋ฃน ํ‚ค, ์ข…์ข… USER_KEY๋กœ ๋ถˆ๋ฆผ)
# ์ด๋ฉ”์ผ ์„ค์ •
SMTP="smtp.gmail.com"
PORT="465"
USERNAME=""
PASSWORD=""
# ๋ฉ”์ผ ๋ด‰ํˆฌ
FROM_NAME=""
FROM_ADDRESS=""
TO_NAME=""
TO_ADDRESS=""
### ์•„๋ž˜ ๋‚ด์šฉ์€ ๋ณ€๊ฒฝํ•˜์ง€ ๋งˆ์„ธ์š”
# Retrieve version
TMPVERS=$(nvram get webs_state_info)
echo "$TMPVERS" | grep 382
if [ $? -ne 0 ]; then
        VERS=${TMPVERS:5:3}.${TMPVERS:8:10}
else
        VERS=$TMPVERS
fi
ROUTER_IP=$(nvram get lan_ipaddr)

email_message () {
echo "From: \"$FROM_NAME\" <$FROM_ADDRESS>" > /tmp/mail.txt
echo "To: \"$TO_NAME\" <$TO_ADDRESS>" >> /tmp/mail.txt
echo "Subject: New router firmware notification" >> /tmp/mail.txt
echo "" >> /tmp/mail.txt
echo "New firmware version $VERS is now available for your router at $ROUTER_IP." >> /tmp/mail.txt
curl --url smtps://$SMTP:$PORT \
  --mail-from "$FROM_ADDRESS" --mail-rcpt "$TO_ADDRESS" \
  --upload-file /tmp/mail.txt \
  --ssl-reqd \
  --user "$USERNAME:$PASSWORD" --insecure
rm /tmp/mail.txt
}

pushover_message () {
curl -s \
  --form-string "token=$pushover_token" \
  --form-string "user=$pushover_username" \
  --form-string "message=New firmware version $VERS is now available for your router at $ROUTER_IP." \
  https://api.pushover.net/1/messages.json
}

pushbullet_message () {
text="New firmware version $VERS is now available for your router at $ROUTER_IP."
title="$USER@$HOSTNAME"
curl -s -u $pushbullet_token: -X POST https://api.pushbullet.com/v2/pushes --header 'Content-Type: application/json' --data-binary '{"type": "note", "title": "'"$title"'", "body": "'"$text"'"}' >/dev/null 2>&1
}

     if [ $use_pushbullet = "enabled" ]; then
        pushbullet_message
     fi
     if [ $use_pushover = "enabled" ]; then
        pushover_message
     fi
     if [ $use_email = "enabled" ]; then
        email_message
     fi