WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: Automatic Vim Downloading Script  (Read 2935 times)

Offline Iguleder

  • WikiUser
  • *
  • Posts: 12
Automatic Vim Downloading Script
« on: December 12, 2009, 07:59:49 AM »
Here's a simple script I wrote for detecting and downloading the latest Vim and patching it with all bug-fix patches. Currently, it has 315 patches ... too much to download and apply manually. It also comes with an "update" script, which simple checks what Vim version is installed, compares it with the latest available and asks the user whether to run the compilation script or not.

To save space, it downloads a patch, applies it and erases it immediately. After patching, it configures with my preferred flags, so change them as you wish. After configuring, it compiles it and installs to ~/vim-version-arch (should be "vim-7.2.315-i486" at the time of writing). Then, it creates a TCZ from that directory.

I haven't tested it with Tiny Core's BusyBox, but I tested the downloading and patching part with my distro (which uses a newer BusyBox and has no GCC) - it worked. It might be useful, as someone might be interested in turning this script into an automatic downloading, patching, compiling and packing script. The whole thing is experimental, don't blame me if something gets messed up, although I don't think something will.

Pay attention to the "force a specific version" part: uncomment it, put the right numbers and delete the version detection part to use it.

Code: [Select]
#!/bin/bash

# detect the latest Vim version
echo "Detecting the latest version ... "
wget -q http://www.vim.org/download.php
vimVersion="`cat download.php | grep "is the latest stable version"`"
vimVersion=${vimVersion:4:3}
rm -rf download.php

# detect latest patch number
wget -q ftp://ftp.vim.org/pub/vim/patches/$vimVersion/README
lastPatch=`tail -1 README`
lastPatch=${lastPatch:12:3}
rm -rf README

echo "
The latest version is $vimVersion.$lastPatch."

# force a specific version
#lastPatch="267"
#vimVersion="7.2"

# download the sources
echo "
Downloading Vim ... "
wget -q http://ftp.vim.org/pub/vim/unix/vim-$vimVersion.tar.bz2
echo "Downloading Vim extras ... "
wget -q http://ftp.vim.org/pub/vim/extra/vim-$vimVersion-extra.tar.gz
echo "Downloading Vim languages ... "
wget -q http://ftp.vim.org/pub/vim/extra/vim-$vimVersion-lang.tar.gz

# extract the sources
echo "
Extracting Vim ... "
tar xjf vim-*.tar.bz2
echo "Extracting Vim extras ... "
tar xzf vim-*-extra.tar.gz
echo "Extracting Vim languages ...
"
tar xzf vim-*-lang.tar.gz

# switch to the sources directory
cd vim${vimVersion:0:1}${vimVersion:2:1}

# patch the sources
for ((i=1;i<=$lastPatch;i+=1)); do

  # patches 1 to 10
  if [ $i -lt 10 ]; then
    patchFile="http://ftp.vim.org/pub/vim/patches/$vimVersion/$vimVersion.00$i"
  else
    # patches 10 to 99
    if [ $i -lt 100 ]; then
      patchFile="http://ftp.vim.org/pub/vim/patches/$vimVersion/$vimVersion.0$i"
    else
      # patches 100+
      patchFile="http://ftp.vim.org/pub/vim/patches/$vimVersion/$vimVersion.$i"
    fi
  fi
  
  # the patch filename
  localFile=${patchFile:39:${#patchFile}-39}
  
  # download the patch
  echo "Downloading patch $localFile ... "
  wget -q $patchFile
  
  # apply the patch
  echo "Applying patch $localFile ... "
  patch -N -s -p0 < $localFile

  echo "Deleting patch $localFile ...
  "
  rm $localFile
  
done
# end of patching

# configure
echo "Configuring ... "

# let it do whatever it does
#./configure > temp

# Iguleder-style
./configure CFLAGS="-march=i486 -mtune=i686 -Os -ffunction-sections -fdata-sections" LDFLAGS=-Wl,--gc-sections --prefix=/usr --bindir=/bin --sysconfdir=/etc --localstatedir=/var --disable-selinux --disable-xsmp --disable-xsmp-interact --disable-netbeans --enable-gui=no --disable-acl --disable-gpm --disable-sysmouse --disable-nls --without-x --without-gnome > temp

# compile
echo "
Compiling ... "
make -s > temp

# install
echo "
Installing to ~/vim-$vimVersion.$lastPatch-$(uname -m) ... "
make -s DESTDIR=~/vim-$vimVersion.$lastPatch-$(uname -m) install > temp

echo "
Creating ~/vim-$vimVersion.$lastPatch-$(uname -m).tcz ... "
mksquashfs ~/vim-$vimVersion.$lastPatch-$(uname -m) ~/vim-$vimVersion.$lastPatch-$(uname -m).tcz

# clean up
rm -rf temp

echo "
Done."
« Last Edit: December 13, 2009, 12:04:29 AM by Iguleder »

Offline jpeters

  • Restricted
  • Hero Member
  • *****
  • Posts: 1017
Re: Automatic Vim Downloading Script
« Reply #1 on: December 12, 2009, 10:40:16 AM »
I require bash for the for loop.  I don't know if people need lang and extras.  I might submit gvim, though.
Thanks.  

edit: submitted with extra patches; included gvim w/ menu/icon.; included extras/removed lang files (could be put in separate extension).  

edit: lang files submitted in separate extension

FYI: There are a number of ways of getting vim patches. In the previous version I used AAP.  This works nicely, though. 
« Last Edit: December 12, 2009, 02:04:10 PM by jpeters »

Offline Iguleder

  • WikiUser
  • *
  • Posts: 12
Re: Automatic Vim Downloading Script
« Reply #2 on: December 12, 2009, 11:20:14 PM »
Quote
... The Vim sources: I recommend to download the full set of sources, even sources never needed on Unix. This way you will later be able to apply all patches without problems ...

The full sources are needed to make the whole process silent.
Read here -> http://users.skynet.be/antoine.mechelynck/vim/compunix.htm