- initial import of revision 374 from cnc
[apt.git] / contrib / apt-wrapper / apt
1 #!/bin/sh\r
2 ##################################################################\r
3 #\r
4 # Copyright (C) 2003 R Bos\r
5 #\r
6 # File:           $RCSfile: apt,v $\r
7 # Revision:       $Revision: 1.20 $\r
8 # Last change:    $Date: 2004/06/24 19:48:38 $\r
9 #\r
10 # Send suggestions to: apt4rpm-devel@lists.sourceforge.net\r
11 # Homepage: http://apt4rpm.sourceforge.net\r
12 #\r
13 # This program is free software; you can redistribute it and/or\r
14 # modify it under the terms of the GNU General Public License\r
15 # as published by the Free Software Foundation; either version 2\r
16 # of the License, or (at your option) any later version.\r
17 #\r
18 # This program is distributed in the hope that it will be useful,\r
19 # but WITHOUT ANY WARRANTY; without even the implied warranty of\r
20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
21 # GNU General Public License for more details.\r
22 #\r
23 # For a copy of the GNU General Public License, visit\r
24 # http://www.gnu.org or write to the Free Software Foundation, Inc.,\r
25 # 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.\r
26 #\r
27 ##################################################################\r
28 \r
29 # It should be possible to show the user which application apt (this tool)\r
30 # is dispatching.  It can't be done via a command line option as the\r
31 # options are passed on to the dispatched application.  Therefor an environment\r
32 # variable is used.  Export APT_VERBOSE in your environment and set it to\r
33 # anything, e.g. APT_VERBOSE=1, APT_VERBOSE=true, etc.  Apt will than show\r
34 # the application that is being dispatched.\r
35 [ -z "$APT_VERBOSE" ] && APT_VERBOSE=no\r
36 \r
37 function usage\r
38 {\r
39         ( echo "$SHORTHELP"\r
40           echo "Use man $PRGNAME for extended help."\r
41         ) >&2\r
42 }\r
43 \r
44 ARGV="$@"\r
45 \r
46 PRGNAME=$(basename $0)\r
47 \r
48 readonly SHORTHELP="Usage: $PRGNAME [options] [apt-rpm options] <action> [packages]"\r
49 \r
50 while [ $# -gt 0 ]; do\r
51         case $1 in\r
52         shell|dump)\r
53                 APTCMD=apt-config\r
54                 break\r
55                 ;;\r
56 \r
57         update|upgrade|install|remove|dist-upgrade|\\r
58           build-dep|clean|autoclean|check|source|moo|script|reinstall|\\r
59           groupinstall|groupremove)\r
60                 APTCMD=apt-get\r
61                 break\r
62                 ;;\r
63 \r
64         add|ident)\r
65                 APTCMD=apt-cdrom\r
66                 break\r
67                 ;;\r
68 \r
69         add|gencaches|showsrc|showpkg|stats|dump|dumpavail|\\r
70           unmet|search|depends|whatdepends|dotty|show|pkgnames|policy|\\r
71           rdepends|xvcg|showgroup|groupnames)\r
72                 APTCMD="apt-cache"\r
73                 break\r
74                 ;;\r
75 \r
76         query)\r
77                 APTCMD=query\r
78                 break\r
79                 ;;\r
80 \r
81         querytags)\r
82                 APTCMD=querytags\r
83                 break\r
84                 ;;\r
85 \r
86         list-extras)\r
87                 APTCMD=list-extras\r
88                 break\r
89                 ;;\r
90 \r
91         list-nodeps)\r
92                 APTCMD=list-nodeps\r
93                 break\r
94                 ;;\r
95 \r
96         -h|--h|--he|--hel|--help)\r
97                 APTCMD=usage\r
98                 ;;\r
99 \r
100         -v|--v|--ve|--ver|--vers|--versi|--version)\r
101                 APTCMD=version\r
102 \r
103                 # Workaround.  apt-config and apt-cache execute the command\r
104                 # instead of showing the version information only.\r
105                 DISPLAY_VERSION=yes\r
106                 ;;\r
107         esac\r
108 \r
109         shift\r
110 done\r
111 \r
112 set -- $ARGV\r
113 \r
114 if [ -z "$APTCMD" ]; then\r
115 \r
116         if [ $# -ne 0 ]; then\r
117                 echo "$PRGNAME: error: no or unrecognized action provided" >&2\r
118         fi\r
119         usage\r
120         exit 100\r
121 fi\r
122 \r
123 case $APTCMD in\r
124 \r
125 apt-get)\r
126 \r
127         # Command line argument parsing, the allowed arguments (for apt-get) are\r
128         # alphabetically listed, keep it this way please.\r
129         APTOPT="arch-only,assume-yes,build,compile,config-file:"\r
130         APTOPT="$APTOPT,default-release,diff-only,download-only,dry-run,fix-broken"\r
131         APTOPT="$APTOPT,fix-missing,force-yes,help,ignore-hold,ignore-missing"\r
132         APTOPT="$APTOPT,just-print,list-cleanup,no-act,no-download,no-list-cleanup"\r
133         APTOPT="$APTOPT,no-remove,no-upgrade,only-source,option:,print-uris,purge"\r
134         APTOPT="$APTOPT,quiet,recon,reinstall,remove,show-upgraded,simulate,tar-only"\r
135         APTOPT="$APTOPT,target-release,trivial-only,version,yes"\r
136         \r
137         # Additional options, provided by this tool\r
138         ADDOPT="checksig,force-rpm,hold:,sourceslist:,no-checksig,no-postscript,postscript"\r
139         ADDOPT="$ADDOPT,show-rpm-command,test"\r
140 \r
141         # Note that we use `"$@"' to let each command-line parameter expand to a\r
142         # separate word. The quotes around `$@' are essential!\r
143         # We need TEMP as the `eval set --' would nuke the return value of getopt.\r
144         TEMP=$(getopt --options=bc:dDfhmo:qstuvy --long $ADDOPT,$APTOPT -n $PRGNAME -- "$@")\r
145         if [ $? -ne 0 ]; then\r
146           echo "Terminating..." >&2\r
147           exit 100\r
148         fi\r
149         \r
150         # Note the quotes around `$TEMP': they are essential!\r
151         eval set -- "$TEMP"\r
152         \r
153         while true\r
154         do\r
155                 case $1 in\r
156                 --arch-only)            ARG="$ARG $1";;\r
157                 --assume-yes)           ARG="$ARG $1";;\r
158                 --build|-b)             ARG="$ARG $1";;\r
159                 --checksig)             ARG="-o RPM::GPG-Check=true $ARG";;\r
160                 --compile)              ARG="$ARG $1";;\r
161                 --config-file|-c)       ARG="$ARG $1 $2"; shift;;\r
162                  -D)                    ARG="$ARG $1";;\r
163                 --default-release)      ARG="$ARG $1";;\r
164                 --diff-only)            ARG="$ARG $1";;\r
165                 --download-only|-d)     ARG="$ARG $1";;\r
166                 --dry-run)              ARG="$ARG $1";;\r
167                 --fix-broken|-f)        APT_FIXBROKEN=yes;;\r
168                 --fix-missing|-m)       ARG="$ARG $1";;\r
169                 --force-rpm)            ARG="-o rpm::Install-Options::=--force $ARG";;\r
170                 --force-yes)            ARG="$ARG $1";;\r
171                 --help|-h)              ARG="$ARG $1";;\r
172                 --hold)                 ARG="$ARG -o rpm::hold::=$2"; shift;;\r
173                 --ignore-hold)          ARG="$ARG $1";;\r
174                 --ignore-missing)       ARG="$ARG $1";;\r
175                 --just-print)           ARG="$ARG $1";;\r
176                 --list-cleanup)         ARG="$ARG $1";;\r
177                 --no-act)               ARG="$ARG $1";;\r
178                 --no-checksig)          ARG="-o RPM::GPG-Check=no $ARG";;\r
179                 --no-download)          ARG="$ARG $1";;\r
180                 --no-list-cleanup)      ARG="$ARG $1";;\r
181                 --no-remove)            ARG="$ARG $1";;\r
182                 --no-postscript)        ARG="-o Scripts::Options::RunPostScript=false $ARG";;\r
183                 --only-source)          ARG="$ARG $1";;\r
184                 --option|-o)            ARG="$ARG $1 $2"; shift;;\r
185                 --postscript)           ARG="-o Scripts::Options::RunPostScript=true $ARG";;\r
186                 --print-uris)           ARG="$ARG $1";;\r
187                 --purge)                ARG="$ARG $1";;\r
188                 --quiet|-q)             ARG="$ARG $1";;\r
189                 --recon)                ARG="$ARG $1";;\r
190                 --reinstall)            ARG="$ARG $1";;\r
191                 --remove)               ARG="$ARG $1";;\r
192                 --show-rpm-command)     RPM_SHOW_CMD=yes;;\r
193                 --show-upgraded)        ARG="$ARG $1";;\r
194                 --simulate|-s)          ARG="$ARG $1";;\r
195                 --sourceslist)          RPM_SRC_LIST=$2; shift;;\r
196                 --tar-only)             ARG="$ARG $1";;\r
197                 --target-release|-t)    ARG="$ARG $1";;\r
198                 --test)                 ARG="-o rpm::options::=--test $ARG";;\r
199                 --trivial-only)         ARG="$ARG $1";;\r
200                 --version|-v)           ARG="$ARG $1";;\r
201                 --yes|-y)               ARG="$ARG $1";;\r
202                 --)                     shift; ARG="$ARG $@"; break;;\r
203                 *)                      echo "unknow argument \"$1\""; exit 100;;\r
204                 esac\r
205                 shift\r
206         done\r
207         \r
208         if [ -n "$RPM_SHOW_CMD" ]; then\r
209 \r
210                 RPM_CMD=/usr/lib/apt/show_rpm_cmd\r
211                 if [ ! -x $RPM_CMD ]; then\r
212 \r
213                         if [ ! -f $RPM_CMD ]; then\r
214 \r
215                                 if [ $(id -u) -eq 0 ]; then\r
216 \r
217                                         # It's dirty to do this, using hardcoded\r
218                                         # path and creating an executable on\r
219                                         # the fly...\r
220                                         echo "echo rpm \$@" > $RPM_CMD\r
221                                         chmod +x $RPM_CMD\r
222                                 else\r
223                                         echo "$PRGNAME: error: you need to be root" >&2\r
224                                         exit 100\r
225                                 fi\r
226                         else\r
227                                 ( echo -n "$PRGNAME: error: the file $RPM_CMD "\r
228                                   echo "must be executable for the option:"\r
229                                   echo "--show-rpm-cmd"\r
230                                 ) >&2\r
231 \r
232                                 exit 100\r
233                         fi\r
234                 fi\r
235 \r
236                 # It might be possible to use -o Debug::pkgRPMPM=true, but\r
237                 # a trial with that, did not show the rpm -Uvh command while\r
238                 # performing a dist-upgrade involving the removal and installation\r
239                 # of packages.\r
240                 ARG="-o RPM::PM=external -o Dir::Bin::rpm=$RPM_CMD $ARG"\r
241                 ARG="$ARG -o Scripts::Options::ShowRpmCmd=true"\r
242         fi\r
243 \r
244         if [ -n "$RPM_SRC_LIST" ]; then\r
245 \r
246                 eval $(apt-config shell ROOT Dir DIR Dir::Etc)\r
247                 if [ -f $ROOT$DIR$RPM_SRC_LIST ]; then\r
248                         ARG="-o dir::etc::sourcelist=$RPM_SRC_LIST $ARG"\r
249                 else\r
250                         echo "error: the provided sourceslist file does not exist" >&2\r
251                         exit 100\r
252                 fi\r
253         fi\r
254         \r
255         if [ "$APT_FIXBROKEN" == "yes" ]; then\r
256           echo "warning: the argument --fix-broken (-f) is not needed normally."\r
257           echo "If you want to use this apt argument, use apt-get directly."\r
258           exit 100\r
259         fi\r
260         \r
261         if [ "$APT_VERBOSE" != "no" ]; then\r
262                 ( echo "$PRGNAME dispatching: apt-get $ARG" | tr -s " "\r
263                   echo\r
264                 ) >&2\r
265         fi\r
266 \r
267         apt-get $ARG\r
268         ;;\r
269 \r
270 apt-config)\r
271 \r
272         if [ "$APT_VERBOSE" != "no" ]; then\r
273                 ( echo "$PRGNAME dispatching: apt-config $ARGV" | tr -s " "\r
274                   echo\r
275                 ) >&2\r
276         fi\r
277         # Workaround.  apt-config executes the action instead of showing\r
278         # the version information only.\r
279         # e.g. apt-config --version dump, in this example "dump" is the\r
280         # command/action.\r
281         if [ "$DISPLAY_VERSION" == "yes" ]; then\r
282                 apt-config --version\r
283         else\r
284                 apt-config $ARGV\r
285         fi\r
286         ;;\r
287 \r
288 apt-cache)\r
289 \r
290         if [ "$APT_VERBOSE" != "no" ]; then\r
291                 ( echo "$PRGNAME dispatching: apt-cache $ARGV" | tr -s " "\r
292                   echo\r
293                 ) >&2\r
294         fi\r
295 \r
296         # Workaround.  apt-cache executes the action instead of showing\r
297         # the version information only.\r
298         # e.g. apt-cache --version show, in this example "show" is the\r
299         # command/action.\r
300         if [ "$DISPLAY_VERSION" == "yes" ]; then\r
301                 apt-cache --version\r
302         else\r
303                 apt-cache $ARGV\r
304         fi\r
305         ;;\r
306 \r
307 apt-cdrom)\r
308 \r
309         if [ "$APT_VERBOSE" != "no" ]; then\r
310                 ( echo "$PRGNAME dispatching: apt-cdrom $ARGV" | tr -s " "\r
311                   echo\r
312                 ) >&2\r
313         fi\r
314         apt-cdrom $ARGV\r
315         ;;\r
316 \r
317 list-extras)\r
318         # Like yum's list extras functionality.  As discussed on:\r
319         # http://lwn.net/Articles/60650/\r
320         apt-cache list-extras\r
321         ;;\r
322 \r
323 list-nodeps)\r
324         apt-cache list-nodeps\r
325         ;;\r
326 \r
327 query)\r
328         while [ $# -gt 0 ]; do\r
329                 case $1 in\r
330                 -a|--all)\r
331                         RPM_ARG_ALL=yes\r
332                         ;;\r
333                 -q|query)\r
334                         # -q is supported for rpm users that\r
335                         # have the habit to execute rpm -q...\r
336                         ;;\r
337                 -*)\r
338                         # The user provided e.g. -i or -l as rpm query argument\r
339                         RPM_OPT="yes"\r
340                         break\r
341                         ;;\r
342                 *)\r
343                         if [ -z "$QRYSTR" ]; then\r
344                                 QRYSTR=$1\r
345                         else\r
346                                 QRYSTR="$QRYSTR|$1"\r
347                         fi\r
348                         ;;\r
349                 esac\r
350 \r
351                 shift\r
352         done\r
353 \r
354         if [ "$RPM_OPT" == "yes" ]; then\r
355 \r
356                 if [ "$APT_VERBOSE" != "no" ]; then\r
357                         ( echo "$PRGNAME dispatching: rpm -q $(echo $ARGV |\r
358                            sed s/query//)" | tr -s " "\r
359                           echo\r
360                         ) >&2\r
361                 fi\r
362                 rpm -q $(echo $ARGV | sed s/query//)\r
363         else\r
364 \r
365                 if [ "$RPM_ARG_ALL" == "yes" ]; then\r
366 \r
367                         if [ "$APT_VERBOSE" != "no" ]; then\r
368                                 ( echo "$PRGNAME dispatching: rpm -qa |\r
369                                     grep -E ${QRYSTR:-^}" | tr -s " "\r
370                                   echo\r
371                                 ) >&2\r
372                         fi\r
373                         rpm -qa | grep -Ei -- ${QRYSTR:-^} | sort\r
374                 else\r
375                         if [ "$APT_VERBOSE" != "no" ]; then\r
376                                 ( echo -n "$PRGNAME dispatching: rpm -q"\r
377                                   echo "$(echo $ARGV | sed s/query//)" | tr -s " "\r
378                                   echo\r
379                                 ) >&2\r
380                         fi\r
381                         rpm -q $(echo $ARGV | sed s/query//)\r
382                 fi\r
383         fi\r
384         ;;\r
385 \r
386 querytags)\r
387 \r
388         if [ "$APT_VERBOSE" != "no" ]; then\r
389                 ( echo "$PRGNAME dispatching: rpm --querytags"\r
390                   echo\r
391                 ) >&2\r
392         fi\r
393         rpm --querytags\r
394         ;;\r
395 usage)\r
396         usage\r
397         ;;\r
398 version)\r
399         echo "The version of this wrapper around the apt tools is: 0.22"\r
400         echo\r
401         echo "The version of the apt tools is:"\r
402         apt-cdrom -v\r
403         ;;\r
404 esac\r
405 \r