Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- #
- #Compile and Install transmission bittorrent client on mybooklive
- #
- #Author: Proglin 2015-09-10
- #
- # Update: 2016-02-26 LibEvent Extract Folder name changed + Compile Changed
- # Update: 2016-02-22 LibEvent URL changed
- # Update: 2016-10-06 New source for Transmission. No ssl option added to wget. (olimatis)
- #
- # Note:
- # I strong recommend you to download an update firmware
- # Save it in public folder
- # If anything goes wrong you can update your firmware to clean the mess using:
- # /usr/local/sbin/updateFirmwareFromFile.sh /DataVolume/shares/Public/apnc-024310-048-20150507.deb
- #
- # References:
- #https://trac.transmissionbt.com/wiki/Building#DebianSqueeze
- #https://trac.transmissionbt.com/wiki/Scripts/initd
- #http://falkhusemann.de/blog/2012/05/compiling-transmission-bittorrent-for-debiand/
- #http://community.wd.com/t5/My-Book-Live/GUIDE-How-to-unbrick-a-totally-dead-MBL/td-p/435724
- #http://support.wd.com/product/download.asp?groupid=902&sid=132&lang=en
- start=$SECONDS
- TRANSMISSION_VERSION=2.92
- # CONFIGURATION TRANSMISSION VERSION
- #TRANSMISSIONSOURCE='http://download.transmissionbt.com/files/transmission-2.84.tar.xz'
- #TRANSMISSIONSOURCE='https://github.com/transmission/transmission-releases/raw/master/transmission-2.92.tar.xz'
- TRANSMISSIONSOURCE='https://github.com/transmission/transmission-releases/raw/master/transmission-2.84.tar.xz'
- # EXTRA CONFIGURATIONS
- #TMPFOLDER='/root/temp'
- #LIBEVENTSOURCE='http://sourceforge.net/projects/levent/files/libevent/libevent-2.0/libevent-2.0.18-stable.tar.gz'
- LIBEVENTSOURCE='https://github.com/libevent/libevent/archive/release-2.0.18-stable.tar.gz'
- LIBEVENTEXTRACTNAME='libevent-release-2.0.18-stable.tar.gz'
- #Change TMP Folder to have more space!
- TMPFOLDER='/shares/Public/tmpCompile'
- TMP=$TMPFOLDER
- TEMP=$TMPFOLDER
- TMPDIR=$TMPFOLDER
- export TMPDIR TMP TEMP
- clear
- echo "Welcome! Compile and Install Transmission 2.84"
- echo "Created by Proglin v2015-09-10"
- echo " Last Update: v2016-02-26"
- echo "ALWAYS back up your data before proceeding."
- echo "This script was only tested with MyBookLive firmware 02.43.10-048"
- printf "Your firmware version is: ";tail -1 /var/log/version.log
- echo ""
- echo "We are going to change some configs to install Tranmission"
- read -p "This process takes around 30 minutes. Are you sure? (Y/N)" -n 1 -r
- echo # (optional) move to a new line
- if [[ $REPLY =~ ^[Nn]$ ]]
- then
- echo "OK. Exiting."
- exit
- fi
- mkdir -p $TMPFOLDER
- if [[ $? > 0 ]]
- then
- echo "The command failed, exiting." ; exit
- fi
- rm -f /var/lib/dpkg/info/wd-nas.*
- cp /etc/apt/sources.list $TMPFOLDER/sources.list.bak
- echo ""
- printf "1/22 Configuring repositories... (part 1/3)"
- APTSOURCESOLD="#Modified to install Transmission (old packages)
- deb http://archive.debian.org/debian/ squeeze main
- deb-src http://archive.debian.org/debian/ squeeze main
- #deb http://ftp.br.debian.org/debian/ wheezy main
- #deb-src http://ftp.br.debian.org/debian/ wheezy main\n"
- printf "$APTSOURCESOLD" > /etc/apt/sources.list
- apt-get -qq clean
- apt-get -qq update >/dev/null 2>&1
- if [[ $? > 0 ]]
- then
- echo "The command failed, exiting." ; exit
- else
- echo " OK!"
- fi
- printf "2/22 Installing packages... (part 1/7)"
- apt-get -q -y --force-yes --allow-unauthenticated -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" -o Dpkg::Options::="--force-overwrite" install tar >/dev/null 2>&1
- if [[ $? > 0 ]]
- then
- echo "The command failed, exiting." ; exit
- else
- echo " OK!"
- fi
- printf "3/22 Installing packages... (part 2/7)"
- apt-get -q -y --force-yes --allow-unauthenticated -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" -o Dpkg::Options::="--force-overwrite" install ca-certificates >/dev/null 2>&1
- if [[ $? > 0 ]]
- then
- echo "The command failed, exiting." ; exit
- else
- echo " OK!"
- fi
- printf "4/22 Installing packages... (part 3/7)"
- apt-get -q -y --force-yes --allow-unauthenticated -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" -o Dpkg::Options::="--force-overwrite" install intltool >/dev/null 2>&1
- if [[ $? > 0 ]]
- then
- echo "The command failed, exiting." ; exit
- else
- echo " OK!"
- fi
- printf "5/22 Installing packages... (part 4/7)"
- apt-get -q -y --force-yes --allow-unauthenticated -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" -o Dpkg::Options::="--force-overwrite" install build-essential >/dev/null 2>&1
- if [[ $? > 0 ]]
- then
- echo "The command failed, exiting." ; exit
- else
- echo " OK!"
- fi
- printf "6/22 Installing packages... (part 5/7)"
- apt-get -q -y --force-yes --allow-unauthenticated -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" -o Dpkg::Options::="--force-overwrite" install libtool >/dev/null 2>&1
- if [[ $? > 0 ]]
- then
- echo "The command failed, exiting." ; exit
- else
- echo " OK!"
- fi
- printf "7/22 Configuring repositories... (part 2/3)"
- APTSOURCESNEW="#Modified to install Transmission (new packages)
- #deb http://archive.debian.org/debian/ squeeze main
- #deb-src http://archive.debian.org/debian/ squeeze main
- deb http://ftp.br.debian.org/debian/ wheezy main
- deb-src http://ftp.br.debian.org/debian/ wheezy main\n"
- printf "$APTSOURCESNEW" > /etc/apt/sources.list
- apt-get -qq clean
- apt-get -qq update 2>/dev/null
- if [[ $? > 0 ]]
- then
- echo "The command failed, exiting." ; exit
- else
- echo " OK!"
- fi
- printf "8/22 Installing packages... (part 6/7)"
- export DEBIAN_FRONTEND=noninteractive
- apt-get -qq -y --force-yes --allow-unauthenticated -o Dpkg::Options::="--force-confold" -o Dpkg::Options::="--force-overwrite" -o Dpkg::Options::="--force-confdef" install libssl-dev >/dev/null 2>&1
- if [[ $? > 0 ]]
- then
- echo "The command failed, exiting." ; exit
- else
- echo " OK!"
- fi
- printf "9/22 Configuring repositories... (part 3/3)"
- APTSOURCESOLD="#Modified to install Transmission (old packages)
- deb http://archive.debian.org/debian/ squeeze main
- deb-src http://archive.debian.org/debian/ squeeze main
- #deb http://ftp.br.debian.org/debian/ wheezy main
- #deb-src http://ftp.br.debian.org/debian/ wheezy main\n"
- printf "$APTSOURCESOLD" > /etc/apt/sources.list
- apt-get -qq clean
- apt-get -qq update >/dev/null 2>&1
- if [[ $? > 0 ]]
- then
- echo "The command failed, exiting." ; exit
- else
- echo " OK!"
- fi
- printf "10/22 Installing packages... (part 7/7)"
- apt-get -q -y --force-yes --allow-unauthenticated -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" -o Dpkg::Options::="--force-overwrite" install libcurl4-openssl-dev >/dev/null 2>&1
- if [[ $? > 0 ]]
- then
- echo "The command failed, exiting." ; exit
- else
- echo " OK!"
- fi
- printf "11/22 Downloading sources of LIBEVENT..."
- #Getting sources of Transmission and LibEvent
- #wget -q $LIBEVENTSOURCE -O $TMPFOLDER/${LIBEVENTSOURCE##*/} >/dev/null 2>&1
- wget -q $LIBEVENTSOURCE -O $TMPFOLDER/$LIBEVENTEXTRACTNAME >/dev/null 2>&1
- if [[ $? > 0 ]]
- then
- echo "The command failed, exiting." ; exit
- fi
- #extract
- #tar xf $TMPFOLDER/${LIBEVENTSOURCE##*/} -C $TMPFOLDER >/dev/null 2>&1
- tar xf $TMPFOLDER/$LIBEVENTEXTRACTNAME -C $TMPFOLDER >/dev/null 2>&1
- if [[ $? > 0 ]]
- then
- echo "The command failed, exiting." ; exit
- else
- echo " OK!"
- fi
- printf "12/22 Downloading sources of TRANSMISSION"
- #Getting sources of Transmission and LibEvent
- wget -q --no-check-certificate $TRANSMISSIONSOURCE -O $TMPFOLDER/${TRANSMISSIONSOURCE##*/} >/dev/null 2>&1
- if [[ $? > 0 ]]
- then
- echo "The command failed, exiting." ; exit
- fi
- #extract
- tar xf $TMPFOLDER/${TRANSMISSIONSOURCE##*/} -C $TMPFOLDER >/dev/null 2>&1
- if [[ $? > 0 ]]
- then
- echo "The command failed, exiting." ; exit
- else
- echo " OK!"
- fi
- #clean cache
- apt-get clean
- #Getfilenames of directories
- #AFTER_SLASH=${LIBEVENTSOURCE##*/}
- #file="${AFTER_SLASH%%\?*}"
- file=${LIBEVENTEXTRACTNAME}
- DIRLIBEVENTSOURCE=${file%.tar.xz}
- DIRLIBEVENTSOURCE=${DIRLIBEVENTSOURCE%.tar.gz}
- #Configure LIBEVENT
- cd $TMPFOLDER/$DIRLIBEVENTSOURCE
- printf "13/22 Configuring LIBEVENT to compile..."
- ./autogen.sh >/dev/null 2>&1
- if [[ $? > 0 ]]
- then
- echo "The command failed, exiting." ; exit
- fi
- ./configure --prefix=/usr >/dev/null 2>&1
- if [[ $? > 0 ]]
- then
- echo "The command failed, exiting." ; exit
- else
- echo " OK!"
- fi
- #Compile LIBEVENT
- printf "14/22 Compiling LIBEVENT..."
- make >/dev/null 2>&1
- if [[ $? > 0 ]]
- then
- echo "The command failed, exiting." ; exit
- else
- echo " OK!"
- fi
- #Install LIBEVENT
- printf "15/22 Installing LIBEVENT..."
- make install >/dev/null 2>&1
- if [[ $? > 0 ]]
- then
- echo "The command failed, exiting." ; exit
- else
- echo " OK!"
- fi
- #Configure TRANSMISSION
- AFTER_SLASH=${TRANSMISSIONSOURCE##*/}
- file="${AFTER_SLASH%%\?*}"
- DIRTRANSMISSION=${file%.tar.xz}
- DIRTRANSMISSION=${DIRTRANSMISSION%.tar.gz}
- cd $TMPFOLDER/$DIRTRANSMISSION
- printf "16/22 Configuring TRANSMISSION to compile..."
- ./configure --prefix=/usr --enable-lightweight --enable-daemon --enable-utp >/dev/null 2>&1
- if [[ $? > 0 ]]
- then
- echo "The command failed, exiting."
- echo $AFTER_SLASH
- echo file
- echo $DIRTRANSMISSION
- exit
- else
- echo " OK!"
- fi
- #Compile TRANSMISSION
- printf "17/22 Compiling TRANSMISSION..."
- make >/dev/null 2>&1
- if [[ $? > 0 ]]
- then
- echo "The command failed, exiting." ; exit
- else
- echo " OK!"
- fi
- #Install TRANSMISSION
- printf "18/22 Installing TRANSMISSION..."
- #mkdir -p /root/.config/transmissiond
- make install >/dev/null 2>&1
- if [[ $? > 0 ]]
- then
- echo "The command failed, exiting." ; exit
- else
- echo " OK!"
- fi
- #settings.json
- read -d '' SETTINGSJSON <<"EOF"
- {
- "alt-speed-down": 300,
- "alt-speed-enabled": true,
- "alt-speed-time-begin": 420,
- "alt-speed-time-day": 127,
- "alt-speed-time-enabled": true,
- "alt-speed-time-end": 30,
- "alt-speed-up": 10,
- "bind-address-ipv4": "0.0.0.0",
- "bind-address-ipv6": "::",
- "blocklist-enabled": true,
- "blocklist-url": "http://list.iblocklist.com/?list=bt_level1&fileformat=p2p&archiveformat=gz",
- "cache-size-mb": 8,
- "dht-enabled": true,
- "download-dir": "/DataVolume/shares/Public/Torrents/Completed",
- "download-queue-enabled": true,
- "download-queue-size": 5,
- "encryption": 2,
- "idle-seeding-limit": 30,
- "idle-seeding-limit-enabled": true,
- "incomplete-dir": "/DataVolume/shares/Public/Torrents/Incomplete",
- "incomplete-dir-enabled": true,
- "lazy-bitfield-enabled": true,
- "lpd-enabled": false,
- "message-level": 2,
- "peer-congestion-algorithm": "lp",
- "peer-id-ttl-hours": 6,
- "peer-limit-global": 260,
- "peer-limit-per-torrent": 80,
- "peer-port": 51003,
- "peer-port-random-high": 65535,
- "peer-port-random-low": 49152,
- "peer-port-random-on-start": false,
- "peer-socket-tos": "lowcost",
- "pex-enabled": true,
- "port-forwarding-enabled": false,
- "preallocation": 2,
- "prefetch-enabled": 0,
- "queue-stalled-enabled": true,
- "queue-stalled-minutes": 60,
- "ratio-limit": 0.1000,
- "ratio-limit-enabled": true,
- "rename-partial-files": true,
- "rpc-authentication-required": false,
- "rpc-bind-address": "0.0.0.0",
- "rpc-enabled": true,
- "rpc-password": "{ee82e7a5337f8d06704c133d83fd69da54bdc785ixojPp6Z",
- "rpc-port": 9091,
- "rpc-url": "/transmission/",
- "rpc-username": "transmission",
- "rpc-whitelist": "127.0.0.1,192.168.*.*",
- "rpc-whitelist-enabled": true,
- "scrape-paused-torrents-enabled": true,
- "script-torrent-done-enabled": false,
- "script-torrent-done-filename": "/DataVolume/shares/Public/Torrents/Scripts/processaTorrent.sh",
- "seed-queue-enabled": true,
- "seed-queue-size": 10,
- "speed-limit-down": 1100,
- "speed-limit-down-enabled": true,
- "speed-limit-up": 85,
- "speed-limit-up-enabled": true,
- "start-added-torrents": true,
- "trash-original-torrent-files": true,
- "umask": 0,
- "upload-slots-per-torrent": 8,
- "utp-enabled": true,
- "watch-dir": "/DataVolume/shares/Public/Torrents/Monitora",
- "watch-dir-enabled": false
- }
- EOF
- #INIT.D file
- read -d '' INITD <<"EOF"
- #! /bin/sh
- ### BEGIN INIT INFO
- # Provides: transmission-daemon
- # Required-Start: networking
- # Required-Stop: networking
- # Default-Start: 2 3 5
- # Default-Stop: 0 1 6
- # Short-Description: Start the transmission BitTorrent daemon client.
- ### END INIT INFO
- # Original Author: Lennart A. Jaette, based on Rob Howell's script
- # Modified by Maarten Van Coile & others (on IRC)
- # Do NOT "set -e"
- #
- # ----- CONFIGURATION -----
- #
- # For the default location Transmission uses, visit:
- # http://trac.transmissionbt.com/wiki/ConfigFiles
- # For a guide on how set the preferences, visit:
- # http://trac.transmissionbt.com/wiki/EditConfigFiles
- # For the available environement variables, visit:
- # http://trac.transmissionbt.com/wiki/EnvironmentVariables
- #
- # The name of the user that should run Transmission.
- # It's RECOMENDED to run Transmission in it's own user,
- # by default, this is set to 'transmission'.
- # For the sake of security you shouldn't set a password
- # on this user
- USERNAME=root
- # ----- *ADVANCED* CONFIGURATION -----
- # Only change these options if you know what you are doing!
- #
- # The folder where Transmission stores the config & web files.
- # ONLY change this you have it at a non-default location
- #TRANSMISSION_HOME="/var/config/transmission-daemon"
- #TRANSMISSION_WEB_HOME="/usr/share/transmission/web"
- #
- # The arguments passed on to transmission-daemon.
- # ONLY change this you need to, otherwise use the
- # settings file as per above.
- #TRANSMISSION_ARGS=""
- # ----- END OF CONFIGURATION -----
- #
- # PATH should only include /usr/* if it runs after the mountnfs.sh script.
- PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
- DESC="bittorrent client"
- NAME=transmission-daemon
- DAEMON=$(which $NAME)
- PIDFILE=/var/run/$NAME.pid
- SCRIPTNAME=/etc/init.d/$NAME
- # Exit if the package is not installed
- [ -x "$DAEMON" ] || exit 0
- # Read configuration variable file if it is present
- [ -r /etc/default/$NAME ] && . /etc/default/$NAME
- # Load the VERBOSE setting and other rcS variables
- [ -f /etc/default/rcS ] && . /etc/default/rcS
- #
- # Function that starts the daemon/service
- #
- do_start()
- {
- # Export the configuration/web directory, if set
- if [ -n "$TRANSMISSION_HOME" ]; then
- export TRANSMISSION_HOME
- fi
- if [ -n "$TRANSMISSION_WEB_HOME" ]; then
- export TRANSMISSION_WEB_HOME
- fi
- # Return
- # 0 if daemon has been started
- # 1 if daemon was already running
- # 2 if daemon could not be started
- start-stop-daemon --chuid $USERNAME --start --pidfile $PIDFILE --make-pidfile \
- --exec $DAEMON --background --test -- -f $TRANSMISSION_ARGS > /dev/null \
- || return 1
- start-stop-daemon --chuid $USERNAME --start --pidfile $PIDFILE --make-pidfile \
- --exec $DAEMON --background -- -f $TRANSMISSION_ARGS \
- || return 2
- }
- #
- # Function that stops the daemon/service
- #
- do_stop()
- {
- # Return
- # 0 if daemon has been stopped
- # 1 if daemon was already stopped
- # 2 if daemon could not be stopped
- # other if a failure occurred
- start-stop-daemon --stop --quiet --retry=TERM/10/KILL/5 --pidfile $PIDFILE --exec $DAEMON
- RETVAL="$?"
- [ "$RETVAL" = 2 ] && return 2
- # Wait for children to finish too if this is a daemon that forks
- # and if the daemon is only ever run from this initscript.
- # If the above conditions are not satisfied then add some other code
- # that waits for the process to drop all resources that could be
- # needed by services started subsequently. A last resort is to
- # sleep for some time.
- start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $DAEMON
- [ "$?" = 2 ] && return 2
- # Many daemons don't delete their pidfiles when they exit.
- rm -f $PIDFILE
- return "$RETVAL"
- }
- case "$1" in
- start)
- echo "Starting $DESC" "$NAME..."
- do_start
- case "$?" in
- 0|1) echo " Starting $DESC $NAME succeeded" ;;
- *) echo " Starting $DESC $NAME failed" ;;
- esac
- ;;
- stop)
- echo "Stopping $DESC $NAME..."
- do_stop
- case "$?" in
- 0|1) echo " Stopping $DESC $NAME succeeded" ;;
- *) echo " Stopping $DESC $NAME failed" ;;
- esac
- ;;
- restart|force-reload)
- #
- # If the "reload" option is implemented then remove the
- # 'force-reload' alias
- #
- echo "Restarting $DESC $NAME..."
- do_stop
- case "$?" in
- 0|1)
- do_start
- case "$?" in
- 0|1) echo " Restarting $DESC $NAME succeeded" ;;
- *) echo " Restarting $DESC $NAME failed: couldn't start $NAME" ;;
- esac
- ;;
- *)
- echo " Restarting $DESC $NAME failed: couldn't stop $NAME" ;;
- esac
- ;;
- *)
- echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2
- exit 3
- ;;
- esac
- EOF
- #Setting TRANSMISSION to auto startup
- printf "19/22 Configuring TRANSMISSION to auto startup"
- printf "$INITD" > /etc/init.d/transmission-daemon
- chmod +x /etc/init.d/transmission-daemon
- chown root:root /etc/init.d/transmission-daemon
- #Adding autostart to transmission
- update-rc.d transmission-daemon defaults >/dev/null 2>&1
- if [[ $? > 0 ]]
- then
- echo "The command failed, exiting." ; exit
- else
- echo " OK!"
- fi
- #Starting TRANSMISSION
- printf "20/22 Configuring TRANSMISSION settings.json"
- /etc/init.d/transmission-daemon start >/dev/null 2>&1
- if [[ $? > 0 ]]
- then
- echo "The command failed, exiting." ; exit
- fi
- #Wait transmission to create config files structure
- sleep 5
- /etc/init.d/transmission-daemon stop >/dev/null 2>&1
- if [[ $? > 0 ]]
- then
- echo "The command failed, exiting." ; exit
- fi
- #configuring SETTINGS.JSON
- printf "$SETTINGSJSON" > /root/.config/transmission-daemon/settings.json
- echo " OK!"
- printf "21/22 Cleaning temp files"
- #Cleaning temp files
- cp /etc/apt/sources.list /etc/apt/sources.list.new
- cat $TMPFOLDER/sources.list.bak > /etc/apt/sources.list
- rm -rf $TMPFOLDER
- apt-get clean
- echo " OK!"
- #Starting TRANSMISSION
- printf "22/22 Starting TRANSMISSION"
- /etc/init.d/transmission-daemon start >/dev/null 2>&1
- if [[ $? > 0 ]]
- then
- echo "The command failed, exiting." ; exit
- else
- echo " OK!"
- fi
- end=$SECONDS
- echo "Total time: $((end - start)) secs."
- echo "Done!"
- echo "Cross your fingers and access http://mybooklive:9091/"
- echo "TODO: REMEMBER to configure: settings.json"
- echo ""
Add Comment
Please, Sign In to add comment