You are not logged in.

#1 2008-07-23 13:31:07

carlocci
Member
From: Padova - Italy
Registered: 2008-02-12
Posts: 368

fakeinstall - grab packets info from everywhere but the actual package

At the moment I'm working on a (not so) smart version of pacfix which recognizes installation sessions in pacman.log and based on those tries to understand which packages were explicitly installed.
The script works at the moment, but it needs some group install detection support as well as some polishing (I can guarantee I will never write anything in bash anymore, and neither should you!).

While testing the script, a problem arose: how do I restore the packet database without having to redownload every packet?
The answer is this script: this script grabs desc and depends from the database, files* from the mirror, install from abs and put the content in ./local/$pkg_name-$pkg_ver
You should pacman -Sy && abs before using this script.

Limits:
_I don't know how to make the parsing of /etc/pacman.conf for the mirrors, so you should edit the script by yourself (the wget line)

_*files: unfortunately the files provided in every repository are stripped of the %BACKUP% section (don't know why), so I just invented an md5sum for the files to backup. This means that on the subsequent upgrade there could be a bunch of unnecessary pacsave/pacnew files (if I understood how %BACKUP% works right)

#!/bin/bash
# What you wanna fake today?

#
# Env checks
#

if [ ! "$1" = "--yes" ];then
    echo "WARNING: you should update your pacman database and abs repository"
    echo "WARNING: the entries will be saved in $PWD/local"
    echo "Run as $0 --yes <repo1/pkg1> <repo2/pkg2> ..."
    echo ""
    echo "EXAMPLE: $0 --yes core/patch core/sudo extra/gimp"
    exit 0
else
    shift
fi

# pacman.conf parsing
if [ ! -r /etc/pacman.conf ]; then
    echo "ERROR: unable to read /etc/pacman.conf"
    exit 1
else
    eval $(awk '/DBPath/ {print $1$2$3}' /etc/pacman.conf)
fi

pac_db="${DBPath:-/var/lib/pacman}/sync"

if [ ! -d "$pac_db" ] ; then
    echo "ERROR: pacman database directory ${pac_db} not found"
    exit 1
fi


# abs.conf parsing
if [ ! -r /etc/abs.conf ]; then
    echo "ERROR: unable to read /etc/abs.conf"
    exit 1
else
    source /etc/abs.conf
fi
abs_dir="${ABSROOT:-/var/abs/}"

if [ ! -d "$abs_dir" ]; then
    echo "ERROR: abs directory $abs_dir not found"
fi

# working directory related stuff
work_dir="$PWD/local"
if [ ! -d "$work_dir" ]; then
    mkdir "local"
fi


#
# Main loop
#

cd "$work_dir"
for argument in $@ ; do
    echo "Processing $argument"
    pkg_name="${argument#*/}"
    repository="${argument%/*}"
    pkg_dbdir=$(echo "$pac_db"/$repository/$pkg_name-[0-9]*)
    pkg_namever="${pkg_dbdir##*/}"

    if [ -d "$work_dir/$pkg_namever" ];then
        echo "The entry $pkg_namever already exists in $work_dir, skipping" >&2
        continue
    fi

    wget -q -nc ftp://mi.mirror.garr.it/mirrors/archlinux/$repository/os/i686/$repository.files.tar.gz


    # DESC, DEPENDS AND FILES
    bsdtar -xf $work_dir/$repository.files.tar.gz $pkg_namever/files
    echo -ne "\n" >> $pkg_namever/files
    cp "$pkg_dbdir"/{depends,desc} $pkg_namever/


    # INSTALL AND BACKUP
    eval $(source "$abs_dir/$repository/$pkg_name/PKGBUILD" && echo "install=$install backup=$backup")

    if [ -n "$install" ]; then
        cp "$abs_dir/$repository/$pkg_name/$install" "$pkg_namever/install"
        unset install
    fi

    if [ -n "$backup" ]; then
        echo -ne "%BACKUP%\n" >> "$pkg_namever/files"
        for element in ${backup[@]} ;do
            echo -e "$element\tGENERATEDWITHFAKEDB1234567890123" >> "$pkg_namever/files"
        done
        echo -ne "\n" >> "$pkg_namever/files"
        unset backup
    fi

done

echo done!

# vim: set ts=2 sw=2 noet:

Offline

#2 2008-07-23 14:18:20

shining
Pacman Developer
Registered: 2006-05-10
Posts: 2,043

Re: fakeinstall - grab packets info from everywhere but the actual package

carlocci wrote:

While testing the script, a problem arose: how do I restore the packet database without having to redownload every packet?
The answer is this script: this script grabs desc and depends from the database, files* from the mirror, install from abs and put the content in ./local/$pkg_name-$pkg_ver

I don't think you should do that, there are many differences between sync and local db : changelog, install scriptlet, install time, maybe extracted package size too?, etc...
Besides, you should always keep at least your currently installed packages. If you really need to delete the older ones, that is what pacman -Sc is for. Then if some needs to be redownloaded, no big deal. But you don't really have an option anyway.


pacman roulette : pacman -S $(pacman -Slq | LANG=C sort -R | head -n $((RANDOM % 10)))

Offline

#3 2008-07-23 16:15:05

carlocci
Member
From: Padova - Italy
Registered: 2008-02-12
Posts: 368

Re: fakeinstall - grab packets info from everywhere but the actual package

shining wrote:
carlocci wrote:

While testing the script, a problem arose: how do I restore the packet database without having to redownload every packet?
The answer is this script: this script grabs desc and depends from the database, files* from the mirror, install from abs and put the content in ./local/$pkg_name-$pkg_ver

I don't think you should do that, there are many differences between sync and local db : changelog, install scriptlet, install time, maybe extracted package size too?, etc...

Well, changelog isn't used for install/remove/upgrade functions, as well as install time; the install scriplet is taken from abs, the extracted package size is already in the desc.
The goal is to regenerate a db well enough to perform the next update.

Besides, you should always keep at least your currently installed packages.

I couldn't agree more, but people aren't supposed to wipe their databases (damn you, pacman-cage!) either.
I read about a guy complaining he would have to redownload every packet he had installed on the forums once, and I've been thinking whether he could have avoided the huge download ever since.

If you really need to delete the older ones, that is what pacman -Sc is for.

Unfortunately, my hand slips most of the times and I end up pacman -Scc smile
The whole point of bacman was that I don't keep my package cache.

Offline

Board footer

Powered by FluxBB