#!/bin/bash
### BEGIN INIT INFO
# Provides: utorrent
# Required-Start: $local_fs $network
# Required-Stop: $local_fs $network
# Default-Start: 4 5
# Default-Stop: 0 1 6
# Short-Description: Start/stop utorrent client+web server
### END INIT INFO
#
# utorrent This init.d script is used to start uTorrent.
#
# This script is made for Ubuntu 8.04 and requires a few packages:
# sudo apt-get install wine vnc-java vnc4server msttcorefonts fluxbox
# I wanted a lean windowmanager so i chose fluxbox, but anything would do.
#
# Create VNC password-file:
# mkdir $HOME/.vnc && vnc4passwd $HOME/.vnc/passwd
#
# Install this script in /etc/init.d/ and run "chmod 755 utorrent"
# and then "sudo update-rc.d utorrent multiuser" after that you might
# want to try to start it out to see that it is working alright.
# Try it like this: sudo invoke-rc.d utorrent start
#
# I suggest you run uTorrent as usual on your desktop and set
# it up like you want it. Remeber to install & enable the webui.
#
# Connect with a vnc-viewer to either port 5902 or screen 2,
# or you could make use of the built-in webserver on port 5802.
#
# Samuel Thollander <samuel@thollander.net>
# Change this!
USER=sam
test -f /lib/lsb/init-functions && . /lib/lsb/init-functions
test -f /etc/default/rcS && . /etc/default/rcS
ut_start() {
su $USER -c '( Xvnc4 -screen 0 800x600x16 -br -ac \
-PasswordFile /home/$USER/.vnc/passwd \
-httpd /usr/share/vnc-java/ -httpport 5802 :2 >/dev/null 2>&1 &) \
&& sleep 2 && export DISPLAY=:2 && \
(exec fluxbox >/dev/null 2>&1 &) && sleep 2 && \
(wine /home/$USER/.wine/drive_c/Program\ Files/utorrent/uTorrent.exe >/dev/null 2>&1 & )'
}
ut_stop() {
su $USER -c 'DISPLAY=:2 WINEDEBUG=-all wineboot -e >/dev/null 2>&1'
sleep 1
# Well, this is rather optimistic...
pkill -u $USER Xvnc4 >/dev/null 2>&1
}
case $1 in
start)
log_daemon_msg "Starting uTorrent"
ut_start
log_end_msg $?
;;
stop)
log_daemon_msg "Stopping uTorrent"
ut_stop
log_end_msg $?
;;
restart)
log_daemon_msg "Restarting uTorrent"
ut_stop
ut_start
log_end_msg $?
;;
*)
log_success_msg "Usage: /etc/init.d/utorrent {start|stop|restart}"
exit 1
;;
esac