#!/usr/bin/php query($q); } $interactive=posix_isatty(STDIN); $opts=getopt('R'); $pdo=new PDO('mysql:host='.$conf['sqlhost'], $conf['sqluser'], $conf['sqlpass']); if (isset($opts['R'])) { echo_and_query('DROP DATABASE IF EXISTS `'.$conf['sqldb'].'`'); } echo_and_query('CREATE DATABASE IF NOT EXISTS `'.$conf['sqldb'].'`'); // We can add charset and collate here if we want echo_and_query('USE `'.$conf['sqldb'].'`'); sql_row_obj::set_pdo_obj($pdo); foreach (get_declared_classes() as $class) { if (!is_subclass_of($class, 'sql_row_obj')) { continue; } $o=new $class(); // TODO this will be static once 5.3.0 is out if (isset($opts['R'])) { echo_and_query($o->drop_table()); } echo_and_query($o->create_table()); } foreach (get_pkgdirs() as $dir) { echo 'Creating profile for '.$conf['pkgdir_root'].'/'.$dir.'...'; $profile=new sql_profile(); $profile->pkgdir=$dir; $profile->write(); echo "done\n"; } do { if ($user->email) { echo 'Invalid entry: '.$user->email."\n"; } echo 'Admin email address: '; $user=new sql_user(); $user->email=trim(fgets(STDIN)); if (!$interactive) { echo "\n"; } } while (!Validate::email($user->email)); do { if ($user->name) { echo 'Invalid entry: '.$user->name."\n"; } echo 'Admin display name: '; $user->name=trim(fgets(STDIN)); if (!$interactive) { echo "\n"; } } while (!Validate::username($user->name)); if ($interactive) { system('stty -echo'); } do { if ($pass && $passconfirm) { echo "Entered passwords did not match. Try again.\n"; } echo 'Admin password: '; $pass=trim(fgets(STDIN)); echo "\nRepeat password: "; $passconfirm=trim(fgets(STDIN)); echo "\n"; } while (!$pass || $pass != $passconfirm); if ($interactive) { system('stty echo'); } $user->passhash=sha1($pass); $user->flags='a'; $user->write(); ?>