Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(518)

Side by Side Diff: list_installed_packages.sh

Issue 6287010: crosutils:Remove dead scripts (Closed) Base URL: ssh://git@gitrw.chromium.org:9222/crosutils.git@master
Patch Set: Created 9 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « get_svn_repos.sh ('k') | make_relative_solution » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 #!/bin/bash
2
3 # Copyright (c) 2009 The Chromium OS Authors. All rights reserved.
4 # Use of this source code is governed by a BSD-style license that can be
5 # found in the LICENSE file.
6
7 # Print a list of installed packages
8 #
9 # This list is used by make_local_repo.sh to construct a local repository
10 # with only those packages.
11 #
12 # Usage:
13 # list_installed_packages.sh > package_list.txt
14
15 # Die on error
16 set -e
17
18 USAGE='usage: '"$0"' [options]
19
20 options:
21 -v Print verbose output.
22 -? Print this help.
23 '
24
25 # Handle command line options.
26 # Note: Can't use shflags, since this must run inside the rootfs image.
27 VERBOSE=0
28 # Option processing using getopts
29 while getopts "v?" OPTVAR
30 do
31 case $OPTVAR in
32 "v")
33 VERBOSE=1
34 ;;
35 "?")
36 echo "$USAGE";
37 exit 1
38 ;;
39 esac
40 done
41 shift `expr $OPTIND - 1`
42
43 # Print information on a single package
44 function print_deb {
45 # Positional parameters from calling script. :? means "fail if unset".
46 DEB_NAME=${1:?}
47
48 # Get the installed version of the package.
49 DEB_VER=`dpkg-query --show -f='${Version}' $DEB_NAME`
50
51 # Get information on package from apt-cache. Use a temporary file since
52 # we need to extract multiple fields.
53 rm -f /tmp/print_deb
54 apt-cache show $DEB_NAME > /tmp/print_deb
55 # The apt cache may have more than one version of the package available.
56 # For example, if the user has added another repository to
57 # /etc/apt/sources.list to install/upgrade packages. Use bash arrays to
58 # hold all the results until we can find information on the version we want.
59 # TODO: Is there a way to do this using only awk, so we can use /bin/sh
60 # instead of /bin/bash?
61 ALL_VER=( `grep '^Version: ' < /tmp/print_deb | awk '{print $2}'` )
62 ALL_PRIO=( `grep '^Priority: ' < /tmp/print_deb | awk '{print $2}'` )
63 ALL_SECTION=( `grep '^Section: ' < /tmp/print_deb | awk '{print $2}'` )
64 ALL_FILENAME=( `grep '^Filename: ' < /tmp/print_deb | awk '{print $2}'` )
65 rm -f /tmp/print_deb
66
67 # Find only the package version the user has installed.
68 NUM_VER=${#ALL_VER[@]}
69 FOUND_MATCH=0
70 for ((I=0; I<$NUM_VER; I++));
71 do
72 if [ "${ALL_VER[$I]}" = "$DEB_VER" ]
73 then
74 FOUND_MATCH=1
75 DEB_PRIO="${ALL_PRIO[$I]}"
76 DEB_SECTION="${ALL_SECTION[$I]}"
77 DEB_FILENAME="${ALL_FILENAME[$I]}"
78 fi
79 done
80
81 # Determine if the package filename appears to be from a locally-built
82 # repository (as created in build_image.sh). Use ! to ignore non-zero
83 # exit code, since grep exits 1 if no match.
84 ! DEB_FILENAME_IS_LOCAL=`echo $DEB_FILENAME | grep 'local_packages'`
85
86 if [ $FOUND_MATCH -eq 0 ]
87 then
88 # Can't find information on package in apt cache
89 if [ $VERBOSE -eq 1 ]
90 then
91 echo "Unable to locate package $DEB_NAME version $DEB_VER" 1>&2
92 echo "in apt cache. It may have been installed directly, or the" 1>&2
93 echo "cache has been updated since installation and no longer" 1>&2
94 echo "contains information on that version. Omitting it in the" 1>&2
95 echo "list, since we can't determine where it came from." 1>&2
96 fi
97 echo "# Skipped $DEB_NAME $DEB_VER: not in apt cache"
98 elif [ "x$DEB_FILENAME" = "x" ]
99 then
100 # No filename, so package was installed via dpkg -i.
101 if [ $VERBOSE -eq 1 ]
102 then
103 echo "Package $DEB_NAME appears to have been installed directly" 1>&2
104 echo "(perhaps using 'dpkg -i'). Omitting it in the list, since we" 1>&2
105 echo "can't determine where it came from." 1>&2
106 fi
107 echo "# Skipped $DEB_NAME $DEB_VER: installed directly"
108 elif [ "x$DEB_FILENAME_IS_LOCAL" != "x" ]
109 then
110 # Package was installed from a local_packages directory.
111 # For example, chromeos-wm
112 if [ $VERBOSE -eq 1 ]
113 then
114 echo "Package $DEB_NAME appears to have been installed from a local" 1>&2
115 echo "package repository. Omitting it in the list, since future" 1>&2
116 echo "installs will also need to be local." 1>&2
117 fi
118 echo "# Skipped $DEB_NAME $DEB_VER $DEB_FILENAME: local install"
119 else
120 # Package from external repository.
121 # Don't change the order of these fields; make_local_repo.sh depends
122 # upon this order.
123 echo "$DEB_NAME $DEB_VER $DEB_PRIO $DEB_SECTION $DEB_FILENAME"
124 fi
125 }
126
127 # Header
128 echo "# Copyright (c) 2009 The Chromium Authors. All rights reserved."
129 echo "# Use of this source code is governed by a BSD-style license that can be"
130 echo "# found in the LICENSE file."
131 echo
132 echo "# Package list created by list_installed_packages.sh"
133 echo "# Creation time: `date`"
134 echo "#"
135 echo "# Contents of /etc/apt/sources.list:"
136 cat /etc/apt/sources.list | sed 's/^/# /'
137 echo "#"
138 echo "# package_name version priority section repo_filename"
139
140 # List all installed packages
141 for DEB in `dpkg-query --show -f='${Package}\n'`
142 do
143 print_deb $DEB
144 done
OLDNEW
« no previous file with comments | « get_svn_repos.sh ('k') | make_relative_solution » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698