Share Pastebin
Guest
Public paste!

Samuel

By: a guest | Apr 26th, 2008 | Syntax: Bash | Size: 2.22 KB | Hits: 513 | Expires: Never
Copy text to clipboard
  1. #!/bin/bash
  2. ### BEGIN INIT INFO
  3. # Provides:          utorrent
  4. # Required-Start:    $local_fs $network
  5. # Required-Stop:     $local_fs $network
  6. # Default-Start:     4 5
  7. # Default-Stop:      0 1 6
  8. # Short-Description: Start/stop utorrent client+web server
  9. ### END INIT INFO
  10. #
  11. # utorrent              This init.d script is used to start uTorrent.
  12. #
  13. # This script is made for Ubuntu 8.04 and requires a few packages:
  14. # sudo apt-get install wine vnc-java vnc4server msttcorefonts fluxbox
  15. # I wanted a lean windowmanager so i chose fluxbox, but anything would do.
  16. #
  17. # Create VNC password-file:
  18. # mkdir $HOME/.vnc && vnc4passwd $HOME/.vnc/passwd
  19. #
  20. # Install this script in /etc/init.d/ and run "chmod 755 utorrent"
  21. # and then "sudo update-rc.d utorrent multiuser" after that you might
  22. # want to try to start it out to see that it is working alright.
  23. # Try it like this: sudo invoke-rc.d utorrent start
  24. #
  25. # I suggest you run uTorrent as usual on your desktop and set
  26. # it up like you want it. Remeber to install & enable the webui.
  27. #
  28. # Connect with a vnc-viewer to either port 5902 or screen 2,
  29. # or you could make use of the built-in webserver on port 5802.
  30. #
  31. # Samuel Thollander <samuel@thollander.net>
  32.  
  33. # Change this!
  34. USER=sam
  35.  
  36. test -f /lib/lsb/init-functions && . /lib/lsb/init-functions
  37. test -f /etc/default/rcS && . /etc/default/rcS
  38.  
  39. ut_start() {
  40.         su $USER -c '( Xvnc4  -screen 0 800x600x16 -br -ac \
  41.         -PasswordFile /home/$USER/.vnc/passwd \
  42.         -httpd /usr/share/vnc-java/ -httpport 5802 :2 >/dev/null 2>&1 &) \
  43.         && sleep 2 && export DISPLAY=:2 && \
  44.         (exec fluxbox >/dev/null 2>&1 &) && sleep 2 && \
  45.         (wine /home/$USER/.wine/drive_c/Program\ Files/utorrent/uTorrent.exe >/dev/null 2>&1 & )'
  46. }
  47.  
  48. ut_stop() {
  49.         su $USER -c 'DISPLAY=:2 WINEDEBUG=-all wineboot -e >/dev/null 2>&1'
  50.         sleep 1
  51.         # Well, this is rather optimistic...
  52.         pkill -u $USER Xvnc4 >/dev/null 2>&1
  53. }
  54.  
  55. case $1 in
  56.         start)
  57.                 log_daemon_msg "Starting uTorrent"
  58.                 ut_start
  59.                 log_end_msg $?
  60.         ;;
  61.         stop)
  62.                 log_daemon_msg "Stopping uTorrent"
  63.                 ut_stop
  64.                 log_end_msg $?
  65.         ;;
  66.         restart)
  67.                 log_daemon_msg "Restarting uTorrent"
  68.                 ut_stop
  69.                 ut_start
  70.                 log_end_msg $?
  71.         ;;
  72.         *)
  73.                 log_success_msg "Usage: /etc/init.d/utorrent {start|stop|restart}"
  74.                 exit 1
  75.         ;;
  76.  
  77. esac