cornucopia: bump SRCREV
[openembedded.git] / bin / stage-manager-opkg
blob5a2347a5341926b3cdebcf861c6e9bc5a716acfa
1 #!/bin/sh
2 # ipkg - the itsy package management system
4 # Copyright (C) 2001 Carl D. Worth
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2, or (at your option)
9 # any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 set -e
18 # Uncomment for debugging
19 #set -x
21 # By default do not do globbing. Any command wanting globbing should
22 # explicitly enable it first and disable it afterwards.
23 set -o noglob
25 ipkg_srcs() {
26 local srcre="$1"
27 sed -ne "s/^src[[:space:]]\+$srcre[[:space:]]\+//p" < $IPKG_CONF
30 ipkg_src_names() {
31 sed -ne "s/^src[[:space:]]\+\([^[:space:]]\+\).*/\1/p" < $IPKG_CONF
34 ipkg_src_byname() {
35 local src="$1"
36 ipkg_srcs $src | head -n1
39 ipkg_dests() {
40 local destre=`echo $1 | ipkg_protect_slashes`
41 sed -ne "/^dest[[:space:]]\+$destre/{
42 s/^dest[[:space:]]\+[^[:space:]]\+[[:space:]]\+//
43 s/^/`echo $IPKG_OFFLINE_ROOT | ipkg_protect_slashes`/
45 }" < $IPKG_CONF
48 ipkg_dest_names() {
49 sed -ne "s/^dest[[:space:]]\+\([^[:space:]]\+\).*/\1/p" < $IPKG_CONF
52 ipkg_dests_all() {
53 ipkg_dests '.*'
56 ipkg_state_dirs() {
57 ipkg_dests_all | sed "s|\$|/$IPKG_DIR_PREFIX|"
60 ipkg_dest_default() {
61 ipkg_dests_all | head -n1
64 ipkg_dest_default_name() {
65 ipkg_dest_names | head -n1
68 ipkg_dest_byname() {
69 local dest="$1"
70 ipkg_dests $dest | head -n1
73 ipkg_option() {
74 local option="$1"
75 sed -ne "s/^option[[:space:]]\+$option[[:space:]]\+//p" < $IPKG_CONF
78 ipkg_load_configuration() {
79 if [ -z "$IPKG_CONF_DIR" ]; then
80 IPKG_CONF_DIR=/etc
83 if [ -z "$IPKG_CONF" ]; then
84 IPKG_CONF=$IPKG_CONF_DIR/ipkg.conf
87 if [ -z "$IPKG_OFFLINE_ROOT" ]; then
88 IPKG_OFFLINE_ROOT=`ipkg_option offline_root`
90 # Export IPKG_OFFLINE_ROOT for use by update-alternatives
91 export IPKG_OFFLINE_ROOT
92 if [ -n "$DEST_NAME" ]; then
93 IPKG_ROOT=`ipkg_dest_byname $DEST_NAME`
94 if [ -z "$IPKG_ROOT" ]; then
95 if [ -d "$IPKG_OFFLINE_ROOT$DEST_NAME" ]; then
96 IPKG_ROOT="$IPKG_OFFLINE_ROOT$DEST_NAME";
97 else
98 echo "ipkg: invalid destination specification: $DEST_NAME
99 Valid destinations are directories or one of the dest names from $IPKG_CONF:" >&2
100 ipkg_dest_names >&2
101 return 1
104 else
105 IPKG_ROOT=`ipkg_dest_default`
108 # Global ipkg state directories
109 IPKG_DIR_PREFIX=usr/lib/ipkg
110 IPKG_LISTS_DIR=$IPKG_OFFLINE_ROOT/$IPKG_DIR_PREFIX/lists
111 IPKG_PENDING_DIR=$IPKG_OFFLINE_ROOT/$IPKG_DIR_PREFIX/pending
113 # test for bsd mktemp and pass -t <prefix> when needed
114 if (mktemp -V) ; then
115 IPKG_TMP=`mktemp -d`
116 else
117 IPKG_TMP=`mktemp -d -t ipkg`
120 if [ ! -d "$IPKG_TMP" ]; then
121 echo "Error, could not create a temp directory"
122 return 1
125 # Destination specific ipkg meta-data directory
126 IPKG_STATE_DIR=$IPKG_ROOT/$IPKG_DIR_PREFIX
128 # Proxy Support
129 IPKG_PROXY_USERNAME=`ipkg_option proxy_username`
130 IPKG_PROXY_PASSWORD=`ipkg_option proxy_password`
131 IPKG_HTTP_PROXY=`ipkg_option http_proxy`
132 IPKG_FTP_PROXY=`ipkg_option ftp_proxy`
133 IPKG_NO_PROXY=`ipkg_option no_proxy`
134 if [ -n "$IPKG_HTTP_PROXY" ]; then
135 export http_proxy="$IPKG_HTTP_PROXY"
138 if [ -n "$IPKG_FTP_PROXY" ]; then
139 export ftp_proxy="$IPKG_FTP_PROXY"
142 if [ -n "$IPKG_NO_PROXY" ]; then
143 export no_proxy="$IPKG_NO_PROXY"
146 IPKG_STATUS_FIELDS='\(Package\|Status\|Essential\|Version\|Conffiles\|Root\)'
149 ipkg_usage() {
150 [ $# -gt 0 ] && echo "ipkg: $*"
151 echo "
152 usage: ipkg [options...] sub-command [arguments...]
153 where sub-command is one of:
155 Package Manipulation:
156 update Update list of available packages
157 upgrade Upgrade all installed packages to latest version
158 install <pkg> Download and install <pkg> (and dependencies)
159 install <file.ipk> Install package <file.ipk>
160 install <file.deb> Install package <file.deb>
161 remove <pkg> Remove package <pkg>
163 Informational Commands:
164 list List available packages and descriptions
165 files <pkg> List all files belonging to <pkg>
166 search <file> Search for a packaging providing <file>
167 info [pkg [<field>]] Display all/some info fields for <pkg> or all
168 status [pkg [<field>]] Display all/some status fields for <pkg> or all
169 depends <pkg> Print uninstalled package dependencies for <pkg>
171 Options:
172 -d <dest_name> Use <dest_name> as the the root directory for
173 -dest <dest_name> package installation, removal, upgrading.
174 <dest_name> should be a defined dest name from the
175 configuration file, (but can also be a directory
176 name in a pinch).
177 -o <offline_root> Use <offline_root> as the root for offline installation.
178 -offline <offline_root>
180 Force Options (use when ipkg is too smart for its own good):
181 -force-depends Make dependency checks warnings instead of errors
182 -force-defaults Use default options for questions asked by ipkg.
183 (no prompts). Note that this will not prevent
184 package installation scripts from prompting.
185 " >&2
186 exit 1
189 ipkg_dir_part() {
190 local dir=`echo $1 | sed -ne 's/\(.*\/\).*/\1/p'`
191 if [ -z "$dir" ]; then
192 dir="./"
194 echo $dir
197 ipkg_file_part() {
198 echo $1 | sed 's/.*\///'
201 ipkg_protect_slashes() {
202 sed -e 's/\//\\\//g'
205 ipkg_download() {
206 local src="$1"
207 local dest="$2"
209 local src_file=`ipkg_file_part $src`
210 local dest_dir=`ipkg_dir_part $dest`
211 if [ -z "$dest_dir" ]; then
212 dest_dir="$IPKG_TMP"
215 local dest_file=`ipkg_file_part $dest`
216 if [ -z "$dest_file" ]; then
217 dest_file="$src_file"
220 # Proxy support
221 local proxyuser=""
222 local proxypassword=""
223 local proxyoption=""
225 if [ -n "$IPKG_PROXY_USERNAME" ]; then
226 proxyuser="--proxy-user=\"$IPKG_PROXY_USERNAME\""
227 proxypassword="--proxy-passwd=\"$IPKG_PROXY_PASSWORD\""
230 if [ -n "$IPKG_PROXY_HTTP" -o -n "$IPKG_PROXY_FTP" ]; then
231 proxyoption="--proxy=on"
234 echo "Downloading $src ..."
235 rm -f $IPKG_TMP/$src_file
236 case "$src" in
237 http://* | ftp://*)
238 if ! wget --passive-ftp -nd $proxyoption $proxyuser $proxypassword -P $IPKG_TMP $src; then
239 echo "ipkg_download: ERROR: Failed to retrieve $src, returning $err"
240 return 1
242 mv $IPKG_TMP/$src_file $dest_dir/$dest_file 2>/dev/null
244 file:/* )
245 ln -s `echo $src | sed 's/^file://'` $dest_dir/$dest_file 2>/dev/null
248 echo "DEBUG: $src"
250 esac
252 echo "Done."
253 return 0
256 ipkg_update() {
257 if [ ! -e "$IPKG_LISTS_DIR" ]; then
258 mkdir -p $IPKG_LISTS_DIR
261 local err=
262 for src_name in `ipkg_src_names`; do
263 local src=`ipkg_src_byname $src_name`
264 if ! ipkg_download $src/Packages $IPKG_LISTS_DIR/$src_name; then
265 echo "ipkg_update: Error downloading $src/Packages to $IPKG_LISTS_DIR/$src_name" >&2
266 err=t
267 else
268 echo "Updated list of available packages in $IPKG_LISTS_DIR/$src_name"
270 done
272 [ -n "$err" ] && return 1
274 return 0
277 ipkg_list() {
278 for src in `ipkg_src_names`; do
279 if ipkg_require_list $src; then
280 # black magic...
281 sed -ne "
282 /^Package:/{
283 s/^Package:[[:space:]]*\<\([a-z0-9.+-]*$1[a-z0-9.+-]*\).*/\1/
286 /^Description:/{
287 s/^Description:[[:space:]]*\(.*\)/\1/
290 s/\\
291 / - /
294 " $IPKG_LISTS_DIR/$src
296 done
299 ipkg_extract_paragraph() {
300 local pkg="$1"
301 sed -ne "/Package:[[:space:]]*$pkg[[:space:]]*\$/,/^\$/p"
304 ipkg_extract_field() {
305 local field="$1"
306 # blacker magic...
307 sed -ne "
308 : TOP
309 /^$field:/{
312 b FIELD
315 : FIELD
316 /^$/b TOP
317 /^[^[:space:]]/b TOP
320 b FIELD
324 ipkg_extract_value() {
325 sed -e "s/^[^:]*:[[:space:]]*//"
328 ipkg_require_list() {
329 [ $# -lt 1 ] && return 1
330 local src="$1"
331 if [ ! -f "$IPKG_LISTS_DIR/$src" ]; then
332 echo "ERROR: File not found: $IPKG_LISTS_DIR/$src" >&2
333 echo " You probably want to run \`ipkg update'" >&2
334 return 1
336 return 0
339 ipkg_info() {
340 for src in `ipkg_src_names`; do
341 if ipkg_require_list $src; then
342 case $# in
344 cat $IPKG_LISTS_DIR/$src
347 ipkg_extract_paragraph $1 < $IPKG_LISTS_DIR/$src
350 ipkg_extract_paragraph $1 < $IPKG_LISTS_DIR/$src | ipkg_extract_field $2
352 esac
354 done
357 ipkg_status_sd() {
358 [ $# -lt 1 ] && return 0
359 sd="$1"
360 shift
361 if [ -f $sd/status ]; then
362 case $# in
364 cat $sd/status
367 ipkg_extract_paragraph $1 < $sd/status
370 ipkg_extract_paragraph $1 < $sd/status | ipkg_extract_field $2
372 esac
374 return 0
377 ipkg_status_all() {
378 for sd in `ipkg_state_dirs`; do
379 ipkg_status_sd $sd $*
380 done
383 ipkg_status() {
384 if [ -n "$DEST_NAME" ]; then
385 ipkg_status_sd $IPKG_STATE_DIR $*
386 else
387 ipkg_status_all $*
391 ipkg_status_matching_sd() {
392 local sd="$1"
393 local re="$2"
394 if [ -f $sd/status ]; then
395 sed -ne "
396 : TOP
397 /^Package:/{
398 s/^Package:[[:space:]]*//
399 s/[[:space:]]*$//
402 /$re/{
405 b NEXT
408 : NEXT
409 /^$/b TOP
411 b NEXT
412 " < $sd/status
414 return 0
417 ipkg_status_matching_all() {
418 for sd in `ipkg_state_dirs`; do
419 ipkg_status_matching_sd $sd $*
420 done
423 ipkg_status_matching() {
424 if [ -n "$DEST_NAME" ]; then
425 ipkg_status_matching_sd $IPKG_STATE_DIR $*
426 else
427 ipkg_status_matching_all $*
431 ipkg_status_installed_sd() {
432 local sd="$1"
433 local pkg="$2"
434 ipkg_status_sd $sd $pkg Status | grep -q "Status: install user installed"
437 ipkg_status_installed_all() {
438 local ret=1
439 for sd in `ipkg_state_dirs`; do
440 if `ipkg_status_installed_sd $sd $*`; then
441 ret=0
443 done
444 return $ret
447 ipkg_status_mentioned_sd() {
448 local sd="$1"
449 local pkg="$2"
450 [ -n "`ipkg_status_sd $sd $pkg Status`" ]
453 ipkg_files() {
454 local pkg="$1"
455 if [ -n "$DEST_NAME" ]; then
456 dests=$IPKG_ROOT
457 else
458 dests=`ipkg_dests_all`
460 for dest in $dests; do
461 if [ -f $dest/$IPKG_DIR_PREFIX/info/$pkg.list ]; then
462 dest_sed=`echo $dest | ipkg_protect_slashes`
463 sed -e "s/^/$dest_sed/" < $dest/$IPKG_DIR_PREFIX/info/$pkg.list
465 done
468 ipkg_search() {
469 local pattern="$1"
471 for dest_name in `ipkg_dest_names`; do
472 dest=`ipkg_dest_byname $dest_name`
473 dest_sed=`echo $dest | ipkg_protect_slashes`
475 set +o noglob
476 local list_files=`ls -1 $dest/$IPKG_DIR_PREFIX/info/*.list 2>/dev/null`
477 set -o noglob
478 for file in $list_files; do
479 if sed "s/^/$dest_sed/" $file | grep -q $pattern; then
480 local pkg=`echo $file | sed "s/^.*\/\(.*\)\.list/\1/"`
481 [ "$dest_name" != `ipkg_dest_default_name` ] && pkg="$pkg ($dest_name)"
482 sed "s/^/$dest_sed/" $file | grep $pattern | sed "s/^/$pkg: /"
484 done
485 done
488 ipkg_status_remove_sd() {
489 local sd="$1"
490 local pkg="$2"
492 if [ ! -f $sd/status ]; then
493 mkdir -p $sd
494 touch $sd/status
496 sed -ne "/Package:[[:space:]]*$pkg[[:space:]]*\$/,/^\$/!p" < $sd/status > $sd/status.new
497 mv $sd/status.new $sd/status
500 ipkg_status_remove_all() {
501 for sd in `ipkg_state_dirs`; do
502 ipkg_status_remove_sd $sd $*
503 done
506 ipkg_status_remove() {
507 if [ -n "$DEST_NAME" ]; then
508 ipkg_status_remove_sd $IPKG_STATE_DIR $*
509 else
510 ipkg_status_remove_all $*
514 ipkg_status_update_sd() {
515 local sd="$1"
516 local pkg="$2"
518 ipkg_status_remove_sd $sd $pkg
519 ipkg_extract_field "$IPKG_STATUS_FIELDS" >> $sd/status
520 echo "" >> $sd/status
523 ipkg_status_update() {
524 ipkg_status_update_sd $IPKG_STATE_DIR $*
527 ipkg_unsatisfied_dependences() {
528 local pkg=$1
529 local deps=`ipkg_get_depends $pkg`
530 local remaining_deps=
531 for dep in $deps; do
532 local installed=`ipkg_get_installed $dep`
533 if [ "$installed" != "installed" ] ; then
534 remaining_deps="$remaining_deps $dep"
536 done
537 ## echo "ipkg_unsatisfied_dependences pkg=$pkg $remaining_deps" > /dev/console
538 echo $remaining_deps
541 ipkg_safe_pkg_name() {
542 local pkg=$1
543 local spkg=`echo pkg_$pkg | sed -e y/-+./___/`
544 echo $spkg
547 ipkg_set_depends() {
548 local pkg=$1; shift
549 local new_deps="$*"
550 pkg=`ipkg_safe_pkg_name $pkg`
551 ## setvar ${pkg}_depends "$new_deps"
552 echo $new_deps > $IPKG_TMP/${pkg}.depends
555 ipkg_get_depends() {
556 local pkg=$1
557 pkg=`ipkg_safe_pkg_name $pkg`
558 cat $IPKG_TMP/${pkg}.depends
559 ## eval "echo \$${pkg}_depends"
562 ipkg_set_installed() {
563 local pkg=$1
564 pkg=`ipkg_safe_pkg_name $pkg`
565 echo installed > $IPKG_TMP/${pkg}.installed
566 ## setvar ${pkg}_installed "installed"
569 ipkg_set_uninstalled() {
570 local pkg=$1
571 pkg=`ipkg_safe_pkg_name $pkg`
572 ### echo ipkg_set_uninstalled $pkg > /dev/console
573 echo uninstalled > $IPKG_TMP/${pkg}.installed
574 ## setvar ${pkg}_installed "uninstalled"
577 ipkg_get_installed() {
578 local pkg=$1
579 pkg=`ipkg_safe_pkg_name $pkg`
580 if [ -f $IPKG_TMP/${pkg}.installed ]; then
581 cat $IPKG_TMP/${pkg}.installed
583 ## eval "echo \$${pkg}_installed"
586 ipkg_depends() {
587 local new_pkgs="$*"
588 local all_deps=
589 local installed_pkgs=`ipkg_status_matching_all 'Status:.*[[:space:]]installed'`
590 for pkg in $installed_pkgs; do
591 ipkg_set_installed $pkg
592 done
593 while [ -n "$new_pkgs" ]; do
594 all_deps="$all_deps $new_pkgs"
595 local new_deps=
596 for pkg in $new_pkgs; do
597 if echo $pkg | grep -q '[^a-z0-9.+-]'; then
598 echo "ipkg_depends: ERROR: Package name $pkg contains illegal characters (should be [a-z0-9.+-])" >&2
599 return 1
601 # TODO: Fix this. For now I am ignoring versions and alternations in dependencies.
602 new_deps="$new_deps "`ipkg_info $pkg '\(Pre-\)\?Depends' | ipkg_extract_value | sed -e 's/([^)]*)//g
603 s/\(|[[:space:]]*[a-z0-9.+-]\+[[:space:]]*\)\+//g
604 s/,/ /g
605 s/ \+/ /g'`
606 ipkg_set_depends $pkg $new_deps
607 done
609 new_deps=`echo $new_deps | sed -e 's/[[:space:]]\+/\\
610 /g' | sort | uniq`
612 local maybe_new_pkgs=
613 for pkg in $new_deps; do
614 if ! echo $installed_pkgs | grep -q "\<$pkg\>"; then
615 maybe_new_pkgs="$maybe_new_pkgs $pkg"
617 done
619 new_pkgs=
620 for pkg in $maybe_new_pkgs; do
621 if ! echo $all_deps | grep -q "\<$pkg\>"; then
622 if [ -z "`ipkg_info $pkg`" ]; then
623 echo "ipkg_depends: Warning: $pkg mentioned in dependency but no package found in $IPKG_LISTS_DIR" >&2
624 ipkg_set_installed $pkg
625 else
626 new_pkgs="$new_pkgs $pkg"
627 ipkg_set_uninstalled $pkg
629 else
630 ipkg_set_uninstalled $pkg
632 done
633 done
635 echo $all_deps
638 ipkg_get_install_dest() {
639 local dest="$1"
640 shift
641 local sd=$dest/$IPKG_DIR_PREFIX
642 local info_dir=$sd/info
644 local requested_pkgs="$*"
645 local pkgs=`ipkg_depends $*`
647 mkdir -p $info_dir
648 for pkg in $pkgs; do
649 if ! ipkg_status_mentioned_sd $sd $pkg; then
650 echo "Package: $pkg
651 Status: install ok not-installed" | ipkg_status_update_sd $sd $pkg
653 done
654 ## mark the packages that we were directly requested to install as uninstalled
655 for pkg in $requested_pkgs; do ipkg_set_uninstalled $pkg; done
657 local new_pkgs=
658 local pkgs_installed=0
659 while [ -n "pkgs" ]; do
660 curcheck=0
661 ## echo "pkgs to install: {$pkgs}" > /dev/console
662 for pkg in $pkgs; do
663 curcheck=`expr $curcheck + 1`
664 local is_installed=`ipkg_get_installed $pkg`
665 if [ "$is_installed" = "installed" ]; then
666 echo "$pkg is installed" > /dev/console
667 continue
670 local remaining_deps=`ipkg_unsatisfied_dependences $pkg`
671 if [ -n "$remaining_deps" ]; then
672 new_pkgs="$new_pkgs $pkg"
673 ### echo "Dependences not satisfied for $pkg: $remaining_deps"
674 if [ $curcheck -ne `echo $pkgs|wc -w` ]; then
675 continue
679 local filename=
680 for src in `ipkg_src_names`; do
681 if ipkg_require_list $src; then
682 filename=`ipkg_extract_paragraph $pkg < $IPKG_LISTS_DIR/$src | ipkg_extract_field Filename | ipkg_extract_value`
683 [ -n "$filename" ] && break
685 done
687 if [ -z "$filename" ]; then
688 echo "ipkg_get_install: ERROR: Cannot find package $pkg in $IPKG_LISTS_DIR"
689 echo "ipkg_get_install: Check the spelling and maybe run \`ipkg update'."
690 ipkg_status_remove_sd $sd $pkg
691 return 1;
694 echo ""
695 local tmp_pkg_file="$IPKG_TMP/"`ipkg_file_part $filename`
696 if ! ipkg_download `ipkg_src_byname $src`/$filename $tmp_pkg_file; then
697 echo "ipkg_get_install: Perhaps you need to run \`ipkg update'?"
698 return 1
701 if ! ipkg_install_file_dest $dest $tmp_pkg_file; then
702 echo "ipkg_get_install: ERROR: Failed to install $tmp_pkg_file"
703 echo "ipkg_get_install: I'll leave it there for you to try a manual installation"
704 return 1
707 ipkg_set_installed $pkg
708 pkgs_installed=`expr $pkgs_installed + 1`
709 rm $tmp_pkg_file
710 done
711 ### echo "Installed $pkgs_installed package(s) this round"
712 if [ $pkgs_installed -eq 0 ]; then
713 if [ -z "$new_pkgs" ]; then
714 break
717 pkgs_installed=0
718 pkgs="$new_pkgs"
719 new_pkgs=
720 curcheck=0
721 done
724 ipkg_get_install() {
725 ipkg_get_install_dest $IPKG_ROOT $*
728 ipkg_install_file_dest() {
729 local dest="$1"
730 local filename="$2"
731 local sd=$dest/$IPKG_DIR_PREFIX
732 local info_dir=$sd/info
734 if [ ! -f "$filename" ]; then
735 echo "ipkg_install_file: ERROR: File $filename not found"
736 return 1
739 local pkg=`ipkg_file_part $filename | sed 's/\([a-z0-9.+-]\+\)_.*/\1/'`
740 local ext=`echo $filename | sed 's/.*\.//'`
741 local pkg_extract_stdout
742 #if [ "$ext" = "ipk" ]; then
743 # pkg_extract_stdout="tar -xzOf"
744 #elif [ "$ext" = "deb" ]; then
745 pkg_extract_stdout="ar p"
746 #else
747 # echo "ipkg_install_file: ERROR: File $filename has unknown extension $ext (not .ipk or .deb)"
748 # return 1
751 # Check dependencies
752 local depends=`ipkg_depends $pkg | sed -e "s/\<$pkg\>//"`
754 # Don't worry about deps that are scheduled for installation
755 local missing_deps=
756 for dep in $depends; do
757 if ! ipkg_status_all $dep | grep -q 'Status:[[:space:]]install'; then
758 missing_deps="$missing_deps $dep"
760 done
762 if [ ! -z "$missing_deps" ]; then
763 if [ -n "$FORCE_DEPENDS" ]; then
764 echo "ipkg_install_file: Warning: $pkg depends on the following uninstalled programs: $missing_deps"
765 else
766 echo "ipkg_install_file: ERROR: $pkg depends on the following uninstalled programs:
767 $missing_deps"
768 echo "ipkg_install_file: You may want to use \`ipkg install' to install these."
769 return 1
773 mkdir -p $IPKG_TMP/$pkg/control
774 mkdir -p $IPKG_TMP/$pkg/data
775 mkdir -p $info_dir
777 # In certain some versions of Ubuntu, or at least Ubuntu 9.10, tar has some
778 # signal handling problems. The symptom is a sigpipe signal to gzip when
779 # using the -z option on tar. Here and in subsequent sections, we get around
780 # this by using temp files instead of the tar -z option or piping straight
781 # from gzip.
783 rm -f $IPKG_TMP/control.tar.gz $IPKG_TMP/control.tar
784 if ! { $pkg_extract_stdout $filename control.tar.gz > $IPKG_TMP/control.tar.gz &&
785 gzip -d $IPKG_TMP/control.tar.gz &&
786 tar -C $IPKG_TMP/$pkg/control -xf $IPKG_TMP/control.tar ; } ; then
787 echo "ipkg_install_file: ERROR unpacking control.tar.gz from $filename"
788 return 1
790 rm -f $IPKG_TMP/control.tar.gz $IPKG_TMP/control.tar
792 if [ -n "$IPKG_OFFLINE_ROOT" ]; then
793 if grep -q '^InstallsOffline:[[:space:]]*no' $IPKG_TMP/$pkg/control/control; then
794 echo "*** Warning: Package $pkg may not be installed in offline mode"
795 echo "*** Warning: Scheduling $filename for pending installation (installing into $IPKG_PENDING_DIR)"
796 echo "Package: $pkg
797 Status: install ok pending" | ipkg_status_update_sd $sd $pkg
798 mkdir -p $IPKG_PENDING_DIR
799 cp $filename $IPKG_PENDING_DIR
800 rm -r $IPKG_TMP/$pkg/control
801 rm -r $IPKG_TMP/$pkg/data
802 rmdir $IPKG_TMP/$pkg
803 return 0
808 echo -n "Unpacking $pkg..."
809 set +o noglob
810 for file in $IPKG_TMP/$pkg/control/*; do
811 local base_file=`ipkg_file_part $file`
812 mv $file $info_dir/$pkg.$base_file
813 done
814 set -o noglob
815 rm -r $IPKG_TMP/$pkg/control
817 rm -f $IPKG_TMP/data.tar.gz $IPKG_TMP/data.tar
818 if ! { $pkg_extract_stdout $filename ./data.tar.gz > $IPKG_TMP/data.tar.gz &&
819 gzip -d $IPKG_TMP/data.tar.gz &&
820 tar -C $IPKG_TMP/$pkg/data -xf $IPKG_TMP/data.tar ; } ; then
821 echo "ipkg_install_file: ERROR unpacking data.tar.gz from $filename"
822 return 1
824 rm -f $IPKG_TMP/data.tar.gz $IPKG_TMP/data.tar
825 echo "Done."
827 echo -n "Configuring $pkg..."
828 export PKG_ROOT=$dest
829 if [ -x "$info_dir/$pkg.preinst" ]; then
830 if ! $info_dir/$pkg.preinst install; then
831 echo "$info_dir/$pkg.preinst failed. Aborting installation of $pkg"
832 rm -rf $IPKG_TMP/$pkg/data
833 rmdir $IPKG_TMP/$pkg
834 return 1
838 local old_conffiles=`ipkg_status_sd $sd $pkg Conffiles | ipkg_extract_value`
839 local new_conffiles=
840 if [ -f "$info_dir/$pkg.conffiles" ]; then
841 for conffile in `cat $info_dir/$pkg.conffiles`; do
842 if [ -f "$dest/$conffile" ] && ! echo " $old_conffiles " | grep -q " $conffile "`md5sum $dest/$conffile | sed 's/ .*//'`; then
843 local use_maintainers_conffile=
844 if [ -z "$FORCE_DEFAULTS" ]; then
845 while true; do
846 echo -n "Configuration file \`$conffile'
847 ==> File on system created by you or by a script.
848 ==> File also in package provided by package maintainer.
849 What would you like to do about it ? Your options are:
850 Y or I : install the package maintainer's version
851 N or O : keep your currently-installed version
852 D : show the differences between the versions (if diff is installed)
853 The default action is to keep your current version.
854 *** `ipkg_file_part $conffile` (Y/I/N/O/D) [default=N] ? "
855 read response
856 case "$response" in
857 [YyIi] | [Yy][Ee][Ss])
858 use_maintainers_conffile=t
859 break
861 [Dd])
862 echo "
863 diff -u $dest/$conffile $IPKG_TMP/$pkg/data/$conffile"
864 diff -u $dest/$conffile $IPKG_TMP/$pkg/data/$conffile || true
865 echo "[Press ENTER to continue]"
866 read junk
869 break
871 esac
872 done
874 if [ -n "$use_maintainers_conffile" ]; then
875 local md5sum=`md5sum $IPKG_TMP/$pkg/data/$conffile | sed 's/ .*//'`
876 new_conffiles="$new_conffiles $conffile $md5sum"
877 else
878 new_conffiles="$new_conffiles $conffile <custom>"
879 rm $IPKG_TMP/$pkg/data/$conffile
881 else
882 md5sum=`md5sum $IPKG_TMP/$pkg/data/$conffile | sed 's/ .*//'`
883 new_conffiles="$new_conffiles $conffile $md5sum"
885 done
888 local owd=`pwd`
889 (cd $IPKG_TMP/$pkg/data/; tar cf - . | (cd $owd; cd $dest; tar xf -))
890 rm -rf $IPKG_TMP/$pkg/data
891 rmdir $IPKG_TMP/$pkg
892 rm -f $IPKG_TMP/data.tar.gz $IPKG_TMP/data.tar
893 $pkg_extract_stdout $filename ./data.tar.gz > $IPKG_TMP/data.tar.gz
894 tar tzf $IPKG_TMP/data.tar.gz | sed -e 's/^\.//' > $info_dir/$pkg.list
895 rm -f $IPKG_TMP/data.tar.gz $IPKG_TMP/data.tar
897 if [ -x "$info_dir/$pkg.postinst" ]; then
898 $info_dir/$pkg.postinst configure
901 if [ -n "$new_conffiles" ]; then
902 new_conffiles='Conffiles: '`echo $new_conffiles | ipkg_protect_slashes`
904 local sed_safe_root=`echo $dest | sed -e "s#^${IPKG_OFFLINE_ROOT}##" | ipkg_protect_slashes`
905 sed -e "s/\(Package:.*\)/\1\\
906 Status: install ok installed\\
907 Root: ${sed_safe_root}\\
908 ${new_conffiles}/" $info_dir/$pkg.control | ipkg_status_update_sd $sd $pkg
910 rm -f $info_dir/$pkg.control
911 rm -f $info_dir/$pkg.conffiles
912 rm -f $info_dir/$pkg.preinst
913 rm -f $info_dir/$pkg.postinst
915 echo "Done."
918 ipkg_install_file() {
919 ipkg_install_file_dest $IPKG_ROOT $*
922 ipkg_install() {
924 while [ $# -gt 0 ]; do
925 local pkg="$1"
926 shift
928 case "$pkg" in
929 http://* | ftp://*)
930 local tmp_pkg_file="$IPKG_TMP/"`ipkg_file_part $pkg`
931 if ipkg_download $pkg $tmp_pkg_file; then
932 ipkg_install_file $tmp_pkg_file
933 rm $tmp_pkg_file
936 file:/*.ipk | file://*.deb)
937 local ipkg_filename="`echo $pkg|sed 's/^file://'`"
938 ipkg_install_file $ipkg_filename
940 *.ipk | *.deb)
941 if [ -f "$pkg" ]; then
942 ipkg_install_file $pkg
943 else
944 echo "File not found $pkg" >&2
948 ipkg_get_install $pkg || true
950 esac
951 done
954 ipkg_install_pending() {
955 [ -n "$IPKG_OFFLINE_ROOT" ] && return 0
957 if [ -d "$IPKG_PENDING_DIR" ]; then
958 set +o noglob
959 local pending=`ls -1d $IPKG_PENDING_DIR/*.ipk 2> /dev/null` || true
960 set -o noglob
961 if [ -n "$pending" ]; then
962 echo "The following packages in $IPKG_PENDING_DIR will now be installed:"
963 echo $pending
964 for filename in $pending; do
965 if ipkg_install_file $filename; then
966 rm $filename
968 done
971 return 0
974 ipkg_install_wanted() {
975 local wanted=`ipkg_status_matching 'Status:[[:space:]]*install.*not-installed'`
977 if [ -n "$wanted" ]; then
978 echo "The following package were previously requested but have not been installed:"
979 echo $wanted
981 if [ -n "$FORCE_DEFAULTS" ]; then
982 echo "Installing them now."
983 else
984 echo -n "Install them now [Y/n] ? "
985 read response
986 case "$response" in
987 [Nn] | [Nn][Oo])
988 return 0
990 esac
993 ipkg_install $wanted
996 return 0
999 ipkg_upgrade_pkg() {
1000 local pkg="$1"
1001 local avail_ver=`ipkg_info $pkg Version | ipkg_extract_value | head -n1`
1003 is_installed=
1004 for dest_name in `ipkg_dest_names`; do
1005 local dest=`ipkg_dest_byname $dest_name`
1006 local sd=$dest/$IPKG_DIR_PREFIX
1007 local inst_ver=`ipkg_status_sd $sd $pkg Version | ipkg_extract_value`
1008 if [ -n "$inst_ver" ]; then
1009 is_installed=t
1011 if [ -z "$avail_ver" ]; then
1012 echo "Assuming locally installed package $pkg ($inst_ver) is up to date"
1013 return 0
1016 if [ "$avail_ver" = "$inst_ver" ]; then
1017 echo "Package $pkg ($inst_ver) installed in $dest_name is up to date"
1018 elif opkg-compare-versions $avail_ver '>>' $inst_ver; then
1019 echo "Upgrading $pkg ($dest_name) from $inst_ver to $avail_ver"
1020 ipkg_get_install_dest $dest $pkg
1021 else
1022 echo "Not downgrading package $pkg from $inst_ver to $avail_ver"
1025 done
1027 if [ -z "$is_installed" ]; then
1028 echo "Package $pkg does not appear to be installed"
1029 return 0
1034 ipkg_upgrade() {
1035 if [ $# -lt 1 ]; then
1036 local pkgs=`ipkg_status_matching 'Status:.*[[:space:]]installed'`
1037 else
1038 pkgs="$*"
1041 for pkg in $pkgs; do
1042 ipkg_upgrade_pkg $pkg
1043 done
1046 ipkg_remove_pkg_dest() {
1047 local dest="$1"
1048 local pkg="$2"
1049 local sd=$dest/$IPKG_DIR_PREFIX
1050 local info_dir=$sd/info
1052 if ! ipkg_status_installed_sd $sd $pkg; then
1053 echo "ipkg_remove: Package $pkg does not appear to be installed in $dest"
1054 if ipkg_status_mentioned_sd $sd $pkg; then
1055 echo "Purging mention of $pkg from the ipkg database"
1056 ipkg_status_remove_sd $sd $pkg
1058 return 1
1061 echo "ipkg_remove: Removing $pkg... "
1063 local files=`cat $info_dir/$pkg.list`
1065 export PKG_ROOT=$dest
1066 if [ -x "$info_dir/$pkg.prerm" ]; then
1067 $info_dir/$pkg.prerm remove
1070 local conffiles=`ipkg_status_sd $sd $pkg Conffiles | ipkg_extract_value`
1072 local dirs_to_remove=
1073 for file in $files; do
1074 if [ -d "$dest/$file" ]; then
1075 dirs_to_remove="$dirs_to_remove $dest/$file"
1076 else
1077 if echo " $conffiles " | grep -q " $file "; then
1078 if echo " $conffiles " | grep -q " $file "`md5sum $dest/$file | sed 's/ .*//'`; then
1079 rm -f $dest/$file
1081 else
1082 rm -f $dest/$file
1085 done
1087 local removed_a_dir=t
1088 while [ -n "$removed_a_dir" ]; do
1089 removed_a_dir=
1090 local new_dirs_to_remove=
1091 for dir in $dirs_to_remove; do
1092 if rmdir $dir >/dev/null 2>&1; then
1093 removed_a_dir=t
1094 else
1095 new_dirs_to_remove="$new_dirs_to_remove $dir"
1097 done
1098 dirs_to_remove="$new_dirs_to_remove"
1099 done
1101 if [ -n "$dirs_to_remove" ]; then
1102 echo "ipkg_remove: Warning: Not removing the following directories since they are not empty:" >&2
1103 echo "$dirs_to_remove" | sed -e 's/\/[/]\+/\//g' >&2
1106 if [ -x "$info_dir/$pkg.postrm" ]; then
1107 $info_dir/$pkg.postrm remove
1110 ipkg_status_remove_sd $sd $pkg
1111 set +o noglob
1112 rm -f $info_dir/$pkg.*
1113 set -o noglob
1115 echo "Done."
1118 ipkg_remove_pkg() {
1119 local pkg="$1"
1120 for dest in `ipkg_dests_all`; do
1121 local sd=$dest/$IPKG_DIR_PREFIX
1122 if ipkg_status_mentioned_sd $sd $pkg; then
1123 ipkg_remove_pkg_dest $dest $pkg
1125 done
1128 ipkg_remove() {
1129 while [ $# -gt 0 ]; do
1130 local pkg="$1"
1131 shift
1132 if [ -n "$DEST_NAME" ]; then
1133 ipkg_remove_pkg_dest $IPKG_ROOT $pkg
1134 else
1135 ipkg_remove_pkg $pkg
1137 done
1140 ipkg_list_installed() {
1141 echo `ipkg_status_matching 'Status:.*[[:space:]]installed'`
1143 ###########
1144 # ipkg main
1145 ###########
1147 # Parse options
1148 while [ $# -gt 0 ]; do
1149 arg="$1"
1150 case $arg in
1151 -d | -dest)
1152 [ $# -gt 1 ] || ipkg_usage "option $arg requires an argument"
1153 DEST_NAME="$2"
1154 shift
1156 -o | -offline)
1157 [ $# -gt 1 ] || ipkg_usage "option $arg requires an argument"
1158 IPKG_OFFLINE_ROOT="$2"
1159 shift
1161 -force-depends)
1162 FORCE_DEPENDS=t
1164 -force-defaults)
1165 FORCE_DEFAULTS=t
1168 [ $# -gt 1 ] || ipkg_usage "option $arg requires an argument"
1169 IPKG_CONF="$2"
1170 shift
1173 ipkg_usage "unknown option $arg"
1176 break
1178 esac
1179 shift
1180 done
1182 [ $# -lt 1 ] && ipkg_usage "ipkg must have one sub-command argument"
1183 cmd="$1"
1184 shift
1186 ipkg_load_configuration
1188 case "$cmd" in
1189 update|upgrade|list|info|status|install_pending|list_installed)
1191 install|depends|remove|files|search)
1192 [ $# -lt 1 ] && ipkg_usage "ERROR: the \`\`$cmd'' command requires an argument"
1195 echo "ERROR: unknown sub-command \`$cmd'"
1196 ipkg_usage
1198 esac
1200 # Only install pending if we have an interactive sub-command
1201 case "$cmd" in
1202 upgrade|install)
1203 ipkg_install_pending
1204 ipkg_install_wanted
1206 esac
1208 ipkg_$cmd $*
1209 rm -rf $IPKG_TMP