#!/bin/sh # # Unpack our source archive from where it was downloaded to a new # location. To cope with files which contain compressed upstream # source tarballs we'll recursively uncompress any archive we find # and recognise. # # Steve # -- # # # Setup PATH so that `dls` may be found. # PATH=/home/skx/bin:$PATH # # Destination directory beneath which to place all our unpacked files. # DST=/mnt/mirror/unpacked # # Make sure the destination directory exists. # if [ ! -d "${DST}" ]; then echo "Destination directory not found: ${DST}" exit fi # # Accept a single .dsc file upon the command line. # dsc=$1 if [ ! -e "${dsc}" ]; then print "File not found: ${dsc}" exit fi # # Recursively # function unarchive() { prefix=$1 if [ ! -d "${prefix}" ]; then echo "Not found: ${prefix}" exit fi # for each file over 500K. for i in `find $prefix -type f -size +500k -print` ; do # if we recognise it unpack it. case "$i" in *.tar.gz) tar -zxf $i rm -f $i ;; *.tar.bz2) tar -jxf $i rm -f $i ;; *.gz) gunzip $i rm -f $i ;; *.tar) tar -xf $i rm -f $i ;; *) # NOP ;; esac done } # # Copy the .dsc file to our temporary file # cp "${dsc}" "${DST}" # # copy the referenced files too. # cp `dls $dsc` "${DST}/" # # Unpack that source in that directory. # cd $DST dpkg-source -x `basename ${dsc}` # # Now remove the source files # for i in `dls ${dsc}`; do rm ${DST}/`basename $i` done rm ${DST}/`basename $dsc` # # Now we'll recursively unarchive from the new file which will be: # # /path/to/unpacked/$NAME-$VER # # We can get the NAME from the .dsc file, along with the version. # # NOTE: We will get a version like 1.2.3-N, we don't care about the -N which # will be the Debian package revision number. # # name. src=$(grep Source: ${dsc} | awk '{print $2}') # ver. ver=$(grep ^Version: ${dsc} | awk '{print $2}') # strip debian revision. ver=$(echo $ver | awk -F- '{print $1}') # any spaces afterwards with names? Ignore them. ver=$(echo $ver | awk '{print $1}') # recursively unarchive from the unpacked location. unarchive "${DST}/${src}-${ver}"