Overhaul the Redhat, Ubuntu and Debian installation instructions.
authorDave Page <dpage@pgadmin.org>
Wed, 10 Jun 2020 13:07:57 +0000 (14:07 +0100)
committerDave Page <dpage@pgadmin.org>
Wed, 10 Jun 2020 13:08:04 +0000 (14:08 +0100)
* Merge all commands into a single text area for ease of copy/paste.
* Add a Copy Script button to each text area to copy the script (without comments and blanks) to the clipboard.
* Centralise the copy/paste code so it can be used elsewhere.
* Always install the database server.

Based on reviews/discussion with Magnus, Jonathan, Daniel and Sehrope.

media/css/main.css
media/js/main.js
templates/downloads/js/yum.js
templates/pages/download/linux/debian.html
templates/pages/download/linux/redhat.html
templates/pages/download/linux/ubuntu.html

index a27ab0d9dcd79c3fed1c4d5178d7962a688f777f..0eb6e06c3cf85d9789f71f298300e31eaf2daf64 100644 (file)
@@ -1526,3 +1526,14 @@ table.sponsor-table tbody tr td:nth-child(3) {
     font-size: 1.5rem;
   }
 }
+
+/* Script copy buttons */
+.pg-script-container {
+  position: relative;
+}
+
+.pg-script-copy-btn {
+  position: absolute;
+  top: 8px;
+  right: 8px;
+}
\ No newline at end of file
index 0b37fee8734c24fe136759fc7ee09e98fa7b0ba9..aa939f1e3f0ff9c4aef38bd2f5af81be607a4908 100644 (file)
@@ -18,12 +18,58 @@ if (location.hash) shiftWindow();
 window.addEventListener("hashchange", shiftWindow);
 
 
-/*
- * Debian/Ubuntu download dropdowns
+/* Copy a script from an HTML element to the clipboard,
+ * removing comments and blank lines.
+ * Arguments:
+ *   trigger: The button calling the function, whose label will be updated
+ *   elem: The element containing the script to copy
  */
-$(function() {
-    $('select#debseries').change(function() {
-       var deb = document.getElementById('series-deb');
-       deb.innerHTML = $(this).val();
-    });
-});
+
+function copyScript(trigger, elem) {
+    var raw = document.getElementById(elem).innerHTML;
+
+    // Create a scratch div to copy from
+    var scratch = document.createElement("div");
+    document.body.appendChild(scratch);
+
+    // Copy the contents of the script box into the scratch div, removing
+    // comments and blank lines
+    var lines = raw.split("\n");
+    var output = '';
+    for (var l = 0; l < lines.length; l++) {
+        if (lines[l][0] != '#' && lines[l].trim() != '')
+            output += lines[l] + '<br />';
+    }
+    scratch.innerHTML = output.trim();
+
+    // Perform the copy
+    if(document.body.createTextRange) {
+        // IE 11
+        var range = document.body.createTextRange();
+        range.moveToElementText(scratch);
+        range.select();
+        document.execCommand("Copy");
+        document.getSelection().removeAllRanges()
+    }
+    else if(window.getSelection) {
+        // Sane browsers
+        var selection = window.getSelection();
+        var range = document.createRange();
+        range.selectNodeContents(scratch);
+        selection.removeAllRanges();
+        selection.addRange(range);
+        document.execCommand("Copy");
+        selection.removeAllRanges();
+    }
+
+    // Remove the scratch div
+    scratch.parentNode.removeChild(scratch);
+
+    // Indicate to the user that the script was copied
+    var label = trigger.innerHTML;
+    trigger.innerHTML = 'Copied!';
+
+    setTimeout(function() {
+        trigger.innerHTML = label;
+    }, 3000);
+}
index 74b57024464dd80df03eeee7c7978cf313df7f2b..a2d63389ba1ddd6be5465907f90468ae173c35c6 100644 (file)
@@ -119,13 +119,11 @@ function archChanged() {
    var ver = document.getElementById('version').value;
    var plat = document.getElementById('platform').value;
    var arch = document.getElementById('arch').value;
+   var scriptBox = document.getElementById('script-box')
 
    if (!plat || plat == -1) {
-      document.getElementById('reporpm').innerHTML = 'Select version and platform above';
-      document.getElementById('clientpackage').innerHTML = 'Select version and platform above';
-      document.getElementById('serverpackage').innerHTML = 'Select version and platform above';
-      document.getElementById('initdb').innerHTML = 'Select version and platform above';
-      document.getElementById('dnfmodule').style.display = 'none';
+      document.getElementById('copy-btn').style.display = 'none';
+      scriptBox.innerHTML = 'Select version and platform above';
       return;
    }
 
@@ -135,21 +133,28 @@ function archChanged() {
    var url = 'https://download.postgresql.org/pub/repos/yum/reporpms/' + plat + '-' + arch + '/pgdg-' + get_rpm_prefix(plat) +'-repo-latest.noarch.rpm';
 
    var installer = get_installer(plat);
-   document.getElementById('reporpm').innerHTML = installer + ' install ' + url;
-   document.getElementById('clientpackage').innerHTML = installer + ' install postgresql' + shortver;
-   document.getElementById('serverpackage').innerHTML = installer + ' install postgresql' + shortver + '-server';
+   scriptBox.innerHTML = '# Install the repository RPM:\n';
+   scriptBox.innerHTML += installer + ' install ' + url + '\n\n';
 
-   document.getElementById('dnfmodule').style.display = disable_module_on(plat) ? 'list-item' : 'none';
+   scriptBox.innerHTML += '# Install PostgreSQL:\n';
+   scriptBox.innerHTML += installer + ' install postgresql' + shortver + '-server\n\n';
 
+   if (disable_module_on(plat)) {
+      scriptBox.innerHTML += '# Disable the built-in PostgreSQL module:\n';
+      scriptBox.innerHTML += 'dnf -qy module disable postgresql\n\n';
+   }
+
+   scriptBox.innerHTML += '# Optionally initialize the database and enable automatic start:\n';
    if (uses_systemd(plat)) {
        var setupcmd = 'postgresql-' + shortver + '-setup';
        if (ver < 10) {
-          setupcmd = 'postgresql' + shortver + '-setup';
+              setupcmd = 'postgresql' + shortver + '-setup';
        }
-
-       document.getElementById('initdb').innerHTML = '/usr/pgsql-' + ver + '/bin/' + setupcmd + ' initdb<br/>systemctl enable postgresql-' + ver + '<br/>systemctl start postgresql-' + ver;
+       scriptBox.innerHTML += '/usr/pgsql-' + ver + '/bin/' + setupcmd + ' initdb\nsystemctl enable postgresql-' + ver + '\nsystemctl start postgresql-' + ver;
    }
    else {
-       document.getElementById('initdb').innerHTML = 'service postgresql-' + ver + ' initdb<br/>chkconfig postgresql-' + ver + ' on<br/>service postgresql-' + ver + ' start';
+       scriptBox.innerHTML += 'service postgresql-' + ver + ' initdb\nchkconfig postgresql-' + ver + ' on\nservice postgresql-' + ver + ' start';
    }
+
+   document.getElementById('copy-btn').style.display = 'block';
 }
index 0944edb6aa574eddd36a52f820bd29a163c95196..a3bc9776358243a5da047f99884e7319b5449901 100644 (file)
@@ -41,30 +41,23 @@ versions of Debian:
 <p>
 To use the apt repository, follow these steps:
 </p>
-<ol>
- <li>
-  <select id="debseries" name="field.series" class="custom-select">
-   <option selected="selected" value="YOUR_DEBIAN_VERSION_HERE">Choose your Debian version</option>
-   <option value="buster">Buster (10.x)</option>
-   <option value="stretch">Stretch (9.x)</option>
-   <option value="jessie">Jessie (8.x)</option>
-   <option value="bullseye">Bullseye (11.x, testing)</option>
-   <option value="sid">Sid (unstable)</option>
-  </select>
- </li>
- <li>
-   Create the file <var>/etc/apt/sources.list.d/pgdg.list</var>, and add a line
- for the repository:
-   <pre class="code">
-     deb http://apt.postgresql.org/pub/repos/apt/ <span id="series-deb">YOUR_DEBIAN_VERSION_HERE</span>-pgdg main</pre>
- </li>
- <li>
-   Import the repository signing key, and update the package lists:
-   <pre class="code">
-     wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
-     sudo apt-get update</pre>
- </li>
-</ol>
+
+<div class="pg-script-container">
+    <pre id="script-box" class="code"># Create the file repository configuration:
+sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
+
+# Import the repository signing key:
+wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
+
+# Update the package lists:
+sudo apt-get update
+
+# Install the latest version of PostgreSQL.
+# If you want a specific version, use 'postgresql-12' or similar instead of 'postgresql':
+sudo apt-get install postgresql</pre>
+    <button class="pg-script-copy-btn" onclick="copyScript(this, 'script-box')">Copy Script</button>
+</div>
+
 <p>
 For more information about the apt repository, including answers to frequent
 questions, please see the apt page on
index bc309d644240cfd69c1009a82872b2ec02a23693..29161ddafb1cd618fb23ee62921688c753bf15a2 100644 (file)
@@ -59,20 +59,11 @@ To use the PostgreSQL Yum Repository, follow these steps:
   <li>Select version: <select id="version" class="custom-select" onChange="verChanged()"></select><br/></li>
   <li>Select platform: <select id="platform" class="custom-select" onChange="platChanged()"></select></li>
   <li>Select architecture: <select id="arch" class="custom-select" onChange="archChanged()"></select></li>
-  <li>Install the repository RPM:
-    <pre id="reporpm" class="code"></pre>
-  </li>
-  <li id="dnfmodule">Disable the built-in PostgreSQL module
-    <pre class="code">dnf -qy module disable postgresql</pre>
-  </li>
-  <li>Install the client packages:
-    <pre id="clientpackage" class="code"></pre>
-  </li>
-  <li>Optionally install the server packages:
-    <pre id="serverpackage" class="code"></pre>
-  </li>
-  <li>Optionally initialize the database and enable automatic start:
-      <pre id="initdb" class="code"></pre>
+  <li>Copy, paste and run the relevant parts of the setup script:
+    <div class="pg-script-container">
+        <pre id="script-box" class="code"></pre>
+        <button id="copy-btn" class="pg-script-copy-btn" onclick="copyScript(this, 'script-box')">Copy Script</button>
+    </div>
   </li>
 </ol>
 
index 5675e8117954381d3712dbb80045acb1c5d77091..04650452f2687a494f783d98134f4451a5ac42d8 100644 (file)
@@ -40,25 +40,23 @@ by using the closest LTS version available.
 <p>
 To use the apt repository, follow these steps:
 </p>
-<ul>
-  <li>
-    <select id="debseries" name="field.series" class="custom-select">
-      <option selected="selected" value="YOUR_UBUNTU_VERSION_HERE">Choose your Ubuntu version</option>
-      <option value="focal">Focal (20.04)</option>
-      <option value="bionic">Bionic (18.04)</option>
-      <option value="xenial">Xenial (16.04)</option>
-    </select>
- </li>
-  <li>Create the file <code>/etc/apt/sources.list.d/pgdg.list</code> and add a line
-    for the repository
-    <pre class="code">deb http://apt.postgresql.org/pub/repos/apt/ <span id="series-deb">YOUR_UBUNTU_VERSION_HERE</span>-pgdg main</pre>
- </li>
-  <li>
-    Import the repository signing key, and update the package lists
-    <pre class="code">wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
-sudo apt-get update</pre>
-  </li>
-</ul>
+
+<div class="pg-script-container">
+    <pre id="script-box" class="code"># Create the file repository configuration:
+sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
+
+# Import the repository signing key:
+wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
+
+# Update the package lists:
+sudo apt-get update
+
+# Install the latest version of PostgreSQL.
+# If you want a specific version, use 'postgresql-12' or similar instead of 'postgresql':
+sudo apt-get install postgresql</pre>
+    <button class="pg-script-copy-btn" onclick="copyScript(this, 'script-box')">Copy Script</button>
+</div>
+
 <p>
 For more information about the apt repository, including answers to frequent
 questions, please see the <a href="https://wiki.postgresql.org/wiki/Apt" target="_blank">PostgreSQL Apt Repository</a> page on