sintonia/dev_tools/fabric/fab_liquidsoap_compile.py

215 lines
7.5 KiB
Python
Raw Normal View History

#Airtime Liquidsoap compile infrastructure
#author martin.konecny@sourcefabric.org
#Documentation for this page:
import os
import time
import sys
from fabric.api import *
from fabric.contrib.files import comment, sed, append
from ConfigParser import ConfigParser
from xml.dom.minidom import parse
from xml.dom.minidom import Node
from xml.dom.minidom import Element
env.user = 'martin'
env.password = 'test'
env.hosts = []
env.host_string
env.vm_download_url = "http://host.sourcefabric.org/vms/VirtualBox"
2012-09-19 00:19:29 +02:00
#fab -f fab_setup.py ubuntu_lucid_64 airtime_182_tar airtime_190_tar
2011-12-02 19:37:29 +01:00
def do_sudo(command):
result = sudo(command)
if result.return_code != 0:
print "Error running command: %s" %command
shutdown()
sys.exit(1)
else:
return result
2012-09-19 00:19:29 +02:00
2011-12-02 19:37:29 +01:00
def do_run(command):
result = run(command)
if result.return_code != 0:
print "Error running command: %s" %command
shutdown()
sys.exit(1)
else:
return result
2012-09-19 00:19:29 +02:00
2011-12-02 19:37:29 +01:00
def do_local(command, capture=True):
result = local(command, capture)
if result.return_code != 0:
print "Error running command: %s" %command
shutdown()
sys.exit(1)
else:
return result
def shutdown():
2011-12-02 19:37:29 +01:00
do_sudo("poweroff")
time.sleep(30)
2012-09-19 00:19:29 +02:00
def download_if_needed(vdi_dir, xml_dir, vm_name, vm_vdi_file, vm_xml_file):
if not os.path.exists(vdi_dir):
os.makedirs(vdi_dir)
2012-09-19 00:19:29 +02:00
if os.path.exists(os.path.join(vdi_dir, vm_vdi_file)):
print "File %s already exists. No need to re-download" % os.path.join(vdi_dir, vm_vdi_file)
else:
print "File %s not found. Downloading" % vm_vdi_file
2011-12-02 19:37:29 +01:00
tmpPath = do_local("mktemp", capture=True)
do_local("wget %s/%s/%s -O %s"%(env.vm_download_url, vm_name, vm_vdi_file, tmpPath))
os.rename(tmpPath, os.path.join(vdi_dir, vm_vdi_file))
2012-09-19 00:19:29 +02:00
2011-12-02 19:37:29 +01:00
if os.path.exists(os.path.join(xml_dir, vm_xml_file)):
print "File %s already exists. No need to re-download" % os.path.join(xml_dir, vm_xml_file)
else:
2012-09-19 00:19:29 +02:00
do_local("wget %s/%s/%s -O %s"%(env.vm_download_url, vm_name, vm_xml_file, os.path.join(xml_dir, vm_xml_file)))
def create_fresh_os(vm_name, debian=False):
2012-09-19 00:19:29 +02:00
vm_vdi_file = '%s.vdi'%vm_name
vm_xml_file = '%s.xml'%vm_name
vdi_dir = os.path.expanduser('~/tmp/vms/%s'%vm_name)
vdi_snapshot_dir = os.path.expanduser('~/tmp/vms/%s/Snapshots'%vm_name)
xml_dir = os.path.expanduser('~/.VirtualBox')
vm_xml_path = os.path.join(xml_dir, vm_xml_file)
2012-09-19 00:19:29 +02:00
download_if_needed(vdi_dir, xml_dir, vm_name, vm_vdi_file, vm_xml_file)
2012-09-19 00:19:29 +02:00
if not os.path.exists("%s/vm_registered"%vdi_dir):
2011-12-02 19:37:29 +01:00
do_local("VBoxManage registervm %s"%os.path.join(xml_dir, vm_xml_file), capture=True)
do_local('VBoxManage storagectl "%s" --name "SATA Controller" --add sata'%vm_name)
do_local('VBoxManage storageattach "%s" --storagectl "SATA Controller" --port 0 --device 0 --type hdd --medium %s'%(vm_name, os.path.join(vdi_dir, vm_vdi_file)))
do_local("VBoxManage modifyvm %s --snapshotfolder %s"%(vm_name, vdi_snapshot_dir))
do_local("VBoxManage snapshot %s take fresh_install"%vm_name)
do_local("touch %s/vm_registered"%vdi_dir)
do_local('VBoxManage snapshot %s restore fresh_install'%vm_name)
do_local('VBoxManage modifyvm "%s" --bridgeadapter1 eth0'%vm_name)
do_local('VBoxManage startvm %s'%vm_name)
print "Please wait while attempting to acquire IP address"
2012-09-19 00:19:29 +02:00
time.sleep(15)
try_again = True
while try_again:
2011-12-02 19:37:29 +01:00
ret = do_local('VBoxManage --nologo guestproperty get "%s" /VirtualBox/GuestInfo/Net/0/V4/IP'%vm_name, capture=True)
triple = ret.partition(':')
ip_addr = triple[2].strip(' \r\n')
print "Address found %s"%ip_addr
2012-09-19 00:19:29 +02:00
try_again = (len(ip_addr) == 0)
time.sleep(1)
2012-09-19 00:19:29 +02:00
env.hosts.append(ip_addr)
env.host_string = ip_addr
2012-09-19 00:19:29 +02:00
if debian:
append('/etc/apt/sources.list', "deb http://www.debian-multimedia.org squeeze main non-free", use_sudo=True)
2012-09-19 00:19:29 +02:00
def ubuntu_lucid_32(fresh_os=True):
if (fresh_os):
create_fresh_os('Ubuntu_10.04_32')
def ubuntu_lucid_64(fresh_os=True):
if (fresh_os):
create_fresh_os('Ubuntu_10.04_64')
2012-09-19 00:19:29 +02:00
def ubuntu_maverick_32(fresh_os=True):
if (fresh_os):
create_fresh_os('Ubuntu_10.10_32')
def ubuntu_maverick_64(fresh_os=True):
if (fresh_os):
create_fresh_os('Ubuntu_10.10_64')
def ubuntu_natty_32(fresh_os=True):
if (fresh_os):
create_fresh_os('Ubuntu_11.04_32')
2012-09-19 00:19:29 +02:00
def ubuntu_natty_64(fresh_os=True):
if (fresh_os):
create_fresh_os('Ubuntu_11.04_64')
2012-09-19 00:19:29 +02:00
def ubuntu_oneiric_32(fresh_os=True):
if (fresh_os):
create_fresh_os('Ubuntu_11.10_32')
2012-09-19 00:19:29 +02:00
def ubuntu_oneiric_64(fresh_os=True):
if (fresh_os):
create_fresh_os('Ubuntu_11.10_64')
2012-09-19 00:19:29 +02:00
def ubuntu_precise_64(fresh_os=True):
if (fresh_os):
create_fresh_os('Ubuntu_12.04_64')
2012-09-19 00:19:29 +02:00
def ubuntu_precise_32(fresh_os=True):
if (fresh_os):
create_fresh_os('Ubuntu_12.04_32')
2012-09-19 00:19:29 +02:00
def debian_squeeze_32(fresh_os=True):
if (fresh_os):
create_fresh_os('Debian_Squeeze_32', debian=True)
2012-09-19 00:19:29 +02:00
def debian_squeeze_64(fresh_os=True):
if (fresh_os):
create_fresh_os('Debian_Squeeze_64', debian=True)
def compile_liquidsoap(filename="liquidsoap"):
2012-09-19 00:19:29 +02:00
config = ConfigParser()
config.readfp(open('fab_liquidsoap_compile.cfg'))
url = config.get('main', 'liquidsoap_tar_url')
2012-09-19 00:19:29 +02:00
print "Will get liquidsoap from " + url
2012-09-19 00:19:29 +02:00
2011-12-02 19:37:29 +01:00
do_sudo('apt-get update')
do_sudo('apt-get upgrade -y --force-yes')
2012-09-19 22:01:26 +02:00
do_sudo('''apt-get install -y --force-yes ocaml-findlib libao-ocaml-dev libportaudio-ocaml-dev \
libmad-ocaml-dev libtaglib-ocaml-dev libalsa-ocaml-dev libtaglib-ocaml-dev libvorbis-ocaml-dev \
libspeex-dev libspeexdsp-dev speex libladspa-ocaml-dev festival festival-dev \
libsamplerate-dev libxmlplaylist-ocaml-dev libxmlrpc-light-ocaml-dev libflac-dev \
libxml-dom-perl libxml-dom-xpath-perl patch autoconf libmp3lame-dev \
libcamomile-ocaml-dev libcamlimages-ocaml-dev libtool libpulse-dev libjack-dev
camlidl libfaad-dev libpcre-ocaml-dev''')
2012-09-19 00:19:29 +02:00
root = '/home/martin/src'
2011-12-02 19:37:29 +01:00
do_run('mkdir -p %s' % root)
2012-09-19 00:19:29 +02:00
2011-12-02 19:37:29 +01:00
tmpPath = do_local("mktemp", capture=True)
do_run('wget %s -O %s' % (url, tmpPath))
do_run('mv %s %s/liquidsoap.tar.gz' % (tmpPath, root))
do_run('cd %s && tar xzf liquidsoap.tar.gz' % root)
2012-09-19 00:19:29 +02:00
#do_run('cd %s/liquidsoap-1.0.1-full && cp PACKAGES.minimal PACKAGES' % root)
#sed('%s/liquidsoap-1.0.1-full/PACKAGES' % root, '#ocaml-portaudio', 'ocaml-portaudio')
#sed('%s/liquidsoap-1.0.1-full/PACKAGES' % root, '#ocaml-alsa', 'ocaml-alsa')
#sed('%s/liquidsoap-1.0.1-full/PACKAGES' % root, '#ocaml-pulseaudio', 'ocaml-pulseaudio')
#sed('%s/liquidsoap-1.0.1-full/PACKAGES' % root, '#ocaml-faad', 'ocaml-faad')
#do_run('cd %s/liquidsoap-1.0.1-full && ./bootstrap' % root)
#do_run('cd %s/liquidsoap-1.0.1-full && ./configure' % root)
#do_run('cd %s/liquidsoap-1.0.1-full && make' % root)
#get('%s/liquidsoap-1.0.1-full/liquidsoap-1.0.1/src/liquidsoap' % root, filename)
do_run('cd %s/savonet && cp PACKAGES.minimal PACKAGES' % root)
sed('%s/savonet/PACKAGES' % root, '#ocaml-portaudio', 'ocaml-portaudio')
sed('%s/savonet/PACKAGES' % root, '#ocaml-alsa', 'ocaml-alsa')
sed('%s/savonet/PACKAGES' % root, '#ocaml-pulseaudio', 'ocaml-pulseaudio')
sed('%s/savonet/PACKAGES' % root, '#ocaml-faad', 'ocaml-faad')
do_run('cd %s/savonet && make clean' % root)
2012-09-19 00:19:29 +02:00
do_run('cd %s/savonet && ./bootstrap' % root)
do_run('cd %s/savonet && ./configure' % root)
do_run('cd %s/savonet && make' % root)
get('%s/savonet/liquidsoap/src/liquidsoap' % root, filename)