여리군의 홈페이지~♡

 

 

ASUS TM-AC1900 기가비트 공유기와 WD Elements 포터블 4테라 외장하드 (image from amazon.com)

 

 

이번에 구입한 ASUS TM-AC1900 공유기와 WD Elements Portable 4TB 외장하드를 가지고 간이 NAS를 구성하였습니다.

 

기존에 쓰던 NAS는 WD MyBookLive 인데, 주로 사용하는 기능은 세가지였습니다.

 - transmission으로 자료를 받기

 - 다 받아지면 telegram으로 알려주기

 - 받아진 자료를 U+ TVG UHD 셋탑을 이용해서 시청

 

찾아보니 쉽게 할 수 있는 방법이 있어서 그대로 따라해보았습니다.

 

 

간이 NAS에 transmission 설치 방법은 기존에 TM-AC1900 공유기에 설치한 멀린펌 위키에 해당 내용이 있습니다.

순서는 1. entware설치 -> 2. transmission 설치 입니다.

준비물은 공유기, 외장하드, USB메모리 입니다.

 

* 공유기 간이NAS에 entware 설치 

출처 https://github.com/RMerl/asuswrt-merlin/wiki/Entware

 

1. 저는 USB메모리를 ext2로 포맷해서 각종 설정파일을 저장하는 용도로 사용하고, 외장하드는 다 받아진 자료를 저장하는 용도로만 사용합니다.

별도의 USB메모리가 아니라 외장하드 하나로 구성하실분은 USB메모리 없이 외장하드를 ext4로 포맷하시면 된다고 합니다.

 

2. USB메모리를 ext2로 포맷합니다. (minitool partition wizard를 이용하면 쉽습니다.)

 

3. USB메모리를 공유기 USB 2.0포트에 꼽습니다.

 

4. putty 등의 프로그램으로 공유기 SSH에 접속합니다. 보통 192.168.1.1 입니다.

 

5. entware-setup.sh  라고 입력후 엔터를 누릅니다.

 

6. 설치할 곳을 지정하라고 나오는데, USB메모리만 꼽혀있으므로 1을 누르고 엔터를 누릅니다.

 

7. 끝.

 

6과 7 사이에 뭔가 주르륵 다운도 받고 설치도 하는데, fail 같은 단어만 들어가지 않으면 정상 설치된 겁니다.

usb메모리를 포맷할때 볼륨레이블을 지정했다면 6번에서 /tmp/mnt/sda1 대신에 /tmp/mnt/볼륨명 으로 나옵니다.

제 경우에는 usb16g 로 해놓았습니다. (예시: /tmp/mnt/usb16g)

 

 

* 공유기 간이NAS에 transmission 설치

출처 https://github.com/RMerl/asuswrt-merlin/wiki/Installing-Transmission-through-Entware

 

1. 공유기에 entware가 설치된 USB메모리와 외장하드를 꼽습니다.

 

2. putty 등의 프로그램으로 공유기 SSH에 접속합니다. 보통 192.168.1.1 입니다.

 

3. 아래 명령을 순서대로 입력합니다.

cd /tmp/mnt

ls

 

4. 여기에서 나온 단어를 기억해둡니다. sda1, sdb1이거나, 포맷할때 지정한 볼륨레이블입니다.

제 경우에는 USB메모리는 usb16g, 4테라 외장하드는 Elements 입니다.

 

5. opkg install nano   라고 입력후 엔터를 누릅니다.

텍스트 에디터인 nano가 설치됩니다.

 

6. opkg install transmission-web transmission-daemon-openssl   라고 입력후 엔터를 누릅니다.

transmission이 설치 완료되었습니다. 어??
이게 끝이 아니고, 이제 다운받는 디렉토리, 트랜스미션 로그인 설정 등을 해야 합니다.

 

7. 아래 명령을 순서대로 입력해서 토렌트를 받을 디렉토리를 생성합니다.

mkdir /mnt/usb16g/Torrent/
mkdir /mnt/usb16g/Torrent/Incomplete
mkdir /mnt/usb16g/Torrent/Watch
mkdir /mnt/Elements/Torrent/

저는 외장하드에 자료를 저장할 것이라서 마지막 줄에 Elements에 디렉토리를 생성했습니다.

 

8. 아래 명령을 입력해서 트랜스미션을 멈춥니다. 안멈추면 설정변경이 안됩니다.

/opt/etc/init.d/S88transmission stop

 

9. 아래 명령을 입력해서 설정파일을 수정합니다.

nano -w /opt/etc/transmission/settings.json

 

10. 화살표키를 이용해서 내용을 찾아서 아래 내용대로 수정합니다. 7번에서 입력한 내용이 그대로 들어갑니다.

"download-dir": "/mnt/Elements/Torrent/",
"incomplete-dir": "/mnt/usb16g/Torrent/Incomplete",

"watch-dir": "/mnt/usb16g/Torrent/Watch",

"rpc-authentication-required": true,
"rpc-username": "접속용아이디",
"rpc-password": "접속용패스워드",

 

11. 컨트롤+O, 엔터, 컨트롤+X를 순서대로 눌러서 저장하고 종료합니다.

위 세줄은 다운로드 완료된 파일의 저장경로, 임시파일의 저장경로, 토렌트 시드파일을 올리는 경로이고,

아래 세줄은 웹으로 접속가능여부,  인증 아이디와 패스워드입니다.

패스워드는 한번 실행하고나면 암호화되어 저장됩니다.

 

12. 방화벽 설정을 위해서 아래 명령을 입력합니다.

nano -w /jffs/scripts/firewall-start

 

13. 빈 화면이 나오면 아래 내용을 붙여넣고, 컨트롤+O, 엔터, 컨트롤+X를 순서대로 눌러 저장하고 종료합니다.

#!/bin/sh
iptables -I INPUT -p tcp --destination-port 51413 -j ACCEPT
iptables -I INPUT -p udp --destination-port 51413 -j ACCEPT

 

14.  chmod a+rx /jffs/scripts/firewall-start  를 입력하고 엔터를 눌러 방화벽 설정을 완료합니다.

 

15. 방화벽과 트랜스미션을 즉시 실행하기 위해서 아래 명령을 순서대로 입력합니다.

/jffs/scripts/firewall-start
/opt/etc/init.d/S88transmission start

 

16. 끝!


 

* 부연설명하자면, entware는 각종 프로그램들을 쉽게 설치할 수 있게 해주는 프로그램입니다.

optware가 원조이고, 단점을 개선해서 나온 것이 entware라고 합니다.

그래서 entware를 설치하고, 이를 이용해서 텍스트 에디터인 nano와 transmission을 설치하는 겁니다.

 

* transmission webUI 접속은 http://192.168.1.1:9091 로 해도 되고, 윈도우나 안드로이드용 프로그램을 이용해도 됩니다.

 

* watch디렉토리는 ftp나 윈도탐색기로 토렌트 시드파일을 여기에 놓으면 다운로드가 자동으로 시작되는 기능을 합니다.

 

* 다 받아진 자료는 U+ TVG UHD셋탑에 설치된 kodi를 이용해서 보고 있습니다.

초기 설정이 좀 귀찮은데, 내가 불편하면 아내와 아이가 편하게 볼 수 있을 것 같아 고민하고 있습니다.

 

 

 

참고 : 멀린 펌웨어 위키 https://github.com/RMerl/asuswrt-merlin/wiki/

참고 : Minitool Partition Wizard 다운로드 https://www.partitionwizard.com/download.html

참고 : 유플러스 셋탑에 kodi 설치 및 한글화하기 http://comterman.tistory.com/1653

참고 : putty 프로그램 다운로드 http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html

 

 

 

며칠전 웹서핑을 하다가 재미있는 글을 봐서 직접 시도해보고, 그 결과를 정리해보았습니다.

I just found an interesting article on the internet, and I tried. 

 

그 내용은, MyBookLive에 세팅된 트랜스미션Transmission에서 토렌트가 다운로드 완료되면 완료메시지를 텔레그램으로 받는 방법입니다.

It is about receiving alarm via telegram when trasmission completes downloading a torrent on your MyBookLive.

 

 

할 일은 크게 2가지 입니다.

1. 텔레그램 봇 설정

2. MyBookLive에서 알람 설정

It is seperated on 2 parts.

1. set up telegram bot

2. set up alarm on MyBookLive

 

 

 

먼저, 텔레그램 봇 설정 방법입니다.

This is how-to set up telegram bot.

 

1. https://telegram.me/botfather 주소를 눌러서 봇파더 BotFather 에게 말을 겁니다.

   PC에서 잘 안되면 텔레그램이 설치된 핸드폰에서 위 주소를 누르면 botfather와의 대화창이 열립니다.

2. /newbot   이라고 입력합니다.

3. 봇의 이름을 적당히 입력합니다. 한글도 가능하고 나중에 바꿀수도 있습니다.

4. 봇의 username을 영어로 입력합니다. 마지막은 반드시 bot으로 끝나야 합니다.

1. press https://telegram.me/botfather . Use cellphone if your computer doesn't work.

2. type /newbot

3. Name your bot

4. choose a username for your bot

위 2~4번의 내용을 대화형태로 표현하면 이렇습니다. "나" 부분의 빨간 글씨가  사용자가 입력해야 하는 부분입니다.

Here's the chat between me and @BotFather. You need to type red characters next to "나". 

 

나: /newbot

BotFather: Alright, a new bot. How are we going to call it? Please choose a name for your bot.

 

나: 토렌트알리미 TorrentAlarm

BotFather: Good. Now let's choose a username for your bot. It must end in `bot`. Like this, for example: TetrisBot or tetris_bot.

 

나: torrent_transmission_alarm_bot

BotFather: Done! Congratulations on your new bot. You will find it at telegram.me/torrent_transmission_alarm_bot. You can now add a description, about section and profile picture for your bot, see /help for a list of commands.

Use this token to access the HTTP API:

123457890:ABCDEFGHIJKLMNOPQRSTUVWXYZABCDE

For a description of the Bot API, see this page: https://core.telegram.org/bots/api

 

 

 파란색으로 칠해진 token 부분을 써먹게 되니 잘 알아두시기 바랍니다. (임의의 문자열로 대체했습니다.)

 Keep the token(in blue color) somewhere like notepad.

 

5. telegram.me/torrent_transmission_alarm_bot 부분을 클릭하면 자신이 만든 봇과의 대화창이 열립니다. (username에 따라 주소가 다릅니다)

6. 적당히 대화를 한두개 보냅니다. 반응이 없는 것이 정상입니다.

7. 이제, 아래 주소를 자신의 token으로 바꾸어서 인터넷 브라우저 주소창에 입력합니다.

   https://api.telegram.org/bot123457890:ABCDEFGHIJKLMNOPQRSTUVWXYZABCDE/getUpdates

8. 그러면 getUpdates.json 파일을 하나 다운받게 되는데, 이 getUpdates.json 파일을 메모장으로 열어봅니다.

5. click telegram.me/torrent_transmission_alarm_bot (depends on your bot username)

6. send your bot some message like "hello"

7. type following text on your browser after replacing blue text with your token from 4

    https://api.telegram.org/bot123457890:ABCDEFGHIJKLMNOPQRSTUVWXYZABCDE/getUpdates

8. your browser will download a file named getUpdates.json. open it with notepad

다음은 getUpdates.json 파일의 내용입니다.

This is the getUpdates.json file. 

 

{"ok":true,"result":[{"update_id":987654321,
"message":{"message_id":1,"from":{"id":12345678,"first_name":"ABCDEFG","last_name":"VWXYZ","username":"USERNAME"},"chat":{"id":12345678,"first_name":"ABCDEFG","last_name":"VWXYZ","username":"USERNAME","type":"private"},"date":1452737400,"text":"\/start"}},{"update_id":987654321,
"message":{"message_id":2,"from":{"id":12345678,"first_name":"ABCDEFG","last_name":"VWXYZ","username":"USERNAME"},"chat":{"id":12345678,"first_name":"ABCDEFG","last_name":"VWXYZ","username":"USERNAME","type":"private"},"date":1452737404,"text":"hello"}}]}

 

 

여기서 id 뒤의 숫자가 중요하니 이것도 잘 알아두시기 바랍니다.

Keep the id number(in blue color) along with your token.

 

9. 텔레그램 봇의 기본적인 설정은 끝입니다.

BotFather에게 /setuserpic 등의 명령어를 주어서 꾸미세요. ^^

9. Now you're done with setting up telegram bot. Tell @BotFather /setuserpic to change the picture.

 

 

 

이제 MyBookLive의 Transmission에서 다운로드 완료시 텔레그램으로 메시지를 보내도록 설정하는 방법입니다.

Transmission 설치방법은 우성군의 NAS 홈페이지 http://www.wsgvet.com/bbs/board.php?bo_table=iomega&wr_id=35 를 참고하시기 바랍니다.

This is how-to set up MyBookLive to send message to telegram bot when transmission finishes downloading a torrent.

The link above is about how-to install transmission on MyBookLive, written in Korean.

If you need to install transmission on your MBL, please google it. sorry. :) 

 

1. putty 등으로 ssh를 통해 MyBookLive에 접속합니다.

2. cd /opt/bin  라고 입력합니다. 커서 앞쪽이 MyBookLive:/opt/bin#로 바뀌는게 보입니다.

3. nano nas_notify.sh  라고 입력합니다. 파일이름은 마음대로 바꾸어도 됩니다.

4. 새 창이 뜨면 아래내용을 복사해서 붙여넣습니다. (putty에서는 마우스 오른쪽 버튼을 누르면 붙여넣기가 됩니다.)

1. connect to MyBookLive with putty, etc.

2. type cd /opt/bin

3. type nano nas_notify.sh

4. copy and paste following text. right click on your mouse for paste on your putty

 

#!/bin/sh

 

# telegram configuration
TOKEN='123457890:ABCDEFGHIJKLMNOPQRSTUVWXYZABCDE'
URL='https://api.telegram.org/bot'$TOKEN
MSG_URL=$URL'/sendMessage?chat_id='
CHAT_ID="12345678"

 

# function setting
function send_message {
res=$(/usr/bin/curl --data-urlencode "text=$TR_TORRENT_NAME download completed" "$MSG_URL"$CHAT_ID"&")
}

 

# telegram notify gogo
send_message

 

 

이때, TOKEN과 CHAT_ID는 위 텔레그램 봇 설정에서 나온 문자열로 바꿔줍니다.

 

그리고 CTRL+O, 엔터, CTRL+X를 차례로 한번씩 누르면 파일이 저장되고 다시 밖으로 나옵니다.

replace TOKEN and CHAT_ID with your token and chat_id, press Ctrl+O, enter, Ctrl+X to save & exit.

 

4. chmod a+x nas_notify.sh  라고 입력합니다. 파일이 실행가능으로 변경됩니다.

5. chmod 777 nas_notify.sh  라고 입력합니다. 트랜스미션에도 실행권한을 줍니다.

6. /opt/etc/init.d/S90transmission stop  라고 입력합니다. 실행중인 트랜스미션을 정지시킵니다.

7. nano /root/.config/transmission-daemon/settings.json  라고 입력합니다. 트랜스미션 설정파일을 수정합니다.

4. type chmod a+x nas_notify.sh  to change the sh file executable

5. type chmod 777 nas_notify.sh  to give permission to be executed

6. type /opt/etc/init.d/S90transmission stop  to stop transmission

7. type nano /root/.config/transmission-daemon/settings.json to alter setting file of transmission

아래 문자열을 찾습니다. 

    "script-torrent-done-enabled": false,
    "script-torrent-done-filename": "",
 

이렇게 수정합니다.

    "script-torrent-done-enabled": true,
    "script-torrent-done-filename": "/opt/bin/nas_notify.sh",

 

 

 

바뀐 부분은 제일 뒷부분만 이지만, 두줄 전체를 바꾸어버려도 됩니다. 

 

그리고 CTRL+O, 엔터, CTRL+X를 차례로 한번씩 누르면 파일이 저장되고 다시 밖으로 나옵니다.

 

find blue text, and replace them to red text.

press Ctrl+O, enter, Ctrl+X to save & exit.

 

8. /opt/etc/init.d/S90transmission start   라고 입력합니다. 트랜스미션을 다시 시작합니다.

8. type /opt/etc/init.d/S90transmission start  to start transmission again.

 

9. 트랜스미션의 설정이 완료되었습니다.

9. now you're done with everything!

 

 

 

 

참고 : 포고플러그에서 트랜스미션 다운로드 완료시 스마트폰으로 알람받기 http://www.clien.net/cs2/bbs/board.php?bo_table=lecture&wr_id=233890

참고 : 트랜스미션, Flexget 다운로드 완료시 텔레그램으로 알람받기 http://www.clien.net/cs2/bbs/board.php?bo_table=lecture&wr_id=303717

참고 : 텔레그램 봇 설정 http://domoticz.com/wiki/Telegram_Bot

참고 : 텔레그램 봇 설정 https://core.telegram.org/bots

참고 : putty 프로그램 다운로드 http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html