gpocentek..blog

octobre 10, 2009

Utiliser une config apt autre que celle du système

Filed under: FOSS — Mots-clefs :, — gpocentek @ 15:29

En guise de reminder personnel et pour faire croire que ce blog est vivant, je vous propose un petit script qui crée une arborescence apt temporaire et qui l’utilise pour récupérer des données. Le but premier du script est d’extraire les traductions firefox et xulrunner des paquets de langue Ubuntu. Tout ça sous GPL 2 (il faut au moins ça pour un tel script !).

#!/bin/sh
 
HERE=$(pwd)
 
# Drop the old data
rm -rf $HERE/usr
 
# Set the apt config
# First create the needed directories and files
mkdir -p apt/archives/partial
mkdir -p apt/lists/partial
mkdir -p apt/preferences.d
mkdir -p apt/tmp
touch apt/status
# Set the sources.list
cat > apt/sources.list << EOF
deb http://archive.ubuntu.com/ubuntu karmic main
deb http://archive.ubuntu.com/ubuntu karmic-updates main
deb http://archive.ubuntu.com/ubuntu karmic-security main
EOF
# And the config file
cat > apt.conf << EOF
APT
{
  // We don't want to install the package, just download the binaries
  Get::Download-Only "true";
  // We don't want interaction
  Get::Assume-Yes "true";
  Get::force-yes "true";
};
 
Dir
{
  State "$HERE/apt/";
  State::status "status";
 
  Cache "$HERE/apt/tmp/";
  Cache::archives "$HERE/apt/archives/";
 
  Etc "$HERE/apt/";
};
EOF
 
APT_GET="apt-get -c $HERE/apt.conf"
APT_CACHE="apt-cache -c $HERE/apt.conf"
 
$APT_GET update
 
# Get the list of known langs
LANGS=$($APT_CACHE search --names-only language-pack | egrep -v "(gnome|base|kde)"  | cut -d ' ' -f 1 | cut -d '-' -f3-)
 
# Install the package (download only)
for lang in $LANGS; do
    $APT_GET install language-pack-$lang
    dpkg -x apt/archives/language-pack-"$lang"_* $HERE
done
 
# Cleanup, we only want FF 3.5 and Xul 1.9.1 translations
rm -rf apt.conf lock apt/
rm -rf usr/share
rm -rf $(find usr -name "*firefox-3.0*")
rm -rf $(find usr -name "*xulrunner-1.9.ubuntu*")
 
exit 0

Powered by WordPress