diff --git a/install/airtime-install.php b/install/airtime-install.php index 55d5ba068..ffcdea662 100644 --- a/install/airtime-install.php +++ b/install/airtime-install.php @@ -55,6 +55,9 @@ AirtimeInstall::SetUpPythonEggs(); echo PHP_EOL."*** Pypo Installation ***".PHP_EOL; system("python ".__DIR__."/../pypo/install/pypo-install.py"); +echo PHP_EOL."*** Recorder Installation ***".PHP_EOL; +system("python ".__DIR__."/../python_apps/show-recorder/install/recorder-install.py"); + echo "******************************* Install Complete *******************************".PHP_EOL; diff --git a/install/airtime-uninstall.php b/install/airtime-uninstall.php index 181006efd..d175856d5 100644 --- a/install/airtime-uninstall.php +++ b/install/airtime-uninstall.php @@ -83,5 +83,8 @@ AirtimeInstall::DeleteFilesRecursive($CC_CONFIG['storageDir']); $command = "python ".__DIR__."/../pypo/install/pypo-uninstall.py"; system($command); + +$command = "python ".__DIR__."/../python_apps/show-recorder/install/recorder-uninstall.py"; +system($command); echo "****************************** Uninstall Complete ******************************".PHP_EOL; diff --git a/pypo/install/pypo-install.py b/pypo/install/pypo-install.py index 07cb43cd9..cff58175e 100644 --- a/pypo/install/pypo-install.py +++ b/pypo/install/pypo-install.py @@ -44,6 +44,8 @@ def create_user(username): print "User already exists." #add pypo to audio group os.system("adduser " + username + " audio 1>/dev/null 2>&1") + #add pypo to pulse-access group + os.system("adduser " + username + " pulse-access 1>/dev/null 2>&1") def copy_dir(src_dir, dest_dir): if (os.path.exists(dest_dir)) and (dest_dir != "/"): diff --git a/python_apps/show-recorder/config.cfg b/python_apps/show-recorder/config.cfg index f75ea204c..d1bb763ab 100644 --- a/python_apps/show-recorder/config.cfg +++ b/python_apps/show-recorder/config.cfg @@ -6,4 +6,4 @@ show_schedule_url = 'Recorder/get-show-schedule/format/json' upload_file_url = 'Plupload/upload-recorded/format/json' # base path to store recordered shows at -base_recorded_files = '/home/naomi/Music/' +base_recorded_files = '/home/pypo/Music/' diff --git a/python_apps/show-recorder/install/recorder-daemontools-logger.sh b/python_apps/show-recorder/install/recorder-daemontools-logger.sh new file mode 100644 index 000000000..9673575db --- /dev/null +++ b/python_apps/show-recorder/install/recorder-daemontools-logger.sh @@ -0,0 +1,2 @@ +#!/bin/sh +exec setuidgid pypo multilog t ./main diff --git a/python_apps/show-recorder/install/recorder-daemontools.sh b/python_apps/show-recorder/install/recorder-daemontools.sh new file mode 100644 index 000000000..c36996b40 --- /dev/null +++ b/python_apps/show-recorder/install/recorder-daemontools.sh @@ -0,0 +1,14 @@ +#!/bin/sh +recorder_user="pypo" +export HOME="/home/pypo/" +# Location of pypo_cli.py Python script +recorder_path="/opt/recorder/bin/" +recorder_script="testrecordscript.py" +echo "*** Daemontools: starting daemon" +cd ${recorder_path} +exec 2>&1 +# Note the -u when calling python! we need it to get unbuffered binary stdout and stderr +exec setuidgid ${recorder_user} \ + python -u ${recorder_path}${recorder_script} \ + -f +# EOF diff --git a/python_apps/show-recorder/install/recorder-install.py b/python_apps/show-recorder/install/recorder-install.py new file mode 100644 index 000000000..1b8186391 --- /dev/null +++ b/python_apps/show-recorder/install/recorder-install.py @@ -0,0 +1,128 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +import time +import os +import traceback +from optparse import * +import sys +import time +import datetime +import logging +import logging.config +import shutil +import string +import platform +from subprocess import Popen, PIPE, STDOUT + +if os.geteuid() != 0: + print "Please run this as root." + sys.exit(1) + +BASE_PATH = '/opt/recorder/' + +def create_path(path): + if not (os.path.exists(path)): + print "Creating directory " + path + os.makedirs(path) + +def create_user(username): + print "Checking for user "+username + p = Popen('id '+username, shell=True, stdin=PIPE, stdout=PIPE, stderr=STDOUT, close_fds=True) + output = p.stdout.read() + if (output[0:3] != "uid"): + # Make the pypo user + print "Creating user "+username + os.system("adduser --system --quiet --group --shell /bin/bash "+username) + + #set pypo password + p = os.popen('/usr/bin/passwd pypo 1>/dev/null 2>&1', 'w') + p.write('pypo\n') + p.write('pypo\n') + p.close() + else: + print "User already exists." + #add pypo to audio group + os.system("adduser " + username + " audio 1>/dev/null 2>&1") + +def copy_dir(src_dir, dest_dir): + if (os.path.exists(dest_dir)) and (dest_dir != "/"): + print "Removing old directory "+dest_dir + shutil.rmtree(dest_dir) + if not (os.path.exists(dest_dir)): + print "Copying directory "+src_dir+" to "+dest_dir + shutil.copytree(src_dir, dest_dir) + +def get_current_script_dir(): + current_script_dir = os.path.realpath(__file__) + index = current_script_dir.rindex('/') + print current_script_dir[0:index] + return current_script_dir[0:index] + + +try: + current_script_dir = get_current_script_dir() + print "Checking and removing any existing recorder processes" + os.system("python %s/recorder-uninstall.py 1>/dev/null 2>&1"% current_script_dir) + time.sleep(5) + + # Create users + create_user("pypo") + + print "Creating home directory" + create_path("/home/pypo") + os.system("chmod -R 755 /home/pypo") + os.system("chown -R pypo:pypo /home/pypo") + + print "Creating home directory" + create_path("/home/pypo/Music") + os.system("chmod -R 755 /home/pypo/Music") + os.system("chown -R pypo:pypo /home/pypo/Music") + + print "Creating log directories" + create_path("/var/log/recorder") + os.system("chmod -R 755 /var/log/recorder") + os.system("chown -R pypo:pypo /var/log/recorder") + + create_path(BASE_PATH) + create_path(BASE_PATH+"bin") + create_path(BASE_PATH+"cache") + create_path(BASE_PATH+"files") + create_path(BASE_PATH+"tmp") + create_path(BASE_PATH+"archive") + + copy_dir("%s/.."%current_script_dir, BASE_PATH+"bin/") + + print "Setting permissions" + os.system("chmod -R 755 "+BASE_PATH) + os.system("chown -R pypo:pypo "+BASE_PATH) + + print "Installing recorder daemon" + create_path("/etc/service/recorder") + create_path("/etc/service/recorder/log") + shutil.copy("%s/recorder-daemontools.sh"%current_script_dir, "/etc/service/recorder/run") + shutil.copy("%s/recorder-daemontools-logger.sh"%current_script_dir, "/etc/service/recorder/log/run") + os.system("chmod -R 755 /etc/service/recorder") + os.system("chown -R pypo:pypo /etc/service/recorder") + + print "Waiting for processes to start..." + time.sleep(5) + os.system("python %s/recorder-start.py" % (get_current_script_dir())) + time.sleep(2) + + found = True + + p = Popen('svstat /etc/service/recorder', shell=True, stdin=PIPE, stdout=PIPE, stderr=STDOUT, close_fds=True) + output = p.stdout.read() + if (output.find("unable to open supervise/ok: file does not exist") >= 0): + found = False + print output + + if not found: + print "Recorder install has completed, but daemontools is not running, please make sure you have it installed and then reboot." +except Exception, e: + print "exception:" + str(e) + sys.exit(1) + + + diff --git a/python_apps/show-recorder/install/recorder-start.py b/python_apps/show-recorder/install/recorder-start.py new file mode 100644 index 000000000..084b2b1ad --- /dev/null +++ b/python_apps/show-recorder/install/recorder-start.py @@ -0,0 +1,16 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +import os +import sys + +if os.geteuid() != 0: + print "Please run this as root." + sys.exit(1) + +try: + print "Starting daemontool script recorder" + os.system("svc -u /etc/service/recorder") + +except Exception, e: + print "exception:" + str(e) diff --git a/python_apps/show-recorder/install/recorder-stop.py b/python_apps/show-recorder/install/recorder-stop.py new file mode 100644 index 000000000..388c0bc4b --- /dev/null +++ b/python_apps/show-recorder/install/recorder-stop.py @@ -0,0 +1,25 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +import os +import sys + +if os.geteuid() != 0: + print "Please run this as root." + sys.exit(1) + +try: + print "Stopping daemontool script pypo" + os.system("svc -dx /etc/service/pypo 1>/dev/null 2>&1") + + if os.path.exists("/etc/service/pypo-fetch"): + os.system("svc -dx /etc/service/pypo-fetch 1>/dev/null 2>&1") + if os.path.exists("/etc/service/pypo-push"): + os.system("svc -dx /etc/service/pypo-push 1>/dev/null 2>&1") + + print "Stopping daemontool script pypo-liquidsoap" + os.system("svc -dx /etc/service/pypo-liquidsoap 1>/dev/null 2>&1") + os.system("killall liquidsoap") + +except Exception, e: + print "exception:" + str(e) diff --git a/python_apps/show-recorder/install/recorder-uninstall.py b/python_apps/show-recorder/install/recorder-uninstall.py new file mode 100644 index 000000000..f8ab96432 --- /dev/null +++ b/python_apps/show-recorder/install/recorder-uninstall.py @@ -0,0 +1,46 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +import os +import sys +import time + +if os.geteuid() != 0: + print "Please run this as root." + sys.exit(1) + +BASE_PATH = '/opt/recorder/' + +def remove_path(path): + os.system("rm -rf " + path) + +def remove_user(username): + os.system("killall -u %s 1>/dev/null 2>&1" % username) + + #allow all process to be completely closed before we attempt to delete user + print "Waiting for processes to close..." + time.sleep(5) + + os.system("deluser --remove-home " + username + " 1>/dev/null 2>&1") + +def get_current_script_dir(): + current_script_dir = os.path.realpath(__file__) + index = current_script_dir.rindex('/') + return current_script_dir[0:index] + +try: + os.system("python %s/recorder-stop.py" % get_current_script_dir()) + + print "Removing log directories" + remove_path("/var/log/recorder") + + print "Removing recorder files" + remove_path(BASE_PATH) + + print "Removing daemontool script recorder" + remove_path("rm -rf /etc/service/recorder") + + remove_user("pypo") + print "Uninstall complete." +except Exception, e: + print "exception:" + str(e) diff --git a/python_apps/show-recorder/testsoundcloud.py b/python_apps/show-recorder/testsoundcloud.py deleted file mode 100644 index 0ba6fd20d..000000000 --- a/python_apps/show-recorder/testsoundcloud.py +++ /dev/null @@ -1,59 +0,0 @@ -import webbrowser -import scapi - -# the host to connect to. Normally, this -# would be api.soundcloud.com -API_HOST = "api.soundcloud.com" - -# This needs to be the consumer ID you got from -# http://soundcloud.com/settings/applications/new -CONSUMER = "2CLCxcSXYzx7QhhPVHN4A" -# This needs to be the consumer secret password you got from -# http://soundcloud.com/settings/applications/new -CONSUMER_SECRET = "pZ7beWmF06epXLHVUP1ufOg2oEnIt9XhE8l8xt0bBs" - -# first, we create an OAuthAuthenticator that only knows about consumer -# credentials. This is done so that we can get an request-token as -# first step. -oauth_authenticator = scapi.authentication.OAuthAuthenticator(CONSUMER, - CONSUMER_SECRET, - None, - None) - -# The connector works with the authenticator to create and sign the requests. It -# has some helper-methods that allow us to do the OAuth-dance. -connector = scapi.ApiConnector(host=API_HOST, authenticator=oauth_authenticator) - -# First step is to get a request-token, and to let the user authorize that -# via the browser. -token, secret = connector.fetch_request_token() -authorization_url = connector.get_request_token_authorization_url(token) -webbrowser.open(authorization_url) -oauth_verifier = raw_input("please enter verifier code as seen in the browser:") - -# Now we create a new authenticator with the temporary token & secret we got from -# the request-token. This will give us the access-token -oauth_authenticator = scapi.authentication.OAuthAuthenticator(CONSUMER, - CONSUMER_SECRET, - token, - secret) - -# we need a new connector with the new authenticator! -connector = scapi.ApiConnector(API_HOST, authenticator=oauth_authenticator) -token, secret = connector.fetch_access_token(oauth_verifier) - - -# now we are finally ready to go - with all four parameters OAuth requires, -# we can setup an authenticator that allows for actual API-calls. -oauth_authenticator = scapi.authentication.OAuthAuthenticator(CONSUMER, - CONSUMER_SECRET, - token, - secret) - -# we pass the connector to a Scope - a Scope is essentially a path in the REST-url-space. -# Without any path-component, it's the root from which we can then query into the -# resources. -root = scapi.Scope(scapi.ApiConnector(host=API_HOST, authenticator=oauth_authenticator)) - -# Hey, nice meeting you! Connected to SoundCloud using OAuth will allow you to access protected resources, like the current user's name. -print "Hello, %s" % root.me().username