diff --git a/config.example.php b/config.example.php index 6ed3f93..208ea81 100644 --- a/config.example.php +++ b/config.example.php @@ -5,7 +5,7 @@ // /srv/media/courses/ // Course 1/Intro/Video1.mp4 // Course 2/Module 3/Advanced/lesson.mp4 -define('VIDEOS_ROOT', '/home/harwinder/Development/coursehub/videos'); +define('VIDEOS_ROOT', '/srv/courses'); define('DB_HOST', '127.0.0.1'); define('DB_PORT', 3306); diff --git a/install.php b/install.php index 5244ce5..7507c30 100644 --- a/install.php +++ b/install.php @@ -2,7 +2,7 @@ // CourseHub installer — sets up the database and schema. // // Browser: open install.php and fill in the form. -// CLI: php install.php [db_admin_user] [db_admin_pass] +// CLI: php install.php [db_admin_user] [db_admin_pass] [--videos=/path/to/courses] // // Steps performed: // 1. Creates config.php from config.example.php if missing (edit it, re-run). @@ -51,17 +51,27 @@ require_once __DIR__ . '/config.php'; // -- Collect input ----------------------------------------------------------- if ($isCli) { - $adminUser = $_SERVER['argv'][1] ?? ''; - $adminPass = $_SERVER['argv'][2] ?? ''; + $args = array_slice($_SERVER['argv'], 1); + $videosRoot = ''; + foreach ($args as $i => $a) { + if (str_starts_with($a, '--videos=')) { + $videosRoot = substr($a, strlen('--videos=')); + unset($args[$i]); + } + } + $args = array_values($args); + $adminUser = $args[0] ?? ''; + $adminPass = $args[1] ?? ''; $appUser = ''; $appPass = ''; $run = true; } else { - $adminUser = trim($_POST['admin_user'] ?? ''); - $adminPass = $_POST['admin_pass'] ?? ''; - $appUser = trim($_POST['app_user'] ?? ''); - $appPass = $_POST['app_pass'] ?? ''; - $run = $_SERVER['REQUEST_METHOD'] === 'POST'; + $adminUser = trim($_POST['admin_user'] ?? ''); + $adminPass = $_POST['admin_pass'] ?? ''; + $appUser = trim($_POST['app_user'] ?? ''); + $appPass = $_POST['app_pass'] ?? ''; + $videosRoot = trim($_POST['videos_root'] ?? ''); + $run = $_SERVER['REQUEST_METHOD'] === 'POST'; } if (!$run) { @@ -70,7 +80,7 @@ if (!$run) { } // -- Run the installation ---------------------------------------------------- -[$done, $steps, $notice] = performInstall($adminUser, $adminPass, $appUser, $appPass); +[$done, $steps, $notice] = performInstall($adminUser, $adminPass, $appUser, $appPass, $videosRoot); if ($done && @file_put_contents($lockFile, date('c') . "\n") === false) { $steps[] = [false, 'Could not write .install.lock — the installer will stay re-runnable. ' . 'Delete or protect install.php on a production server.']; @@ -80,7 +90,7 @@ respond($steps, $done, $notice); // ----------------------------------------------------------------------------- function performInstall(string $adminUser, string $adminPass, - string $appUser, string $appPass): array + string $appUser, string $appPass, string $videosRoot): array { $steps = []; $notice = ''; @@ -162,9 +172,33 @@ function performInstall(string $adminUser, string $adminPass, } } - if (!is_dir(VIDEOS_ROOT)) { - $steps[] = [false, 'Warning: VIDEOS_ROOT (' . VIDEOS_ROOT . ') does not exist yet — ' - . 'set it in config.php before scanning.']; + // Videos folder: optionally persist a new path into config.php, then + // make sure the effective path exists. + $effectiveRoot = VIDEOS_ROOT; + if ($videosRoot !== '' && $videosRoot !== VIDEOS_ROOT) { + $cfgFile = __DIR__ . '/config.php'; + $cfg = file_get_contents($cfgFile); + $new = preg_replace( + "/define\('VIDEOS_ROOT',\s*'[^']*'\);/", + "define('VIDEOS_ROOT', '" . addslashes($videosRoot) . "');", + $cfg, 1, $replaced + ); + if ($replaced === 1 && @file_put_contents($cfgFile, $new) !== false) { + $effectiveRoot = $videosRoot; + $steps[] = [true, 'Set VIDEOS_ROOT in config.php to ' . $videosRoot . '.']; + } else { + $steps[] = [false, 'Could not update config.php — set VIDEOS_ROOT to ' + . $videosRoot . ' manually.']; + } + } + if (!is_dir($effectiveRoot)) { + if (@mkdir($effectiveRoot, 0755, true)) { + $steps[] = [true, 'Created videos folder ' . $effectiveRoot . '.']; + } else { + $steps[] = [false, 'Warning: videos folder ' . $effectiveRoot . ' does not exist ' + . 'and could not be created — create it (or fix VIDEOS_ROOT in config.php) ' + . 'before scanning.']; + } } $notice = 'Installation complete. Open the app, log in, and use "Rescan library" ' @@ -237,6 +271,16 @@ function renderPage(?array $steps, bool $done, string $notice): void
+