-cleaned up install scripts
This commit is contained in:
parent
740a157627
commit
a881358378
3 changed files with 194 additions and 190 deletions
|
@ -15,134 +15,45 @@ if (isset($arr["DOCUMENT_ROOT"]) && ($arr["DOCUMENT_ROOT"] != "") ) {
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
createAPIKey();
|
|
||||||
|
|
||||||
require_once(dirname(__FILE__).'/../application/configs/conf.php');
|
require_once(dirname(__FILE__).'/../application/configs/conf.php');
|
||||||
require_once(dirname(__FILE__).'/installInit.php');
|
require_once(dirname(__FILE__).'/installInit.php');
|
||||||
|
|
||||||
|
echo "******************************** Install Begin *********************************".PHP_EOL;
|
||||||
function rand_string($len=20, $chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789')
|
|
||||||
{
|
|
||||||
$string = '';
|
|
||||||
for ($i = 0; $i < $len; $i++)
|
|
||||||
{
|
|
||||||
$pos = mt_rand(0, strlen($chars)-1);
|
|
||||||
$string .= $chars{$pos};
|
|
||||||
}
|
|
||||||
return $string;
|
|
||||||
}
|
|
||||||
|
|
||||||
function createAPIKey(){
|
|
||||||
|
|
||||||
$api_key = rand_string();
|
|
||||||
updateINIKeyValues(__DIR__.'/../build/airtime.conf', 'api_key', $api_key);
|
|
||||||
updateINIKeyValues(__DIR__.'/../pypo/config.cfg', 'api_key', "'$api_key'");
|
|
||||||
}
|
|
||||||
|
|
||||||
function checkIfRoot(){
|
|
||||||
// Need to check that we are superuser before running this.
|
|
||||||
if(exec("whoami") != "root"){
|
|
||||||
echo "Must be root user.\n";
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function updateINIKeyValues($filename, $property, $value){
|
|
||||||
$lines = file($filename);
|
|
||||||
$n=count($lines);
|
|
||||||
for ($i=0; $i<$n; $i++) {
|
|
||||||
if (strlen($lines[$i]) > strlen($property))
|
|
||||||
if ($property == substr($lines[$i], 0, strlen($property))){
|
|
||||||
$lines[$i] = "$property = $value\n";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$fp=fopen($filename, 'w');
|
|
||||||
for($i=0; $i<$n; $i++){
|
|
||||||
fwrite($fp, $lines[$i]);
|
|
||||||
}
|
|
||||||
fclose($fp);
|
|
||||||
}
|
|
||||||
|
|
||||||
function directorySetup($CC_CONFIG){
|
|
||||||
//------------------------------------------------------------------------
|
|
||||||
// Install storage directories
|
|
||||||
//------------------------------------------------------------------------
|
|
||||||
echo " *** Directory Setup ***\n";
|
|
||||||
foreach (array('baseFilesDir', 'storageDir') as $d) {
|
|
||||||
if ( !file_exists($CC_CONFIG[$d]) ) {
|
|
||||||
@mkdir($CC_CONFIG[$d], 02775, true);
|
|
||||||
if (file_exists($CC_CONFIG[$d])) {
|
|
||||||
$rp = realpath($CC_CONFIG[$d]);
|
|
||||||
echo " * Directory $rp created\n";
|
|
||||||
} else {
|
|
||||||
echo " * Failed creating {$CC_CONFIG[$d]}\n";
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
} elseif (is_writable($CC_CONFIG[$d])) {
|
|
||||||
$rp = realpath($CC_CONFIG[$d]);
|
|
||||||
echo " * Skipping directory already exists: $rp\n";
|
|
||||||
} else {
|
|
||||||
$rp = realpath($CC_CONFIG[$d]);
|
|
||||||
echo " * WARNING: Directory already exists, but is not writable: $rp\n";
|
|
||||||
}
|
|
||||||
$CC_CONFIG[$d] = $rp;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
checkIfRoot();
|
checkIfRoot();
|
||||||
|
createAPIKey();
|
||||||
updateINIKeyValues('../build/build.properties', 'project.home', realpath(__dir__.'/../'));
|
updateINIKeyValues('../build/build.properties', 'project.home', realpath(__dir__.'/../'));
|
||||||
|
|
||||||
echo "******************************** Install Begin *********************************\n";
|
|
||||||
echo " *** Database Installation ***\n";
|
|
||||||
|
|
||||||
// Create the database user
|
echo PHP_EOL."*** Database Installation ***".PHP_EOL;
|
||||||
$command = "sudo -u postgres psql postgres --command \"CREATE USER {$CC_CONFIG['dsn']['username']} "
|
|
||||||
." ENCRYPTED PASSWORD '{$CC_CONFIG['dsn']['password']}' LOGIN CREATEDB NOCREATEUSER;\" 2>/dev/null";
|
|
||||||
|
|
||||||
@exec($command, $output, $results);
|
echo "* Creating Airtime Database User".PHP_EOL;
|
||||||
if ($results == 0) {
|
createAirtimeDatabaseUser();
|
||||||
echo " * User {$CC_CONFIG['dsn']['username']} created.\n";
|
|
||||||
} else {
|
echo "* Creating Airtime Database".PHP_EOL;
|
||||||
echo " * User {$CC_CONFIG['dsn']['username']} already exists.\n";
|
createAirtimeDatabase();
|
||||||
}
|
|
||||||
|
|
||||||
$command = "sudo -u postgres createdb {$CC_CONFIG['dsn']['database']} --owner {$CC_CONFIG['dsn']['username']} 2> /dev/null";
|
|
||||||
@exec($command, $output, $results);
|
|
||||||
if ($results == 0) {
|
|
||||||
echo " * Database '{$CC_CONFIG['dsn']['database']}' created.\n";
|
|
||||||
} else {
|
|
||||||
echo " * Database '{$CC_CONFIG['dsn']['database']}' already exists.\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
// Connect to DB
|
|
||||||
airtime_db_connect(true);
|
airtime_db_connect(true);
|
||||||
|
|
||||||
// Install postgres scripting language
|
echo "* Install Postgresql Scripting Language".PHP_EOL;
|
||||||
$langIsInstalled = $CC_DBC->GetOne('SELECT COUNT(*) FROM pg_language WHERE lanname = \'plpgsql\'');
|
installPostgresScriptingLanguage();
|
||||||
if ($langIsInstalled == '0') {
|
|
||||||
echo " * Installing Postgres scripting language\n";
|
|
||||||
$sql = "CREATE LANGUAGE 'plpgsql'";
|
|
||||||
airtime_install_query($sql, false);
|
|
||||||
} else {
|
|
||||||
echo " * Postgres scripting language already installed\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
echo " * Creating database tables\n";
|
echo "* Creating Database Tables".PHP_EOL;
|
||||||
// Put Propel sql files in Database
|
createAirtimeDatabaseTables();
|
||||||
$command = __DIR__."/../library/propel/generator/bin/propel-gen ../build/ insert-sql 2>propel-error.log";
|
|
||||||
@exec($command, $output, $results);
|
|
||||||
|
|
||||||
directorySetup($CC_CONFIG);
|
echo "* Storage Directory Setup".PHP_EOL;
|
||||||
|
storageDirectorySetup($CC_CONFIG);
|
||||||
|
|
||||||
echo " * Setting dir permissions...\n";
|
echo "* Setting Dir Permissions".PHP_EOL;
|
||||||
install_setDirPermissions($CC_CONFIG["storageDir"]);
|
install_setDirPermissions($CC_CONFIG["storageDir"]);
|
||||||
|
|
||||||
echo " * Importing sample audio clips \n";
|
echo "* Importing Sample Audio Clips".PHP_EOL;
|
||||||
$command = __DIR__."/../utils/airtime-import --copy ../audio_samples/ > /dev/null";
|
system(__DIR__."/../utils/airtime-import --copy ../audio_samples/ > /dev/null");
|
||||||
@exec($command, $output, $results);
|
|
||||||
|
|
||||||
$command = "python ".__DIR__."/../pypo/install/pypo-install.py";
|
echo PHP_EOL."*** Pypo Installation ***".PHP_EOL;
|
||||||
system($command);
|
system("python ".__DIR__."/../pypo/install/pypo-install.py");
|
||||||
echo "******************************* Install Complete *******************************\n";
|
|
||||||
|
|
||||||
|
echo "******************************* Install Complete *******************************".PHP_EOL;
|
||||||
|
|
||||||
|
|
|
@ -10,22 +10,21 @@ $arr = array_diff_assoc($_SERVER, $_ENV);
|
||||||
if (isset($arr["DOCUMENT_ROOT"]) && ($arr["DOCUMENT_ROOT"] != "") ) {
|
if (isset($arr["DOCUMENT_ROOT"]) && ($arr["DOCUMENT_ROOT"] != "") ) {
|
||||||
header("HTTP/1.1 400");
|
header("HTTP/1.1 400");
|
||||||
header("Content-type: text/plain; charset=UTF-8");
|
header("Content-type: text/plain; charset=UTF-8");
|
||||||
echo "400 Not executable\r\n";
|
echo "400 Not executable".PHP_EOL;
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Need to check that we are superuser before running this.
|
|
||||||
if(exec("whoami") != "root"){
|
|
||||||
echo "Must be root user.\n";
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
echo "******************************* Uninstall Begin ********************************\n";
|
|
||||||
|
|
||||||
require_once(dirname(__FILE__).'/../application/configs/conf.php');
|
require_once(dirname(__FILE__).'/../application/configs/conf.php');
|
||||||
require_once(dirname(__FILE__).'/installInit.php');
|
require_once(dirname(__FILE__).'/installInit.php');
|
||||||
|
|
||||||
|
// Need to check that we are superuser before running this.
|
||||||
|
checkIfRoot();
|
||||||
|
|
||||||
|
|
||||||
|
echo "******************************* Uninstall Begin ********************************".PHP_EOL;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function airtime_uninstall_delete_files($p_path)
|
function airtime_uninstall_delete_files($p_path)
|
||||||
{
|
{
|
||||||
$command = "rm -rf $p_path";
|
$command = "rm -rf $p_path";
|
||||||
|
@ -38,7 +37,7 @@ function airtime_uninstall_delete_files($p_path)
|
||||||
// before this function, even if you called $CC_DBC->disconnect(), there will
|
// before this function, even if you called $CC_DBC->disconnect(), there will
|
||||||
// still be a connection to the database and you wont be able to delete it.
|
// still be a connection to the database and you wont be able to delete it.
|
||||||
//------------------------------------------------------------------------
|
//------------------------------------------------------------------------
|
||||||
echo " * Dropping the database '".$CC_CONFIG['dsn']['database']."'...\n";
|
echo " * Dropping the database '".$CC_CONFIG['dsn']['database']."'...".PHP_EOL;
|
||||||
$command = "sudo -u postgres dropdb {$CC_CONFIG['dsn']['database']} 2> /dev/null";
|
$command = "sudo -u postgres dropdb {$CC_CONFIG['dsn']['database']} 2> /dev/null";
|
||||||
@exec($command, $output, $dbDeleteFailed);
|
@exec($command, $output, $dbDeleteFailed);
|
||||||
|
|
||||||
|
@ -47,7 +46,7 @@ $command = "sudo -u postgres dropdb {$CC_CONFIG['dsn']['database']} 2> /dev/null
|
||||||
// We do this if dropping the database fails above.
|
// We do this if dropping the database fails above.
|
||||||
//------------------------------------------------------------------------
|
//------------------------------------------------------------------------
|
||||||
if ($dbDeleteFailed) {
|
if ($dbDeleteFailed) {
|
||||||
echo " * Couldn't delete the database, so deleting all the DB tables...\n";
|
echo " * Couldn't delete the database, so deleting all the DB tables...".PHP_EOL;
|
||||||
airtime_db_connect(true);
|
airtime_db_connect(true);
|
||||||
if (!PEAR::isError($CC_DBC)) {
|
if (!PEAR::isError($CC_DBC)) {
|
||||||
if (airtime_db_table_exists($CC_CONFIG['prefTable'])) {
|
if (airtime_db_table_exists($CC_CONFIG['prefTable'])) {
|
||||||
|
@ -56,9 +55,9 @@ if ($dbDeleteFailed) {
|
||||||
airtime_install_query($sql, false);
|
airtime_install_query($sql, false);
|
||||||
|
|
||||||
$CC_DBC->dropSequence($CC_CONFIG['prefTable']."_id");
|
$CC_DBC->dropSequence($CC_CONFIG['prefTable']."_id");
|
||||||
echo "done.\n";
|
echo "done.".PHP_EOL;
|
||||||
} else {
|
} else {
|
||||||
echo " * Skipping: database table ".$CC_CONFIG['prefTable']."\n";
|
echo " * Skipping: database table $CC_CONFIG[prefTable]".PHP_EOL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -68,9 +67,9 @@ if ($dbDeleteFailed) {
|
||||||
airtime_install_query($sql, false);
|
airtime_install_query($sql, false);
|
||||||
|
|
||||||
$CC_DBC->dropSequence($CC_CONFIG['transTable']."_id");
|
$CC_DBC->dropSequence($CC_CONFIG['transTable']."_id");
|
||||||
echo "done.\n";
|
echo "done.".PHP_EOL;
|
||||||
} else {
|
} else {
|
||||||
echo " * Skipping: database table ".$CC_CONFIG['transTable']."\n";
|
echo " * Skipping: database table $CC_CONFIG[transTable]".PHP_EOL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (airtime_db_table_exists($CC_CONFIG['filesTable'])) {
|
if (airtime_db_table_exists($CC_CONFIG['filesTable'])) {
|
||||||
|
@ -80,7 +79,7 @@ if ($dbDeleteFailed) {
|
||||||
$CC_DBC->dropSequence($CC_CONFIG['filesTable']."_id");
|
$CC_DBC->dropSequence($CC_CONFIG['filesTable']."_id");
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
echo " * Skipping: database table ".$CC_CONFIG['filesTable']."\n";
|
echo " * Skipping: database table $CC_CONFIG[filesTable]".PHP_EOL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (airtime_db_table_exists($CC_CONFIG['playListTable'])) {
|
if (airtime_db_table_exists($CC_CONFIG['playListTable'])) {
|
||||||
|
@ -90,7 +89,7 @@ if ($dbDeleteFailed) {
|
||||||
$CC_DBC->dropSequence($CC_CONFIG['playListTable']."_id");
|
$CC_DBC->dropSequence($CC_CONFIG['playListTable']."_id");
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
echo " * Skipping: database table ".$CC_CONFIG['playListTable']."\n";
|
echo " * Skipping: database table $CC_CONFIG[playListTable]".PHP_EOL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (airtime_db_table_exists($CC_CONFIG['playListContentsTable'])) {
|
if (airtime_db_table_exists($CC_CONFIG['playListContentsTable'])) {
|
||||||
|
@ -100,7 +99,7 @@ if ($dbDeleteFailed) {
|
||||||
$CC_DBC->dropSequence($CC_CONFIG['playListContentsTable']."_id");
|
$CC_DBC->dropSequence($CC_CONFIG['playListContentsTable']."_id");
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
echo " * Skipping: database table ".$CC_CONFIG['playListContentsTable']."\n";
|
echo " * Skipping: database table $CC_CONFIG[playListContentsTable]".PHP_EOL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (airtime_db_table_exists($CC_CONFIG['accessTable'])) {
|
if (airtime_db_table_exists($CC_CONFIG['accessTable'])) {
|
||||||
|
@ -108,7 +107,7 @@ if ($dbDeleteFailed) {
|
||||||
$sql = "DROP TABLE ".$CC_CONFIG['accessTable'];
|
$sql = "DROP TABLE ".$CC_CONFIG['accessTable'];
|
||||||
airtime_install_query($sql);
|
airtime_install_query($sql);
|
||||||
} else {
|
} else {
|
||||||
echo " * Skipping: database table ".$CC_CONFIG['accessTable']."\n";
|
echo " * Skipping: database table $CC_CONFIG[accessTable]".PHP_EOL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (airtime_db_table_exists($CC_CONFIG['permTable'])) {
|
if (airtime_db_table_exists($CC_CONFIG['permTable'])) {
|
||||||
|
@ -117,9 +116,9 @@ if ($dbDeleteFailed) {
|
||||||
airtime_install_query($sql, false);
|
airtime_install_query($sql, false);
|
||||||
|
|
||||||
$CC_DBC->dropSequence($CC_CONFIG['permTable']."_id");
|
$CC_DBC->dropSequence($CC_CONFIG['permTable']."_id");
|
||||||
echo "done.\n";
|
echo "done.".PHP_EOL;
|
||||||
} else {
|
} else {
|
||||||
echo " * Skipping: database table ".$CC_CONFIG['permTable']."\n";
|
echo " * Skipping: database table $CC_CONFIG[permTable]".PHP_EOL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (airtime_db_table_exists($CC_CONFIG['sessTable'])) {
|
if (airtime_db_table_exists($CC_CONFIG['sessTable'])) {
|
||||||
|
@ -127,7 +126,7 @@ if ($dbDeleteFailed) {
|
||||||
$sql = "DROP TABLE ".$CC_CONFIG['sessTable'];
|
$sql = "DROP TABLE ".$CC_CONFIG['sessTable'];
|
||||||
airtime_install_query($sql);
|
airtime_install_query($sql);
|
||||||
} else {
|
} else {
|
||||||
echo " * Skipping: database table ".$CC_CONFIG['sessTable']."\n";
|
echo " * Skipping: database table $CC_CONFIG[sessTable]".PHP_EOL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (airtime_db_table_exists($CC_CONFIG['subjTable'])) {
|
if (airtime_db_table_exists($CC_CONFIG['subjTable'])) {
|
||||||
|
@ -137,9 +136,9 @@ if ($dbDeleteFailed) {
|
||||||
$sql = "DROP TABLE ".$CC_CONFIG['subjTable']." CASCADE";
|
$sql = "DROP TABLE ".$CC_CONFIG['subjTable']." CASCADE";
|
||||||
airtime_install_query($sql, false);
|
airtime_install_query($sql, false);
|
||||||
|
|
||||||
echo "done.\n";
|
echo "done.".PHP_EOL;
|
||||||
} else {
|
} else {
|
||||||
echo " * Skipping: database table ".$CC_CONFIG['subjTable']."\n";
|
echo " * Skipping: database table $CC_CONFIG[subjTable]".PHP_EOL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (airtime_db_table_exists($CC_CONFIG['smembTable'])) {
|
if (airtime_db_table_exists($CC_CONFIG['smembTable'])) {
|
||||||
|
@ -148,68 +147,53 @@ if ($dbDeleteFailed) {
|
||||||
airtime_install_query($sql, false);
|
airtime_install_query($sql, false);
|
||||||
|
|
||||||
$CC_DBC->dropSequence($CC_CONFIG['smembTable']."_id");
|
$CC_DBC->dropSequence($CC_CONFIG['smembTable']."_id");
|
||||||
echo "done.\n";
|
echo "done.".PHP_EOL;
|
||||||
} else {
|
} else {
|
||||||
echo " * Skipping: database table ".$CC_CONFIG['smembTable']."\n";
|
echo " * Skipping: database table $CC_CONFIG[smembTable]".PHP_EOL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (airtime_db_table_exists($CC_CONFIG['scheduleTable'])) {
|
if (airtime_db_table_exists($CC_CONFIG['scheduleTable'])) {
|
||||||
echo " * Removing database table ".$CC_CONFIG['scheduleTable']."...";
|
echo " * Removing database table ".$CC_CONFIG['scheduleTable']."...";
|
||||||
airtime_install_query("DROP TABLE ".$CC_CONFIG['scheduleTable']);
|
airtime_install_query("DROP TABLE ".$CC_CONFIG['scheduleTable']);
|
||||||
} else {
|
} else {
|
||||||
echo " * Skipping: database table ".$CC_CONFIG['scheduleTable']."\n";
|
echo " * Skipping: database table $CC_CONFIG[scheduleTable]".PHP_EOL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (airtime_db_table_exists($CC_CONFIG['backupTable'])) {
|
if (airtime_db_table_exists($CC_CONFIG['backupTable'])) {
|
||||||
echo " * Removing database table ".$CC_CONFIG['backupTable']."...";
|
echo " * Removing database table ".$CC_CONFIG['backupTable']."...";
|
||||||
airtime_install_query("DROP TABLE ".$CC_CONFIG['backupTable']);
|
airtime_install_query("DROP TABLE ".$CC_CONFIG['backupTable']);
|
||||||
} else {
|
} else {
|
||||||
echo " * Skipping: database table ".$CC_CONFIG['backupTable']."\n";
|
echo " * Skipping: database table $CC_CONFIG[backupTable]".PHP_EOL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Delete Database
|
||||||
//------------------------------------------------------------------------
|
//system("dropdb -h localhost -U airtime -W airtime");
|
||||||
// Uninstall Cron job
|
//select * from pg_stat_activity where datname='airtime';
|
||||||
//------------------------------------------------------------------------
|
|
||||||
/*
|
/*
|
||||||
$old_regex = '/transportCron\.php/';
|
$rows = airtime_get_query("select procpid from pg_stat_activity where datname='airtime'");
|
||||||
echo " * Uninstalling cron job...";
|
$rowsCount = count($rows);
|
||||||
|
for ($i=0; $i<$rowsCount; $i++){
|
||||||
$cron = new Cron();
|
$command = "kill -2 {$rows[$i]['procpid']}";
|
||||||
$access = $cron->openCrontab('write');
|
echo $command.PHP_EOL;
|
||||||
if ($access != 'write') {
|
system($command);
|
||||||
do {
|
|
||||||
$r = $cron->forceWriteable();
|
|
||||||
} while ($r);
|
|
||||||
}
|
}
|
||||||
foreach ($cron->ct->getByType(CRON_CMD) as $id => $line) {
|
echo "still here!";
|
||||||
if (preg_match($old_regex, $line['command'])) {
|
system("dropdb -h localhost -U airtime -W airtime");
|
||||||
//echo " removing cron entry\n";
|
exit;
|
||||||
$cron->ct->delEntry($id);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$cron->closeCrontab();
|
|
||||||
echo "done.\n";
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------
|
|
||||||
// Disconnect from the database
|
|
||||||
//------------------------------------------------------------------------
|
|
||||||
//echo " * Disconnecting from database...\n";
|
|
||||||
//$CC_DBC->disconnect();
|
|
||||||
|
|
||||||
//------------------------------------------------------------------------
|
//------------------------------------------------------------------------
|
||||||
// Delete the user
|
// Delete the user
|
||||||
//------------------------------------------------------------------------
|
//------------------------------------------------------------------------
|
||||||
echo " * Deleting database user '{$CC_CONFIG['dsn']['username']}'...\n";
|
echo " * Deleting database user '{$CC_CONFIG['dsn']['username']}'...".PHP_EOL;
|
||||||
$command = "sudo -u postgres psql postgres --command \"DROP USER {$CC_CONFIG['dsn']['username']}\" 2> /dev/null";
|
$command = "sudo -u postgres psql postgres --command \"DROP USER {$CC_CONFIG['dsn']['username']}\" 2> /dev/null";
|
||||||
@exec($command, $output, $results);
|
@exec($command, $output, $results);
|
||||||
if ($results == 0) {
|
if ($results == 0) {
|
||||||
echo " * User '{$CC_CONFIG['dsn']['username']}' deleted.\n";
|
echo " * User '{$CC_CONFIG['dsn']['username']}' deleted.".PHP_EOL;
|
||||||
} else {
|
} else {
|
||||||
echo " * Nothing to delete..\n";
|
echo " * Nothing to delete..".PHP_EOL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -221,5 +205,5 @@ airtime_uninstall_delete_files($CC_CONFIG['storageDir']);
|
||||||
|
|
||||||
$command = "python ".__DIR__."/../pypo/install/pypo-uninstall.py";
|
$command = "python ".__DIR__."/../pypo/install/pypo-uninstall.py";
|
||||||
system($command);
|
system($command);
|
||||||
echo "****************************** Uninstall Complete ******************************\n";
|
echo "****************************** Uninstall Complete ******************************".PHP_EOL;
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,7 @@ if (!function_exists('pg_connect')) {
|
||||||
}
|
}
|
||||||
|
|
||||||
require_once(dirname(__FILE__).'/../library/pear/DB.php');
|
require_once(dirname(__FILE__).'/../library/pear/DB.php');
|
||||||
|
require_once(dirname(__FILE__).'/../application/configs/conf.php');
|
||||||
|
|
||||||
function airtime_db_table_exists($p_name)
|
function airtime_db_table_exists($p_name)
|
||||||
{
|
{
|
||||||
|
@ -17,6 +18,16 @@ function airtime_db_table_exists($p_name)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function airtime_get_query($sql)
|
||||||
|
{
|
||||||
|
global $CC_DBC;
|
||||||
|
$result = $CC_DBC->GetAll($sql);
|
||||||
|
if (PEAR::isError($result)) {
|
||||||
|
return array();
|
||||||
|
}
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
function airtime_install_query($sql, $verbose = true)
|
function airtime_install_query($sql, $verbose = true)
|
||||||
{
|
{
|
||||||
global $CC_DBC;
|
global $CC_DBC;
|
||||||
|
@ -36,16 +47,16 @@ function airtime_db_connect($p_exitOnError = true) {
|
||||||
global $CC_DBC, $CC_CONFIG;
|
global $CC_DBC, $CC_CONFIG;
|
||||||
$CC_DBC = DB::connect($CC_CONFIG['dsn'], TRUE);
|
$CC_DBC = DB::connect($CC_CONFIG['dsn'], TRUE);
|
||||||
if (PEAR::isError($CC_DBC)) {
|
if (PEAR::isError($CC_DBC)) {
|
||||||
echo $CC_DBC->getMessage()."\n";
|
echo $CC_DBC->getMessage().PHP_EOL;
|
||||||
echo $CC_DBC->getUserInfo()."\n";
|
echo $CC_DBC->getUserInfo().PHP_EOL;
|
||||||
echo "Database connection problem.\n";
|
echo "Database connection problem.".PHP_EOL;
|
||||||
echo "Check if database '{$CC_CONFIG['dsn']['database']}' exists".
|
echo "Check if database '{$CC_CONFIG['dsn']['database']}' exists".
|
||||||
" with corresponding permissions.\n";
|
" with corresponding permissions.".PHP_EOL;
|
||||||
if ($p_exitOnError) {
|
if ($p_exitOnError) {
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
echo " * Connected to database\n";
|
echo "* Connected to database".PHP_EOL;
|
||||||
$CC_DBC->setFetchMode(DB_FETCHMODE_ASSOC);
|
$CC_DBC->setFetchMode(DB_FETCHMODE_ASSOC);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -57,20 +68,118 @@ function install_setDirPermissions($filePath) {
|
||||||
$fileperms = $fileperms | 0x0010; // group write bit
|
$fileperms = $fileperms | 0x0010; // group write bit
|
||||||
$fileperms = $fileperms | 0x0400; // group sticky bit
|
$fileperms = $fileperms | 0x0400; // group sticky bit
|
||||||
chmod($filePath, $fileperms);
|
chmod($filePath, $fileperms);
|
||||||
|
}
|
||||||
|
|
||||||
// // Verify Smarty template dir permissions
|
function rand_string($len=20, $chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789')
|
||||||
// $fileGroup = filegroup($CC_CONFIG["smartyTemplateCompiled"]);
|
{
|
||||||
// $groupOwner = (function_exists('posix_getgrgid'))?@posix_getgrgid($fileGroup):'';
|
$string = '';
|
||||||
// if (!empty($groupOwner) && ($groupOwner["name"] != $CC_CONFIG["webServerUser"])) {
|
for ($i = 0; $i < $len; $i++)
|
||||||
// echo " * Error: Your directory permissions for {$filePath} are not set correctly.<br>\n";
|
{
|
||||||
// echo " * The group perms need to be set to the web server user, in this case '{$CC_CONFIG['webServerUser']}'.<br>\n";
|
$pos = mt_rand(0, strlen($chars)-1);
|
||||||
// echo " * Currently the group is set to be '{$groupOwner['name']}'.<br>\n";
|
$string .= $chars{$pos};
|
||||||
// exit(1);
|
}
|
||||||
// }
|
return $string;
|
||||||
// if (!($fileperms & 0x0400)) {
|
}
|
||||||
// echo " * Error: Sticky bit not set for {$filePath}.<br>\n";
|
|
||||||
// exit(1);
|
function createAPIKey(){
|
||||||
// }
|
|
||||||
|
$api_key = rand_string();
|
||||||
|
updateINIKeyValues(__DIR__.'/../build/airtime.conf', 'api_key', $api_key);
|
||||||
|
updateINIKeyValues(__DIR__.'/../pypo/config.cfg', 'api_key', "'$api_key'");
|
||||||
|
}
|
||||||
|
|
||||||
|
function checkIfRoot(){
|
||||||
|
// Need to check that we are superuser before running this.
|
||||||
|
if(exec("whoami") != "root"){
|
||||||
|
echo "Must be root user.\n";
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function updateINIKeyValues($filename, $property, $value){
|
||||||
|
$lines = file($filename);
|
||||||
|
$n=count($lines);
|
||||||
|
for ($i=0; $i<$n; $i++) {
|
||||||
|
if (strlen($lines[$i]) > strlen($property))
|
||||||
|
if ($property == substr($lines[$i], 0, strlen($property))){
|
||||||
|
$lines[$i] = "$property = $value\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$fp=fopen($filename, 'w');
|
||||||
|
for($i=0; $i<$n; $i++){
|
||||||
|
fwrite($fp, $lines[$i]);
|
||||||
|
}
|
||||||
|
fclose($fp);
|
||||||
|
}
|
||||||
|
|
||||||
|
function storageDirectorySetup($CC_CONFIG){
|
||||||
|
global $CC_CONFIG, $CC_DBC;
|
||||||
|
|
||||||
|
echo PHP_EOL."*** Directory Setup ***".PHP_EOL;
|
||||||
|
foreach (array('baseFilesDir', 'storageDir') as $d) {
|
||||||
|
if ( !file_exists($CC_CONFIG[$d]) ) {
|
||||||
|
@mkdir($CC_CONFIG[$d], 02775, true);
|
||||||
|
if (file_exists($CC_CONFIG[$d])) {
|
||||||
|
$rp = realpath($CC_CONFIG[$d]);
|
||||||
|
echo "* Directory $rp created".PHP_EOL;
|
||||||
|
} else {
|
||||||
|
echo "* Failed creating {$CC_CONFIG[$d]}".PHP_EOL;
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
} elseif (is_writable($CC_CONFIG[$d])) {
|
||||||
|
$rp = realpath($CC_CONFIG[$d]);
|
||||||
|
echo "* Skipping directory already exists: $rp".PHP_EOL;
|
||||||
|
} else {
|
||||||
|
$rp = realpath($CC_CONFIG[$d]);
|
||||||
|
echo "* WARNING: Directory already exists, but is not writable: $rp".PHP_EOL;
|
||||||
|
}
|
||||||
|
$CC_CONFIG[$d] = $rp;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function createAirtimeDatabaseUser(){
|
||||||
|
global $CC_CONFIG;
|
||||||
|
// Create the database user
|
||||||
|
$command = "sudo -u postgres psql postgres --command \"CREATE USER {$CC_CONFIG['dsn']['username']} "
|
||||||
|
." ENCRYPTED PASSWORD '{$CC_CONFIG['dsn']['password']}' LOGIN CREATEDB NOCREATEUSER;\" 2>/dev/null";
|
||||||
|
|
||||||
|
@exec($command, $output, $results);
|
||||||
|
if ($results == 0) {
|
||||||
|
echo "* User {$CC_CONFIG['dsn']['username']} created.".PHP_EOL;
|
||||||
|
} else {
|
||||||
|
echo "* User {$CC_CONFIG['dsn']['username']} already exists.".PHP_EOL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function createAirtimeDatabase(){
|
||||||
|
global $CC_CONFIG;
|
||||||
|
|
||||||
|
$command = "sudo -u postgres createdb {$CC_CONFIG['dsn']['database']} --owner {$CC_CONFIG['dsn']['username']} 2> /dev/null";
|
||||||
|
@exec($command, $output, $results);
|
||||||
|
if ($results == 0) {
|
||||||
|
echo "* Database '{$CC_CONFIG['dsn']['database']}' created.".PHP_EOL;
|
||||||
|
} else {
|
||||||
|
echo "* Database '{$CC_CONFIG['dsn']['database']}' already exists.".PHP_EOL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function installPostgresScriptingLanguage(){
|
||||||
|
global $CC_DBC;
|
||||||
|
// Install postgres scripting language
|
||||||
|
$langIsInstalled = $CC_DBC->GetOne('SELECT COUNT(*) FROM pg_language WHERE lanname = \'plpgsql\'');
|
||||||
|
if ($langIsInstalled == '0') {
|
||||||
|
echo "* Installing Postgres scripting language".PHP_EOL;
|
||||||
|
$sql = "CREATE LANGUAGE 'plpgsql'";
|
||||||
|
airtime_install_query($sql, false);
|
||||||
|
} else {
|
||||||
|
echo "* Postgres scripting language already installed".PHP_EOL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function createAirtimeDatabaseTables(){
|
||||||
|
// Put Propel sql files in Database
|
||||||
|
$command = __DIR__."/../library/propel/generator/bin/propel-gen ../build/ insert-sql 2>propel-error.log";
|
||||||
|
@exec($command, $output, $results);
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue