[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

cross-get script



One thing that has been missing from debian for easy cross-building is
a simple way to download non-native packages in order to feed them to
dpkg-cross. I got very bored of having to run up a browser and look at
packages.debian.org for the right suite and arch to find the actual
deb name and package version and then use wget to get that.

It irritated me one final time tonight so I wrote a script cross-get
which lets you do 
cross-get <package> [arch] [suite] [mirror]

and it will download the relevant deb.

It maitains a set of apt and dpkg cross-status info in
/var/lib/apt-cross and /var/lib/dpkg-cross, so that your notive
databases are not messed-up.

There is plenty of room for improvement (it should take defaults from
/etc/dpkg-cross/ config), it could have much smarter command-line
processing etc. Perhaps it should be written in perl and be combined
into dpkg-cross.

If it got a bit smarter and could check and optionally get
dependencies too then it could become apt-cross - that is a miuch
bigger job, I think.

So I hereby preseent v0.1 which solves my basic problem, and
thus should be useful to others for that reason. 

I'll check it into debian-embedded svn tomorrow.

Wookey
-- 
Aleph One Ltd, Bottisham, CAMBRIDGE, CB5 9BA, UK  Tel +44 (0) 1223 811679
work: http://www.aleph1.co.uk/                 play: http://wookware.org/
#!/bin/sh -e

#maybe this would be better as a perl script?

if [ "" = "$1" ]; then
  echo -e "you must suply a package name\napt-cross package [arch] [suite] [mirror]"
  exit 1
else
  package=$1
fi


#defaults should be derived from dpkg-cross config
#mirror=http://us.arm.mirror.debian.net/debian/   
mirror=http://ftp.uk.debian.org/debian/   
arch=arm
suite=unstable

dpkg_dir=/var/lib/dpkg-cross
apt_dir=/var/lib/apt-cross

if [ "" != "$2" ]; then
  arch=$2
fi

if [ "" != "$3" ]; then
  suite=$2
fi

if [ "" != "$4" ]; then
  mirror=$2
fi

function do_once_a_day
{
  # $1 is touchfile $2 is command
  # find finds touchfile if created in this 24hrs.
  if [ ! -n "find . -name $1 -daystart -mtime 0" ] ; then
    if $2; then touch $1; fi
  fi
}
  

function download_arch_packages()                          
{ 
  archivename=`cat $apt_dir/sources.$suite | grep "deb " | cut -d " " -f 2`        
#  for package in $packagelist
#  do    
    filename=`fakeroot apt-cache -o Apt::Architecture=$arch -c \
	$apt_dir/apt.conf-$suite show  $package | \
	grep ^Filename: | sed -e "s/Filename: //"`        
	wget -nd -N -nv ${archivename}${filename}         
#  done    

}

function update_sources()             
{ 
  #start by downloading sources, but only if not already done this 24hrs
  do_once_a_day "$apt_dir/.aptupdate-touchfile" "fakeroot apt-get -o Apt::Architecture=$arch -c $apt_dir/apt.conf-$suite update"

  #this doesn't work - but should - needs bug filing
  #               (cd $native_dir && sudo aptitude -o   Apt::Architecture=$arch  \
  #                  -o Apt::Dir="/var/emdebian/tools/apt/" \
  #                  -o Apt::Dir::Etc="/var/emdebian/tools/apt/" \
  #                  -o Apt::Dir::Etc::SourceList="sources.$suite" \
  #                  -o Apt::Dir::State=$suite/ \
  #                  -o Apt::Dir::Cache=$suite/ \
  #                  download $packages
}


function setup_config()
{
  #set up necessary dirs for cross-dpkg database
  for dir in $suite/lists/partial $suite/archives/partial; do
    mkdir -p $apt_dir/$dir
  done

  for file in alternatives info parts updates; do
    mkdir -p $dpkg_dir/$file
  done

  for file in diversion statoverride status lock; do
    if [ ! -e $dpkg_dir/$file ] ; then touch $dpkg_dir/$file; fi                         
  done

  #make apt-conf file and sources files
  if [ ! -e $apt_dir/apt.conf-$suite ]; then
    cat > $apt_dir/apt.conf-$suite << **END**
Dir "$apt_dir/"
{
  Etc "$apt_dir/"
  {
    SourceList "sources.$suite";
  };
  State "$suite/";
  Cache "$suite/";
};
**END**
  fi

#should check if $mirror is diff to what's in this file and if so re-write.
  if [ ! -e $apt_dir/sources.$suite ]; then
    cat > $apt_dir/sources.$suite << **END**
deb $mirror $suite main
deb-src $mirror $suite main
**END**
  fi
}

#-----------------
#here is the program proper
setup_config
update_sources
download_arch_packages








































Reply to: