Reference Code
#!/bin/bash
#Compile and Install transmission bittorrent client on mybooklive
#Author: Proglin 2015-09-10
Update: 2019-06-13 by milosgacanovic: Changed wheezy repository to archive.debian.org
Update: 2019-01-30 Using predownloaded sources to avoid wget SSL permission
Update: 2017-06-14 Update main code with suggestions from HTaborda and olimatis.
Update: 2016-10-06 by olimatis: New source for Transmission
Update: 2016-04-24 by HTaborda: Introduced --no-check-certificate to the Transmission source download; server certificate outdated
Update: 2016-02-26 LibEvent Extract Folder name changed + Compile Changed
Update: 2016-02-22 LibEvent URL changed
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:
#Building â Transmission
#Scripts/initd â Transmission
#http://falkhusemann.de/blog/2012/05/compiling-transmission-bittorrent-for-debiand/
#[GUIDE] How to unbrick a totally dead MBL - My Book Live - WD Community
#Support | Western Digital
start=$SECONDS
#Pre-downloaded folder location
/shares/Public/tmpDL
CONFIGURATION TRANSMISSION VERSION
#TRANSMISSIONSOURCE=âhttps://github.com/transmission/transmission-releases/raw/master/transmission-2.84.tar.xzâ
TRANSMISSIONSOURCE=â/shares/Public/tmpDL/transmission-2.84.tar.xzâ
DIRTRANSMISSIONSOURCE=âtransmission-2.84â
EXTRA CONFIGURATIONS
#TMPFOLDER=â/root/tempâ
#LIBEVENTSOURCE=âhttps://github.com/downloads/libevent/libevent/libevent-2.0.18-stable.tar.gzâ
LIBEVENTSOURCE=â/shares/Public/tmpDL/libevent-2.0.18-stable.tar.gzâ
#LIBEVENTEXTRACTNAME=âlibevent-release-2.0.18-stable.tar.gzâ
DIRLIBEVENTSOURCE=âlibevent-2.0.18-stableâ
#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: v2019-06-13"
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 âNOTE from Author: I have not MyBookLive since 2016. Changes after 2016 are basedâ
echo " on user forum comments.â
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 =~ $ ]]
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 Index of /debian squeeze main
deb-src Index of /debian squeeze main
#deb Index of /debian wheezy main
#deb-src Index of /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 Index of /debian squeeze main
#deb-src Index of /debian squeeze main
deb Index of /debian wheezy main
deb-src Index of /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 Index of /debian squeeze main
deb-src Index of /debian squeeze main
#deb Index of /debian wheezy main
#deb-src Index of /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 Extracting 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
#cp $LIBEVENTSOURCE $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 $LIBEVENTSOURCE -C $TMPFOLDER >/dev/null 2>&1
if [[ $? > 0 ]]
then
echo âThe command failed, exiting.â ; exit
else
echo " OK!"
fi
printf â12/22 Extracting sources of TRANSMISSIONâ
#Getting sources of Transmission and LibEvent
#wget -q $TRANSMISSIONSOURCE -O $TMPFOLDER/${TRANSMISSIONSOURCE##/} >/dev/null 2>&1
#wget --no-check-certificate -q $TRANSMISSIONSOURCE -O $TMPFOLDER/${TRANSMISSIONSOURCE##/} >/dev/null 2>&1
#cp $TRANSMISSIONSOURCE $TMPFOLDER >/dev/null 2>&1
#if [[ $? > 0 ]]
#then
echo âThe command failed, exiting.â ; exit
#fi
#extract
tar xf $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%%?}"
#DIRTRANSMISSIONSOURCE=${file%.tar.xz}
#DIRTRANSMISSIONSOURCE=${DIRTRANSMISSIONSOURCE%.tar.gz}
cd $TMPFOLDER/$DIRTRANSMISSIONSOURCE
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.â ; 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:
For a guide on how set the preferences, visit:
For the available environement variables, visit:
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 ââ