Showing 1 changed files with 30 additions and 3 deletions
+30 -3
setup/setup.php
... ...
@@ -1,6 +1,7 @@
1 1
 <?php
2 2
   # Config
3 3
   $setup_dir = getcwd();
4
+  $script_dir = realpath($setup_dir . '/../script');
4 5
   $app_home_dir = realpath($setup_dir . '/..');
5 6
   $cpanm_path = "$app_home_dir/cpanm";
6 7
   putenv("PERL_CPANM_HOME=$setup_dir");
... ...
@@ -11,6 +12,10 @@
11 12
   $current_path = $_SERVER["SCRIPT_NAME"];
12 13
   $app_path = $current_path;
13 14
   $app_path = preg_replace('/\/setup\/setup\.php/', '', $app_path) . '.cgi';
15
+  preg_match("/([0-9a-zA-Z-_]+\.cgi)$/", $app_path, $matches);
16
+  $script_base_name = $matches[0];
17
+  $script = "$script_dir/$script_base_name";
18
+  $to_script = realpath("$app_home_dir/../$script_base_name");
14 19
   $output = array('');
15 20
   $app_home_dir = getcwd() . '/..';
16 21
   $setup_command_success = true;
... ...
@@ -22,10 +27,25 @@
22 27
     }
23 28
     exec("perl cpanm -n -l extlib Module::CoreList 2>&1", $output, $ret);
24 29
     
30
+    $output = array();
25 31
     if ($ret == 0) {
26 32
       exec("perl -Iextlib/lib/perl5 cpanm -n -L extlib --installdeps . 2>&1", $output, $ret);
27 33
       if ($ret == 0) {
28
-        $setup_command_success = true;
34
+        if (copy($script, $to_script)) {
35
+          array_push($output, "$script is moved to $to_script");
36
+          if (chmod($to_script, 0755)) {
37
+            array_push($output, "change $to_script mode to 755");
38
+            $setup_command_success = true;
39
+          }
40
+          else {
41
+            array_push($output, "Can't change mode $to_script");
42
+            $setup_command_success = false;
43
+          }
44
+        }
45
+        else {
46
+          array_push($output, "Can't move $script to $to_script");
47
+          $setup_command_success = false;
48
+        }
29 49
       }
30 50
       else {
31 51
         $setup_command_success = false;
... ...
@@ -48,6 +68,7 @@
48 68
     <link rel="stylesheet" href="css/bootstrap-responsive.css" />
49 69
   </head>
50 70
   <body>
71
+    <?php echo $script ?>
51 72
     <div class="container">
52 73
       <div class="text-center"><h1>Setup Tool</h1></div>
53 74
     </div>
... ...
@@ -59,10 +80,12 @@
59 80
           <input type="submit" style="width:200px;height:50px;font-size:200%" value="Setup">
60 81
         </div>
61 82
       </form>
83
+
84
+<?php if ($op == 'setup') { ?>
62 85
       <span class="label">Result</span>
63 86
 <pre style="height:300px;overflow:auto;margin-bottom:30px">
64 87
 <?php if (!$setup_command_success) { ?>
65
-<span style="color:red">Error(Setup command failed)</span>
88
+<span style="color:red">Error, Setup failed.</span>
66 89
 <?php } ?>
67 90
 <?php if ($setup_command_success) { ?>
68 91
 <?php foreach ($output as $line) { ?>
... ...
@@ -71,7 +94,11 @@
71 94
 <?php } ?>
72 95
 <?php } ?>
73 96
 </pre>
74
-      <div style="font-size:150%;margin-bottom:30px;">Go to <a href="<?php echo $app_path ?>">Application</a></div>
97
+<?php } ?>
98
+
99
+      <?php if ($op == 'setup' && $setup_command_success) { ?>
100
+        <div style="font-size:150%;margin-bottom:30px;">Go to <a href="<?php echo $app_path ?>">Application</a></div>
101
+      <?php } ?>
75 102
     </div>
76 103
   </body>
77 104
 </html>