File: parse_apt_url_get_rpm.sh

package info (click to toggle)
drbl 5.8.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 6,996 kB
  • sloc: sh: 43,555; perl: 8,820; xml: 867; makefile: 135
file content (80 lines) | stat: -rwxr-xr-x 2,090 bytes parent folder | download | duplicates (4)
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
#!/bin/bash
# Steven Shiau <steven _at_ clonezilla org>
# License: GPL
# Description: To parse the /etc/apt/sourcesl.list and get the installed pacakge
# Usage: $0 PKGNAME
# Ex: $0 glibc

# Load DRBL setting and functions
DRBL_SCRIPT_PATH="${DRBL_SCRIPT_PATH:-/usr/share/drbl}"

. $DRBL_SCRIPT_PATH/sbin/drbl-conf-functions

#
usage() {
 echo Usage: $0 [OPTION] PKGNAME
 echo "OPTION:"
 echo " -a|--append DIRNAME  set the DIRNAME to append in the URL"
 echo " -r|--arch ARCH  set the search CPU type as ARCH (like i586, i686)"
 echo " -n|--no-specific-ver Do not match the running version."
 echo Ex: $0 -p RPMS.base -p RPMS.update -r i586 -n glibc
 echo "This will try to search the URL found in /etc/apt/sources.list with URL/RPMS.base and URL/RPMS.update, and the version no. is not important."
}

# option
DIRNAME=
while [ $# -gt 0 ]; do
  case "$1" in
    -a|--append)
            shift; DIRNAME="$DIRNAME $1"
	    if [ -z "$DIRNAME" ]; then
              usage >& 2
              exit 2
	    fi
	    shift;;
    -r|--arch)
            shift; arch="$1"
	    if [ -z "$arch" ]; then
              usage >& 2
              exit 2
	    fi
	    shift;;
    -n|--no-specific-ver)
            specivic_ver="no"
	    shift;;
    -*)	    echo "${0}: ${1}: invalid option" >&2
	    usage >& 2
	    exit 2 ;;
    *)	    break ;;
  esac
done
pkg=$1

[ -z "$pkg" ] && exit 0
[ -z "$arch" ] && exit 0

if [ "$specivic_ver" = "no" ]; then
  pkg_ver_filter="grep -iE ^${pkg}-[0-9]+"
else
  pkg_ver="$(rpm -q $pkg 2>/dev/null)"
  if [ -n "$pkg_ver" ]; then
   pkg_ver_filter="grep -iE ^$pkg_ver"
  else
   exit 2
  fi
fi
arch_filter="grep -iE ^.*.${arch}.rpm"

#
for im in $DIRNAME; do
  # it's like: rpm ftp://ftp.gwdg.de/pub/linux/suse/apt SuSE/9.3-i386 base
  url=$(grep -E "^[[:space:]]*rpm .* ${im/RPMS./}.*" /etc/apt/sources.list | awk -F" " '{print $2"/"$3}')
  for iurl in $url; do
   pkg_rpm="$(LC_ALL=C list_available_rpm $iurl/${im} | $pkg_ver_filter | $arch_filter)"
   if [ -n "$pkg_rpm" ];then
     echo "$iurl/${im}/$pkg_rpm"
     break
   fi
  done
   [ -n "$pkg_rpm" ] && break
done