gitprep / setup / templates / index.html.ep /
Newer Older
153 lines | 4.019kb
improved install process
Yuki Kimoto authored on 2013-04-09
1
<%
2
  use Cwd qw/getcwd realpath/;
3
  use File::Copy 'copy';
4

            
5
  # Parameter
removed jquery and bootstrup...
Yuki Kimoto authored on 2013-04-21
6
  my $op = param('op') || '';
7

            
improved install process
Yuki Kimoto authored on 2013-04-09
8
  # Outputs
9
  my @outputs;
10
  
11
  # Error
12
  my $error;
removed jquery and bootstrup...
Yuki Kimoto authored on 2013-04-21
13
  
14
  # App absolute path
15
  my $app_abs_path;
16
  
17
  if ($op eq 'setup') {
18

            
19
    # Setup directory
20
    my $setup_dir = getcwd;
21

            
22
    # Home directory
23
    my $home_dir = realpath($setup_dir . '/..');
24
    
25
    # Script directory
26
    my $script_dir = realpath($setup_dir . '/../script');
27
    
28
    # cpanm Path
29
    my $cpanm_path = "$home_dir/cpanm";
30
    
31
    # cpanm home directory
32
    $ENV{PERL_CPANM_HOME} = $setup_dir;
33
    
34
    # Setup script absolute path
35
    my $setup_script_abs_path = url_for->to_string;
36
    
37
    # Application script absolute path
fixed bug that application a...
Yuki Kimoto authored on 2013-04-21
38
    $app_abs_path = $setup_script_abs_path;
removed jquery and bootstrup...
Yuki Kimoto authored on 2013-04-21
39
    $app_abs_path =~ s#\Q/setup/setup.cgi#.cgi#;
40
    
41
    # Application script name
42
    my ($app_name) = $app_abs_path =~ /([0-9a-zA-Z-_]+\.cgi)$/;
43
    
44
    # Application script file
45
    my $app_file = "$script_dir/$app_name";
46
    
47
    # Place application script is moved to 
48
    my $app_to = realpath("$home_dir/../$app_name");
improved install process
Yuki Kimoto authored on 2013-04-09
49
    
50
    # Change directory
51
    if (chdir $home_dir) {
52
    
53
      # Install Module::CoreList
54
      my $cmd = 'perl cpanm -n -l extlib Module::CoreList 2>&1';
55
      if (open my $fh, "$cmd |") {
56
        local $/;
57
        my $output = <$fh>;
58
        push @outputs, $output;
59
        if (close $fh) {
60
        
61
          # Install modules
62
          my $cmd = 'perl -Iextlib/lib/perl5 '
63
            . 'cpanm -n -L extlib --installdeps . 2>&1';
64
          if (open my $fh, "$cmd |") {
65
            local $/;
66
            my $output = <$fh>;
67
            push @outputs, $output;
68
            if (close $fh) {
69
              
70
              # Copy application file
71
              if (copy $app_file, $app_to) {
72
                push @outputs, "$app_file is moved to $app_to";
73
                
74
                # Change mode
75
                if (chmod(0755, $app_to)) {
76
                  push @outputs, "change $app_to mode to 755";
77
                }
78
                else {
79
                  $error = 1;
80
                  app->log->error("Can't change mode $app_to");
81
                }
82
              }
83
              else {
84
                $error = 1;
85
                app->log->error("Can't move $app_file to $app_to");
86
              }
87
            }
88
            else {
89
              $error = 1;
90
              app->log->error("Can't close pipe install modules: $!");
91
            }
92
          }
93
          else {
94
            my $error = 1;
95
            app->log->error("Can't open pipe install modules: $!");
96
          }
97
        }
98
        else {
99
          $error = 1;
100
          app->log->error("Can't close pipe install Module::CoreList: $!");
101
        }
102
      }
103
      else {
104
        $error = 1;
105
        app->log->error("Can't open pipe install Module::CoreList: $!");
106
      }
107
    }
108
    else {
109
      $error = 1;
110
      app->log->error("Can't cahgne directory: $!");
111
    }
112
  }
113
%>
114

            
115
<!DOCTYPE html>
116
<html>
117
  <head>
118
    <meta charset="UTF-8">
removed jquery and bootstrup...
Yuki Kimoto authored on 2013-04-21
119
    <title>Setup</title>
improved install process
Yuki Kimoto authored on 2013-04-09
120
  </head>
121
  <body>
removed jquery and bootstrup...
Yuki Kimoto authored on 2013-04-21
122
    <div>
123
      <div style="text-align:center"><h1>Setup</h1></div>
improved install process
Yuki Kimoto authored on 2013-04-09
124
    </div>
125
    <hr style="margin-top:0;margin-bottom:0">
removed jquery and bootstrup...
Yuki Kimoto authored on 2013-04-21
126
    <div>
127
      <div style="text-align:center"><b><h3>Click only once. Wait for a few minutes.</h3></b></div>
improved install process
Yuki Kimoto authored on 2013-04-09
128
      <form action="<%= url_for->query(op => 'setup') %>" method="post">
removed jquery and bootstrup...
Yuki Kimoto authored on 2013-04-21
129
        <div style="text-align:center;margin-bottom:10px">
improved install process
Yuki Kimoto authored on 2013-04-09
130
          <input type="submit" style="width:200px;height:50px;font-size:200%" value="Setup">
131
        </div>
132
      </form>
133

            
134
      % if ($op eq 'setup') {
removed jquery and bootstrup...
Yuki Kimoto authored on 2013-04-21
135
        <span">Result</span>
improved install process
Yuki Kimoto authored on 2013-04-09
136
<pre style="height:300px;overflow:auto;margin-bottom:30px">
137
% if ($error) {
138
<span style="color:red">Error, Setup failed. See setup/log/production.log</span>
139
% }
140
% unless ($error) {
141
% for my $line (@outputs) {
142
%= $line
143
% }
144
% }
145
</pre>
146
      % }
147

            
148
      % if ($op eq 'setup' && !$error) {
149
        <div style="font-size:150%;margin-bottom:30px;">Go to <a href="<%= $app_abs_path %>">Application</a></div>
150
      % }
151
    </div>
152
  </body>
153
</html>