daily pastebin goal
58%
SHARE
TWEET

PiTunes

sweenig Aug 20th, 2014 366 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/bash
  2. apt-get update
  3. apt-get -y install mpg321 snmpd lighttpd
  4. #create snmp config file
  5. echo 'agentAddress udp:161
  6. rocommunity public
  7. sysLocation Attic
  8. sysContact Stuart Weenig (stuart@weenig.com)
  9. sysServices 72
  10. ' > /etc/snmp/snmpd.conf
  11. #restart snmp
  12. /etc/init.d/snmpd restart
  13. #configure 3.5mm port for use
  14. modprobe snd_bcm2835
  15. amixer cset numid=3 1
  16. #setup destination folder for sounds
  17. mkdir /home/pi/PiTunes
  18. #create btsync config file
  19. echo '{
  20.  "device_name": "PiTunes",
  21.  "listening_port" : 0,
  22.  "use_upnp" : true,
  23.  "download_limit" : 0,
  24.  "upload_limit" : 0,
  25.  "shared_folders" :
  26.  [
  27.    {
  28.      "secret" : "BZR6O5BRDGVWNY3A73NL5BJC3KMSFT2SF","dir" : "/home/pi/PiTunes",
  29.      "use_relay_server" : true,
  30.      "use_tracker" : true,
  31.      "use_dht" : false,
  32.      "search_lan" : true,
  33.      "use_sync_trash" : false
  34.    }
  35.  ]
  36. }' > sync.conf
  37. #download btsync
  38. wget http://btsync.s3-website-us-east-1.amazonaws.com/btsync_arm.tar.gz -O /tmp/btsync_arm.tar.gz
  39. tar -xzf /tmp/btsync_arm.tar.gz
  40. cp /tmp/btsync /home/pi/btsync
  41. #launch btsync & start download of sounds
  42. /home/pi/btsync --config sync.conf
  43.  
  44. echo '#!/usr/bin/env python
  45. import time
  46. import os
  47. import logging
  48. logging.basicConfig(format="'"%(asctime)s %(levelname)s:%(message)s"'",filename="/home/pi/PiTunes/play.log",level=logging.DEBUG,datefmt="'"%m/%d/%Y %I:%M:%S %p"'")
  49. day = time.strftime("%j")
  50. logging.debug("DAY: %s",day)
  51. playlist = int(day) % 2
  52. logging.debug("Playlist: %s",playlist)
  53. if playlist == 0:
  54.         if day > 330:
  55.                 logging.debug("Playing Christmas music...")
  56.                 cmd = "mpg321 --random /home/pi/PiTunes/christmas/* &"
  57.                 logging.debug("Executing command: %s",cmd)
  58.                 os.system(cmd)
  59.         else:
  60.                 logging.debug("Playing music...")
  61.                 cmd = "mpg321 --random /home/pi/PiTunes/music/* &"
  62.                 logging.debug("Executing command: %s",cmd)
  63.                 os.system(cmd)
  64. elif playlist ==1:
  65.         logging.debug("Playing waves...")
  66.         cmd = "mpg321 --random /home/pi/PiTunes/waves/* &"
  67.         logging.debug("Executing command: %s",cmd)
  68.         os.system(cmd)
  69. elif playlist ==2:
  70.         logging.debug("Playing nothing...")
  71. else:
  72.         logging.warning("Problem determining which playlist to play.")
  73. vol = 0
  74. cmd = "amixer -q set PCM " + str(vol) + "%"
  75. logging.debug("Executing command: %s",cmd)
  76. os.system(cmd)
  77. while vol < 100 :
  78.         vol += 1
  79.         cmd = "amixer -q set PCM " + str(vol) + "%"
  80.         logging.debug("Executing command: %s",cmd)
  81.         os.system(cmd)
  82.         time.sleep(1)
  83. time.sleep(10800)
  84. while vol > 0:
  85.         vol -= 1
  86.         cmd = "amixer -q set PCM " + str(vol) + "%"
  87.         logging.debug("Executing command: %s",cmd)
  88.         os.system(cmd)
  89.         time.sleep(10)
  90. logging.debug("Killing mpg321...")
  91. os.system("killall mpg321")
  92. ' > play.py
  93.  
  94. chmod +x play.py
  95. (crontab -l ; echo "30 18 * * * /usr/bin/python /home/pi/play.py") | crontab - -u pi
  96.  
  97. #setup web server
  98. cp /etc/lighttpd/lighttpd.conf /etc/lighttpd/lighttpd.conf.old
  99. echo 'server.modules = (
  100.         "mod_access",
  101.         "mod_alias",
  102.         "mod_compress",
  103.         "mod_redirect",
  104.         "mod_cgi",
  105. )
  106.  
  107. server.document-root        = "/home/pi/PiTunes/www"
  108. server.upload-dirs          = ( "/var/cache/lighttpd/uploads" )
  109. server.errorlog             = "/var/log/lighttpd/error.log"
  110. server.pid-file             = "/var/run/lighttpd.pid"
  111. server.username             = "www-data"
  112. server.groupname            = "www-data"
  113. server.port                 = 80
  114.  
  115. cgi.assign = ( ".sh" => "" )
  116.  
  117. index-file.names            = ( "index.sh", "index.php", "index.html", "index.lighttpd.html" )
  118. url.access-deny             = ( "~", ".inc" )
  119. static-file.exclude-extensions = ( ".php", ".pl", ".fcgi" )
  120.  
  121. compress.cache-dir          = "/var/cache/lighttpd/compress/"
  122. compress.filetype           = ( "application/javascript", "text/css", "text/html", "text/plain" )
  123.  
  124. # default listening port for IPv6 falls back to the IPv4 port
  125. include_shell "/usr/share/lighttpd/use-ipv6.pl " + server.port
  126. include_shell "/usr/share/lighttpd/create-mime.assign.pl"
  127. include_shell "/usr/share/lighttpd/include-conf-enabled.pl"' > /etc/lighttpd/lighttpd.conf
  128. /etc/init.d/lighttpd restart
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top