Drupal & shell bookmarklet for updating modules

*Note: A new post is available here: Drupal & shell bookmarklet for updating modules 5 (updated – mulitple dbs, backup only option)
There is a follow up to this post here: Drupal & shell bookmarklet for updating modules 2 ->just Recommended

Here are some bookmarks I’ve been working on to help make Drupal module updates easier.

These are currently just for my convenience. Which means I haven’t done any cross-browser testing. I only use them in Firefox on Mac at this point. Feel free to make use of the code and update it as you see fit. Personally I’ve created versions without all the pop up prompts for my primary sites.

The idea behind these is that when you are on your admin/reports/updates page you can choose a download and get the script you need to get the job done without having to type it from scratch each time. I’ve been using the ‘Install all mods wget’ one to download and install new modules from the Drupal site or Open Atrium as well. Infact anytime I see a tar.gz link that I want to unzip and install I click this one.

In each of these bookmarks: you can choose the download you want in one of four ways:

  1. Highlight the download link
  2. Double click just to the left of the download link (which highlights the link, but also includes the table cell, which I parse out to get the link)
  3. Choose from each of the download links on the page (you are prompted for each one found on the page)
  4. Manually type in/paste the file name to be processed (must be a tar.gz file)

In addition you can choose if you want the connection information included. This adds “ssh vpfa-prod” before and “ls -al” after.
Lastly you can add the path to your modules folder. I have mine hard coded into the bookmarklet.

This first one gives you the lines of shell script you need to unpack the module you’ve downloaded.

Install Mod update script

This one creates the script that you need to download the module directly from the shell saving you several steps if you’re used to using ftp to download and upload updates:
Install Mod wget

Next up is one that collects all the download links on the page and creates the script to fetch all of them and install them in turn.

Install all mods

Here again are the links but this time with the code:

install mod update script

This bookmarklet takes the name of the file you are going to download and creates the shell script that you would need to install it in your modules directory.
You still have to download it yourself. The file type needs to be tar.gz and should be located in the same directory that it will be unpacked in – over writting the existing module folder.

Install Mod update script

javascript:
q=%22%22;
grab=window.getSelection?window.getSelection():document.getSelection?document.getSelection():document.selection.createRange().text;
if(grab!=%22%22){
lnk=grab.getRangeAt(0).commonAncestorContainer.parentNode;
switch(lnk.tagName.toLowerCase()){
case(%22a%22):  q=lnk;
break;
case(%22td%22):q=lnk.childNodes[0].childNodes[0].childNodes[0].href;
break;
}
}
if(q==%22%22){
lnks=document.links;
for(var i=0;i
if(q==%22%22 || !q){
if(lnks[i].innerHTML.toLowerCase()==%22download%22){
q=prompt(%22Is this the Download Link you want?%22,escape(lnks[i].href).split(%27/%27).pop());
}
}
}
}
/*alert(q);*/
if(q!=%22%22){
/*alert(q);*/
q=q.toString().split(%27/%27).pop();
}
else{
q=prompt(%27No%20link%20was%20highlighted.%20What%20is%20the%20name%20of%20the%20file%20you%20would%20like%20to%20unzip/install?%27,%27%27);
}
if(q!=%22%22){
connect=confirm(%27Would%20you%20like%20to%20include%20the%20connection%20information?%27);
if(connect){
shellLocation=prompt(%27What%20is%20the%20location%20of%20your%20install%20directory?%27,%27/var/www/html/YOUR_SITE_HERE/sites/all/modules/%27);
}
else{
shellLocation=%27%27;
}
shellText=%22%22;
if(q!==%22%22){
if(connect){
shellText=%22ssh%20vpfa-prod
cd%20%22+shellLocation+%22
%22;
}
shellText=shellText+%22gzip%20-dc%20%22+escape(q)+%22%20|%20tar%20-x%22;
if(connect){
shellText=shellText+%22
ls%20-al%22;
}
}
(function(){
if(q!==%22%22){
if(window.clipboardData){
window.clipboardData.setData(%27Text%27,shellText);
}
else{
wnd=open(%27%27,%27Shell_Command%27,%27width=500,height=100,top=0,left=0,scrollbars,resizable%27);
with(wnd.document){
writeln(%27
<pre>%27);
          writeln(shellText);
          writeln(%27</pre>
%27);
}
wnd.document.close();
}
}
}
)()
}

Here are some of the notes I made on the way there:

On the title of the module link:
javascript:alert(window.getSelection().getRangeAt(0).commonAncestorContainer.tagName)
Div

javascript:alert(window.getSelection().getRangeAt(0).commonAncestorContainer.childNodes[0].tagName)
a

javascript:alert(window.getSelection().getRangeAt(0).commonAncestorContainer.childNodes[0].href)
http://drupal.org/project/cck

javascript:alert((window.getSelection()).getRangeAt(0))
Download

javascript:alert(window.getSelection().getRangeAt(0).commonAncestorContainer)
[object text]

javascript:alert(window.getSelection().getRangeAt(0).commonAncestorContainer.parentNode)
=
http://ftp.drupal.org/files/projects/cck-6.x-3.x-dev.tar.gz
Horay!!!!

Double clicking next to the download link to highlight it:
javascript:alert(window.getSelection().getRangeAt(0).commonAncestorContainer.parentNode.tagName)
=
td
Child node
javascript:alert(window.getSelection().getRangeAt(0).commonAncestorContainer.parentNode.childNodes[0].tagName)
ul

Children:
javascript:alert(window.getSelection().getRangeAt(0).commonAncestorContainer.parentNode.childNodes[0].childNodes.length)
4

javascript:alert(window.getSelection().getRangeAt(0).commonAncestorContainer.parentNode.childNodes[0].childNodes[0].childNodes[0].tagName)
a
javascript:alert(window.getSelection().getRangeAt(0).commonAncestorContainer.parentNode.childNodes[0].childNodes[0].childNodes[0].href)
http://ftp.drupal.org/files/projects/cck-6.x-3.x-dev.tar.gz
Bingo!!!!


Install Mod wget

This one creates the script that you need to download the module directy from the shell saving you several steps if you%27re used to using ftp to download and upload updates:
Install Mod wget

javascript:
l=%22%22;
q=%22%22;
grab=window.getSelection?window.getSelection():document.getSelection?document.getSelection():document.selection.createRange().text;
if(grab!=%22%22){
lnk=grab.getRangeAt(0).commonAncestorContainer.parentNode;
switch(lnk.tagName.toLowerCase()){
case(%22a%22):l=lnk;
break;
case(%22td%22):l=lnk.childNodes[0].childNodes[0].childNodes[0].href;
break;
}
}
if(l==%22%22){
lnks=document.links;
for(var%20i=0;i
if(q==%22%22||!q){
if(lnks[i].innerHTML.toLowerCase()==%22download%22){
q=prompt(%22Is%20this%20the%20Download%20Link%20you%20want?%22,escape(lnks[i].href).split(%27/%27).pop());
if(q!=%22%22||q){
l=escape(lnks[i].href);
}
}
}
}
}
/*alert(q);*/
if(l!=%22%22){
/*alert(q);*/
q=l.toString().split(%27/%27).pop();
}
else{
q=prompt(%27No%20link%20was%20highlighted.%20What%20is%20the%20name%20of%20the%20file%20you%20would%20like%20to%20unzip/install?%27,%27%27);
}
if(q!=%22%22){
connect=confirm(%27Would%20you%20like%20to%20include%20the%20connection%20information?%27);
shellLocation=%27%27;
shellLocation=prompt(%27What%20is%20the%20location%20of%20your%20install%20directory?%27,%27/var/www/html/YOUR_SITE_HERE/sites/all/modules/%27);
shellText=%22%22;
if(q!==%22%22){
if(connect){
shellText=%22ssh%20vpfa-prod;%22;
}
if(shellLocation!=null){
shellText=shellText+%22
cd%20%22+shellLocation+%22;%22;
}
shellText=shellText+%22
wget %22+unescape(l)+%22;%22;
shellText=shellText+%22
gzip%20-dc%20%22+escape(q)+%22%20|%20tar%20-x;%22;
shellText=shellText+%22
rm %22+escape(q)+%22;%22;
if(connect){
shellText=shellText+%22
ls%20-al;%22;
}
}
(function(){
if(q!==%22%22){
if(window.clipboardData){
window.clipboardData.setData(%27Text%27,shellText);
}
else{
wnd=open(%27%27,%27Shell_Command%27,%27width=500,height=100,top=0,left=0,scrollbars,resizable%27);
with(wnd.document){
writeln(%27
<pre>%27);
          writeln(shellText);
          writeln(%27</pre>
%27);
}
wnd.document.close();
}
}
}
)()
}

install all mods

Install all mods


javascript:
(function(){
var n_to_open,dl,dll,i;
var l=new Array();
var connect=confirm('Would%20you%20like%20to%20include%20the%20connection%20information?');
var shellLocation=prompt('What%20is%20the%20location%20of%20your%20install%20directory?','/var/www/html/YOUR_SITE_HERE/sites/all/modules/');
var shellText=%22%22;
function linkIsSafe(u){
if(u.substr(0,7)=='mailto:')
return false;
if(u.substr(0,11)=='javascript:')
return false;
return true;
}
n_to_open=0;
dl=document.links;
dll=dl.length;
if(window.getSelection&amp;&amp;window.getSelection().containsNode){
/*%20mozilla%20*/
for(i=0;i

if(window.getSelection().containsNode(dl[i],true)&amp;&amp;linkIsSafe(dl[i].href))
++n_to_open;
}
if(n_to_open&amp;&amp;confirm('Open%20all%20Download%20links%20with%20in%20the%20selection?')){
for(i=0;i
if(window.getSelection().containsNode(dl[i],true)&amp;&amp;linkIsSafe(dl[i].href)){
/*window.open(dl[i].href);*/
if(dl[i].innerHTML.toLowerCase()==%22download%22){
l.push(escape(dl[i].href));
}
}
}
}
/*%20/mozilla%20*/
if(!n_to_open){
/*ie,%20or%20mozilla%20with%20no%20links%20selected:%20this%20section%20matches%20open_all_links,%20except%20for%20the%20alert%20text%20*/
for(i=0;i
if(linkIsSafe(dl[i].href))
++n_to_open;
}
if(!n_to_open)
alert('no%20links');
else{
if(confirm('No%20links%20selected.%20%20Add all Download links%20to%20the%20script?'))
for(i=0;i0){
q=%22%22;
if(connect){
shellText=%22ssh%20vpfa-prod;
%22;
}
if(shellLocation!=null){
shellText=shellText+%22
cd%20%22+shellLocation+%22;
%22;
}
for(j=0;j
q=l[j].toString().split('/').pop();
if(q!=%22%22){
if(q!==%22%22&amp;&amp;l[j]!=""){
shellText=shellText+%22
wget%20%22+unescape(l[j])+%22;
%22;
shellText=shellText+%22
gzip%20-dc%20%22+escape(q)+%22%20|%20tar%20-x;
%22;
shellText=shellText+%22
rm%20%22+escape(q)+%22;
%22;
}
}
}
shellText=shellText+%22
wait;
%20##finish%20processing%20before%20listing%22;
if(connect){
shellText=shellText+%22
ls%20-al;
%22;
}
/*end for j*/
if(q!==%22%22){
if(window.clipboardData){
window.clipboardData.setData('Text',shellText);
}
else{
wnd=open('','Shell_Command','width=500,height=100,top=0,left=0,scrollbars,resizable');
with(wnd.document){
writeln('
<pre>');
          writeln(shellText);
          writeln('</pre>
');
}
wnd.document.close();
}
}
/*if q!==%22%22*/

}
/*end if l.length*/

}
)();

Comments
Leave a Comment