#!/bin/bash
apt-get update
apt-get -y install mpg321 snmpd lighttpd
#create snmp config file
echo \'agentAddress udp:161
rocommunity public
sysLocation Attic
sysContact Stuart Weenig (stuart@weenig.com)
sysServices 72
\' > /etc/snmp/snmpd.conf
#restart snmp
/etc/init.d/snmpd restart
#configure 3.5mm port for use
modprobe snd_bcm2835
amixer cset numid=3 1
#setup destination folder for sounds
mkdir /home/pi/PiTunes
#create btsync config file
echo \'{
"device_name": "PiTunes",
"listening_port" : 0,
"use_upnp" : true,
"download_limit" : 0,
"upload_limit" : 0,
"shared_folders" :
[
{
"secret" : "BZR6O5BRDGVWNY3A73NL5BJC3KMSFT2SF","dir" : "/home/pi/PiTunes",
"use_relay_server" : true,
"use_tracker" : true,
"use_dht" : false,
"search_lan" : true,
"use_sync_trash" : false
}
]
}\' > sync.conf
#download btsync
wget http://btsync.s3-website-us-east-1.amazonaws.com/btsync_arm.tar.gz -O /tmp/btsync_arm.tar.gz
tar -xzf /tmp/btsync_arm.tar.gz
cp /tmp/btsync /home/pi/btsync
#launch btsync & start download of sounds
/home/pi/btsync --config sync.conf
echo \'#!/usr/bin/env python
import time
import os
import logging
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"\'")
day = time.strftime("%j")
logging.debug("DAY: %s",day)
playlist = int(day) % 2
logging.debug("Playlist: %s",playlist)
if playlist == 0:
if day > 330:
logging.debug("Playing Christmas music...")
cmd = "mpg321 --random /home/pi/PiTunes/christmas/* &"
logging.debug("Executing command: %s",cmd)
os.system(cmd)
else:
logging.debug("Playing music...")
cmd = "mpg321 --random /home/pi/PiTunes/music/* &"
logging.debug("Executing command: %s",cmd)
os.system(cmd)
elif playlist ==1:
logging.debug("Playing waves...")
cmd = "mpg321 --random /home/pi/PiTunes/waves/* &"
logging.debug("Executing command: %s",cmd)
os.system(cmd)
elif playlist ==2:
logging.debug("Playing nothing...")
else:
logging.warning("Problem determining which playlist to play.")
vol = 0
cmd = "amixer -q set PCM " + str(vol) + "%"
logging.debug("Executing command: %s",cmd)
os.system(cmd)
while vol < 100 :
vol += 1
cmd = "amixer -q set PCM " + str(vol) + "%"
logging.debug("Executing command: %s",cmd)
os.system(cmd)
time.sleep(1)
time.sleep(10800)
while vol > 0:
vol -= 1
cmd = "amixer -q set PCM " + str(vol) + "%"
logging.debug("Executing command: %s",cmd)
os.system(cmd)
time.sleep(10)
logging.debug("Killing mpg321...")
os.system("killall mpg321")
\' > play.py
chmod +x play.py
(crontab -l ; echo "30 18 * * * /usr/bin/python /home/pi/play.py") | crontab - -u pi
#setup web server
cp /etc/lighttpd/lighttpd.conf /etc/lighttpd/lighttpd.conf.old
echo \'server.modules = (
"mod_access",
"mod_alias",
"mod_compress",
"mod_redirect",
"mod_cgi",
)
server.document-root = "/home/pi/PiTunes/www"
server.upload-dirs = ( "/var/cache/lighttpd/uploads" )
server.errorlog = "/var/log/lighttpd/error.log"
server.pid-file = "/var/run/lighttpd.pid"
server.username = "www-data"
server.groupname = "www-data"
server.port = 80
cgi.assign = ( ".sh" => "" )
index-file.names = ( "index.sh", "index.php", "index.html", "index.lighttpd.html" )
url.access-deny = ( "~", ".inc" )
static-file.exclude-extensions = ( ".php", ".pl", ".fcgi" )
compress.cache-dir = "/var/cache/lighttpd/compress/"
compress.filetype = ( "application/javascript", "text/css", "text/html", "text/plain" )
# default listening port for IPv6 falls back to the IPv4 port
include_shell "/usr/share/lighttpd/use-ipv6.pl " + server.port
include_shell "/usr/share/lighttpd/create-mime.assign.pl"
include_shell "/usr/share/lighttpd/include-conf-enabled.pl"\' > /etc/lighttpd/lighttpd.conf
/etc/init.d/lighttpd restart