Ver Fonte

Detect/install repo file RPM via API

Andy Baugh há 5 anos atrás
pai
commit
4156a2ab55
2 ficheiros alterados com 38 adições e 7 exclusões
  1. 14 6
      js/pgupgrade.js
  2. 24 1
      lib/Troglodyne/API/Postgres.pm

+ 14 - 6
js/pgupgrade.js

@@ -1,3 +1,12 @@
+function doAsyncRequest (mod, func, handler) {
+    'use strict';
+    var oReq = new XMLHttpRequest();
+    oReq.addEventListener("load", handler);
+    oReq.open("GET", `api.cgi?module=${mod}&function=${func}`);
+    oReq.send();
+    return false;
+}
+
 function versionHandler () {
     'use strict';
     let obj = JSON.parse(this.responseText);
@@ -42,14 +51,13 @@ function versionHandler () {
     }
 }
 
-document.getElementById('submit').disabled = true;
-var oReq = new XMLHttpRequest();
-oReq.addEventListener("load", versionHandler);
-oReq.open("GET", "api.cgi?module=Postgres&function=get_postgresql_versions");
-oReq.send();
-
 window.doUpgrade = function (form) {
+    'use strict';
     console.log(form.get('selectedVersion'));
     // TODO Replace table with upgrade biewer after doing xhr
     return false;
 }
+
+// Now kickoff the page load post bits
+document.getElementById('submit').disabled = true;
+doAsyncRequest ('Postgres', 'get_postgresql_versions', versionHandler);

+ 24 - 1
lib/Troglodyne/API/Postgres.pm

@@ -18,7 +18,30 @@ sub get_postgresql_versions {
 
 sub enable_community_repositories {
     Cpanel::LoadModule::Custom::load_perl_module('Troglodyne::CpPostgreSQL');
-    return { 'status' => 'OK' };
+    require Cpanel::Sys::OS;
+    my $centos_ver = substr( Cpanel::Sys::OS::getreleaseversion(), 0, 1 );
+    my $repo_rpm_url = $Troglodyne::CpPostgreSQL::REPO_RPM_URLS{$centos_ver};
+   
+    # TODO Use Cpanel::SafeRun::Object to run the install? 
+    require Capture::Tiny;
+    my @cmd = qw{/bin/rpm -q pgdg-redhat-repo};
+    my ( $stdout, $stderr, $ret ) = Capture::Tiny::capture( sub {
+        system(@cmd);
+    });
+    my $installed = !$ret;
+    if( !$installed ) {
+        @cmd = qw{/bin/rpm -i}, $repo_rpm_url;
+        ( $stdout, $stderr, $ret ) = Capture::Tiny::capture( sub {
+            system(@cmd);
+        } );
+    }
+    return {
+        'last_yum_command'  => join( " ", @cmd ),
+        'already_installed' => $installed,
+        'stdout'            => $stdout,
+        'stderr'            => $stderr,
+        'exit_code'         => $ret,
+    };
 }
 
 1;