aboutsummaryrefslogtreecommitdiff
path: root/trunk/src/lspkg
blob: 74ed684e58fefd92e03c0cb1548094a9c4b8f5af (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#!/bin/bash
#
# lspkg v0.3: view installed and contents of slackware packages
#
# feedback: rhatto at riseup.net | gpl
#
#  Lspkg is free software; you can redistribute it and/or modify it under the
#  terms of the GNU General Public License as published by the Free Software
#  Foundation; either version 2 of the License, or any later version.
#
#  Lspkg is distributed in the hope that it will be useful, but WITHOUT ANY
#  WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
#  A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License along with
#  this program; if not, write to the Free Software Foundation, Inc., 59 Temple
#  Place - Suite 330, Boston, MA 02111-1307, USA
#
function head_line {
    echo "usage: [ROOT=/otherroot] `basename $0` [option expression]"
}

function usage {
    head_line
    echo "
options are:

   -v, --view: view installed package contents
   -p, --print: print the contents of a package file
   -r, --remove: remove matching packages
   -s, --search: search a file under installed packages
   -d, --description: show matching packages' descriptions
"
}

# -----------------------------------------------------
#                       lspkg
# -----------------------------------------------------
COMMON="/usr/libexec/simplepkg/common.sh"

if [ -f "$COMMON" ]; then
    source $COMMON
else
    echo "error: file $COMMON not found, check your `basename $0` installation"
    exit 1
fi

if [ $# -eq 2 ]; then
    LIST_PKGS=`ls /$ROOT/var/log/packages/$2-[0-9]* 2> /dev/null`
    if [ -z "$LIST_PKGS" ]; then
        LIST_PKGS=`ls /$ROOT/var/log/packages/$2* 2> /dev/null`
    fi
elif [ $# -eq 1 ]; then
    LIST_PKGS=`ls /$ROOT/var/log/packages/$1-[0-9]* 2> /dev/null`
    if [ -z "$LIST_PKGS" ]; then
        LIST_PKGS=`ls /$ROOT/var/log/packages/$1* 2> /dev/null`
    fi
else
    LIST_PKGS=`ls /$ROOT/var/log/packages/ 2> /dev/null`
fi

LIST_PKGS="`slash $LIST_PKGS`"

case $1 in
    "-h"|"--help")
        usage
    ;;
    "-v"|"--view")
        if [ ! -z "$2" ]; then
            if [ ! -z "$LIST_PKGS" ]; then
                for file in $LIST_PKGS; do
                    less $file
                done
            else
                if [ ! -z "$ROOT" ]; then
                    echo "$2: package not found on /$ROOT/var/log/packages"
                else
                    echo "$2: package not found on /var/log/packages"
                fi
            fi
        else
            head_line
            exit 1
        fi
    ;;
    "-p"|"--print")
        if [ -f "$2" ]; then
            tar ztvf $2
        else
            echo $2: file not found
        fi
    ;;
    "-r"|"--remove")
        if [ ! -z "$2" ]; then
            if [ ! -z "$LIST_PKGS" ]; then
                removepkg /$ROOT/var/log/packages/$1-[0-9]*
            fi
        fi
    ;;
    "-s"|"--search")
        if [ ! -z "$2" ]; then
            eval "grep -l '\/$2$' /$ROOT/var/log/packages/*"
        fi
    ;;
    "-d"|"--description")
        if [ ! -z "$2" ]; then
            for file in $LIST_PKGS; do
                echo -e " Package description for $file:\n"
                sed -n '/^xine-ui:/ { s/xine-ui://; p; }' $file
            done
        else
            head_line
            exit 1
        fi
    ;;
    *)
        if [ ! -z "$LIST_PKGS" ]; then
            echo "$LIST_PKGS"
        else
            if [ ! -z "$ROOT" ]; then
                echo "$2: package not found on /$ROOT/var/log/packages"
            else
                echo "$2: package not found on /var/log/packages"
            fi
        fi
    ;;
esac