4

I'm trying to pull up the latest Drupal release, and download it via a bash script.

I don't have any idea on how I can do that, except that I found out I can list the files on the FTP server, and get all the filenames containing Drupal, like so:

lynx --dump http://ftp.drupal.org/files/projects/ | awk '/http/{print $2}' | grep drupal-7 > latest.txt

How I can pull the latest version from that list, and download it?

2
  • Some HTTP and FTP clients can download the newest file matching a wildcard if you point them to a directory. IIRC Curl has this functionality.
    – tripleee
    Commented Feb 26, 2012 at 17:19
  • You could use sort with version sort option i.e. sort -V. Assuming you don't want dev, alpha or beta (untested): lynx --dump http://ftp.drupal.org/files/projects/ | awk '/http/{print $2}' | grep drupal-7 |sort -V |grep -v dev|grep -v alpha|grep -v beta|tail -n 1
    – another.anon.coward
    Commented Feb 26, 2012 at 17:20

6 Answers 6

3

This command will do it.

wget  http://ftp.drupal.org/files/projects/$(wget -O- http://drupal.org/project/drupal | egrep -o 'drupal-[0-9\.]+.tar.gz' | sort -V  | tail -1)

Here goes the explanation.

wget -O- http://drupal.org/project/drupal |  # <- Download drupal main download site
    egrep -o 'drupal-[0-9\.]+.tar.gz' | # <- searching drupal-[0-9\.]+.tar.gz pattern
                                        # Also only showing the matched pattern
    sort -V  |  # <- sort it by version number (default sort order is ascending) 
    tail -1  | grab the last name which would be highest version

After this we get something like drupal-7.12.tar.gz or drupal-7.12.zip. Then it gets replaced in the final wget invocation.

wget  http://ftp.drupal.org/files/projects/drupal-7.12.tar.gz
5
  • That will fail in many cases unless you are using a version of sort that supports --version-sort (and use that option).
    – jordanm
    Commented Feb 26, 2012 at 17:26
  • Yeah. I was experimenting on console. Updated already.
    – Shiplu
    Commented Feb 26, 2012 at 17:28
  • Actually this one worked, but unfortunately I cant seem to understand the sorting thing with egrep, seems a bit tricky for me. Thanks indeed.
    – Altin Ukshini
    Commented Feb 26, 2012 at 17:33
  • @AltinUkshini answer is updated with explanation. Check again.
    – Shiplu
    Commented Feb 26, 2012 at 17:44
  • Aha now I get it. I was confused at 0-9\. now I see that it means from 0 to 9 :) . Thank ou so much again :D
    – Altin Ukshini
    Commented Feb 26, 2012 at 17:59
8

For all your command line and script needs there is Drush. To download the latest Drupal 7 with it, you simply do

drush pm-download drupal
1

If GNU grep is available and GET from perl's libwww, you can use the following, but it will fail if the format of their project page ever changes:

wget $(GET http://drupal.org/project/drupal | grep -Po '(?<=<a href=")http://ftp.drupal.org/files/projects/drupal-7[.]\d{1,2}[.]tar[.]gz(?=">tar.gz)')
3
  • Im getting an error at this one:
    – Altin Ukshini
    Commented Feb 26, 2012 at 17:31
  • grep: Support for the -P option is not compiled into this --disable-perl-regexp binary wget: missing URL Usage: wget [OPTION]... [URL]...
    – Altin Ukshini
    Commented Feb 26, 2012 at 17:31
  • @AltinUkshini What version of Linux are you using that doesn't have -P support for grep?
    – jordanm
    Commented Feb 26, 2012 at 17:36
1

The currently accepted answer no longer works after the update to the Drupal website.

This method utilizes the update XML and should hopefully be more reliable.

As stated in other answers, the best option is to use drush, but if that is not an option then this should do:

wget $(wget -O- -q https://updates.drupal.org/release-history/drupal/7.x | grep -oPm1 "(?<=<download_link>)[^<]+" | head -1)

Credit to this stackoverflow answer for the XML extraction: https://stackoverflow.com/a/17333829/2383249

2
  • It downloads all the version. I only want the latest one, how do I do that. Commented Mar 6, 2017 at 10:57
  • I just updated the code so that there is a | head -1 after the grep statement so it only retrieves the latest one. Commented Apr 25, 2017 at 13:24
0

I know @Shiplu's answer works best for OP, but just to add a comment; sometimes you may find it convenient to ask Apache which is the newest file:

$ wget 'http://ftp.drupal.org/files/projects/?C=M;O=A' -O- | egrep -o 'drupal-[0-9\.]+\.zip' | tail -1
(snip)
drupal-7.12.zip

The above URL was copied from the link labelled as "Last Modified". See also

1
  • Last modified could be a 6.0 or dev version.
    – jordanm
    Commented Feb 26, 2012 at 22:23
0

If you can install (and don't mind installing) the nokogiri cli (e.g. sudo apt-get install ruby-nokogiri on ubuntu), you could do the following

nokogiri https://updates.drupal.org/release-history/drupal/7.x -e 'print @doc.at_xpath("//download_link/text()")'

which outputs

https://www.drupal.org/project/drupal/releases/7.50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.