3 #-----------------------------------------------------------
4 # A utility for discovering which ArchLinux package contains
5 # a given file. Downloads filelists for all active repos in
6 # pacman.conf; uses mirrors in order according to pacman's
11 # Modified by tuxce.net@gmail.com
12 #-----------------------------------------------------------
14 db
=/var
/lib
/pacman
/filelists
15 pacmanconf
=/etc
/pacman.conf
17 #-----------------------------------------------------------
18 # Print active repos in $pacmanconf.
19 #-----------------------------------------------------------
20 function list_repos
() {
21 sed -n '/REPOSITORIES/,$ s/^\[\(.*\)\]/\1/p' $pacmanconf
24 #-----------------------------------------------------------
25 # Download the filelist for repo $1. Assumes $mirrors
26 # is an array of urls to check for $file.
27 #-----------------------------------------------------------
30 file="${repo}.files.tar.gz"
32 #for mirror in $(eval echo \${$repo[*]})
35 wget
--connect-timeout=15 -P "$db" "$mirror/${file}"
36 [ -e "${db}/${file}" ] && break
40 #-----------------------------------------------------------
41 # Decompress $1 into dir $2.
42 #-----------------------------------------------------------
43 function decompress
() {
48 tar -xzf "${db}/${file}" -C "${db}/${repo}"
52 #-----------------------------------------------------------
53 # Download the filelist for each active repo in
54 # pacman.conf. Try mirrors in order until successful.
55 #-----------------------------------------------------------
57 (LC_ALL
=C pacman
--debug |
grep 'adding new server' \
58 |
sed "s|.*adding new server URL to database '\(.*\)': \(.*\)|\1 \2|g"
59 echo) |
while read repo_cur url
61 [ -z "$repo_ex" ] && repo_ex
=$repo_cur
62 if [ "$repo_ex" != "$repo_cur" ]
64 echo "Fetching filelist for $repo_ex"
65 download
"$repo_ex" "${list[@]}"
66 if [[ $?
== 0 ]]; then
67 decompress
"$file" "$repo_ex"
70 echo "Error: unable to retrieve $file from any mirror."; echo
75 list
=( "${list[@]}" $url )
79 #-----------------------------------------------------------
80 # Print usage message.
81 #-----------------------------------------------------------
83 echo "usage: $(basename $0) [options] [pattern]"
85 echo "Search package filelists for [pattern]."
87 echo " $(basename $0) [-h --help] Print this help message."
88 echo " $(basename $0) [-S --sync] Syncronize package filelists."
91 #-----------------------------------------------------------
93 #-----------------------------------------------------------
96 if [[ $EUID != 0 ]]; then
97 echo "error: you cannot perform this operation unless you are root."
101 echo "Syncronizing ${db}..."; echo
102 rm -rf "$db" && mkdir
-p "$db"
111 if [[ $# < 1 ]]; then
112 echo "not enough parameters"; echo
117 if [[ ! -d "$db" ]]; then
118 echo "File database \"$db\" does not exist!"
119 echo "Have you synchronized the database?"; echo
123 grep -rE "$@" "$db" |
sed "s|$db/\(.*\)/files:|\1 |g"