From f108ac846f86774ca457197ae7f633e718bb4984 Mon Sep 17 00:00:00 2001 From: martin Date: Thu, 24 Mar 2011 02:12:08 -0400 Subject: [PATCH] CC-2058: Utilities are not in the system $PATH -Added airtime-clean-storage and airtime-import symbolic links --- install/airtime-install.php | 3 + install/airtime-uninstall.php | 1 + install/installInit.php | 16 +++ utils/{CleanStor.sh => airtime-clean-storage} | 2 +- utils/airtime-clean-storage.php | 124 ++++++++++++++++++ utils/airtime-import | 11 +- utils/airtime-import.php | 2 +- utils/{CleanStor.php => cleanStor.php} | 2 +- utils/resetStorage.sh | 41 ------ 9 files changed, 153 insertions(+), 49 deletions(-) rename utils/{CleanStor.sh => airtime-clean-storage} (95%) create mode 100644 utils/airtime-clean-storage.php rename utils/{CleanStor.php => cleanStor.php} (98%) delete mode 100755 utils/resetStorage.sh diff --git a/install/airtime-install.php b/install/airtime-install.php index fdd867ee5..1d350f1e1 100644 --- a/install/airtime-install.php +++ b/install/airtime-install.php @@ -46,6 +46,9 @@ AirtimeInstall::SetupStorageDirectory($CC_CONFIG); echo "* Setting Dir Permissions".PHP_EOL; AirtimeInstall::ChangeDirOwnerToWebserver($CC_CONFIG["storageDir"]); +echo "* Creating /usr/bin symlinks".PHP_EOL; +AirtimeInstall::CreateSymlinks($CC_CONFIG["storageDir"]); + echo "* Importing Sample Audio Clips".PHP_EOL; system(__DIR__."/../utils/airtime-import --copy ../audio_samples/ > /dev/null"); diff --git a/install/airtime-uninstall.php b/install/airtime-uninstall.php index d175856d5..d30b4ee76 100644 --- a/install/airtime-uninstall.php +++ b/install/airtime-uninstall.php @@ -20,6 +20,7 @@ require_once(dirname(__FILE__).'/installInit.php'); // Need to check that we are superuser before running this. AirtimeInstall::ExitIfNotRoot(); +AirtimeInstall::RemoveSymlinks(); echo "******************************* Uninstall Begin ********************************".PHP_EOL; //------------------------------------------------------------------------ diff --git a/install/installInit.php b/install/installInit.php index fdb4d4d0f..ffad0ac29 100644 --- a/install/installInit.php +++ b/install/installInit.php @@ -203,4 +203,20 @@ class AirtimeInstall { exec($command); } + public static function CreateSymlinks(){ + AirtimeInstall::RemoveSymlinks(); + + $dir = realpath(__DIR__."/../utils/airtime-import"); + exec("ln -s $dir /usr/bin/airtime-import"); + + $dir = realpath(__DIR__."/../utils/airtime-clean-storage"); + exec("ln -s $dir /usr/bin/airtime-clean-storage"); + } + + public static function RemoveSymlinks(){ + exec("rm /usr/bin/airtime-import"); + exec("rm /usr/bin/airtime-clean-storage"); + } + + } diff --git a/utils/CleanStor.sh b/utils/airtime-clean-storage similarity index 95% rename from utils/CleanStor.sh rename to utils/airtime-clean-storage index 2b862ec6e..b96bb7d21 100755 --- a/utils/CleanStor.sh +++ b/utils/airtime-clean-storage @@ -23,4 +23,4 @@ #------------------------------------------------------------------------------- # This script cleans audio files in the Airtime storageServer. -php -q CleanStor.php "$@" || exit 1 +php -q airtime-clean-storage.php "$@" || exit 1 diff --git a/utils/airtime-clean-storage.php b/utils/airtime-clean-storage.php new file mode 100644 index 000000000..d1a063788 --- /dev/null +++ b/utils/airtime-clean-storage.php @@ -0,0 +1,124 @@ + 4)) { + list($dirList,$fileList) = File_Find::maptree($p_path); + + $array_mus; + foreach ($fileList as $filepath) { + + if (@substr($filepath, strlen($filepath) - 3) != "xml") { + $array_mus[] = $filepath; + } + } + + foreach ($array_mus as $audio_file) { + + if (@is_link($audio_file) && !@stat($audio_file)) { + + //filesystem clean up. + @unlink($audio_file); + echo "unlinked $audio_file\n"; + @unlink($audio_file . ".xml"); + echo "unlinked " . $audio_file . ".xml\n"; + @rmdir(@dirname($audio_file)); + echo "removed dir " . @dirname($audio_file) . "\n"; + + //database clean up. + $stored_audio_file = StoredFile::RecallByGunid(@basename($audio_file)); + $stored_audio_file->delete(); + } + } + + } +} + +function airtime_remove_files($p_path) { + + if (!empty($p_path) && (strlen($p_path) > 4)) { + list($dirList,$fileList) = File_Find::maptree($p_path); + + foreach ($fileList as $filepath) { + echo " * Removing $filepath\n"; + @unlink($filepath); + echo "done.\n"; + } + foreach ($dirList as $dirpath) { + echo " * Removing $dirpath\n"; + @rmdir($dirpath); + echo "done.\n"; + } + } +} + +function airtime_empty_db($db) { + global $CC_CONFIG; + + if (!PEAR::isError($db)) { + if (AirtimeInstall::DbTableExists($CC_CONFIG['filesTable'])) { + echo " * Deleting from database table ".$CC_CONFIG['filesTable']."\n"; + $sql = "DELETE FROM ".$CC_CONFIG['filesTable']; + AirtimeInstall::InstallQuery($sql, false); + } + else { + echo " * Skipping: database table ".$CC_CONFIG['filesTable']."\n"; + } + } +} + + +global $CC_CONFIG; + +$CC_DBC = DB::connect($CC_CONFIG['dsn'], TRUE); +$CC_DBC->setFetchMode(DB_FETCHMODE_ASSOC); + +if ($argc != 2){ + printUsage(); + exit(1); +} + +switch($argv[1]){ + + case '-e': + case '--empty': + airtime_empty_db($CC_DBC); + airtime_remove_files($CC_CONFIG['storageDir']); + break; + case '-c': + case '--clean': + airtime_clean_files($CC_CONFIG['storageDir']); + break; + default: + printUsage(); + +} + diff --git a/utils/airtime-import b/utils/airtime-import index 5098cc01d..4c8d8fdc1 100755 --- a/utils/airtime-import +++ b/utils/airtime-import @@ -29,15 +29,16 @@ #------------------------------------------------------------------------------- # Determine directories, files #------------------------------------------------------------------------------- -reldir=`dirname $0` -phpdir=$reldir -filelistpathname=. + +# Absolute path to this script +SCRIPT=`readlink -f $0` +# Absolute path this script is in +SCRIPTPATH=`dirname $SCRIPT` #------------------------------------------------------------------------------- # Do import #------------------------------------------------------------------------------- invokePwd=$PWD -#echo $invokePwd -cd $phpdir +cd $SCRIPTPATH php -q airtime-import.php --dir "$invokePwd" "$@" || exit 1 diff --git a/utils/airtime-import.php b/utils/airtime-import.php index 9e0696728..168bf0765 100644 --- a/utils/airtime-import.php +++ b/utils/airtime-import.php @@ -56,7 +56,7 @@ function printUsage() echo " -h, --help Print this message and exit.\n"; echo "\n"; echo "Files will be imported to directory:\n"; - echo " ". $CC_CONFIG["storageDir"] ."\n"; + echo " ". realpath($CC_CONFIG["storageDir"]) ."\n"; echo "\n"; } diff --git a/utils/CleanStor.php b/utils/cleanStor.php similarity index 98% rename from utils/CleanStor.php rename to utils/cleanStor.php index 1b4ed9f97..6f0719508 100644 --- a/utils/CleanStor.php +++ b/utils/cleanStor.php @@ -18,7 +18,7 @@ function printUsage() { global $CC_CONFIG; echo "Usage:\n"; - echo " ./CleanStor [OPTION] \n"; + echo " ./cleanStor [OPTION] \n"; echo "\n"; echo "Options:\n"; echo " -c, --clean Removes all broken links from the storage server\n"; diff --git a/utils/resetStorage.sh b/utils/resetStorage.sh deleted file mode 100755 index 9bb49fcee..000000000 --- a/utils/resetStorage.sh +++ /dev/null @@ -1,41 +0,0 @@ -#!/bin/bash -#------------------------------------------------------------------------------- -# Copyright (c) 2010 Sourcefabric O.P.S. -# -# This file is part of the Airtime project. -# http://airtime.sourcefabric.org/ -# To report bugs, send an e-mail to contact@sourcefabric.org -# -# Airtime is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. -# -# Airtime is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with Airtime; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -# -#------------------------------------------------------------------------------- - -#------------------------------------------------------------------------------- -# This script call locstor.resetStorage XMLRPC method -#------------------------------------------------------------------------------- - -reldir=`dirname $0`/.. -WWW_ROOT=`cd $reldir/var/install; php -q getWwwRoot.php` || exit $? -echo "# storageServer root URL: $WWW_ROOT" - -#$reldir/var/xmlrpc/xr_cli_test.py -s $WWW_ROOT/xmlrpc/xrLocStor.php \ -# resetStorage || exit $? - -cd $reldir/var/xmlrpc -php -q xr_cli_test.php -s $WWW_ROOT/xmlrpc/xrLocStor.php \ - resetStorage 1 1 || exit $? - -echo "# resetStorage: OK" -exit 0