2011-10-27 20:01:59 +02:00
|
|
|
import os
|
2012-05-29 00:48:40 +02:00
|
|
|
import grp
|
|
|
|
import stat
|
2011-10-27 20:01:59 +02:00
|
|
|
import shutil
|
|
|
|
import sys
|
2012-03-26 23:59:44 +02:00
|
|
|
import subprocess
|
|
|
|
import random
|
|
|
|
import string
|
2011-10-27 20:01:59 +02:00
|
|
|
from configobj import ConfigObj
|
|
|
|
|
|
|
|
if os.geteuid() != 0:
|
|
|
|
print "Please run this as root."
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
def get_current_script_dir():
|
|
|
|
current_script_dir = os.path.realpath(__file__)
|
|
|
|
index = current_script_dir.rindex('/')
|
|
|
|
return current_script_dir[0:index]
|
|
|
|
|
|
|
|
def copy_dir(src_dir, dest_dir):
|
|
|
|
if (os.path.exists(dest_dir)) and (dest_dir != "/"):
|
|
|
|
shutil.rmtree(dest_dir)
|
|
|
|
if not (os.path.exists(dest_dir)):
|
2011-11-01 20:21:09 +01:00
|
|
|
#print "Copying directory "+os.path.realpath(src_dir)+" to "+os.path.realpath(dest_dir)
|
2011-10-27 20:01:59 +02:00
|
|
|
shutil.copytree(src_dir, dest_dir)
|
|
|
|
|
|
|
|
def create_dir(path):
|
|
|
|
try:
|
|
|
|
os.makedirs(path)
|
|
|
|
except Exception, e:
|
|
|
|
pass
|
2012-04-01 06:20:47 +02:00
|
|
|
|
|
|
|
def get_rand_string(length=10):
|
|
|
|
return ''.join(random.choice(string.ascii_uppercase + string.digits) for x in range(length))
|
2011-10-27 20:01:59 +02:00
|
|
|
|
2012-03-26 23:59:44 +02:00
|
|
|
def get_rand_string(length=10):
|
|
|
|
return ''.join(random.choice(string.ascii_uppercase + string.digits) for x in range(length))
|
|
|
|
|
2011-10-27 20:01:59 +02:00
|
|
|
PATH_INI_FILE = '/etc/airtime/pypo.cfg'
|
|
|
|
|
2011-11-24 23:31:26 +01:00
|
|
|
try:
|
2011-10-27 20:01:59 +02:00
|
|
|
# Absolute path this script is in
|
|
|
|
current_script_dir = get_current_script_dir()
|
|
|
|
|
2011-11-24 23:31:26 +01:00
|
|
|
if not os.path.exists(PATH_INI_FILE):
|
|
|
|
shutil.copy('%s/../pypo.cfg'%current_script_dir, PATH_INI_FILE)
|
2012-05-29 00:48:40 +02:00
|
|
|
|
|
|
|
try:
|
|
|
|
os.remove("/etc/airtime/liquidsoap.cfg")
|
|
|
|
except Exception, e:
|
|
|
|
pass
|
|
|
|
gid = grp.getgrnam("pypo").gr_gid
|
|
|
|
os.chown("/etc/airtime", -1, gid)
|
|
|
|
os.chmod("/etc/airtime", stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR | stat.S_IRGRP | stat.S_IWGRP | stat.S_IXGRP | stat.S_IROTH | stat.S_IXOTH)
|
|
|
|
|
2011-11-24 23:31:26 +01:00
|
|
|
# load config file
|
|
|
|
try:
|
|
|
|
config = ConfigObj(PATH_INI_FILE)
|
|
|
|
except Exception, e:
|
|
|
|
print 'Error loading config file: ', e
|
|
|
|
sys.exit(1)
|
|
|
|
|
2011-10-27 20:01:59 +02:00
|
|
|
#copy monit files
|
|
|
|
shutil.copy('%s/../../monit/monit-airtime-generic.cfg'%current_script_dir, '/etc/monit/conf.d/')
|
2012-03-26 23:59:44 +02:00
|
|
|
subprocess.call('sed -i "s/\$admin_pass/%s/g" /etc/monit/conf.d/monit-airtime-generic.cfg' % get_rand_string(), shell=True)
|
2011-12-23 21:32:48 +01:00
|
|
|
shutil.copy('%s/../../monit/monit-airtime-rabbitmq-server.cfg'%current_script_dir, '/etc/monit/conf.d/')
|
2012-04-05 20:56:11 +02:00
|
|
|
|
|
|
|
shutil.copy('%s/../monit-airtime-liquidsoap.cfg'%current_script_dir, '/etc/monit/conf.d/')
|
|
|
|
shutil.copy('%s/../monit-airtime-playout.cfg'%current_script_dir, '/etc/monit/conf.d/')
|
2011-10-27 20:01:59 +02:00
|
|
|
|
|
|
|
#create pypo log dir
|
|
|
|
create_dir(config['pypo_log_dir'])
|
2011-10-27 21:22:35 +02:00
|
|
|
os.system("chown -R pypo:pypo "+config["pypo_log_dir"])
|
2011-10-27 20:01:59 +02:00
|
|
|
|
|
|
|
#create liquidsoap log dir
|
|
|
|
create_dir(config['liquidsoap_log_dir'])
|
2011-10-27 21:22:35 +02:00
|
|
|
os.system("chown -R pypo:pypo "+config["liquidsoap_log_dir"])
|
2011-10-27 20:01:59 +02:00
|
|
|
|
|
|
|
#create cache, tmp, file dirs
|
|
|
|
create_dir(config['cache_dir'])
|
|
|
|
create_dir(config['file_dir'])
|
|
|
|
create_dir(config['tmp_dir'])
|
2012-02-24 19:12:50 +01:00
|
|
|
|
|
|
|
create_dir(config["base_recorded_files"])
|
2011-10-27 20:01:59 +02:00
|
|
|
|
|
|
|
#copy files to bin dir
|
|
|
|
copy_dir("%s/.."%current_script_dir, config["bin_dir"]+"/bin/")
|
|
|
|
|
|
|
|
# delete /usr/lib/airtime/pypo/bin/liquidsoap_scripts/liquidsoap.cfg
|
|
|
|
# as we don't use it anymore.(CC-2552)
|
|
|
|
os.remove(config["bin_dir"]+"/bin/liquidsoap_scripts/liquidsoap.cfg")
|
|
|
|
|
|
|
|
#set permissions in bin dir and cache dir
|
|
|
|
os.system("chmod 755 "+os.path.join(config["bin_dir"], "bin/liquidsoap_scripts/notify.sh"))
|
|
|
|
os.system("chown -R pypo:pypo "+config["bin_dir"])
|
|
|
|
os.system("chown -R pypo:pypo "+config["cache_base_dir"])
|
2012-02-24 19:12:50 +01:00
|
|
|
os.system("chown -R pypo:pypo "+config["base_recorded_files"])
|
2011-10-27 20:01:59 +02:00
|
|
|
|
|
|
|
#copy init.d script
|
|
|
|
shutil.copy(config["bin_dir"]+"/bin/airtime-playout-init-d", "/etc/init.d/airtime-playout")
|
2012-08-19 03:52:06 +02:00
|
|
|
shutil.copy(config["bin_dir"]+"/bin/airtime-liquidsoap-init-d", "/etc/init.d/airtime-liquidsoap")
|
2011-10-27 20:01:59 +02:00
|
|
|
|
|
|
|
#copy log rotate script
|
|
|
|
shutil.copy(config["bin_dir"]+"/bin/liquidsoap_scripts/airtime-liquidsoap.logrotate", "/etc/logrotate.d/airtime-liquidsoap")
|
|
|
|
|
|
|
|
except Exception, e:
|
|
|
|
print e
|
|
|
|
|
|
|
|
|