fab_liquidsoap_compile.py 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. #Airtime Liquidsoap compile infrastructure
  2. #author martin.konecny@sourcefabric.org
  3. #Documentation for this page:
  4. import os
  5. import time
  6. import sys
  7. from fabric.api import *
  8. from fabric.contrib.files import comment, sed, append
  9. from ConfigParser import ConfigParser
  10. from xml.dom.minidom import parse
  11. from xml.dom.minidom import Node
  12. from xml.dom.minidom import Element
  13. env.user = 'martin'
  14. env.password = 'test'
  15. env.hosts = []
  16. env.host_string
  17. env.vm_download_url = "http://host.sourcefabric.org/vms/VirtualBox"
  18. #fab -f fab_setup.py ubuntu_lucid_64 airtime_182_tar airtime_190_tar
  19. def do_sudo(command):
  20. result = sudo(command)
  21. if result.return_code != 0:
  22. print "Error running command: %s" %command
  23. shutdown()
  24. sys.exit(1)
  25. else:
  26. return result
  27. def do_run(command):
  28. result = run(command)
  29. if result.return_code != 0:
  30. print "Error running command: %s" %command
  31. shutdown()
  32. sys.exit(1)
  33. else:
  34. return result
  35. def do_local(command, capture=True):
  36. result = local(command, capture)
  37. if result.return_code != 0:
  38. print "Error running command: %s" %command
  39. shutdown()
  40. sys.exit(1)
  41. else:
  42. return result
  43. def shutdown():
  44. do_sudo("poweroff")
  45. time.sleep(30)
  46. def download_if_needed(vdi_dir, xml_dir, vm_name, vm_vdi_file, vm_xml_file):
  47. if not os.path.exists(vdi_dir):
  48. os.makedirs(vdi_dir)
  49. if os.path.exists(os.path.join(vdi_dir, vm_vdi_file)):
  50. print "File %s already exists. No need to re-download" % os.path.join(vdi_dir, vm_vdi_file)
  51. else:
  52. print "File %s not found. Downloading" % vm_vdi_file
  53. tmpPath = do_local("mktemp", capture=True)
  54. do_local("wget %s/%s/%s -O %s"%(env.vm_download_url, vm_name, vm_vdi_file, tmpPath))
  55. os.rename(tmpPath, os.path.join(vdi_dir, vm_vdi_file))
  56. if os.path.exists(os.path.join(xml_dir, vm_xml_file)):
  57. print "File %s already exists. No need to re-download" % os.path.join(xml_dir, vm_xml_file)
  58. else:
  59. 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)))
  60. def create_fresh_os(vm_name, debian=False):
  61. vm_vdi_file = '%s.vdi'%vm_name
  62. vm_xml_file = '%s.xml'%vm_name
  63. vdi_dir = os.path.expanduser('~/tmp/vms/%s'%vm_name)
  64. vdi_snapshot_dir = os.path.expanduser('~/tmp/vms/%s/Snapshots'%vm_name)
  65. xml_dir = os.path.expanduser('~/.VirtualBox')
  66. vm_xml_path = os.path.join(xml_dir, vm_xml_file)
  67. download_if_needed(vdi_dir, xml_dir, vm_name, vm_vdi_file, vm_xml_file)
  68. if not os.path.exists("%s/vm_registered"%vdi_dir):
  69. do_local("VBoxManage registervm %s"%os.path.join(xml_dir, vm_xml_file), capture=True)
  70. do_local('VBoxManage storagectl "%s" --name "SATA Controller" --add sata'%vm_name)
  71. 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)))
  72. do_local("VBoxManage modifyvm %s --snapshotfolder %s"%(vm_name, vdi_snapshot_dir))
  73. do_local("VBoxManage snapshot %s take fresh_install"%vm_name)
  74. do_local("touch %s/vm_registered"%vdi_dir)
  75. do_local('VBoxManage snapshot %s restore fresh_install'%vm_name)
  76. do_local('VBoxManage modifyvm "%s" --bridgeadapter1 eth0'%vm_name)
  77. do_local('VBoxManage startvm %s'%vm_name)
  78. print "Please wait while attempting to acquire IP address"
  79. time.sleep(30)
  80. try_again = True
  81. while try_again:
  82. ret = do_local('VBoxManage --nologo guestproperty get "%s" /VirtualBox/GuestInfo/Net/0/V4/IP'%vm_name, capture=True)
  83. triple = ret.partition(':')
  84. ip_addr = triple[2].strip(' \r\n')
  85. print "Address found %s"%ip_addr
  86. try_again = (len(ip_addr) == 0)
  87. time.sleep(1)
  88. env.hosts.append(ip_addr)
  89. env.host_string = ip_addr
  90. if debian:
  91. append('/etc/apt/sources.list', "deb http://backports.debian.org/debian-backports squeeze-backports main", use_sudo=True)
  92. def ubuntu_lucid_32(fresh_os=True):
  93. if (fresh_os):
  94. create_fresh_os('Ubuntu_10.04_32')
  95. def ubuntu_lucid_64(fresh_os=True):
  96. if (fresh_os):
  97. create_fresh_os('Ubuntu_10.04_64')
  98. def ubuntu_maverick_32(fresh_os=True):
  99. if (fresh_os):
  100. create_fresh_os('Ubuntu_10.10_32')
  101. def ubuntu_maverick_64(fresh_os=True):
  102. if (fresh_os):
  103. create_fresh_os('Ubuntu_10.10_64')
  104. def ubuntu_natty_32(fresh_os=True):
  105. if (fresh_os):
  106. create_fresh_os('Ubuntu_11.04_32')
  107. def ubuntu_natty_64(fresh_os=True):
  108. if (fresh_os):
  109. create_fresh_os('Ubuntu_11.04_64')
  110. def ubuntu_oneiric_32(fresh_os=True):
  111. if (fresh_os):
  112. create_fresh_os('Ubuntu_11.10_32')
  113. def ubuntu_oneiric_64(fresh_os=True):
  114. if (fresh_os):
  115. create_fresh_os('Ubuntu_11.10_64')
  116. def ubuntu_precise_64(fresh_os=True):
  117. if (fresh_os):
  118. create_fresh_os('Ubuntu_12.04_64')
  119. def ubuntu_precise_32(fresh_os=True):
  120. if (fresh_os):
  121. create_fresh_os('Ubuntu_12.04_32')
  122. def ubuntu_quantal_32(fresh_os=True):
  123. if (fresh_os):
  124. create_fresh_os('Ubuntu_12.10_32')
  125. def ubuntu_quantal_64(fresh_os=True):
  126. if (fresh_os):
  127. create_fresh_os('Ubuntu_12.10_64')
  128. def debian_squeeze_32(fresh_os=True):
  129. if (fresh_os):
  130. create_fresh_os('Debian_Squeeze_32', debian=True)
  131. def debian_squeeze_64(fresh_os=True):
  132. if (fresh_os):
  133. create_fresh_os('Debian_Squeeze_64', debian=True)
  134. def debian_wheezy_32(fresh_os=True):
  135. if (fresh_os):
  136. create_fresh_os('Debian_Wheezy_32')
  137. def debian_wheezy_64(fresh_os=True):
  138. if (fresh_os):
  139. create_fresh_os('Debian_Wheezy_64')
  140. def compile_liquidsoap(filename="liquidsoap"):
  141. config = ConfigParser()
  142. config.readfp(open('fab_liquidsoap_compile.cfg'))
  143. url = config.get('main', 'liquidsoap_tar_url')
  144. print "Will get liquidsoap from " + url
  145. do_sudo('apt-get update')
  146. do_sudo('apt-get upgrade -y --force-yes')
  147. do_sudo('''apt-get install -y --force-yes ocaml-findlib libao-ocaml-dev libportaudio-ocaml-dev \
  148. libmad-ocaml-dev libtaglib-ocaml-dev libalsa-ocaml-dev libtaglib-ocaml-dev libvorbis-ocaml-dev \
  149. libspeex-dev libspeexdsp-dev speex libladspa-ocaml-dev festival festival-dev \
  150. libsamplerate-dev libxmlplaylist-ocaml-dev libflac-dev \
  151. libxml-dom-perl libxml-dom-xpath-perl patch autoconf libmp3lame-dev \
  152. libcamomile-ocaml-dev libcamlimages-ocaml-dev libtool libpulse-dev libjack-dev \
  153. camlidl libfaad-dev libpcre-ocaml-dev''')
  154. #libxmlrpc-light-ocaml-dev
  155. root = '/home/martin/src'
  156. do_run('mkdir -p %s' % root)
  157. tmpPath = do_local("mktemp", capture=True)
  158. do_run('wget %s -O %s' % (url, tmpPath))
  159. do_run('mv %s %s/liquidsoap.tar.gz' % (tmpPath, root))
  160. do_run('cd %s && tar xzf liquidsoap.tar.gz' % root)
  161. #do_run('cd %s/liquidsoap-1.0.1-full && cp PACKAGES.minimal PACKAGES' % root)
  162. #sed('%s/liquidsoap-1.0.1-full/PACKAGES' % root, '#ocaml-portaudio', 'ocaml-portaudio')
  163. #sed('%s/liquidsoap-1.0.1-full/PACKAGES' % root, '#ocaml-alsa', 'ocaml-alsa')
  164. #sed('%s/liquidsoap-1.0.1-full/PACKAGES' % root, '#ocaml-pulseaudio', 'ocaml-pulseaudio')
  165. #sed('%s/liquidsoap-1.0.1-full/PACKAGES' % root, '#ocaml-faad', 'ocaml-faad')
  166. #do_run('cd %s/liquidsoap-1.0.1-full && ./bootstrap' % root)
  167. #do_run('cd %s/liquidsoap-1.0.1-full && ./configure' % root)
  168. #do_run('cd %s/liquidsoap-1.0.1-full && make' % root)
  169. #get('%s/liquidsoap-1.0.1-full/liquidsoap-1.0.1/src/liquidsoap' % root, filename)
  170. do_run('cd %s/liquidsoap && cp PACKAGES.minimal PACKAGES' % root)
  171. sed('%s/liquidsoap/PACKAGES' % root, '#ocaml-portaudio', 'ocaml-portaudio')
  172. sed('%s/liquidsoap/PACKAGES' % root, '#ocaml-alsa', 'ocaml-alsa')
  173. sed('%s/liquidsoap/PACKAGES' % root, '#ocaml-pulseaudio', 'ocaml-pulseaudio')
  174. sed('%s/liquidsoap/PACKAGES' % root, '#ocaml-faad', 'ocaml-faad')
  175. do_run('cd %s/liquidsoap && ./bootstrap' % root)
  176. do_run('cd %s/liquidsoap && ./configure' % root)
  177. do_run('cd %s/liquidsoap && make clean' % root)
  178. do_run('cd %s/liquidsoap && make' % root)
  179. do_sudo('chmod 755 %s/liquidsoap/liquidsoap/src/liquidsoap' % root)
  180. get('%s/liquidsoap/liquidsoap/src/liquidsoap' % root, filename)