You are not logged in.

#1 2005-01-30 16:05:07

Pajaro
Member
Registered: 2004-04-21
Posts: 884

pajman - my pacman improvement (updated)

In page 2 of this topic you can find a big improvement of pajman

pajman is a script that has my own version of pacman -Ss and -Qs and pacman -Sc.

pajman -Ps [string] (search) will search for a package looking only in the package name. Lots of times faster than -Ss, and usually you only look for the package name.

pajman -Psi [string] (search, info) is the same than "pajman -Ps" but it also shows the description of the package.

pajman -Pc (clean) will remove from cache all packages that are not installed though they are not outdated. I thought of it after uninstalling gnome: lots of packages that I didn't want where kept in cache because they where up to date.

Another point against usual pacman search is that it shows in yellow the packages that you have installed

It also looks for packages that you have installed but that are not in a repo

If you pass an argument different than -P?? it calls to srcpac if you've got it installed, otherwise it calls to pacman.

looks like this:
pajman8lx.jpg

and here's the source:

/usr/bin/pajman

#!/bin/bash

PACDIR="/var/lib/pacman/"
TEMP_FILE="/tmp/busca.$USER.$$"

REPOS=$(ls $PACDIR)

function pinfo {
    PROPERA="0"
    RESP=""
    
    for linia in $(cat $1/desc); do
        if [ "$PROPERA" == "1" ]; then
            if (echo $linia|grep "%">/dev/null); then
                echo - $RESP
                break
            else
                RESP="$RESP $linia"
            fi
        fi
        if [ "$linia" == "%DESC%" ]; then
            PROPERA="1"
        fi
    done
}

function search {
    # First we look for packages in the repos
    for repo in $REPOS; do
        if [ "$repo" != "local" ]; then
            if (ls $PACDIR$repo|grep -e $1>$TEMP_FILE); then
                echo -e "33[1;37m[$repo]33[m"
                for ii in $(cat $TEMP_FILE); do
                    if [ -d "$PACDIR"local/"$ii" ]; then
                                    echo -e "33[1;33m$ii33[m"
                    else
                        echo $ii
                    fi
                    if [ "$PINF" == "1" ]; then
                        pinfo $PACDIR$repo/$ii
                    fi
                done
            fi
        fi
    done


    #Then we look for packages that are not in a repo

    cd $PACDIR"/local"

    echo -e "33[1;37m* now looking for packages that are not in a repo. Ctrl + C to stop.33[m"
    
    for package in $(find -name "*"$1"*"); do
        trobat="0"
        for repo in $REPOS; do
            if [ "$repo" != "local" ]; then
                if [ -d $PACDIR/$repo/$package ]; then
                    trobat="1"
                fi
            fi
        done
        if [ "$trobat" == "0" ]; then
            echo -e "33[1;33m$package33[m"|sed 's|./||'
            if [ "$PINF" == "1" ]; then
                    pinfo $PACDIR/local/$package
            fi
        fi
    done
}

function clean {
    for pack in $(ls /var/cache/pacman/pkg|sed 's|.pkg.tar.gz||'); do
        if [ ! -d $PACDIR/local/$pack ]; then
            echo "$pack not installed. Package removed from cache."
            rm /var/cache/pacman/pkg/$pack".pkg.tar.gz"
        fi
    done
}

if (echo $1|grep P>/dev/null); then
    if (echo $1|grep s>/dev/null); then
        if (echo $1|grep i>/dev/null); then
            PINF="1"
        fi
        search $2
    elif (echo $1|grep c>/dev/null); then
        clean
    fi
else
    if [ -f /usr/bin/srcpac ]; then
        srcpac $@
    else
        pacman $@
    fi
fi

Offline

#2 2005-01-30 16:18:28

Pajaro
Member
Registered: 2004-04-21
Posts: 884

Re: pajman - my pacman improvement (updated)

pajman -Ps - will search for all packages.

Offline

#3 2005-01-31 16:07:33

phrakture
Arch Overlord
From: behind you
Registered: 2003-10-29
Posts: 7,879
Website

Re: pajman - my pacman improvement (updated)

the name is funny... i like it

Offline

#4 2005-02-01 02:04:45

linfocito
Member
From: Gurupi - TO, Brasil
Registered: 2003-05-18
Posts: 82

Re: pajman - my pacman improvement (updated)

Very good tool! And funny too.


"...archoholism is a hard disease to cure..."
Archlinux Brasil

Offline

#5 2005-02-01 09:47:43

Pajaro
Member
Registered: 2004-04-21
Posts: 884

Re: pajman - my pacman improvement (updated)

thanks smile

Offline

#6 2005-02-01 10:32:57

kumo
Member
From: VARESE - Italy
Registered: 2004-04-02
Posts: 49
Website

Re: pajman - my pacman improvement (updated)

Very nice indeed  big_smile it would be great to view the list of installed packages in the same way too!

Offline

#7 2005-02-01 11:48:24

Pajaro
Member
Registered: 2004-04-21
Posts: 884

Re: pajman - my pacman improvement (updated)

Very nice indeed Very Happy it would be great to view the list of installed packages in the same way too!

it shows in yellow installed packages. So what do you mean? An option to only list installed packages?

Offline

#8 2005-02-01 13:46:57

kumo
Member
From: VARESE - Italy
Registered: 2004-04-02
Posts: 49
Website

Re: pajman - my pacman improvement (updated)

Pajaro wrote:

So what do you mean? An option to only list installed packages?

What I would like is to have a script that listed all the packages I had installed with descriptions and where they have come from (if that is at all possible?). I didn't mean that I wanted your script to do this, but it reminded me that sometimes I install things and weeks later I don't know what is on my system and I see a list of cryptic commands!

Offline

#9 2005-02-01 16:27:31

cmp
Member
Registered: 2005-01-03
Posts: 350

Re: pajman - my pacman improvement (updated)

use a pacman -Qe this way you'll find any package that's not needed by others, to delete it then use pacman -Rs to remove this package and all deps that are not needed by other packages (ok it's without description, but for me it does the job).

Offline

#10 2005-02-01 19:44:20

Pajaro
Member
Registered: 2004-04-21
Posts: 884

Re: pajman - my pacman improvement (updated)

kumo, i think that cmp answered you. If not tell me what else could you need and I'll see if that is possible.

Offline

#11 2005-02-01 20:11:37

phrakture
Arch Overlord
From: behind you
Registered: 2003-10-29
Posts: 7,879
Website

Re: pajman - my pacman improvement (updated)

also, I believe the -Qii option will list if the package was either installed as a dependancy or by the user...

Offline

#12 2005-02-01 22:57:08

xian
Member
Registered: 2005-01-29
Posts: 19

Re: pajman - my pacman improvement (updated)

Thanks, Pajaro. A very nice tool. :thumbsup

Offline

#13 2005-02-03 15:45:03

Pajaro
Member
Registered: 2004-04-21
Posts: 884

Re: pajman - my pacman improvement (updated)

I've bastly improved pajman

No it can:
- updates databases

- install packages
*** if a package is corrupted it asks you if you want to download it again
*** it uses pacman to install, so there's no much risk of messing your system
*** installs packages one by one, so if you are going to install 90 packages and the 81 is corrupted yo will have the first 80 installed in dependency order.

- the search now tells you if you have another version of the package installed, but it is more than 10 times slower, so you can quicksearch.

but it has two special features:
- when you install a package that is in more than one repo it asks you what version to install

and the key feature:
- you can specify the working repo in command line

I'll post the script once I finish it.
TODO:
- mark automatically installed dependencies as not explicity installed by the user
- manage version requeriments in dependencies
- upgrade the system
- an option to install the previous installed version of a package

I think I'll have it finished next week.

Offline

#14 2005-02-04 02:01:34

xian
Member
Registered: 2005-01-29
Posts: 19

Re: pajman - my pacman improvement (updated)

Pajaro wrote:

you can specify the working repo in command line

Sweet smile

Offline

#15 2005-02-05 09:29:27

kumo
Member
From: VARESE - Italy
Registered: 2004-04-02
Posts: 49
Website

Re: pajman - my pacman improvement (updated)

Hmm, I am not being clear it seems. Simply I would like to have a list of installed packages with descriptions!

Offline

#16 2005-02-05 18:12:11

Pajaro
Member
Registered: 2004-04-21
Posts: 884

Re: pajman - my pacman improvement (updated)

ok, kumo. It's easy. I'll add an option for what you say. smile

Offline

#17 2005-02-05 19:00:50

cmp
Member
Registered: 2005-01-03
Posts: 350

Re: pajman - my pacman improvement (updated)

why not provide a pkgbuild?
my version

pkgname=pajman
pkgver=0.1
pkgrel=1
pkgdesc="a pacman imporvement"
url="http://bbs.archlinux.org/viewtopic.php?t=9590"
license="Public Domain?"
depends=(pacman)
source=($pkgname-$pkgver)

build() {
  mkdir -p $startdir/pkg/usr/bin
  install $startdir/src/$pkgname-$pkgver $startdir/pkg/usr/bin/pajman
}

and btw. it would be nice, if -Ps would behave the same way, as pacman -Ss or -Qs does - printing all packages or just quitting.
currently you get some error message from grep because it's called without any string (grep -e) - should be easily fixable.

great work so far.

Offline

#18 2005-02-10 09:04:25

kumo
Member
From: VARESE - Italy
Registered: 2004-04-02
Posts: 49
Website

Re: pajman - my pacman improvement (updated)

cheers! I look forward to that! Now I will remember what software I am need to restore if I "lose" my arch linux partition

Offline

#19 2005-02-13 19:18:36

Pajaro
Member
Registered: 2004-04-21
Posts: 884

Re: pajman - my pacman improvement (updated)

<edit>
- to avoid using a repo use NOREPOS as you would use REPOS. Example:
NOREPOS="testing unstable" pajman -Pinst <package>
</ediT>
I've got it:

HELP, PLEASE:
I didn't made it to mark not explicitily installed dependencies as not explicitily installed. How is it done by pacman?

TODO:
* ¿download all files and then start installing? now it downloads and installs packages one by one. As pacman does this the other way I think I'll update the script once i've got it.
* do not run if pacman or pajman are already running.

WHAT DOES IT DO?
See help below to see what it can do  (specially see TIPS)

Please, submit bugs and improvements you can find

pajman help:

-P[options] will use pajman routines. All other options will be passed to pacman (or srcpac)
options:
   s     [string]     Search for [string] in packages' names
   sq    [string]    Quick search (like -Ps but won't check if other versions installed. Much more faster)
   o            Only search for installed packages. Use it when searching (-Pso -Psqo)
   i            Show package description. Use it when searching or upgrading
   inst [packages]    Install [packages]
   y            Update database
   c            Remove from cache all packages that are not installed
   u            Compare local versions with database versions and upgrade.
   r    [packages]    Rollback. Install previos installed verisons of packages. Useless if you have
            cleaned package cache
   x    [string] [str]    Search for packages that match [string] and do not match [str] and remove them
   xs   [string] [str]    Same as x but pass 'recursive' parameter to pacman
   xg   [group]        Remove [group] group of packages
   xgs  [group]        Same as xg but pass 'recursive' parameter to pacman
ESPECIAL FEATURE: Especify repo in command line:
usage: REPOS="[repos]" pajman -P[x] [string or packages]
example:
    REPOS="current extra tpowa" pajman -Pyinst kdebase
    - This example will update current, extra and tpowa databases, ask you if you want to install 
      kdebase from extra or tpowa and either you choose extra or tpowa it will install any depencies
      you will need from extra
NOREPOS is a list of repos that will be omited
TIP: create an alias for pacman=pajman
TIP: add export NOREPOS='testing' and add [testing] repo to your pacman.conf
YSKICTUI TIP: you can run simultaneously many pajman instances.
VERY YSKICTUI TIP: rename /sbin/ldconfig /sbin/ldconfig.pajman to speed up package install process
(YSKICTUI = You Should Know Its Consequences To Use It)

/usr/bin/pajman

#!/bin/bash

PACDIR="/var/lib/pacman/"
SPACDIR='/var/lib/pacman/'
TEMP_FILE="/tmp/busca.$USER.$$"

function call_pacman {
    while [ -f /tmp/pacman.lck ]; do
        if ! (ps -A|grep pacman>/dev/null); then
            echo Removed pacman lock since pacman is not running
            rm /tmp/pacman.lck
        elif [ "$SAIDWAIT" == "" ]; then
            echo Pacman is running. Waiting for it to end
            SAIDWAIT="1"
            sleep 1
        else
            sleep 1
        fi
    done
    pacman $@
}

function colorpc {
    if [ "$1" != "" ]; then
        REDPC=""
        YELLOWPC=""
        WHITEPC=""
        GREENPC=""
        ORANGEPC=""
        PINKPC=""
        NORMALPC=""
    else
        REDPC="33[1;31m"
        YELLOWPC="33[1;33m"
        WHITEPC="33[1;37m"
        GREENPC=""
        ORANGEPC="33[2;33m"
        PINKPC="33[1;35m"
        NORMALPC="33[m"
    fi
}

if [ "$COLORPC" == "" ]; then
    colorpc
fi

function getserver {
    local REPOSER=$1
    local PROPERA="0"
    for linia in $(cat /etc/pacman.conf|sed 's/Server *= *//'|sed 's/Include *= *//'|sed 's/^#.*$//'); do
        if [ "$PROPERA" == "1" ]; then
            if ! (echo $linia|grep :>/dev/null); then
                for server in $(cat $linia|sed 's/Server *= *//'|sed 's/^[.*].*$//'|sed 's/^#.*$//'); do
                    CURSERVER="$server"
                    break
                done
            else 
                CURSERVER="$linia"
            fi
            break
        fi
        if [ "$linia" == "[$REPOSER]" ]; then
            PROPERA="1"
        fi
    done
}

if [ "$REPOS" == "" ]; then
    REPOS=$(ls $PACDIR --ignore=local --ignore=rollback)
else
    for repo in $REPOS; do
        getserver $repo
        if [ "$CURSERVER" == "" ]; then
            echo -e $REDPC"ERROR: "$WHITEPC"Repo $repo not found in /etc/pacman.conf"$NORMALPC
            exit
        fi
    done
    DONTLOOKINLOCAL="1"
fi

if [ "$NOREPOS" != "" ]; then
    for i in $NOREPOS; do
        REPOS=$(echo $REPOS|sed 's/[ ]*^*'$i'[ ]*$*/ /g')
    done
fi

function pinfo {
    PROPERA="0"
    RESP=""
    
    for linia in $(cat $1/desc); do
        if [ "$PROPERA" == "1" ]; then
            if (echo $linia|grep "%">/dev/null); then
                echo - $RESP
                break
            else
                RESP="$RESP $linia"
            fi
        fi
        if [ "$linia" == "%DESC%" ]; then
            PROPERA="1"
        fi
    done
}

function pgroup {
    PROPERA="0"
    RESP=""
    
    for linia in $(cat $1/desc); do
        if [ "$PROPERA" == "1" ]; then
            if (echo $linia|grep "%">/dev/null); then
                RESP="$RESP "
                break
            else
                RESP="$RESP $linia"
            fi
        fi
        if [ "$linia" == "%GROUPS%" ]; then
            PROPERA="1"
        fi
    done
}

function localsearch {
    if [ "$DONTLOOKINLOCAL" == "1" ]; then
        return
    fi

    cd $PACDIR"/local"

    echo -e "$WHITEPC* now looking for packages that are not in a repo. Ctrl + C to stop."$NORMALPC
    
    for package in $(find -name "*"$1"*"); do
        trobat="0"
        for repo in $REPOS; do
            if [ -d $PACDIR/$repo/$package ]; then
                trobat="1"
            fi
        done
        if [ "$trobat" == "0" ]; then
            echo -e "$YELLOWPC$package"$NORMALPC|sed 's|./||'
            if [ "$PINF" == "1" ]; then
                    pinfo $PACDIR/local/$package
            fi
        fi
    done
}

function search {
    # First we look for packages in the repos
    local SSTR="$1"
    for repo in $REPOS; do
        if (ls $PACDIR$repo|grep -e $SSTR>$TEMP_FILE); then
            echo -e $WHITEPC"[$repo]"$NORMALPC
            for ii in $(cat $TEMP_FILE); do
                for LOCALVER in $(echo "$PACDIR"local/"$ii"|sed 's/-[0-9,.,_,a-z,A-Z]*-[0-9,.,_,a-z,A-Z]*$//g')-*-*; do
                    localv=$(echo "$LOCALVER"|sed s/$SPACDIR"local/"//)
                    loca=$(echo $localv|sed 's/-[0-9,.,_,a-z,A-Z]*-[0-9,.,_,a-z,A-Z]*$//g')
                    if [ "$localv" == "$ii" ] && [ -d $LOCALVER ]; then
                        echo -e "$YELLOWPC$ii"$NORMALPC
                        if [ "$PINF" == "1" ]; then
                            pinfo $PACDIR$repo/$ii
                        fi
                    elif [ "$loca" == "$(echo $ii|sed 's/-[0-9,.,_,a-z,A-Z]*-[0-9,.,_,a-z,A-Z]*$//g')" ] && [ -d $LOCALVER ]; then
                        echo -e "$ORANGEPC$ii (localver is $(echo $LOCALVER|sed s/$SPACDIR"local/"//))"$NORMALPC
                        if [ "$PINF" == "1" ]; then
                            pinfo $PACDIR$repo/$ii
                        fi
                    elif [ ! $ONLYINSTALLED ]; then
                        echo $ii
                        if [ "$PINF" == "1" ]; then
                            pinfo $PACDIR$repo/$ii
                        fi
                    fi
                done
            done
        fi
    done

    #Then we look for packages that are not in a repo
    localsearch $SSTR
}

function clean {
    for pack in $(ls /var/cache/pacman/pkg|sed 's|.pkg.tar.gz||'); do
        if [ ! -d $PACDIR/local/$pack ]; then
            echo "$pack not installed. Package removed from cache."
            rm /var/cache/pacman/pkg/$pack".pkg.tar.gz"
        fi
    done
}

function upgrade {
    LOCALS=$(ls -l $PACDIR'local/'|grep ^d|sed 's/^.*:[0-9][0-9] //');
    for repo in $REPOS; do
        DATA=$(ls $PACDIR$repo|grep -e -)
        echo -e $WHITEPC"[$repo]"$NORMALPC
        for ii in $DATA; do
            PACKNAME=$(echo $ii|sed 's/-[0-9,.,_,a-z,A-Z]*-[0-9,.,_,a-z,A-Z]*$//g');
            LOCALVER=$(echo $LOCALS|grep -o [ ,^]$PACKNAME-[0-9,.,_,a-z,A-Z]*-[0-9,.,_,a-z,A-Z]*[ ,$])
            if [ "$LOCALVER" != "" ] && [ "$LOCALVER" != "$ii" ]; then
                VER1=$(echo $LOCALVER|sed 's/'$PACKNAME-'//'|sed 's/-[0-9,.,_,a-z,A-Z]*$//g')
                VER2=$(echo $ii|sed 's/'$PACKNAME-'//'|sed 's/-[0-9,.,_,a-z,A-Z]*$//g')
                checkver $VER1 $VER2
                if [ "$GREATVER" == "FIRST" ]; then
                    echo -e "$ORANGEPC$ii local version is newer ($LOCALVER)"$NORMALPC
                    if [ "$PINF" == "1" ]; then
                        pinfo $PACDIR$repo/$ii
                    fi
                elif [ "$GREATVER" == "SECOND" ]; then
                    echo -e "$PINKPC$ii must be upgraded ($LOCALVER)"$NORMALPC
                    PACKSTOINST="$repo/$ii $PACKSTOINST"
                    if [ "$PINF" == "1" ]; then
                        pinfo $PACDIR$repo/$ii
                    fi
                else
                    let "BUILD1=$(echo $LOCALVER|sed s/$PACKNAME-$VER1-//)"
                    let "BUILD2=$(echo $ii|sed s/$PACKNAME-$VER1-//)"
                    if [[ $BUILD1 > $BUILD2 ]]; then
                        echo -e "$ORANGEPC$ii local version is newer ($LOCALVER)"$NORMALPC
                        if [ "$PINF" == "1" ]; then
                            pinfo $PACDIR$repo/$ii
                        fi
                    elif [[ $BUILD1 < $BUILD2 ]]; then
                        echo -e "$PINKPC$ii must be upgraded ($LOCALVER)"$NORMALPC
                        if [ "$PINF" == "1" ]; then
                            pinfo $PACDIR$repo/$ii
                        fi
                        PACKSTOINST="$repo/$ii $PACKSTOINST"
                    fi
                fi
            fi
        done
    done

    for packtoinst in $PACKSTOINST; do
        checkpacktoinst $packtoinst
    done
}

# function to check if a package is installed
function is_installed {
    LPAC="$PACDIR"local/"$1"-[0-9,.,_,a-z,A-Z]*-[0-9,.,_,a-z,A-Z]*
    for llpac in $LPAC; do
        if [ $(echo $llpac|sed 's/-[0-9,.,_,a-z,A-Z]*-[0-9,.,_,a-z,A-Z]*$//g') == "$PACDIR"local/"$1" ]; then
            echo 1
        fi
    done
}


function download {
    local SITE="$1"
    local PACK="$2"
    local REPO="$3"
    if [ -f /var/cache/pacman/pkg/$PACK ]; then
        MD5SUM=$(md5sum /var/cache/pacman/pkg/$PACK | sed 's/ .*$//')
    fi
    local PROPERA="0"
    for linia in $(cat $PACDIR$REPO/$(echo $2|sed 's/.pkg.tar.gz//')/desc); do
        if [ "$PROPERA" == "1" ]; then
            if [ "$linia" == "$MD5SUM" ]; then
                echo Package already downloaded
            else
                snarf $SITE/$PACK /var/cache/pacman/pkg/$PACK
                MD5SUM=$(md5sum /var/cache/pacman/pkg/$PACK | sed 's/ .*$//')
                if [ "$MD5SUM" != "$linia" ]; then
                    echo -e $PINKPC"MD5SUMS do not match."$NORMALPC
                    echo Downloading the package again...
                    rm /var/cache/pacman/pkg/$PACK
                    download $SITE $PACK $REPO
                fi
            fi
            return
        fi
        if [ "$linia" == "%MD5SUM%" ]; then
            PROPERA="1"
        fi
    done
}

function ask {
    echo -e $1
    select opt in $2; do
        ANSWER=$opt
        return
    done
}

function checkpacktoinst {
    local FOUNDS="$1"

    if [ ! -f $PACDIR$FOUNDS'/depends' ]; then
        echo -e $REDPC"ERROR: "$WHITEPC"Cannot find package info"$NORMALPC
        exit
    fi

    echo ==> Checking for conflicts
    PROPERA="0"
    for linia in $(cat $PACDIR$FOUNDS'/depends'); do
        if [ "$PROPERA" == "1" ]; then
            if (echo $linia|grep "%">/dev/null); then
                break
            else
                INSTANCE=$PACDIR'local/'$linia-[0-9,.,_,a-z,A-Z]*-[0-9,.,_,a-z,A-Z]*
                for inst in $INSTANCE; do
                    inst=$(echo $inst|sed 's/-[0-9,.,_,a-z,A-Z]*-[0-9,.,_,a-z,A-Z]*$//g')
                    if [ "$inst" == "$PACDIR"local/"$linia" ]; then
                        echo "STOPING: The package conflicts with "$linia". Install it with 'pacman -S'"
                        exit
                    fi
                done
            fi
        fi
        if [ "$linia" == "%CONFLICTS%" ]; then
            PROPERA="1"
        fi
    done
    
    echo ==> Checking for dependencies
    PROPERA="0"
    for linia in $(cat $PACDIR$FOUNDS'/depends'); do
        if [ "$PROPERA" == "1" ]; then
            COMP=""
            NEEDEDVER=""
            if (echo $linia|grep '<='>/dev/null); then
                NEEDEDVER=$(echo $linia|sed 's/.*<=//')
                linia=$(echo $linia|sed 's/<=.*//')
                COMP="<="
            elif (echo $linia|grep '>='>/dev/null); then
                NEEDEDVER=$(echo $linia|sed 's/.*>=//')
                linia=$(echo $linia|sed 's/>=.*//')
                COMP=">="
            elif (echo $linia|grep '<'>/dev/null); then
                NEEDEDVER=$(echo $linia|sed 's/.*<//')
                linia=$(echo $linia|sed 's/<.*//')
                COMP="<"
            elif (echo $linia|grep '>'>/dev/null); then
                NEEDEDVER=$(echo $linia|sed 's/.*>//')
                linia=$(echo $linia|sed 's/>.*//')
                COMP=">"
            elif (echo $linia|grep '='>/dev/null); then
                NEEDEDVER=$(echo $linia|sed 's/.*=//')
                linia=$(echo $linia|sed 's/=.*//')
                COMP="="
            fi
            if [[ "$COMP" != "" ]]; then
                echo -e $REDPC"WARNING: "$WHITEPC" $FOUNDS needs a concrete version of $linia ( $linia $COMP $NEEDEDVER ). This check will be skiped. Use pacman -S to have this check done."$NORMALPC
            fi
            if (echo $linia|grep "%">/dev/null); then
                break
            elif (echo $PACKSTOINST|grep /$linia-[0-9,.,_,a-z,A-Z]*-[0-9,.,_,a-z,A-Z]*>/dev/null); then
                echo "Needed $linia is to be installed"
            elif (echo $PROVIDENCES|grep "%$linia%">/dev/null); then
                echo "Dependency $linia is provided and has already been check."
            else
                INSTANCE=$PACDIR'local/'$linia-[0-9,.,_,a-z,A-Z]*-[0-9,.,_,a-z,A-Z]*
                for inst in $INSTANCE; do
                    inst=$(echo $inst|sed 's/-[0-9,.,_,a-z,A-Z]*-[0-9,.,_,a-z,A-Z]*$//g')
                    if [ "$inst" == "$PACDIR"local/"$linia" ]; then
                        echo "Needed $linia is already installed"
                        break
                    elif [ "$inst" == "$PACDIR"local/"$linia"'-[0-9,.,_,a-z,A-Z]*-[0-9,.,_,a-z,A-Z]*' ]; then
                        echo
                        echo "Needed $linia needs to be installed..."
                        ipack $linia
                    fi
                done
            fi
        fi
        if [ "$linia" == "%DEPENDS%" ]; then
            PROPERA="1"
        fi
    done
}

# function to install a package
function ipack {
    echo "==> Preparing to install $1"
    if [ "$(is_installed $1)" == "1" ]; then
        echo -e "$YELLOWPC==> Package already installed"$NORMALPC
        ask "Do you want to proceed? n"$YELLOWPC"WARNING:"$WHITEPC" saying yes will render useless to rollback this package"$NORMALPC "yes no"
        if [ "$ANSWER" != "yes" ]; then
            exit
        fi
    else
        echo ==> Package not installed
    fi

    local FOUNDS=""

    for repo in $REPOS; do
        CHECK=$PACDIR$repo/"$1"-[0-9,.,_,a-z,A-Z]*-[0-9,.,_,a-z,A-Z]*
        for this in $CHECK; do
            tthis=$(echo $this|sed 's/-[0-9,.,_,a-z,A-Z]*-[0-9,.,_,a-z,A-Z]*$//g')
            if [ "$tthis" == "$PACDIR"$repo/"$1" ]; then
                if [ -d $PACDIR'local/'$(echo $this|sed s/$SPACDIR$repo'/'//) ]; then
                    this=$(echo -e "$YELLOWPC")$this$(echo -e $NORMALPC)
                fi
                this=$(echo $this|sed 's/'$SPACDIR'//g')
                FOUNDS="$FOUNDS $this"
            fi
        done
    done
    if (echo $FOUNDS|grep ' '>/dev/null); then
        echo -e $WHITEPC==> The package is avaible in more than one repo$NORMALPC
        echo "What version do you want to install?"
        select opt in $(echo $FOUNDS|sed 's/'$SPACDIR'//g'); do
            FOUNDS=$opt
            break
        done
    elif [ "$FOUNDS" == "" ]; then
        echo "Package not found"
        echo "Let's see if it is provided by another package"
        for possib in $(find $PACDIR -name depends); do
            PROPERA="0"
            PROVIDERS=""
            for linia in $(cat $possib); do
                if [ "$PROPERA" == "1" ]; then
                    if (echo $linia|grep "%">/dev/null); then
                        break
                    elif (echo $linia|grep $1>/dev/null); then
                        PROVIDER=$(echo $possib|sed s/$SPACDIR//|sed 's/[a-z]*///'|sed 's//depends//'|sed 's/-[0-9,.,_,a-z,A-Z]*-[0-9,.,_,a-z,A-Z]*$//g')
                        PROVIDERS="$PROVIDERS $PROVIDER"
                        echo $PROVIDER provides $1
                        PROVIDENCES="$PROVIDENCES%$PROVIDER%%$1%"
                        if [ "$(is_installed $PROVIDER)" == "1" ]; then
                            echo $PROVIDER is already installed. Keep going on.
                            PROVIDERS=""
                            return
                        fi
                    fi
                fi
                if [ "$linia" == "%PROVIDES%" ]; then
                    PROPERA="1"
                fi
            done
        done
        if [ "$PROVIDERS" != "" ]; then
            select provider in $PROVIDERS; do
                $FOUNDS=$provider
                break
            done
            exit
        fi
    else
        echo ==> Only one coincidence found:
    fi

    # We remove coloring
    FOUNDS=$(echo $FOUNDS|cat -v|sed 'y/^[[;/§§§§/'|sed s/§§§1§33m//|sed s/§§§m//)

    echo $FOUNDS is going to be installed

    checkpacktoinst $FOUNDS
    
    PACKSTOINST="$FOUNDS $PACKSTOINST"
}

function quicksearch {
    # First we look for packages in the repos
    for repo in $REPOS; do
        if [ "$repo" != "local" ]; then
            if (ls $PACDIR$repo|grep -e $1>$TEMP_FILE); then
                echo -e $WHITEPC"[$repo]"$NORMALPC
                for ii in $(cat $TEMP_FILE); do
                    if [ -d "$PACDIR"local/"$ii" ]; then
                                    echo -e "$YELLOWPC$ii"$NORMALPC
                        if [ "$PINF" == "1" ]; then
                            pinfo $PACDIR$repo/$ii
                        fi
                    elif [ ! $ONLYINSTALLED ]; then
                        echo $ii
                        if [ "$PINF" == "1" ]; then
                            pinfo $PACDIR$repo/$ii
                        fi
                    fi
                done
            fi
        fi
    done


    #Then we look for packages that are not in a repo

    localsearch $1
}

function needroot {
    if [ "$UID" != "0" ]; then
        echo -e $REDPC"ERROR: "$WHITEPC"You cannot perform "$1" unless you are root."$NORMALPC
        exit
    fi
}

function partver {
    local CURRIT
    local NUMITS
    let "NUMITS=$2"
    let "CURRIT=0"
    for partver in $(echo $1|sed 's/./ /g'); do
        let "CURRIT=$CURRIT+1"
        if [[ $CURRIT == $NUMITS ]]; then
            PARTVER="$partver"
            return
        fi
    done
    PARTVER=""
}

function checkver {
    local CURRIT
    let "CURRIT=0"
    SECVER="$2"
    for part in $(echo $1|sed 's/./ /g'); do
        let "CURRIT=$CURRIT+1"
        partver $SECVER $CURRIT
        if [[ "$part" != "0" ]]; then
            part=$(echo $part|sed 's/^0//')
        fi
        if [[ "$PARTVER" != "0" ]]; then
            PARTVER=$(echo $PARTVER|sed 's/^0//')
        fi
        if ! (echo $part|grep [a-z,A-Z,_]>/dev/null) && ! (echo $PARTVER|grep [a-z,A-Z,_]>/dev/null); then
            let "SUM=$part-$PARTVER"
            if [[ $SUM > 0 ]]; then
                GREATVER="FIRST"
                return
            elif [[ $SUM < 0 ]]; then
                GREATVER="SECOND"
                return
            fi
        else
            SUBVER1=$(echo $part|sed 's/[a-z,A-Z,_][0-9]*//g')
            SUBVER2=$(echo $PARTVER|sed 's/[a-z,A-Z,_][0-9]*//g')
            if ! (echo $SUBVER1|grep '^[0-9]'>/dev/null); then
                SUBVER1="0$SUBVER1"
            fi
            if ! (echo $SUBVER2|grep '^[0-9]'>/dev/null); then
                SUBVER2="0$SUBVER2"
            fi
            let "SUM=$SUBVER1-$SUBVER2"
            if [[ $SUM > 0 ]]; then
                GREATVER="FIRST"
                return
            elif [[ SUM < 0 ]]; then
                GREATVER="SECOND"
                return
            elif ! (echo $part|grep [a-z,A-Z,_]>/dev/null) && (echo $PARTVER|grep [a-z,A-Z,_]>/dev/null); then
                GREATVER="FIRST"
                return
            elif (echo $part|grep [a-z,A-Z,_]>/dev/null) && ! (echo $PARTVER|grep [a-z,A-Z,_]>/dev/null); then
                GREATVER="SECOND"
                return
            else
                if [[ $part > $PARTVER ]]; then
                    GREATVER="FIRST"
                    return
                elif [[ $part < $PARTVER ]]; then
                    GREATVER="SECOND"
                    return
                fi
            fi            
        fi
    done
    let "CURRIT=$CURRIT+1"
    partver $SECVER $CURRIT
    if [ "$PARTVER" != "" ]; then
        GREATVER="SECOND"
        return
    fi
    GREATVER="NONE"
}

function instpacks {
    if [ "$PACKSTOINST" == "" ]; then
        echo No packages to be installed
        return
    fi
    echo
    echo -e $WHITEPC"Is it ok to install next packages?"$NORMALPC
    echo $PACKSTOINST
    OPTS="yes no"
    select opt in $OPTS; do
        if [ "$opt" == "yes" ]; then
            break
        fi
        exit
    done
    
    echo
    echo ==> Installing:
    if (echo $PACKSTOINST|grep glibc>/dev/null); then
        echo glibc needs is to be installed. Please, install it with pacman -S.
        exit
    fi

    if [ ! -d /var/lib/pacman/rollback ]; then
        mkdir -p /var/lib/pacman/rollback
    fi

    for pack in $PACKSTOINST; do
        echo -e $WHITEPC"==> Installing $pack"$NORMALPC
        REPO=$(echo $pack|sed 's//.*//')
        PACKN=$(echo $pack|sed 's/.*///').pkg.tar.gz
        getserver $REPO
        download $CURSERVER $PACKN $REPO
        if [ -d $PACDIR/rollback/$PACKN ]; then
            rm -r $PACDIR/rollback/$PACKN
        fi
        OLDPACK=$(echo $PACKN|sed 's/-[0-9,.,_,a-z,A-Z]*-[0-9,.,_,a-z,A-Z]*.pkg.tar.gz$//g')
        INSTANCE=$PACDIR'local/'$OLDPACK-[0-9,.,_,a-z,A-Z]*-[0-9,.,_,a-z,A-Z]*
        for inst in $INSTANCE; do
            insta=$(echo $inst|sed 's/-[0-9,.,_,a-z,A-Z]*-[0-9,.,_,a-z,A-Z]*$//g')
            if [ "$insta" == "$PACDIR"local/"$OLDPACK" ]; then
                cp $inst "$PACDIR"rollback -r
                break
            fi
        done
        
        if [ "$FORCE" == "1" ]; then
            call_pacman -Udf /var/cache/pacman/pkg/$PACKN
        else
            call_pacman -Ud /var/cache/pacman/pkg/$PACKN
        fi
        
        if [ "$(is_installed $OLDPACK)" != "1" ]; then
            echo -e $REDPC"ERROR: $WHITEPC"Package $pack has failed to install$NORMALPC
            ask "Do you want to install it again forcing file conflicts?" "yes no"
            if [ "$ANSWER" == "yes" ]; then
                call_pacman -Udf /var/cache/pacman/pkg/$PACKN
                if [ "$(is_installed $OLDPACK)" != "1" ]; then
                    echo -e $REDPC"ERROR: $WHIETEPC"Package $pack has failed AGAIN to install$NOMALPC
                    ask "Do you want to install remaining packages?" "yes no"
                    if [ "$ANSWER" == "no" ]; then
                        exit
                    fi
                fi
            else
                ask "Do you want to install remaining packages?" "yes no"
                if [ "$ANSWER" == "no" ]; then
                    exit
                fi
            fi
        fi
    done
    echo
    echo Updating shared library links. Ctrl + C to stop.
    if [ -f /sbin/ldconfig.pajman ]; then
        ldconfig.pajman
    fi
}

function searchandremove {
    MATCHSTRING=$1
    shift
    echo -e $WHITEPC"==> Removing packages that match "$MATCHSTRING" and do not match "$@""$NORMALPC

    colorpc "no"

    local TOREMOVE=$(ONLYINSTALLED="1" quicksearch $MATCHSTRING|sed 's/[.*]$//g'|sed 's/* now looking for packages that are not in a repo. Ctrl + C to stop.//g')

    if [ "$COLORPC" == "" ]; then
        colorpc
    fi

    local NEWTOREMOVE=""
    for tore in $TOREMOVE; do
        local FOUND=""
        for noto in $@; do
            if (echo $tore|grep $noto>/dev/null); then
                FOUND="1"
            fi
        done
        if [ "$FOUND" == "" ]; then
            NEWTOREMOVE="$NEWTOREMOVE $tore"
        fi
    done

    TOREMOVE=$NEWTOREMOVE

    if [ "$TOREMOVE" == "" ]; then
        echo No package to be removed
        exit
    fi

    ask $WHITEPC"Is it ok to "$REDPC"REMOVE"$WHITEPC" this packages?"$YELLOWPC"n$(echo $TOREMOVE|sed 's/ /\n/g')$NORMALPC" "yes no"
    TOREMOVE=$(echo $TOREMOVE|sed 's/-[0-9,.,_,a-z,A-Z]*-[0-9,.,_,a-z,A-Z]* / /g')
    TOREMOVE=$(echo $TOREMOVE|sed 's/-[0-9,.,_,a-z,A-Z]*-[0-9,.,_,a-z,A-Z]*$//g')
    echo $TOREMOVE
    if [ $ANSWER == "yes" ]; then
        call_pacman -R$RECURSIVEREMOVE $TOREMOVE
    fi
}

function removegroup {
    echo -e $WHITEPC"==> Removing "$1" group"$NORMALPC
    local TOREMOVE=""
    for pack in $(ls $PACDIR/local); do
        pgroup $PACDIR"local/"$pack
        if [ "$RESP" == " $1 " ]; then
            TOREMOVE="$TOREMOVE $pack"
            echo -e $YELLOWPC$pack$WHITEPC
        fi
    done

    if [ "$TOREMOVE" == "" ]; then
        echo No package to be removed
        exit
    fi

    ask $WHITEPC"Is it ok to "$REDPC"REMOVE"$WHITEPC" above packages?"$NORMALPC "yes no"
    TOREMOVE=$(echo $TOREMOVE|sed 's/-[0-9,.,_,a-z,A-Z]*-[0-9,.,_,a-z,A-Z]* / /g')
    TOREMOVE=$(echo $TOREMOVE|sed 's/-[0-9,.,_,a-z,A-Z]*-[0-9,.,_,a-z,A-Z]*$//g')
    if [ $ANSWER == "yes" ]; then
        call_pacman -R$RECURSIVEREMOVE $TOREMOVE
    fi
}

if (echo $1|grep P>/dev/null); then
    CHECKSNARF=$(snarf --help)
    if [ "$CHECKSNARF" == "" ]; then
        ask "Snarf not installed but required by pajman. Do you want to install it?" "yes no"
        if [ "$ANSWER" != "no" ]; then
            call_pacman -S snarf
        else
            echo If you do not install snarf, there is no pajman for you
            exit
        fi
    fi

    if (echo $1|grep y>/dev/null); then
        needroot "synchronize database"
        echo -e $WHITEPC==> Updating database$NORMALPC
        if [ ! -d /var/lib/pajman ]; then
            mkdir -p /var/lib/pajman
        fi
        for repo in $REPOS; do
            echo ==> Updating $repo
            getserver $repo
            snarf $CURSERVER/$repo.db.tar.gz /var/lib/pajman/$repo.db.tar.gz
            if [ -f /var/lib/pajman/$repo.db.tar.gz ]; then
                cd /var/lib/pajman
                tar xfz /var/lib/pajman/$repo.db.tar.gz
                rm *.db.tar.gz
                rm -r /var/lib/pacman/$repo
                mkdir /var/lib/pacman/$repo
                mv * /var/lib/pacman/$repo
            else
                echo -e $YELLOWPC"WARNING: "$WHITEPC"Repo $repo cannot be updated"$NORMALPC
            fi
        done
        rmdir /var/lib/pajman
    fi

    if (echo $1|grep f>/dev/null); then
        FORCE="1"
    fi    

    if (echo $1|grep u>/dev/null); then
        needroot "update packages"
        if (echo $1|grep i>/dev/null); then
            PINF="1"
        fi
        echo -e $WHITEPC==> Upgrading system$NORMALPC
        upgrade
        instpacks
    fi
    if [ "$1" == "-P" ]; then
        needroot "install packages"

        while [ "$#" != "1" ]; do
            ipack $2
            shift
        done
        
        instpacks
    elif (echo $1|grep x>/dev/null); then
        needroot "search and remove"
        if (echo $1|grep g>/dev/null); then
            RECURSIVEREMOVE="s"
        fi
        if (echo $1|grep g>/dev/null); then
            needroot "remove groups"
            while [ "$#" != "1" ]; do
                removegroup $2
                shift
            done
        else
            shift
            searchandremove $@
        fi
    elif (echo $1|grep r>/dev/null); then
        needroot "rollback"

        while [ "$#" != "1" ]; do
            ROLLINGBACK="1"
            REPOS="$REPOS rollback"
            ipack $2
            shift
        done
        
        instpacks
    elif (echo $1|grep s>/dev/null); then
        if [ "$2" == "" ]; then
            echo No search string provided. Use "pajman -Ps -" to search for all packages
            exit
        fi
        if (echo $1|grep o>/dev/null); then
            ONLYINSTALLED="1"
        fi
        if ! (echo $1|grep q>/dev/null); then
            echo -e $WHITEPC==> Searching for "$2"$NORMALPC
            if (echo $1|grep i>/dev/null); then
                PINF="1"
            fi
            search $2
        else
            echo -e $WHITEPC==> QUICK-Searching for "$2"$NORMALPC
            if (echo $1|grep i>/dev/null); then
                PINF="1"
            fi
            quicksearch $2
        fi
    elif (echo $1|grep c>/dev/null); then
        clean
    elif ! (echo $1|grep [y,u]>/dev/null); then
        echo "Unknow paramater '$1'"
    fi
elif [ "$1" == "--help" ] || [ "$#" == "0" ]; then
    echo "-P[options] will use pajman routines. All other options will be passed to pacman (or srcpac)
options:
   s     [string]     Search for [string] in packages' names
   sq    [string]    Quick search (like -Ps but won't check if other versions installed. Much more faster)
   o            Only search for installed packages. Use it when searching (-Pso -Psqo)
   i            Show package description. Use it when searching or upgrading
   inst [packages]    Install [packages]
   y            Update database
   c            Remove from cache all packages that are not installed
   u            Compare local versions with database versions and upgrade.
   r    [packages]    Rollback. Install previos installed verisons of packages. Useless if you have
            cleaned package cache
   x    [string] [str]    Search for packages that match [string] and do not match [str] and remove them
   xs   [string] [str]    Same as x but pass 'recursive' parameter to pacman
   xg   [group]        Remove [group] group of packages
   xgs  [group]        Same as xg but pass 'recursive' parameter to pacman
ESPECIAL FEATURE: Especify repo in command line:
usage: REPOS="[repos]" pajman -P[x] [string or packages]
example:
    REPOS="current extra tpowa" pajman -Pyinst kdebase
    - This example will update current, extra and tpowa databases, ask you if you want to install 
      kdebase from extra or tpowa and either you choose extra or tpowa it will install any depencies
      you will need from extra
NOREPOS is a list of repos that will be omited
TIP: create an alias for pacman=pajman
TIP: add export NOREPOS='testing' and add [testing] repo to your pacman.conf
YSKICTUI TIP: you can run simultaneously many pajman instances.
VERY YSKICTUI TIP: rename /sbin/ldconfig /sbin/ldconfig.pajman to speed up package install process
(YSKICTUI = You Should Know Its Consequences To Use It)

Now showing pacman (or srcpac) parameters:"
    if [ -f /usr/bin/srcpac ]; then
        srcpac --help
    else
        pacman --help
    fi
else
    if [ -f /usr/bin/srcpac ]; then
        srcpac $@
    else
        call_pacman $@
    fi
fi

Offline

#20 2005-02-13 20:13:48

cmp
Member
Registered: 2005-01-03
Posts: 350

Re: pajman - my pacman improvement (updated)

why don't you just use pajman -P for isntalling, like pacman?

Offline

#21 2005-02-13 20:23:13

Pajaro
Member
Registered: 2004-04-21
Posts: 884

Re: pajman - my pacman improvement (updated)

Because it not only installs packages, it does more things that pacman does,  and I can't use pacman letter's since it calls to pacman if you give it a pacman parameter. So I decided to put all parameters with -P of pajman instead of finding a -K -L -W.. or whatever for each action. this way it keeps the intuitivity of i for info, u for upgrade, s for search... etc.

Offline

#22 2005-02-13 20:42:51

cmp
Member
Registered: 2005-01-03
Posts: 350

Re: pajman - my pacman improvement (updated)

yes - i understood this - but I meant:
pajamn -Ps xfce4   - for searching for xfc4
pajman -P xfce4     - for installing xfc4
just like pacman does it:
pacman -Ss search
pacman -S install

Offline

#23 2005-02-13 20:48:18

Pajaro
Member
Registered: 2004-04-21
Posts: 884

Re: pajman - my pacman improvement (updated)

I'll add this

smile thanks

Offline

#24 2005-02-26 22:41:21

sorcerer
Member
Registered: 2005-02-25
Posts: 18

Re: pajman - my pacman improvement (updated)

great script, having a problem when I try a complete update though:

s0rcerer ~ # pacman -Pu
==> Upgrading system
[current]
[extra]
[link]
ati-drivers-8.8.25-1 local version is newer ( ati-drivers-8.10.19-1 )
ati-drivers-module-kernel26-8.8.25-1 local version is newer ( ati-drivers-module-kernel26-8.10.19-1 )
[testing]
control-center-2.9.91-1 must be upgraded ( control-center-2.8.1-2 )
db-4.3.27-2 must be upgraded ( db-4.2.52.2-2 )
eel-2.9.91-1 must be upgraded ( eel-2.8.2-1 )
<cut>.....

.....</cut>
Needed gnome-menus needs to be installed...
==> Package not installed
==> Only one coincidence found:
sed: -e expression #1, char 19: strings for `y' command are different lengths
is going to be installed
ERROR: Cannot find package info
s0rcerer ~ #

Any ideas?

Offline

#25 2005-02-27 22:13:53

Pajaro
Member
Registered: 2004-04-21
Posts: 884

Re: pajman - my pacman improvement (updated)

I've updated the script. It had a problem with copy-pasting latin characters, I added autoinstalling snarf if not installed a some other minor fixes. I have a lists of things to be done.

Now you default option is inst, so:

pacman -Pinst kdebase

now has to be written:

pacman -P kdebase

Offline

Board footer

Powered by FluxBB