Debian Codegraph @

scripts/bin/parse_apt_url_get_rpm.sh

raw symbols SCIP
1 #!/bin/bash
2 # Steven Shiau <steven _at_ clonezilla org>
3 # License: GPL
4 # Description: To parse the /etc/apt/sourcesl.list and get the installed pacakge
5 # Usage: $0 PKGNAME
6 # Ex: $0 glibc
7
8 # Load DRBL setting and functions
9 DRBL_SCRIPT_PATH="${DRBL_SCRIPT_PATH:-/usr/share/drbl}"
10
11 . $DRBL_SCRIPT_PATH/sbin/drbl-conf-functions
12
13 #
14 usage() {
15 echo Usage: $0 [OPTION] PKGNAME
16 echo "OPTION:"
17 echo " -a|--append DIRNAME set the DIRNAME to append in the URL"
18 echo " -r|--arch ARCH set the search CPU type as ARCH (like i586, i686)"
19 echo " -n|--no-specific-ver Do not match the running version."
20 echo Ex: $0 -p RPMS.base -p RPMS.update -r i586 -n glibc
21 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."
22 }
23
24 # option
25 DIRNAME=
26 while [ $# -gt 0 ]; do
27 case "$1" in
28 -a|--append)
29 shift; DIRNAME="$DIRNAME $1"
30 if [ -z "$DIRNAME" ]; then
31 usage >& 2
32 exit 2
33 fi
34 shift;;
35 -r|--arch)
36 shift; arch="$1"
37 if [ -z "$arch" ]; then
38 usage >& 2
39 exit 2
40 fi
41 shift;;
42 -n|--no-specific-ver)
43 specivic_ver="no"
44 shift;;
45 -*) echo "${0}: ${1}: invalid option" >&2
46 usage >& 2
47 exit 2 ;;
48 *) break ;;
49 esac
50 done
51 pkg=$1
52
53 [ -z "$pkg" ] && exit 0
54 [ -z "$arch" ] && exit 0
55
56 if [ "$specivic_ver" = "no" ]; then
57 pkg_ver_filter="grep -iE ^${pkg}-[0-9]+"
58 else
59 pkg_ver="$(rpm -q $pkg 2>/dev/null)"
60 if [ -n "$pkg_ver" ]; then
61 pkg_ver_filter="grep -iE ^$pkg_ver"
62 else
63 exit 2
64 fi
65 fi
66 arch_filter="grep -iE ^.*.${arch}.rpm"
67
68 #
69 for im in $DIRNAME; do
70 # it's like: rpm ftp://ftp.gwdg.de/pub/linux/suse/apt SuSE/9.3-i386 base
71 url=$(grep -E "^[[:space:]]*rpm .* ${im/RPMS./}.*" /etc/apt/sources.list | awk -F" " '{print $2"/"$3}')
72 for iurl in $url; do
73 pkg_rpm="$(LC_ALL=C list_available_rpm $iurl/${im} | $pkg_ver_filter | $arch_filter)"
74 if [ -n "$pkg_rpm" ];then
75 echo "$iurl/${im}/$pkg_rpm"
76 break
77 fi
78 done
79 [ -n "$pkg_rpm" ] && break
80 done