Early firmware update support
[gamestick-pjgsapi.git] / www / setupcheck.php
1 <?php
2 /**
3  * Check if everything is fine
4  */
5 header('HTTP/1.0 500 Internal Server Error');
6
7 function error($msg)
8 {
9     header('HTTP/1.0 500 Internal Server Error');
10     header('Content-Type: text/plain');
11     echo 'Error: ' . $msg . "\n";
12     exit(1);
13 }
14
15 $configFile = __DIR__ . '/../config.php';
16 if (!file_exists($configFile)) {
17     error('config.php missing. Copy config.php.dist to config.php');
18 }
19
20 require_once $configFile;
21 require_once __DIR__ . '/../src/ProfileDb.php';
22
23 $dbFile = ProfileDb::getDbFilePath();
24 if (!file_exists($dbFile)) {
25     $dbFileDir = dirname($dbFile);
26     if (!is_writable($dbFileDir)) {
27         error('Database file directory is not writable: ' . $dbFileDir);
28     }
29 }
30
31 if (isset($GLOBALS['popuplarTxtFile'])
32     && strlen($GLOBALS['popuplarTxtFile'])
33     && !file_exists($GLOBALS['popuplarTxtFile'])
34 ) {
35     error('Popular games file does not exist: ' . $GLOBALS['popuplarTxtFile']);
36 }
37
38 if (isset($GLOBALS['featuredFile'])
39     && strlen($GLOBALS['featuredFile'])
40     && !file_exists($GLOBALS['featuredFile'])
41 ) {
42     error('Featured games file does not exist: ' . $GLOBALS['featuredFile']);
43 }
44
45 $cacheDir = __DIR__ . '/../cache/';
46 $appsCacheFile         = $cacheDir . 'connect-apps.min.json';
47 $featuredAgesCacheFile = $cacheDir . 'connect-featured-ages.min.json';
48
49 if (!file_exists($appsCacheFile)) {
50     error('Apps cache file does not exist. Run bin/generate-apps-cache.php');
51 }
52 if (!file_exists($featuredAgesCacheFile)) {
53     error('Featured ages cache file does not exist. Run bin/generate-apps-cache.php');
54 }
55
56
57 //FIXME: api tests
58
59 header('HTTP/1.0 200 OK');
60 header('Content-Type: text/plain');
61 echo "Everything looks fine\n";
62 ?>