Magellan Linux

Diff of /branches/mage-next/src/magequery.in

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 60 by niro, Tue Feb 15 22:59:14 2005 UTC revision 1288 by niro, Thu May 12 21:28:23 2011 UTC
# Line 1  Line 1 
1  #!/bin/bash  #!/bin/bash
2    
3  #query mage database for installed packages  #query mage database for installed packages
4  # version: 0.3.6-r13  # $Header: /home/cvsd/magellan-cvs/magellan-src/mage/usr/lib/mage/magequery.sh,v 1.13 2008-10-05 10:33:04 niro Exp $
5    
6  print_usage()  print_usage()
7  {  {
# Line 10  print_usage() Line 10  print_usage()
10   echo "    -n NAME   searches for name NAME"   echo "    -n NAME   searches for name NAME"
11   echo "    -v VER    searches for version VER, needs -n"   echo "    -v VER    searches for version VER, needs -n"
12   echo "    -b BUILD  searches for build number BUILD, needs -n -v"   echo "    -b BUILD  searches for build number BUILD, needs -n -v"
13     echo "    -c CAT    shows all packages of given categorie"
14     echo "    -i        shows an inventory of all installed packages"
15     echo "    -f PATH   searches package names in given path"
16   echo   echo
17   echo " Examples:"   echo " Examples:"
18   echo   echo
# Line 18  print_usage() Line 21  print_usage()
21   echo   echo
22  }  }
23    
24  while getopts "n:v:b:h-" opt ; do  # default args:
25    GET_INVENTORY=false
26    SEARCH_ONLY_PATH=false
27    SEARCH_ONLY_CAT=false
28    
29    while getopts "n:v:b:f:c:hi-" opt
30    do
31   case "${opt}" in   case "${opt}" in
32   n)   n)
33   S_PNAME="${OPTARG}"   S_PNAME="${OPTARG}"
# Line 31  while getopts "n:v:b:h-" opt ; do Line 40  while getopts "n:v:b:h-" opt ; do
40   b)   b)
41   S_PBUILD="${OPTARG}"   S_PBUILD="${OPTARG}"
42   ;;   ;;
43     i)
44     GET_INVENTORY="true"
45     ;;
46     f)
47     SEARCH_ONLY_PATH="true"
48     SEARCH_PATH="${OPTARG}"
49     ;;
50     c)
51     SEARCH_ONLY_CAT="true"
52     SEARCH_CAT="${OPTARG}"
53     ;;
54   h)   h)
55   print_usage   print_usage
56   exit 0   exit 0
# Line 47  while getopts "n:v:b:h-" opt ; do Line 67  while getopts "n:v:b:h-" opt ; do
67  done  done
68  shift $(($OPTIND - 1))  shift $(($OPTIND - 1))
69    
70    source /etc/mage.rc.global
71  source /etc/mage.rc  source /etc/mage.rc
72  RETVAL=1  RETVAL=1
73    
74  for i in ${INSTALLDB}/*/*  if [[ ${SEARCH_ONLY_PATH} = true ]]
75    then
76     unset S_PACKAGES
77     unset i pkg
78     for i in $(fgrep -rl "${SEARCH_PATH}" ${INSTALLDB})
79     do
80     # ignore magefiles!
81     case ${i} in
82     *.mage) continue ;;
83     esac
84    
85     # print categorie and pkgname
86     pkg="$(basename ${i%/*/*})/$(basename ${i%/*})"
87     if [[ -z $(echo ${S_PACKAGES} | grep ${pkg}) ]]
88     then
89     S_PACKAGES="${S_PACKAGES} ${pkg}"
90     fi
91     done
92    
93     # show packages
94     for pkg in ${S_PACKAGES}
95     do
96     echo "${pkg}"
97     done
98    
99     exit 0
100    fi
101    
102    if [[ ${SEARCH_ONLY_CAT} = true ]]
103    then
104     # no packages of SEARCH_CAT are installed
105     [[ ! -d ${MROOT}${INSTALLDB}/${SEARCH_CAT} ]] && exit 1
106    
107     for i in ${INSTALLDB}/${SEARCH_CAT}/*
108     do
109     # print categorie and pkgname
110     echo "$(basename ${i%/*})/$(basename ${i})"
111     done
112    
113     exit 0
114    fi
115    
116    if [[ ${GET_INVENTORY} = true ]]
117    then
118     for package in $(find ${MROOT}${INSTALLDB} -mindepth 2 -maxdepth 2 -type d -printf "%h,%f\n" | sort)
119     do
120     pcat="$(basename $(echo ${package} | cut -d, -f1))"
121     pname="$(echo ${package} | cut -d, -f2)"
122     if [ -z "${invlist}" ]
123     then
124     invlist="${pcat}/${pname}"
125     else
126     invlist="${invlist}
127    ${pcat}/${pname}"
128     fi
129     done
130    
131     # now show the list
132     echo "${invlist}"
133     exit 0
134    fi
135    
136    for i in ${MROOT}${INSTALLDB}/*/*
137  do  do
138   INST_PNAME=no   INST_PNAME=no
139   INST_PVER=no   INST_PVER=no

Legend:
Removed from v.60  
changed lines
  Added in v.1288