Drupal & shell bookmarklet for updating modules 3 (updated – wget bookmarklets)

*Note: A new post is available here: Drupal & shell bookmarklet for updating modules 5 (updated – mulitple dbs, backup only option)

This is a follow up to the post: Drupal & shell bookmarklet for updating modules
Also see: Drupal & shell bookmarklet for updating modules 2 ->just Recommended

I’ve refined the module install bookmarklets. These put the vars you might want to customize at the top so you aren’t changing the details every time:
For example:

  var siteDirName='site_directory';
  var siteBasePath='/var/www/html/';
  var backupBasePath='/home/yourName/drupal_backup/';
  var dbUser='drupal6-db-user';
  var dbName='drupal6-db';
  var serverName='myServer';
 

You can use http://subsimple.com/bookmarklets/jsbuilder.htm to edit the bookmarklet and set the defaults to suit your set up.

I use this first one on the admin/reports/updates page (where I know jQuery is installed) to capture all the ‘recommended’ updates and output them to a shell script that I cut and paste into terminal. Each update is fetched via wget, unpacked into my modules directory, overwriting the old module and then the zip file is removed.

After all the files have been processed, the directory is listed and the db and site is backed up.
Then I can begrudgingly go to the update page and run the script.

install all mods jQuery var

javascript:(function(){var siteDirName='site_directory';var siteBasePath='/var/www/html/';var backupBasePath='/home/yourName/drupal_backup/';var dbUser='drupal6-db-user';var dbName='drupal6-db';var serverName='myServer';var date=new%20Date();var saveDate=date.getMonth()+1+'-'+date.getDate()+'-'+date.getFullYear();var connect=confirm('Would%20you%20like%20to%20include%20the%20connection%20information?');var shellLocation=prompt('What%20is%20the%20location%20of%20your%20install%20directory?',siteBasePath+siteDirName+'/sites/all/modules/');var shellText=%22%22;if(connect){shellText='##ssh%20'+serverName;}if(shellLocation!==null){shellText=shellText+'<br />cd%20'+shellLocation;}with($('table.version-recommended%20td%20li.update-download%20a').each(function(){q=this.href.toString().split('/').pop();if(q!==%22%22&amp;&amp;this.href!=%22%22){shellText=shellText+%22<br />wget%20%22+unescape(this.href);shellText=shellText+%22<br />gzip%20-dc%20%22+escape(q)+%22%20|%20tar%20-x%22;shellText=shellText+%22<br />rm%20%22+escape(q);}}));if(connect){shellText=shellText+%22<br />wait%22;shellText=shellText+%22<br />ls%20-al%22;shellText=shellText+%22<br />sudo%20tar%20-c%20--checkpoint%20%22+siteBasePath+siteDirName+%22/%20|%20bzip2%20&gt;%20%22+backupBasePath+siteDirName+saveDate+%22.tar.bz2;%20%20##Backupfiles%22;shellText=shellText+%22<br />mysqldump%20-u%20%22+dbUser+%22%20-p%20%22+dbName+%22%20&gt;%20%22+backupBasePath+siteDirName+saveDate+%22.sql;%20%20##BackupDB%22;}if(shellText!==%22%22){if(window.clipboardData){window.clipboardData.setData('Text',shellText);}else{wnd=open('','Shell_Command','width=650,height=400,top=0,left=0,scrollbars,resizable');with(wnd.document){writeln('<pre>');writeln(shellText);writeln('</pre>');}wnd.document.close();}}/*if%20shellText!==%22%22*/})()

You’ll have to paste that in to your url bar as something about the syntax breaks the link in wordpress…
But you can grab the bookmarklet here: http://uoregon.edu/~vid/v_drupal_bookmarks.php. It’s the first one in the list.

To see it in action you’ll need to try it on a page with jQuery enabled. As an example, if I click it in my drupal updates report today which tells me that Views has a recommended update, I get this output:

##ssh myServer
cd /var/www/html/site_directory/sites/all/modules/
wget http://ftp.drupal.org/files/projects/views-6.x-2.8.tar.gz
gzip -dc views-6.x-2.8.tar.gz | tar -x
rm views-6.x-2.8.tar.gz
wait
ls -al
sudo tar -c --checkpoint /var/www/html/site_directory/ | bzip2 &gt; /home/yourName/drupal_backup/site_directory12-16-2009.tar.bz2;  ##Backupfiles
sudo mysqldump -u drupal6-db-user -p drupal6-db &gt; /home/yourName/drupal_backup/site_directory12-16-2009.sql;  ##BackupDB

I would also see several optional or additional updates but this bookmarklet only grabs the recommended ones. It’s great if you have 4-5 pending. Blam! they’re all done in one fell swoop.

Here’s the formatted source:

javascript:
(function(){
  var siteDirName='site_directory';
  var siteBasePath='/var/www/html/';
  var backupBasePath='/home/yourName/drupal_backup/';
  var dbUser='drupal6-db-user';
  var dbName='drupal6-db';
  var serverName='myServer';
  var date=new%20Date();
  var saveDate=date.getMonth()+1+'-'+date.getDate()+'-'+date.getFullYear();
  var connect=confirm('Would%20you%20like%20to%20include%20the%20connection%20information?');
  var shellLocation=prompt('What%20is%20the%20location%20of%20your%20install%20directory?',siteBasePath+siteDirName+'/sites/all/modules/');
  var shellText=%22%22;
  if(connect){
    shellText='##ssh%20'+serverName;
  }
  if(shellLocation!==null){
    shellText=shellText+'<br />cd%20'+shellLocation;
  }
  with($('table.version-recommended%20td%20li.update-download%20a').each(function(){q=this.href.toString().split('/').pop();if(q!==%22%22&amp;&amp;this.href!=%22%22){shellText=shellText+%22<br />wget%20%22+unescape(this.href);shellText=shellText+%22<br />gzip%20-dc%20%22+escape(q)+%22%20|%20tar%20-x%22;shellText=shellText+%22<br />rm%20%22+escape(q);}}));
  if(connect){
    shellText=shellText+%22<br />wait%22;
    shellText=shellText+%22<br />ls%20-al%22;
    shellText=shellText+%22<br />sudo%20tar%20-c%20--checkpoint%20%22+siteBasePath+siteDirName+%22/%20|%20bzip2%20&gt;%20%22+backupBasePath+siteDirName+saveDate+%22.tar.bz2;
    %20%20##Backupfiles%22;
    shellText=shellText+%22<br />mysqldump%20-u%20%22+dbUser+%22%20-p%20%22+dbName+%22%20&gt;%20%22+backupBasePath+siteDirName+saveDate+%22.sql;
    %20%20##BackupDB%22;
  }
  if(shellText!==%22%22){
    if(window.clipboardData){
      window.clipboardData.setData('Text',shellText);
    }
    else{
      wnd=open('','Shell_Command','width=650,height=400,top=0,left=0,scrollbars,resizable');
      with(wnd.document){
        writeln('<pre>');
        writeln(shellText);
        writeln('</pre>');
      }
      wnd.document.close();
    }
  }
  /*if%20shellText!==%22%22*/

}
)()

This one, I use on the drupal project pages to install a module right from the source.
install mods wget var

javascript:var siteDirName='site_directory';var siteBasePath='/var/www/html/';var backupBasePath='/home/yourName/drupal_backup/';var dbUser='drupal6-db-user';var dbName='drupal6-db';var serverName='myServer';var l='',q='',r='',date=new Date();var saveDate=(date.getMonth()+1)+'-'+date.getDate()+'-'+date.getFullYear();grab=window.getSelection?window.getSelection():document.getSelection?document.getSelection():document.selection.createRange().text;if(grab!=''){lnk=grab.getRangeAt(0).commonAncestorContainer.parentNode;switch(lnk.tagName.toLowerCase()){case('a'):l=lnk;break;case('td'):l=lnk.childNodes[0].childNodes[0].childNodes[0].href;break;}}if(l==''||!l){lnks=document.links;for(var i=0;i&lt;lnks.length;i++){if(r==&#039;&#039;||r===null){if(lnks[i].innerHTML.toLowerCase().search(&#039;download&#039;)!=-1){r=prompt(&#039;Is this the Download Link you want?&#039;,escape(lnks[i].href).split(&#039;/&#039;).pop()+&#039; (&#039;+unescape(lnks[i].href)+&#039;)&#039;);if(r!==null){l=unescape(lnks[i].href);}}}}}if(l!=&#039;&#039;){q=l.toString().split(&#039;/&#039;).pop();}else{q=prompt(&#039;No link was highlighted. What is the name of the file you would like to unzip/install? (fileName.tar.gz)&#039;,&#039;&#039;);}if(q==&#039;&#039;||q===null){alert(&#039;Nothing to processes. Quiting.&#039;);}else{connect=confirm(&#039;Would you like to include the connection information?&#039;);shellLocation=&#039;&#039;;shellLocation=prompt(&#039;What is the location of your install directory?&#039;,siteBasePath+siteDirName+&#039;/sites/all/modules/&#039;);shellText=&#039;&#039;;if(q!==&#039;&#039;){if(connect){shellText=&#039;##ssh &#039;+serverName;}if(shellLocation!==null){shellText=shellText+&#039;<br />cd '+shellLocation;}if(l!=''){shellText=shellText+'<br />wget '+unescape(l);}shellText=shellText+'<br />gzip -dc '+escape(q)+' | tar -x';shellText=shellText+'<br />rm '+escape(q);if(connect){shellText=shellText+'<br />ls -al';shellText=shellText+'<br />sudo tar -c --checkpoint '+siteBasePath+siteDirName+'/ | bzip2 &gt; '+backupBasePath+siteDirName+saveDate+'.tar.bz2; ##Backupfiles';shellText=shellText+'<br />sudo mysqldump -u '+dbUser+' -p '+dbName+' &gt; '+backupBasePath+siteDirName+saveDate+'.sql; ##BackupDB';}}(function(){if(q!==''){if(window.clipboardData){window.clipboardData.setData('Text',shellText);}else{wnd=open('','Shell_Command','width=650,height=200,top=0,left=0,scrollbars,resizable');with(wnd.document){writeln('<pre>');writeln(shellText);writeln('</pre>');}wnd.document.close();}}})()}

Again you’ll have to paste that in to your url bar as something about the syntax breaks the link in wordpress…
And again you can grab it here: http://uoregon.edu/~vid/v_drupal_bookmarks.php. It’s the 2nd one down.
This one you can try out here in your browser and just type in a random file name. *Note: you’ll probably have to enable pop ups…

Here’s the code

javascript:
var siteDirName='site_directory';
var siteBasePath='/var/www/html/';
var backupBasePath='/home/yourName/drupal_backup/';
var dbUser='drupal6-db-user';
var dbName='drupal6-db';
var serverName='myServer';
var l='',q='',r='',date=new Date();
var saveDate=(date.getMonth()+1)+'-'+date.getDate()+'-'+date.getFullYear();
grab=window.getSelection?window.getSelection():document.getSelection?document.getSelection():document.selection.createRange().text;
if(grab!=''){
  lnk=grab.getRangeAt(0).commonAncestorContainer.parentNode;
  switch(lnk.tagName.toLowerCase()){
    case('a'):l=lnk;
    break;
    case('td'):l=lnk.childNodes[0].childNodes[0].childNodes[0].href;
    break;
  }
}
if(l==''||!l){
  lnks=document.links;
  for(var i=0;i&lt;lnks.length;i++){
    if(r==&#039;&#039;||r===null){
      if(lnks[i].innerHTML.toLowerCase().search(&#039;download&#039;)!=-1){
        r=prompt(&#039;Is this the Download Link you want?&#039;,escape(lnks[i].href).split(&#039;/&#039;).pop()+&#039; (&#039;+unescape(lnks[i].href)+&#039;)&#039;);
        if(r!==null){
          l=unescape(lnks[i].href);
        }
      }
    }
  }
}
if(l!=&#039;&#039;){
  q=l.toString().split(&#039;/&#039;).pop();
}
else{
  q=prompt(&#039;No link was highlighted. What is the name of the file you would like to unzip/install? (fileName.tar.gz)&#039;,&#039;&#039;);
}
if(q==&#039;&#039;||q===null){
  alert(&#039;Nothing to processes. Quiting.&#039;);
}
else{
  connect=confirm(&#039;Would you like to include the connection information?&#039;);
  shellLocation=&#039;&#039;;
  shellLocation=prompt(&#039;What is the location of your install directory?&#039;,siteBasePath+siteDirName+&#039;/sites/all/modules/&#039;);
  shellText=&#039;&#039;;
  if(q!==&#039;&#039;){
    if(connect){
      shellText=&#039;##ssh &#039;+serverName;
    }
    if(shellLocation!==null){
      shellText=shellText+&#039;<br />cd '+shellLocation;
    }
    if(l!=''){
      shellText=shellText+'<br />wget '+unescape(l);
    }
    shellText=shellText+'<br />gzip -dc '+escape(q)+' | tar -x';
    shellText=shellText+'<br />rm '+escape(q);
    if(connect){
      shellText=shellText+'<br />ls -al';
      shellText=shellText+'<br />sudo tar -c --checkpoint '+siteBasePath+siteDirName+'/ | bzip2 &gt; '+backupBasePath+siteDirName+saveDate+'.tar.bz2; ##Backupfiles';
      shellText=shellText+'<br />sudo mysqldump -u '+dbUser+' -p '+dbName+' &gt; '+backupBasePath+siteDirName+saveDate+'.sql; ##BackupDB';
    }
  }
  (function(){
    if(q!==''){
      if(window.clipboardData){
        window.clipboardData.setData('Text',shellText);
      }
      else{
        wnd=open('','Shell_Command','width=650,height=200,top=0,left=0,scrollbars,resizable');
        with(wnd.document){
          writeln('<pre>');
          writeln(shellText);
          writeln('</pre>');
        }
        wnd.document.close();
      }
    }
  }
  )()
}
Leave a Comment