CC-2420: Reinstall fails. Fixed bug where reinstalling the database tables would crash the installer. Fixed the usage message that prints out for airtime-install so that it shows the correct command. Added code documentation for why things work the way that they do.
This commit is contained in:
parent
9c1754dd38
commit
29c6006fc1
|
@ -10,6 +10,8 @@ class AirtimeInstall
|
|||
const CONF_DIR_WWW = "/var/www/airtime";
|
||||
const CONF_DIR_LOG = "/var/log/airtime";
|
||||
|
||||
public static $databaseTablesCreated = false;
|
||||
|
||||
public static function GetAirtimeSrcDir()
|
||||
{
|
||||
return __DIR__."/../../airtime_mvc";
|
||||
|
@ -106,12 +108,11 @@ class AirtimeInstall
|
|||
echo $CC_DBC->getUserInfo().PHP_EOL;
|
||||
echo "Database connection problem.".PHP_EOL;
|
||||
echo "Check if database '{$CC_CONFIG['dsn']['database']}' exists".
|
||||
" with corresponding permissions.".PHP_EOL;
|
||||
" with corresponding permissions.".PHP_EOL;
|
||||
if ($p_exitOnError) {
|
||||
exit(1);
|
||||
}
|
||||
} else {
|
||||
echo "* Connected to database".PHP_EOL;
|
||||
$CC_DBC->setFetchMode(DB_FETCHMODE_ASSOC);
|
||||
}
|
||||
}
|
||||
|
@ -148,15 +149,6 @@ class AirtimeInstall
|
|||
$success = chown($rp, "pypo");
|
||||
$success = chmod($rp, 02777);
|
||||
$CC_CONFIG['storageDir'] = $rp;
|
||||
|
||||
//add stor directory to MusiDirs
|
||||
$sql = "INSERT INTO cc_music_dirs (directory, type) VALUES ('$rp', 'stor')";
|
||||
$result = $CC_DBC->query($sql);
|
||||
if (PEAR::isError($result)) {
|
||||
echo "* Failed inserting {$rp} in cc_music_dirs".PHP_EOL;
|
||||
echo "* Message {$result->getMessage()}".PHP_EOL;
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
public static function CreateDatabaseUser()
|
||||
|
@ -236,6 +228,7 @@ class AirtimeInstall
|
|||
//$command = AirtimeInstall::CONF_DIR_WWW."/library/propel/generator/bin/propel-gen ".AirtimeInstall::CONF_DIR_WWW."/build/ insert-sql";
|
||||
$command = AirtimeInstall::CONF_DIR_WWW."/library/propel/generator/bin/propel-gen ".AirtimeInstall::CONF_DIR_WWW."/build/ insert-sql 2>/dev/null";
|
||||
@exec($command, $output, $results);
|
||||
AirtimeInstall::$databaseTablesCreated = true;
|
||||
}
|
||||
|
||||
public static function BypassMigrations($dir, $version)
|
||||
|
|
|
@ -1,4 +1,9 @@
|
|||
<?php
|
||||
/**
|
||||
* This file is separated out so that it can be run separately for DEB package installation.
|
||||
* When installing a DEB package, Postgresql may not be installed yet and thus the database
|
||||
* cannot be created. So this script is run after all DEB packages have been installed.
|
||||
*/
|
||||
|
||||
set_include_path(__DIR__.'/../airtime_mvc/library' . PATH_SEPARATOR . get_include_path());
|
||||
|
||||
|
@ -39,5 +44,18 @@ if (isset($argv[1]) && $argv[1] == 'y') {
|
|||
AirtimeInstall::CreateDatabaseTables();
|
||||
}
|
||||
|
||||
echo "* Setting Airtime version".PHP_EOL;
|
||||
AirtimeInstall::SetAirtimeVersion(AIRTIME_VERSION);
|
||||
|
||||
if (AirtimeInstall::$databaseTablesCreated) {
|
||||
echo "* Inserting stor directory into music_dirs table".PHP_EOL;
|
||||
$stor_dir = realpath($CC_CONFIG['storageDir']);
|
||||
|
||||
$sql = "INSERT INTO cc_music_dirs (directory, type) VALUES ('$stor_dir', 'stor')";
|
||||
$result = $CC_DBC->query($sql);
|
||||
if (PEAR::isError($result)) {
|
||||
echo "* Failed inserting {$stor_dir} in cc_music_dirs".PHP_EOL;
|
||||
echo "* Message {$result->getMessage()}".PHP_EOL;
|
||||
exit(1);
|
||||
}
|
||||
}
|
|
@ -4,9 +4,10 @@
|
|||
* @copyright 2011 Sourcefabric O.P.S.
|
||||
* @license http://www.gnu.org/licenses/gpl.txt
|
||||
*
|
||||
* Checks if a previous version of Airtime is currently installed, upgrades Airtime if so.
|
||||
* Performs a new install (new configs, database install) if a version of Airtime is not found
|
||||
* If the current version is found to be installed the User is presented with the help menu and can choose -r to reinstall.
|
||||
* Checks if a previous version of Airtime is currently installed and upgrades Airtime if so.
|
||||
* Performs a new install (new configs, database install) if a version of Airtime is not found.
|
||||
* If the current version is found to be installed the user is presented with the help menu and can
|
||||
* choose -r to reinstall.
|
||||
*/
|
||||
set_include_path(__DIR__.'/../../airtime_mvc/library' . PATH_SEPARATOR . get_include_path());
|
||||
|
||||
|
@ -22,31 +23,40 @@ $version = AirtimeInstall::GetVersionInstalled();
|
|||
require_once('Zend/Loader/Autoloader.php');
|
||||
$autoloader = Zend_Loader_Autoloader::getInstance();
|
||||
|
||||
function printUsage($opts)
|
||||
{
|
||||
$msg = $opts->getUsageMessage();
|
||||
echo PHP_EOL."Usage: airtime-install [options]";
|
||||
echo substr($msg, strpos($msg, "\n")).PHP_EOL;
|
||||
}
|
||||
|
||||
try {
|
||||
$opts = new Zend_Console_Getopt(
|
||||
array(
|
||||
'help|h' => 'Displays usage information.',
|
||||
'overwrite|o' => 'Overwrite any existing config files.',
|
||||
'preserve|p' => 'Keep any existing config files.',
|
||||
'no-db|n' => 'Turn off database install.',
|
||||
'no-db|n' => 'Turn off database install.',
|
||||
'reinstall|r' => 'Force a fresh install of this Airtime Version'
|
||||
)
|
||||
);
|
||||
$opts->parse();
|
||||
}
|
||||
catch (Zend_Console_Getopt_Exception $e) {
|
||||
exit($e->getMessage() ."\n\n". $e->getUsageMessage());
|
||||
print $e->getMessage() .PHP_EOL;
|
||||
printUsage($opts);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (isset($opts->h)) {
|
||||
echo $opts->getUsageMessage();
|
||||
printUsage($opts);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
// The current version is already installed.
|
||||
if(isset($version) && ($version != false) && ($version == AIRTIME_VERSION) && !isset($opts->r)) {
|
||||
echo "Airtime $version is already installed.".PHP_EOL;
|
||||
echo $opts->getUsageMessage();
|
||||
printUsage($opts);
|
||||
exit(1);
|
||||
}
|
||||
// A previous version exists - if so, upgrade.
|
||||
|
@ -122,6 +132,8 @@ echo "* Airtime Version: ".AIRTIME_VERSION.PHP_EOL;
|
|||
|
||||
if ($db_install) {
|
||||
if($newInstall) {
|
||||
// This is called with "system" so that we can pass in a parameter. See the file itself
|
||||
// for why we need to do this.
|
||||
system('php '.__DIR__.'/airtime-db-install.php y');
|
||||
AirtimeInstall::DbConnect(true);
|
||||
} else {
|
||||
|
@ -137,11 +149,12 @@ AirtimeInstall::CreateZendPhpLogFile();
|
|||
|
||||
AirtimeInstall::SetUniqueId();
|
||||
|
||||
$h = rand(0,23);
|
||||
$m = rand(0,59);
|
||||
// Create CRON task to run every day. Time of day is initialized to a random time.
|
||||
$hour = rand(0,23);
|
||||
$minute = rand(0,59);
|
||||
|
||||
$fp = fopen('/etc/cron.d/airtime-crons','a');
|
||||
fwrite($fp, "$m $h * * * root /usr/lib/airtime/utils/phone_home_stat\n");
|
||||
fwrite($fp, "$minute $hour * * * root /usr/lib/airtime/utils/phone_home_stat\n");
|
||||
fclose($fp);
|
||||
|
||||
/* FINISHED AIRTIME PHP INSTALLER */
|
||||
|
|
Loading…
Reference in New Issue