Magellan Linux

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

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

revision 3096 by niro, Wed Jan 29 12:21:17 2014 UTC revision 3097 by niro, Mon Jun 4 16:59:42 2018 UTC
# Line 26  print_usage() Line 26  print_usage()
26  }  }
27    
28  # default args:  # default args:
29  GET_INVENTORY=false  GET_INVENTORY=0
30  SEARCH_ONLY_PATH=false  SEARCH_ONLY_PATH=0
31  SEARCH_ONLY_CAT=false  SEARCH_ONLY_CAT=0
32  SEARCH_EXACT_FILENAME=false  SEARCH_EXACT_FILENAME=0
33    
34  # no params given, or is only an arg not ar param, exit  # no params given, or is only an arg not ar param, exit
35  if [[ $# -lt 1 ]] || [[ ${1:0:1} != - ]]  if [[ $# -lt 1 ]] || [[ ${1:0:1} != - ]]
# Line 42  fi Line 42  fi
42  for i in $*  for i in $*
43  do  do
44   case $1 in   case $1 in
45   -n) shift; S_PNAME="$1" ;;   -n) shift; S_PNAME="$1"; if [[ -z ${S_PNAME} ]]; then print_usage; exit 1; fi ;;
46   -v) shift; S_PVER="$1" ;;   -v) shift; S_PVER="$1"; if [[ -z ${S_PVER} ]]; then print_usage; exit 1; fi ;;
47   -b) shift; S_PBUILD="$1" ;;   -b) shift; S_PBUILD="$1"; if [[ -z ${S_PBUILD} ]]; then print_usage; exit 1; fi ;;
48   -i) GET_INVENTORY="true" ;;   -i) GET_INVENTORY="1" ;;
49   -f) SEARCH_ONLY_PATH="true"; shift; SEARCH_PATH="$1" ;;   -f) SEARCH_ONLY_PATH="1"; shift; SEARCH_PATH="$1"; if [[ -z ${SEARCH_PATH} ]]; then print_usage; exit 1; fi ;;
50   -e) SEARCH_ONLY_PATH="true"; SEARCH_EXACT_FILENAME="true"; shift; SEARCH_PATH="$1" ;;   -e) SEARCH_ONLY_PATH="1"; SEARCH_EXACT_FILENAME="1"; shift; SEARCH_PATH="$1"; if [[ -z ${SEARCH_PATH} ]]; then print_usage; exit 1; fi  ;;
51   -c) SEARCH_ONLY_CAT="true"; shift; SEARCH_CAT="$1" ;;   -c) SEARCH_ONLY_CAT="1"; shift; SEARCH_CAT="$1"; if [[ -z ${SEARCH_CAT} ]]; then print_usage; exit 1; fi ;;
52   -h) print_usage; exit 0 ;;   -h) print_usage; exit 0 ;;
53   -*) print_usage; exit 1 ;;   -*) print_usage; exit 1 ;;
54   esac   esac
# Line 59  source /etc/mage.rc.global Line 59  source /etc/mage.rc.global
59  source ${MAGERC}  source ${MAGERC}
60  RETVAL=1  RETVAL=1
61    
62  if [[ ${SEARCH_ONLY_PATH} = true ]]  if [[ ${SEARCH_ONLY_PATH} = 1 ]]
63  then  then
64   unset S_PACKAGES   unset S_PACKAGES
65   unset i pkg   unset i pkg
66   if [[ ${SEARCH_EXACT_FILENAME} = true ]]   if [[ ${SEARCH_EXACT_FILENAME} = 1 ]]
67   then   then
68   # fix ++, which gets interpreted as a regex   # fix ++, which gets interpreted as a regex
69   SEARCH_PATH="${SEARCH_PATH//+/\\+}"   SEARCH_PATH="${SEARCH_PATH//+/\\+}"
# Line 97  then Line 97  then
97   exit 0   exit 0
98  fi  fi
99    
100  if [[ ${SEARCH_ONLY_CAT} = true ]]  if [[ ${SEARCH_ONLY_CAT} = 1 ]]
101  then  then
102   # no packages of SEARCH_CAT are installed   # no packages of SEARCH_CAT are installed
103   [[ ! -d ${MROOT}${INSTALLDB}/${SEARCH_CAT} ]] && exit 1   [[ ! -d ${MROOT}${INSTALLDB}/${SEARCH_CAT} ]] && exit 1
104     find ${MROOT}${INSTALLDB}/${SEARCH_CAT} -maxdepth 1 -mindepth 1 -printf "${SEARCH_CAT}/%P\n" | sort
  for i in ${INSTALLDB}/${SEARCH_CAT}/*  
  do  
  # print categorie and pkgname  
  echo "$(basename ${i%/*})/$(basename ${i})"  
  done  
105    
106   exit 0   exit 0
107  fi  fi
108    
109  if [[ ${GET_INVENTORY} = true ]]  # generate multidim array
110    declare -i INSTALL_DATABASE_COUNT=0
111    for line in $(find ${MROOT}${INSTALLDB} -maxdepth 2 -mindepth 2 -printf '%P\n' | sort)
112    do
113     INSTALL_DATABASE_PCAT[${INSTALL_DATABASE_COUNT}]="${line%/*}"
114     pkgname="${line#*/}"
115     INSTALL_DATABASE_PNAME[${INSTALL_DATABASE_COUNT}]="${pkgname%-*-*}"
116     pkgversion="${pkgname//${pkgname%-*-*}-}"
117     INSTALL_DATABASE_PVER[${INSTALL_DATABASE_COUNT}]="${pkgversion%-*}"
118     INSTALL_DATABASE_PBUILD[${INSTALL_DATABASE_COUNT}]="${pkgname##*-}"
119     (( INSTALL_DATABASE_COUNT++ ))
120    done
121    
122    if [[ ${GET_INVENTORY} = 1 ]]
123  then  then
124   for package in $(find ${MROOT}${INSTALLDB} -mindepth 2 -maxdepth 2 -type d -printf "%h,%f\n" | sort)   # build the list first
125     for ((i=0; i<INSTALL_DATABASE_COUNT; i++))
126   do   do
127   pcat="$(basename $(echo ${package} | cut -d, -f1))"   echo "${INSTALL_DATABASE_PCAT[${i}]}/${INSTALL_DATABASE_PNAME[${i}]}-${INSTALL_DATABASE_PVER[${i}]}-${INSTALL_DATABASE_PBUILD[${i}]}"
  pname="$(echo ${package} | cut -d, -f2)"  
  if [[ -z ${invlist} ]]  
  then  
  invlist="${pcat}/${pname}"  
  else  
  invlist="${invlist}  
 ${pcat}/${pname}"  
  fi  
128   done   done
129    
  # now show the list  
  echo "${invlist}"  
130   exit 0   exit 0
131  fi  fi
132    
133  for i in ${MROOT}${INSTALLDB}/*/*  for ((i=0; i<INSTALL_DATABASE_COUNT; i++))
134  do  do
135   INST_PNAME=no   INST_PNAME=0
136   INST_PVER=no   INST_PVER=0
137   INST_PBUILD=no   INST_PBUILD=0
   
  x=$(basename ${i})  
  PNAME=${x%-*-*}  
  PVER=$(echo ${x#${PNAME}-} | cut -d- -f1)  
  PBUILD=$(echo ${x#${PNAME}-} | cut -d- -f2)  
138    
139   if [[ ${PNAME} == ${S_PNAME} ]]   if [[ ${INSTALL_DATABASE_PNAME[${i}]} == ${S_PNAME} ]]
140   then   then
141   INST_PNAME=yes   INST_PNAME=1
142    
143   if [[ -n ${S_PVER} ]]   if [[ -n ${S_PVER} ]]
144   then   then
145   if [[ ${PVER} == ${S_PVER} ]]   if [[ ${INSTALL_DATABASE_PVER[${i}]} == ${S_PVER} ]]
146   then   then
147   INST_PVER=yes   INST_PVER=1
148   fi   fi
149    
150   if [[ -n ${S_PBUILD} ]]   if [[ -n ${S_PBUILD} ]]
151   then   then
152   if [[ ${PBUILD} == ${S_PBUILD} ]]   if [[ ${INSTALL_DATABASE_PBUILD[${i}]} == ${S_PBUILD} ]]
153   then   then
154   INST_PBUILD=yes   INST_PBUILD=1
155   fi   fi
156   fi   fi
157   fi   fi
# Line 165  do Line 159  do
159   # search for pname only   # search for pname only
160   if [[ -n ${S_PNAME} ]] && [[ -z ${S_PVER} ]] && [[ -z ${S_PBUILD} ]]   if [[ -n ${S_PNAME} ]] && [[ -z ${S_PVER} ]] && [[ -z ${S_PBUILD} ]]
161   then   then
162   if [[ ${INST_PNAME} = yes ]]   if [[ ${INST_PNAME} = 1 ]]
163   then   then
164   echo "${S_PNAME} is installed [ ${PNAME}-${PVER}-${PBUILD} ]"   echo "${S_PNAME} is installed [ ${INSTALL_DATABASE_PCAT[${i}]}/${INSTALL_DATABASE_PNAME[${i}]}-${INSTALL_DATABASE_PVER[${i}]}-${INSTALL_DATABASE_PBUILD[${i}]} ]"
165   RETVAL=0   RETVAL=0
166   break   break
167   fi   fi
# Line 176  do Line 170  do
170   # search for pname and pver   # search for pname and pver
171   if [[ -n ${S_PNAME} ]] && [[ -n ${S_PVER} ]] && [[ -z ${S_PBUILD} ]]   if [[ -n ${S_PNAME} ]] && [[ -n ${S_PVER} ]] && [[ -z ${S_PBUILD} ]]
172   then   then
173   if [[ ${INST_PNAME} = yes ]] && [[ ${INST_PVER} = yes ]]   if [[ ${INST_PNAME} = 1 ]] && [[ ${INST_PVER} = 1 ]]
174   then   then
175   echo "${S_PNAME}-${S_PVER} is installed [ ${PNAME}-${PVER}-${PBUILD} ]"   echo "${S_PNAME}-${S_PVER} is installed [ ${INSTALL_DATABASE_PCAT[${i}]}/${INSTALL_DATABASE_PNAME[${i}]}-${INSTALL_DATABASE_PVER[${i}]}-${INSTALL_DATABASE_PBUILD[${i}]} ]"
176   RETVAL=0   RETVAL=0
177   break   break
178   fi   fi
# Line 187  do Line 181  do
181   # search for pname, pver and pbuild   # search for pname, pver and pbuild
182   if [[ -n ${S_PNAME} ]] && [[ -n ${S_PVER} ]] && [[ -n ${S_PBUILD} ]]   if [[ -n ${S_PNAME} ]] && [[ -n ${S_PVER} ]] && [[ -n ${S_PBUILD} ]]
183   then   then
184   if [[ ${INST_PNAME} = yes ]] && [[ ${INST_PVER} = yes ]] && [[ ${INST_PBUILD} = yes ]]   if [[ ${INST_PNAME} = 1 ]] && [[ ${INST_PVER} = 1 ]] && [[ ${INST_PBUILD} = 1 ]]
185   then   then
186   echo "${S_PNAME}-${S_PVER}-${S_PBUILD} is installed [ ${PNAME}-${PVER}-${PBUILD} ]"   echo "${S_PNAME}-${S_PVER}-${S_PBUILD} is installed [ ${INSTALL_DATABASE_PCAT[${i}]}/${INSTALL_DATABASE_PNAME[${i}]}-${INSTALL_DATABASE_PVER[${i}]}-${INSTALL_DATABASE_PBUILD[${i}]} ]"
187   RETVAL=0   RETVAL=0
188   break   break
189   fi   fi

Legend:
Removed from v.3096  
changed lines
  Added in v.3097