You are not logged in.

#1 2009-06-01 21:10:07

deltaecho
Member
From: Georgia (USA)
Registered: 2008-08-06
Posts: 193

makepkg: Record PKGBUILD sources in .PKGINFO files for maintenance

To me, it seems like a good idea to record all the source files listed in PKGBUILD's to their accompanying .PKGINFO files; then, should the user have configured the $SRCDEST variable in his /etc/makepkg.conf, this would allow old source files to be (optionally) automatically removed when `pacman -Sc' is run, the package is upgraded, or uninstalled.  Such a feature would save (me) a lot of time and effort manually sorting through and cleaning them.

Do you "concur"? ( big_smile )

Of course, for this feature to be really useful, you would have to compile from source often.


Dylon

Offline

#2 2009-06-01 22:09:00

Daenyth
Forum Fellow
From: Boston, MA
Registered: 2008-02-24
Posts: 1,244

Re: makepkg: Record PKGBUILD sources in .PKGINFO files for maintenance

I don't really think this is too useful... makepkg is a tool to create a package, not a system maintenance utility.

Offline

#3 2009-06-01 22:55:16

fukawi2
Ex-Administratorino
From: .vic.au
Registered: 2007-09-28
Posts: 6,237
Website

Re: makepkg: Record PKGBUILD sources in .PKGINFO files for maintenance

EDIT: Yes, I didn't quite understand the OP.

Last edited by fukawi2 (2009-06-02 01:51:40)

Offline

#4 2009-06-02 01:21:26

Allan
Pacman
From: Brisbane, AU
Registered: 2007-06-09
Posts: 11,650
Website

Re: makepkg: Record PKGBUILD sources in .PKGINFO files for maintenance

@fukawi2:  I'm not sure you understood the original request

I also don't think this is the job of makepkg or pacman.  It should be simple enough to write something that reads all the PKGBUILDs within a directory tree, makes a list of the remote source files and uses that to clean SRCDEST.

Offline

#5 2009-06-02 01:56:42

fukawi2
Ex-Administratorino
From: .vic.au
Registered: 2007-09-28
Posts: 6,237
Website

Re: makepkg: Record PKGBUILD sources in .PKGINFO files for maintenance

Right you are Allan big_smile  *edits*

Offline

#6 2009-06-02 02:39:20

Dusty
Schwag Merchant
From: Medicine Hat, Alberta, Canada
Registered: 2004-01-18
Posts: 5,986
Website

Re: makepkg: Record PKGBUILD sources in .PKGINFO files for maintenance

fukawi2 wrote:

Right you are Allan big_smile  *edits*

no he's not, its a bot.

Offline

#7 2009-06-02 21:08:52

deltaecho
Member
From: Georgia (USA)
Registered: 2008-08-06
Posts: 193

Re: makepkg: Record PKGBUILD sources in .PKGINFO files for maintenance

This script will parse all the PKGBUILD's in your $ABSROOT directory, collect all their sources into an array, and interactively remove each package NOT in the array from your $SRCDEST, although recording each pkg's source files into its .PKGINFO file would be SO much easier, faster, simpler, and safer (as no unwanted code -- such as little tid bits outside the build() method of PKGBUILD's -- is executed while the sources are being collected).

#!/bin/bash                                                                              

. /etc/makepkg.conf
. /etc/abs.conf    

if [[ "${SRCDEST}" != "" && "${ABSROOT}" != "" && -d "${SRCDEST}" && -d "${ABSROOT}" ]]; then

        # Holds the column width of the current terminal window
        COLS=$(tput cols)                                      

        # Create an empty row of the width of the current terminal window
        #+ which will be used to erase the current row.                  
        for sp in $(seq $COLS); do                                       
                empty_row="${empty_row} "                                
        done                                                             

        # Array to hold the sources
        sources=()                 

        # Array to hold the files to remove
        remove_files=()                    

        echo "Collecting sources..."
        for PKGBUILD in $(find "${ABSROOT}" -type f -name PKGBUILD); do
                echo -ne "${empty_row}\r${PKGBUILD:0:$COLS}\r"         
                . "${PKGBUILD}" &> /dev/null # Silence is golden       
                sources=(${sources[@]} ${source[@]##*/})               
        done                                                           

        # Sort and prune the files
        sources=($(for src_file in ${sources[@]}; do echo "${src_file}"; done | sort | uniq))

        echo -e "${empty_row}\rExamining ${SRCDEST}..."
        for src_file in $(find "${SRCDEST}" -type f | sort); do

                # Show the status
                echo -ne "${empty_row}\r${src_file:0:$COLS}\r"

                # Copy the basename of the current source file for comparisons
                current=${src_file##*/}                                       

                i=0
                j=${#sources[@]}
                k=$(( (i + j) / 2 ))

                # Perform a binary search for the current file
                for (( c = 0; c < ${#sources[@]}; c++ )); do  
                        let "k = (i + j) / 2"                 
                        if [[ "${sources[k]}" < "${current}" ]]; then
                                let "i = k + 1"                      
                        elif [[ "${sources[k]}" > "${current}" ]]; then
                                let "j = k - 1"                        
                        else                                           
                                break                                  
                        fi                                             
                done                                                   

                # If the file at ${sources[k]} isn't the one we're looking for,
                #+ check the element immediately before and after it.          
                if [[ "${sources[k]}" < "${current}" ]]; then                  
                # Bash will let me slide when I try to print an element beyond its indices ...
                        let "k += 1"                                                          
                elif [[ "${sources[k]}" > "${current}" && $k > 0 ]]; then                     
                # ... but complains when I try to print an element at an index < 0            
                        let "k -= 1"                                                          
                fi                                                                            

                # If a match is not found ...
                if [[ "${sources[k]}" == "${current}" ]]; then
                        # Since both arrays are sorted, I can remove all the elements 
                        #+ in ${sources[@]} up to index k.                            
                        sources=(${sources[@]:k + 1})

                         # Proceed to the next iteration
                        continue
                fi

                # Else, add the file to the list of those to be removed
                remove_files=(${remove_files[@]} ${src_file})
        done

        echo -e "${empty_row}\rFound ${#remove_files[@]} files to remove:"
        if (( ${#remove_files[@]} )); then

                for index in $(seq ${#remove_files[@]}); do
                        echo " ${index}) ${remove_files[index - 1]}"
                done

                echo -n | read # Clear the buffer (I had some issues)
                echo -n "Would you like to remove all these? [Y|n|c]"
                read ans # or `read -n 1 ans' if you prefer

                case "$ans" in
                        ""|[Yy]|[Yy][Ee][Ss])
                                for f2r in ${remove_files[@]}; do
                                        rm "$f2r" || echo "cannot remove $f2r"
                                done
                                ;;
                        [Cc]|[Cc][Hh][Oo][Ss][Ee])
                                for f2r in ${remove_files[@]}; do
                                        echo -n "${f2r}? [Y|n] "
                                        echo -n | read # Clear the buffer, again
                                        read ans

                                        if [[ "$ans" == "" || "$ans" == [Yy] || "$ans" == [Yy][Ee][Ss] ]]; then
                                                rm "$f2r" || echo "cannot remove $f2r"
                                        fi
                                done
                esac
        fi
elif [[ "${SRCDEST}" == "" || ! -d "${SRCDEST}" ]]; then
        echo "Your \$SRCDEST variable is invalid" 1>&2
        echo "Be sure it's set correctly in your \`/etc/makepkg.conf'" 1>&2
        exit 1
else
        echo "Your \$ABSROOT variable is invalid" 1>&2
        echo "Be sure you have \`abs' installed and that \`/etc/abs.conf' exists" 1>&2
        exit 1
fi

(06/02/2009) If we depended on many little scripts to handle our package management, what would then be the purpose of package managers?
(06/02/2009) Minor edit -> changed `echo' to `echo -n'  on line 90 of my script (superficial modification).

Last edited by deltaecho (2009-06-02 21:42:54)


Dylon

Offline

Board footer

Powered by FluxBB