Main Page‎ > ‎

Synology

This page regroups stuff that I have done on my synology to make it my "low power" server at home.

Bootstrap your synology: install optware

First step is to install optware so that with ipkg packet manager you can install a lot of useful programs/services and an environment to compile natively on the synology programs that are lacking in optware distribution:
ipkg install optware-devel
mkdir /volume1/@src

In terms of directory structure, I use /opt for ipkg package, /opt/local for home compiled projects for optimum coexistence and so that it does not interfere with synology firmware updates.

The path I use is the following one for the users:

export PATH=/opt/local/bin:/opt/bin:/opt/sbin:/bin:/sbin:/usr/bin:/usr/sbin:/usr/syno/bin:/usr/syno/sbin
export LD_LIBRARY_PATH=/lib:/usr/lib:/opt/lib:/opt/local/lib

Mosh native compilation on synology

Since the mobile shell mosh is not part (yet) of optware packages, I decided to compile it directly on my synology. Since it was not that obvious, I thought I would share the steps that made it work
  • install openssh
ipkg install openssh
Edit configuration file /opt/etc/openssh/sshd_config to suit your needs.
  • install ncurses development libraries required for mosh:
ipkg install ncurses-dev
ipkg install ncursesw-dev
  • enable libpthreads: use synology's one and not the optware broken one
mkdir /opt/arm-none-linux-gnueabi/lib_disabled
mv /opt/arm-none-linux-gnueabi/lib/libpthread* /opt/arm-none-linux-gnueabi/lib_disabled
cp /lib/libpthread.so.0 /opt/arm-none-linux-gnueabi/lib/
cd /opt/arm-none-linux-gnueabi/lib/
ln -s libpthread.so.0 libpthread.so
ln -s libpthread.so.0 libpthread-2.5.so
    • compile protobuf which is a pre-requisite for mosh
    cd /volume1/@src/
    tar zxvf protobuf-2.5.0.tar.gz
    cd protobuf-2.5.0
    ./configure --prefix=/opt/local
    make
    make install
    find /opt/local -mmin -5 > ../install-protobuf-files.lst
    cd /volume1/@src/
    tar zxvf mosh-1.2.4.tar.gz
    cd mosh-1.2.4
    ./configure --disable-hardening --without-utempter --prefix=/opt/local
    make
    make install
    strip /opt/local/bin/mosh-server
    strip /opt/local/bin/mosh-client
    find /opt/local -mmin -5 > ../install-mosh-files.lst
    #DS211+
    cp arm-none-linux-gnueabi/arm-none-linux-gnueabi/libc/usr/bin/locale /opt/bin/
    cp arm-none-linux-gnueabi/arm-none-linux-gnueabi/libc/usr/bin/localedef /opt/bin/
    cp -r arm-none-linux-gnueabi/arm-none-linux-gnueabi/libc/usr/share/i18n /usr/share
    localdef -a
    /opt/bin/localedef -c -f UTF-8 -i en_US en_US.UTF-8
      • put in /etc/profile
    LANG=en_US.UTF-8
    LC_ALL=en_US.UTF-8
    export LANG LC_ALL
      • reboot by typing guess what... reboot
    • now in order that mosh-server finds libraries located in /opt/lib you need to allow LD_LIBRARY_PATH environment to be passed during ssh
      • in /opt/etc/openssh/sshd_config add PermitUserEnvironment yes
      • modify $HOME/.ssh/environment to add
    PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/syno/bin:/usr/syno/sbin:/opt/bin:/opt/sbin:/opt/local/bin
    LANG=en_US.UTF-8
    LC_ALL=en_US.UTF-8
    LD_LIBRARY_PATH=/lib:/usr/lib:/opt/lib:/opt/local/lib

    Now you should be able to do mosh user@host

    Do not forget if you are behind a port forwarder or NAT to select and forward the UDP port that mosh client should use (e.g. mosh -p 12345 user@host).

    Rsync version that detects renaming

    If you reorder your files and photos normally rsync would take ages to perform the backup but there is a patch not integrated in mainstream that deals with that:

    cd /volume1/@src/
    wget "http://www.samba.org/ftp/rsync/src/rsync-3.1.0.tar.gz"
    wget "http://www.samba.org/ftp/rsync/src/rsync-patches-3.1.0.tar.gz"
    #wget "https://bugzilla.samba.org/attachment.cgi?id=7435" -O detect-renamed.diff
    tar zxf rsync-3.1.0.tar.gz
    tar zxf rsync-patches-3.1.0.tar.gz
    #cp detect-renamed.diff rsync-3.0.9/patches
    cd rsync-3.1.0
    patch -p1 <patches/detect-renamed.diff 
    patch -p1 <patches/detect-renamed-lax.diff
    ./configure --prefix=/opt/local
    make install
    strip /opt/local/bin/rsync
    find /opt/local -mmin -5 > ../install-rsync-files.lst

    Make sftp work

    For some reason openssh package does not provide sftp, in order to enable it install:

    ipkg install openssh-sftp-server

    and add in /opt/etc/openssh/sshd_config the missing sftp command reference:

    Subsystem       sftp    /volume1/@optware/libexec/sftp-server

    Backup your data with history: rsnapshot

    rsnapshot is an rsync based backup system that I like: it is simple yet efficient. 
    • Install it with:
    ipkg install rsnapshot
    • Configure it and make sure that rsync used is the synology one i.e. /usr/syno/bin/rsync and that you use the --syno-acl option if you are keen to preserve any windows ACL in the backup process (not my case because I want the rename detection feature explained above).
    My configuration is the following /opt/etc/rsnapshot.conf:

    config_version  1.2
    snapshot_root   /volumeUSB1/usbshare/backup/rsnapshot
    cmd_cp          /opt/bin/cp
    cmd_rm          /opt/bin/rm
    #cmd_rsync       /usr/syno/bin/rsync
    cmd_rsync       /opt/local/bin/rsync
    cmd_ssh /opt/bin/ssh
    cmd_du          /opt/bin/du
    interval        daily   7
    interval        weekly  4
    interval        monthly 6
    link_dest       1
    verbose         2
    loglevel        3
    logfile         /volume1/backup/rsnapshot.log
    #rsync_long_args -av --progress --delete --numeric-ids --relative --delete-excluded --syno-acl
    rsync_long_args -av --progress --delete --numeric-ids --relative --delete-excluded
    lockfile        /opt/var/run/rsnapshot.pid
    backup  /                                       synosys/        exclude_file=/opt/etc/incexcl-synosys
    backup  /                                       synodata/       exclude_file=/opt/etc/incexcl-synodata

    You can notice that, to be safe, I am performing the backup to an external USB disk that I attach to the synology (located in /volumeUSB1/usbshare).
    All the directories (include and exclude) are specified in the /opt/etc/incexcl-synosys file which has the following format:

    + /etc/
    + /root/
    + /usr/
    + /usr/syno/
    + /usr/syno/etc/
    + /usr/syno/apache/
    - /usr/syno/*
    - /usr/*
    + /opt/
    + /opt/etc/
    + /opt/share/
    + /opt/share/lib/
    - /opt/share/*
    + /opt/lib/
    + /opt/lib/ipkg/
    - /opt/lib/*
    - /opt/*
    - /*

    • Install and configure a simple mail client: nail to receive notifications of failure
    ipkg install nail

    Edit /opt/etc/nail.rc to reflect your smtp server and credentials (here the domain is a google apps business one):

    set hold
    set append
    set ask
    set crt
    set dot
    set keep
    set emptybox
    set indentprefix="> "
    set quote
    set sendcharsets=iso-8859-1,utf-8
    set showname
    set showto
    set newmail=nopoll
    set autocollapse
    ignore received in-reply-to message-id references
    ignore mime-version content-transfer-encoding
    fwdretain subject date from to
    set smtp=smtp.gmail.com:587
    set smtp-use-starttls
    set ssl-verify=ignore
    set ssl-ca-file=/opt/etc/Thawte_Premium_Root_CA.pem
    set from="user@yourdomain.com"
    set smtp-auth-user=user@yourdomain.com
    set smtp-auth-password="YOURPASSWORD"
    • Automate your backups launching rsnapshot in the crontab: edit /etc/crontab to add:
    #minute hour    mday    month   wday    who     command#minute  hour    mday    month   wday            who     command
    55      23      *       *       0,1,2,3,4,5,6   root    /opt/bin/rsnapshot -v daily || nail -s "bkp `date +%Y%m%d` daily" user@yourdomain.com < /volume1/backup/rsnapshot.log
    0       02      *       *       0               root    /opt/bin/rsnapshot -v weekly || nail -s "bkp `date +%Y%m%d` weekly" user@yourdomain.com < /volume1/backup/rsnapshot.log
    0       04      1       *       *               root    /opt/bin/rsnapshot -v montly || nail -s "bkp `date +%Y%m%d` monthly" user@yourdomain.com < /volume1/backup/rsnapshot.log

    Restart cron:

    /usr/syno/etc/rc.d/S04crond.sh stop
    /usr/syno/etc/rc.d/S04crond.sh start

    Install an apache server coexisting with synology's one

    • Install apache
    ipkg install apache
      • edit /opt/etc/apache2/httpd.conf and uncomment ext filter module
    #LoadModule ext_filter_module libexec/mod_ext_filter.so
      • enable ssl support by uncommenting in /opt/etc/apache2/httpd.conf ssl configuration file
    Include etc/apache2/extra/httpd-ssl.conf
      • make ipkg apache listen to port 80 instead of default 8080 by editing /opt/etc/apache2/httpd.conf
    vi /opt/etc/apache2/httpd.conf
    Listen 80
      • use synology's default cert for now
    cd /opt/etc/apache2
    ln -s /usr/syno/etc/ssl/ssl.crt/server.crt
    ln -s /usr/syno/etc/ssl/ssl.key/server.key
    • restrict synology's apache to respectively use port 8080/8443 instead of 80/443 to let them free for ipkg's apache by modifying /usr/syno/apache/conf/httpd.conf-user and /usr/syno/apache/conf/extra/httpd-ssl.conf Listen directive:
    vi /usr/syno/apache/conf/httpd.conf-user
    Listen 8080
    vi /usr/syno/apache/conf/extra/httpd-ssl.conf
    Listen 8443

    Restart all apache servers:
    /opt/sbin/apachectl stop
    /usr/syno/etc/rc.d/S97apache-user.sh restart
    /opt/sbin/apachectl start

    Install self signed custom certificates for your domain

    Since I was tired of chrome's complaints that my domain was using synology.com certificates, I decided to generate my own custom ones following this link: http://forum.synology.com/wiki/index.php/How_to_generate_custom_SSL_certificates. Here is what I did:

    • generate the certificate authority key ca.key (remember the passphrase)
    cd /opt/etc/ssl
    openssl genrsa -des3 -out ca.key 1024
    • generate the key certificate
    openssl req -new -key ca.key -out ca.csr
    • generate the final certificate authority key (valid 10 years):
    openssl x509 -days 3650 -signkey ca.key -in ca.csr -req -out ca.crt
    • generate the server-certificate key:
    openssl genrsa -out server.key 1024
    • generate the key certificate, note that the CommonName needs to match your DNS domainname (wildcards are allowed e.g. *.yourdomain.com)
    openssl req -new -key server.key -out server.csr
    • generate the server certificate
    openssl x509 -days 3650 -CA ca.crt -CAkey ca.key -set_serial 01 -in server.csr -req -out server.crt
    • copy the necessary server certificate and key in the apache directory:
    cp server.key server.crt /opt/etc/apache2/ssl/
    • be sure that apache does use them by editing /opt/etc/apache2/extra/httpd-ssl-vhost-user.conf and checking that the right patch is used
    SSLCertificateFile /opt/etc/ssl/server.crt
    SSLCertificateKeyFile /opt/etc/ssl/server.key
    • restart apache
    /opt/sbin/apachectl stop
    /opt/sbin/apachectl start

    Protect via https some internal http services

    Somtimes you have some service that has a web interface on a specific port (e.g. http://192.168.0.2:1234/servicehttp) but not supporting https that you do not want to expose directly to the outside world in order not to have your password in the clear. In order to overcome this issue you can use the proxy feature of apache by editing /opt/etc/apache2/extra/httpd-ssl-vhost-user.conf the following way:

      SSLProxyEngine on
      ProxyRequests Off
      ProxyVia Off
      <Proxy *>
         Order deny,allow
         Allow from all
      </Proxy> 
     <Location /servicehttp>
        Order deny,allow
        Allow from all
        AuthName "Private area"
        AuthType Basic
        AuthUserFile /opt/etc/apache2/htpasswd
        Require valid-user
        ProxyPass http://192.168.0.2:1234/servicehttp
        ProxyPassReverse http://192.168.0.2:1234/servicehttp
        SSLRequireSSL
      </Location> 

    Create login and password using the following command /opt/sbin/htpasswd /opt/etc/apache2/htpasswd username

    Perform some https redirections towards synology default services without opening the ports on router

     If you do not want to open some ports on your router and forward them to your synology NAS to enable remote access (e.g. 7001 and 5001) you can use the proxy feature of apache to do it by simply editing /opt/etc/apache2/extra/httpd-ssl-vhost-user.conf the following way:

      ProxyPass /filestation https://192.168.0.2:7001/
      ProxyPassReverse /filestation/ https://192.168.0.2:7001/
      ProxyPass /synology https://192.168.0.2:5001/
      ProxyPassReverse /synology/ https://192.168.0.2:5001/ 

    Install other sources of packages on synology web interface

    Synocommunity is a great source of packages to add to the ones provided by synology.
    Interesting packages like transmission can be found that is a good replacement of synology's download station.

    Files renaming

    I use two tools that I find handy;
    • perl-file-rename that I find extremely useful and powerful that handles regexp
    ipkg install perl-file-rename
    • convmv to get rid of non UTF-8 characters
    ipkg install perl
    wget http://www.j3e.de/linux/convmv/convmv-1.15.tar.gz
    tar xzvf convmv-1.15.tar.gz
    cd convmv-1.15
    sed -i -e 's/usr/opt/1p' convmv
    ./convmv
    cp convmv /opt/bin

    Here is an example of how to use convmv recursively on current directory to fix encoding:

    /opt/bin/convmv -f iso-8859-1 -t utf8 --notest -r .

    • files with question marks really do upset samba shares it seems and in order to remove these you can use the following renaming script:
    #!/opt/bin/bash
    for i in `find . | grep "\?"`; do rename "s/\?//g" "$i"; done

    Install temporary easy file sharing service: jirafeau

    In order to share some files for a given period of time I have installed jirafeau. Here are the steps that I followed:
    • install and enable php
    ipkg install php-apache php-pear
    vi /opt/etc/apache2/httpd.conf
    LoadModule php5_module libexec/libphp5.so
    <IfModule php5_module>
      AddType application/x-httpd-php .php
    </IfModule>
    <IfModule dir_module>
        DirectoryIndex index.html index.php index.php3 index.cgi index.htm
    </IfModule>

    • enable jirafeau redirection in apache ssl to protect password
    vi /opt/etc/apache2/extra/httpd-ssl-vhost-user.conf
      Alias /jirafeau /opt/share/lib/jirafeau-jirafeau/
      <Directory /opt/share/lib/jirafeau-jirafeau>
        Order deny,allow
        Allow from all
        SSLRequireSSL
      </Directory>
    /opt/sbin/httpd -k restart
    $cfg['web_root'] = 'https://yourdomain.com/jirafeau/';
    $cfg['upload_password'] = 'UPLDPASSWD"

    Tools to install

    ipkg install git

    Install python

    ipkg install python27
    ipkg install py27-setuptools

    Subtitles downloader

    subliminal is a python tool that downloads subtitles from various sources for video files.

    cd /volume1/@appstore
    git clone https://github.com/Diaoul/subliminal
    cd subliminal
    python setup.py install

    Subtitles download can be automated downloading first english subs if only available to be replaced by french ones once available using a little script like this one:

    #!/opt/bin/bash

    TV_DIR=$1
    BACKTIME=$2
    [ -z "$TV_DIR" ] && TV_DIR=/volume1/video/serie
    [ -z "$BACKTIME" ] && BACKTIME=14
    GETSUB=/opt/bin/subliminal
    cd $TV_DIR
    # try to get the subtitle only for 14 days to avoid exploding list of files to process
    for file in $(find . -mtime -${BACKTIME} -type f \( -iname \*.avi -o -iname \*.mkv -o -iname \*.mp4 \) )
    do
      subtitle="${file%.*}.srt"
      if [ ! -f "$subtitle" ]
      then
        echo processing $file
        # download without .fr.srt or .en.srt to be sure it is from addic7ed in french first in -s single mode
        $GETSUB -s -l fr -p addic7ed --addic7ed-username username --addic7ed-password password -q "$file" && rm "$file".en.srt
        # if it failed with addict7ed get from any other source but with .fr.srt and .en.srt
        [ ! -f "$subtitle" ]  && $GETSUB -l en --addic7ed-username username --addic7ed-password password -q "$file"
      fi
    done

    If you want to update subliminal in the future just do:

    cd /volume1/@appstore/subliminal
    git pull
    python setup.py install

    TV series file renamer

    tvnamer is a very powerful python program that enables to rename tv series.

    cd /volume1/@appstore
    git clone https://github.com/dbr/tvnamer
    cd tvnamer
    python setup.py install

    An example of user configuration of tvnamer capturing the most useful features of the tool can be found below:

    cat .tvnamer.json
    {
        "language": "en",
        "search_all_languages": false,
        "always_rename": false,
        "batch": true,
        "episode_separator": "-",
        "episode_single": "%02d",
        "filename_with_date_and_episode": "%(seriesname)s-e%(episode)s-%(episodename)s%(ext)s",
        "filename_with_date_without_episode": "%(seriesname)s-e%(episode)s%(ext)s",
        "filename_with_episode": "%(seriesname)s-s%(seasonno)02de%(episode)s-%(episodename)s%(ext)s",
        "filename_with_episode_no_season": "%(seriesname)s-e%(episode)s-%(episodename)s%(ext)s",
        "filename_without_episode": "%(seriesname)s-s%(seasonno)02de%(episode)s%(ext)s",
        "filename_without_episode_no_season": "%(seriesname)s-e%(episode)s%(ext)s",
        "lowercase_filename": false,
        "move_files_confirmation": true,
        "move_files_destination": "/volume1/video/serie/%(seriesname)s/%(seriesname)s-s%(seasonnumber)02d",
        "move_files_enable": true,
        "multiep_join_name_with": ", ",
        "normalize_unicode_filenames": false,
        "recursive": false,
        "replace_invalid_characters_with": "_",
        "move_files_fullpath_replacements": [
            {"is_regex": false, "match": " ", "replacement": "_"},
    {"is_regex": false, "match": "_-_", "replacement": "-"},
    {"is_regex": false, "match": ":", "replacement": ""},
            {"is_regex": false, "match": "Serie's_name", "replacement": "Series_Name"}
        ],
        "output_filename_replacements": [
            {"is_regex": false, "match": " ", "replacement": "_"},
    {"is_regex": false, "match": "_-_", "replacement": "-"},
    {"is_regex": false, "match": ":", "replacement": ""},
            {"is_regex": false, "match": "Serie's_name", "replacement": "Series_Name"}
        ],
        "input_filename_replacements": [
            {"is_regex": true, "match": "Serie.US", "replacement": "Serie"},
            {"is_regex": true, "match": "Serie([^:])", "replacement": "Serie_expanded_name\\1"}
        ]
    }

    If you want to update tvnamer in the future just do:

    cd /volume1/@appstore/tvnamer
    git pull
    python setup.py install

    Automatic rss based file downloading

    flexget is a good tool and easy to configure to automate file download based on rss feed matching names.
    It can be installed by:
    ipkg install sqlite
    easy_install flexget
    A typical user configuration can be the following:
    cat .flexget/config.yml
    presets:
      global:
        transmission:
          host: localhost
          port: 9091
          username: username
          password: password
        email:
          active: True
          from: flexget@yourdomain.com
          to: user@yourdomain.com
          smtp_host: smtp.yourdomain.com
          smtp_port: 25
          smtp_login: false
      tv:
        quality: webdl|hdtv <720p
        series:
        - Serie name one
        - Serie name two
    tasks:
      stream1:
        rss: http://streamsiteone.com/feed/
        preset: tv
        priority: 10
      stream2:
        rss: http://streamsitetwo.com/?cat=9
        preset: tv
        priority: 20

    In order to check flexget configuration you can issue:

    flexget --check

    Launch of flexget task can be automated using cron job, edit /etc/crontab and add:

    0 07 * * * root /opt/local/bin/flexget --cron >/dev/null 2>&1

    Relaunch cron service through:

    /usr/syno/etc/rc.d/S04crond.sh stop
    /usr/syno/etc/rc.d/S04crond.sh start

    If you want to update flexget in the future just do:

    pip install --upgrade flexget

    If you experience some issues with seen status or database you can reset it with the following command that should be used only as a last resort:

    flexget --reset 

    Disable power/memory hungry media indexing and thumbnail generation

    /usr/syno/etc/rc.d/S??synoindexd.sh stop
    /usr/syno/etc/rc.d/S??synomkflvd.sh stop
    /usr/syno/etc/rc.d/S??synomkthumbd.sh stop
    killall -9 convert
    killall -9 ffmpeg
    chmod a-x /usr/syno/etc/rc.d/S??synoindexd.sh
    chmod a-x /usr/syno/etc/rc.d/S??synomkflvd.sh
    chmod a-x /usr/syno/etc/rc.d/S??synomkthumbd.sh

    Alternatively you can respectively rename the variables SYNOMKTHUMBD, SYNOMKFLVD in the above files so that it does nothing.

    Note that the above steps need to be reiterated at each synology software update...

    Fill mkv stereo-mode field correctly for Archos Video Player to turn your TV into right 3D mode

    If you happen to have an Archos TV connect and a 3D capable TV (I strongly recommend 3D passive technology) and want to have your TV switched to the appropriate 3D mode automagically you can fill the right field value of your mkv file using this process:
    • install mkv tools: 
    ipkg install mkvtoolnix
    • find the right video track using:
    mkvinfo file.mkv
    Let's assume for the example sake that track1 contains the video
    • assign the right value for the stereo-mode field of the mkv depending on the type of video: 
    mkvpropedit --edit track:1 -s stereo-mode=1 file.mkv
    The possible values for stereo-mode are 0 for mono, 1 for left_right, 11 for right_left, 2 for bottom_top, and 3 for top_bottom, cf. below (http://3dvision-blog.com/tag/mkvtoolnix/#sthash.bXxmB5E1.dpuf)

    StereoMode field values:
    0: mono
    1: side by side (left eye is first)
    2: top-bottom (right eye is first)
    3: top-bottom (left eye is first)
    4: checkboard (right is first)
    5: checkboard (left is first)
    6: row interleaved (right is first)
    7: row interleaved (left is first)
    8: column interleaved (right is first)
    9: column interleaved (left is first)
    10: anaglyph (cyan/red)
    11: side by side (right eye is first)
    12: anaglyph (green/magenta)
    13: both eyes laced in one Block (left eye is first) (field sequential mode)
    14: both eyes laced in one Block (right eye is first) (field sequential mode)

    Transmission tweaks

    If you have installed transmission through Synocommunity your configuration file is located here: /volume1/@appstore/transmission/var/settings.json. Make sure to stop transmission on the synology web interface or using the below commands before editing this file so that your modifications are taken into account:

    /var/packages/transmission/scripts/start-stop-status stop
    vi /volume1/@appstore/transmission/var/settings.json
    /var/packages/transmission/scripts/start-stop-status start
    • learn to use transmission-remote located here: /volume1/@appstore/transmission/bin/transmission-remote
    ln -s /volume1/@appstore/transmission/bin/transmission-remote /opt/bin/transmission-remote
    • in order to execute some actions at the end of a file download a script can be triggered e.g. for moving files around based on tracker name
        "script-torrent-done-enabled": true,
        "script-torrent-done-filename": "/opt/local/bin/transmission-done.sh",

    With /opt/local/bin/transmission-done.sh for instance being:

    #!/bin/sh

    # arguments
    # 'TR_TORRENT_NAME'
    # 'TR_TORRENT_DIR'
    # 'TR_TORRENT_ID'
    # 'TR_APP_VERSION'
    # 'TR_TORRENT_HASH'
    # 'TR_TIME_LOCALTIME'

    TV_SHOW_ID="hdtv"
    MEDIA_DIR="/volume1"
    DOWNLOAD_DIR="${MEDIA_DIR}/download"
    HOST=""

    for d in serie public trackera trackerb
    do
    mkdir -p $DOWNLOAD_DIR/$d
    done

    is_tvshow=false
    is_private=false
    is_trackera=false
    is_trackerb=false

    tremote ()
    {
            transmission-remote -n user:password $HOST -t ${TR_TORRENT_ID} $*
    }

    if [ -z "${TR_TORRENT_NAME}" -o -z "${TR_TORRENT_ID}" -o -z "${TR_TORRENT_DIR}" ]; then
            exit 0
    fi

    if ( tremote -i | grep "Public torrent" | grep -qi No ); then
            is_private=true
    fi
    if ( tremote -it | grep -qi "tracker.a" ); then
            is_trackera=true
            is_private=true
    fi
    if ( tremote -it | grep -qi "tracker.b" ); then
            is_trackerb=true
            is_private=true
    fi
    if ( echo "${TR_TORRENT_NAME}"| grep -Eqi "${TV_SHOW_ID}" ); then
            is_tvshow=true
    fi

    if $is_private; then
            # private torrent
    if $is_trackera; then
                    echo "trackera"
                    mkdir -p "$DOWNLOAD_DIR/trackera"
                    tremote --move "$DOWNLOAD_DIR/trackera"
                    tremote --seedratio 2
            elif $is_trackerb; then
                    echo "trackerb"
                    mkdir -p "$DOWNLOAD_DIR/trackerb"
                    tremote --move "$DOWNLOAD_DIR/trackerb"
                    tremote --seedratio 4
            fi
    else
            # public torrent
            if $is_tvshow; then
                    echo "tvshow"
                    tremote --move "$DOWNLOAD_DIR/serie"
                    tremote -r
            else
                    echo "other public"
                    tremote -S
                    mkdir -p "$DOWNLOAD_DIR/public"
                    tremote --move "$DOWNLOAD_DIR/public"
            fi
    fi
    • periodically you can check if your download and seed is complete based on your seedratio and then decide to move the completed files somewhere and remove it from transmission. This script does this for you:
    #!/opt/bin/bash

    tremote ()
    {
     transmission-remote -n user:password $*
    }

    for t in `tremote -l | grep Done | sed -e 's/^ *//' | sed 's/\*//' | cut -s -d " " -f1`
    do
      if ( tremote -t $t -it | grep -qi "tracker.a" );
      then
        echo processing $t
        tremote -t $t --move "/volume1/files/trackera"
        tremote -t $t -r
      fi
    done
    • enabling blocklist in transmission is a sensible thing to do for this add the following option to /volume1/@appstore/transmission/var/settings.json
        "blocklist-enabled": true,
        "blocklist-url": "http://list.iblocklist.com/?list=bt_level1&fileformat=p2p&archiveformat=gz",
    You can periodically update the blocklist via cron job modifying /etc/crontab
    30      19      *       *       *               root    /opt/bin/transmission-remote -n user:password --blocklist-update
    and restarting cron:
    /usr/syno/etc/rc.d/S04crond.sh stop
    /usr/syno/etc/rc.d/S04crond.sh start
    Alternatively you can concatenate or download multiple blocklists using a script such as the one adapted from Ultimate-Blocklist: vi /usr/local/bin/updblklst.sh
    #!/usr/bin/env bash

    cd /usr/local/transmission/var/blocklists/

    declare -a TITLEs=("Bluetack LVL 1" "Bluetack LVL 2" "Bluetack LVL 3" "Bluetack edu" "Bluetack ads"
            "Bluetack spyware" "Bluetack proxy" "Bluetack badpeers" "Bluetack Microsoft" "Bluetack spider"
            "Bluetack hijacked" "Bluetac dshield" "Bluetack forumspam" "Bluetack webexploit" "TBG Primary Threats"
            "TBG General Corporate Range" "TBG Buissness ISPs" "TBG Educational Institutions"
            )
    declare -a URLs=("http://list.iblocklist.com/?list=bt_level1&fileformat=p2p&archiveformat=gz"
                "http://list.iblocklist.com/?list=bt_level2&fileformat=p2p&archiveformat=gz"
                "http://list.iblocklist.com/?list=bt_level3&fileformat=p2p&archiveformat=gz"
                "http://list.iblocklist.com/?list=bt_edu&fileformat=p2p&archiveformat=gz"
                "http://list.iblocklist.com/?list=bt_ads&fileformat=p2p&archiveformat=gz"
                "http://list.iblocklist.com/?list=bt_spyware&fileformat=p2p&archiveformat=gz"
                "http://list.iblocklist.com/?list=bt_proxy&fileformat=p2p&archiveformat=gz"
                "http://list.iblocklist.com/?list=bt_templist&fileformat=p2p&archiveformat=gz"
                "http://list.iblocklist.com/?list=bt_microsoft&fileformat=p2p&archiveformat=gz"
                "http://list.iblocklist.com/?list=bt_spider&fileformat=p2p&archiveformat=gz"
                "http://list.iblocklist.com/?list=bt_hijacked&fileformat=p2p&archiveformat=gz"
                "http://list.iblocklist.com/?list=bt_dshield&fileformat=p2p&archiveformat=gz"
                "http://list.iblocklist.com/?list=ficutxiwawokxlcyoeye&fileformat=p2p&archiveformat=gz"
                "http://list.iblocklist.com/?list=ghlzqtqxnzctvvajwwag&fileformat=p2p&archiveformat=gz"
                "http://list.iblocklist.com/?list=ijfqtofzixtwayqovmxn&fileformat=p2p&archiveformat=gz"
                "http://list.iblocklist.com/?list=ecqbsykllnadihkdirsh&fileformat=p2p&archiveformat=gz"
                "http://list.iblocklist.com/?list=jcjfaxgyyshvdbceroxf&fileformat=p2p&archiveformat=gz"
                "http://list.iblocklist.com/?list=lljggjrpmefcwqknpalp&fileformat=p2p&archiveformat=gz"
                )

    declare -i index=0
    for url in "${URLs[@]}"; do #For each url
        echo "Now downloading blocklist list ${TITLEs[$index]}"
        wget -q "$url"
        index=$((index+=1))
    done
    echo "unzipping..."
    gunzip *.gz
    echo "Done!"
    echo "Restarting transmission to parse new blocklist files!"
    /var/packages/transmission/scripts/start-stop-status stop
    /var/packages/transmission/scripts/start-stop-status start
    rm `ls | grep -v .bin$`
    You can periodically update the blocklist via cron job modifying /etc/crontab
    30      19      *       *       *               root    /usr/local/bin/updblklst.sh >/dev/null 2>&1
    and restarting cron:
    /usr/syno/etc/rc.d/S04crond.sh stop
    /usr/syno/etc/rc.d/S04crond.sh start

    Useful tools

    • replace dumb vi by vim
    ipkg install vim
    ln -s /opt/bin/vim /opt/bin/vi

    Toubleshooting: if your synology is not booting anymore

    It happened to me that the synology didn't boot anymore or asks to be migrated under synology assistant. If your synology is in that state verify that you have not swapped the disks... and it is always possible to telnet to the synology using this synology secret password that changes everyday.
    Note that your synology might be stuck in 1/11970 and this corresponds to password 101-0101.

    #include <stdlib.h>
    #include <time.h>
    #include <stdio.h>
    void main()
    {
    struct timeval tvTime;
    struct tm tmOutput;

    gettimeofday(&tvTime, 0);
    localtime_r(&(tvTime.tv_sec), &tmOutput);
    tmOutput.tm_mon += 1;

    printf("password for today is: %x%02d-%02x%02d\n\n",
    tmOutput.tm_mon, tmOutput.tm_mon, tmOutput.tm_mday,
    gcd(tmOutput.tm_mon, tmOutput.tm_mday));
    }
    int gcd(int a, int b)
    {
    return (b?gcd(b,a%b):a);
    }
    end

    Comments