ccollect:0.6.2->0.7.0
[nslu2-linux/optware.git] / sources / fsg3-bootstrap / ipkg.sh
blobecdeb1933af8c588b1f34ae6d93e3e54666bc355
1 #!/bin/sh
2 # ipkg - the itsy package management system
4 # Copyright (C) 2001 Carl D. Worth
6 # Modified by Rod Whitby to remove the sort and uniq calls for the fsg3.
8 # This program is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 2, or (at your option)
11 # any later version.
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 set -e
20 # By default do not do globbing. Any command wanting globbing should
21 # explicitly enable it first and disable it afterwards.
22 set -o noglob
24 ipkg_srcs() {
25 local srcre="$1"
26 sed -ne "s/^src[[:space:]]\+$srcre[[:space:]]\+//p" < $IPKG_CONF
29 ipkg_src_names() {
30 sed -ne "s/^src[[:space:]]\+\([^[:space:]]\+\).*/\1/p" < $IPKG_CONF
33 ipkg_src_byname() {
34 local src="$1"
35 ipkg_srcs $src | head -1
38 ipkg_dests() {
39 local destre=`echo $1 | ipkg_protect_slashes`
40 sed -ne "/^dest[[:space:]]\+$destre/{
41 s/^dest[[:space:]]\+[^[:space:]]\+[[:space:]]\+//
42 s/^/`echo $IPKG_OFFLINE_ROOT | ipkg_protect_slashes`/
44 }" < $IPKG_CONF
47 ipkg_dest_names() {
48 sed -ne "s/^dest[[:space:]]\+\([^[:space:]]\+\).*/\1/p" < $IPKG_CONF
51 ipkg_dests_all() {
52 ipkg_dests '.*'
55 ipkg_state_dirs() {
56 ipkg_dests_all | sed "s|\$|/$IPKG_DIR_PREFIX|"
59 ipkg_dest_default() {
60 ipkg_dests_all | head -1
63 ipkg_dest_default_name() {
64 ipkg_dest_names | head -1
67 ipkg_dest_byname() {
68 local dest="$1"
69 ipkg_dests $dest | head -1
72 ipkg_option() {
73 local option="$1"
74 sed -ne "s/^option[[:space:]]\+$option[[:space:]]\+//p" < $IPKG_CONF
77 ipkg_load_configuration() {
78 if [ -z "$IPKG_CONF_DIR" ]; then
79 IPKG_CONF_DIR=/etc
82 IPKG_CONF="$IPKG_CONF_DIR/ipkg.conf"
84 if [ -z "$IPKG_OFFLINE_ROOT" ]; then
85 IPKG_OFFLINE_ROOT=`ipkg_option offline_root`
87 # Export IPKG_OFFLINE_ROOT for use by update-alternatives
88 export IPKG_OFFLINE_ROOT
89 if [ -n "$DEST_NAME" ]; then
90 IPKG_ROOT=`ipkg_dest_byname $DEST_NAME`
91 if [ -z "$IPKG_ROOT" ]; then
92 if [ -d "$IPKG_OFFLINE_ROOT$DEST_NAME" ]; then
93 IPKG_ROOT="$IPKG_OFFLINE_ROOT$DEST_NAME";
94 else
95 echo "ipkg: invalid destination specification: $DEST_NAME
96 Valid destinations are directories or one of the dest names from $IPKG_CONF:" >&2
97 ipkg_dest_names >&2
98 return 1
101 else
102 IPKG_ROOT=`ipkg_dest_default`
105 # Global ipkg state directories
106 IPKG_DIR_PREFIX=usr/lib/ipkg
107 IPKG_LISTS_DIR=$IPKG_OFFLINE_ROOT/$IPKG_DIR_PREFIX/lists
108 IPKG_PENDING_DIR=$IPKG_OFFLINE_ROOT/$IPKG_DIR_PREFIX/pending
109 IPKG_TMP=$IPKG_ROOT/tmp/ipkg
111 # Destination specific ipkg meta-data directory
112 IPKG_STATE_DIR=$IPKG_ROOT/$IPKG_DIR_PREFIX
114 # Proxy Support
115 IPKG_PROXY_USERNAME=`ipkg_option proxy_username`
116 IPKG_PROXY_PASSWORD=`ipkg_option proxy_password`
117 IPKG_HTTP_PROXY=`ipkg_option http_proxy`
118 IPKG_FTP_PROXY=`ipkg_option ftp_proxy`
119 IPKG_NO_PROXY=`ipkg_option no_proxy`
120 if [ -n "$IPKG_HTTP_PROXY" ]; then
121 export http_proxy="$IPKG_HTTP_PROXY"
124 if [ -n "$IPKG_FTP_PROXY" ]; then
125 export ftp_proxy="$IPKG_FTP_PROXY"
128 if [ -n "$IPKG_NO_PROXY" ]; then
129 export no_proxy="$IPKG_NO_PROXY"
132 IPKG_STATUS_FIELDS='\(Package\|Status\|Essential\|Version\|Conffiles\|Root\)'
135 ipkg_usage() {
136 [ $# -gt 0 ] && echo "ipkg: $*"
137 echo "
138 usage: ipkg [options...] sub-command [arguments...]
139 where sub-command is one of:
141 Package Manipulation:
142 update Update list of available packages
143 upgrade Upgrade all installed packages to latest version
144 install <pkg> Download and install <pkg> (and dependencies)
145 install <file.ipk> Install package <file.ipk>
146 install <file.deb> Install package <file.deb>
147 remove <pkg> Remove package <pkg>
149 Informational Commands:
150 list List available packages and descriptions
151 files <pkg> List all files belonging to <pkg>
152 search <file> Search for a packaging providing <file>
153 info [pkg [<field>]] Display all/some info fields for <pkg> or all
154 status [pkg [<field>]] Display all/some status fields for <pkg> or all
155 depends <pkg> Print uninstalled package dependencies for <pkg>
157 Options:
158 -d <dest_name> Use <dest_name> as the the root directory for
159 -dest <dest_name> package installation, removal, upgrading.
160 <dest_name> should be a defined dest name from the
161 configuration file, (but can also be a directory
162 name in a pinch).
163 -o <offline_root> Use <offline_root> as the root for offline installation.
164 -offline <offline_root>
166 Force Options (use when ipkg is too smart for its own good):
167 -force-depends Make dependency checks warnings instead of errors
168 -force-defaults Use default options for questions asked by ipkg.
169 (no prompts). Note that this will not prevent
170 package installation scripts from prompting.
171 " >&2
172 exit 1
175 ipkg_dir_part() {
176 local dir=`echo $1 | sed -ne 's/\(.*\/\).*/\1/p'`
177 if [ -z "$dir" ]; then
178 dir="./"
180 echo $dir
183 ipkg_file_part() {
184 echo $1 | sed 's/.*\///'
187 ipkg_protect_slashes() {
188 sed -e 's/\//\\\//g'
191 ipkg_download() {
192 local src="$1"
193 local dest="$2"
195 local src_file=`ipkg_file_part $src`
196 local dest_dir=`ipkg_dir_part $dest`
197 if [ -z "$dest_dir" ]; then
198 dest_dir="$IPKG_TMP"
201 local dest_file=`ipkg_file_part $dest`
202 if [ -z "$dest_file" ]; then
203 dest_file="$src_file"
206 # Proxy support
207 local proxyuser=""
208 local proxypassword=""
209 local proxyoption=""
211 if [ -n "$IPKG_PROXY_USERNAME" ]; then
212 proxyuser="--proxy-user=\"$IPKG_PROXY_USERNAME\""
213 proxypassword="--proxy-passwd=\"$IPKG_PROXY_PASSWORD\""
216 if [ -n "$IPKG_PROXY_HTTP" -o -n "$IPKG_PROXY_FTP" ]; then
217 proxyoption="--proxy=on"
220 echo "Downloading $src ..."
221 rm -f $IPKG_TMP/$src_file
222 case "$src" in
223 http://* | ftp://*)
224 if ! wget --passive-ftp -nd $proxyoption $proxyuser $proxypassword -P $IPKG_TMP $src; then
225 echo "ipkg_download: ERROR: Failed to retrieve $src, returning $err"
226 return 1
228 mv $IPKG_TMP/$src_file $dest_dir/$dest_file 2>/dev/null
230 file:/* )
231 ln -s `echo $src | sed 's/^file://'` $dest_dir/$dest_file 2>/dev/null
234 echo "DEBUG: $src"
236 esac
238 echo "Done."
239 return 0
242 ipkg_update() {
243 if [ ! -e "$IPKG_LISTS_DIR" ]; then
244 mkdir -p $IPKG_LISTS_DIR
247 local err=
248 for src_name in `ipkg_src_names`; do
249 local src=`ipkg_src_byname $src_name`
250 if ! ipkg_download $src/Packages $IPKG_LISTS_DIR/$src_name; then
251 echo "ipkg_update: Error downloading $src/Packages to $IPKG_LISTS_DIR/$src_name" >&2
252 err=t
253 else
254 echo "Updated list of available packages in $IPKG_LISTS_DIR/$src_name"
256 done
258 [ -n "$err" ] && return 1
260 return 0
263 ipkg_list() {
264 for src in `ipkg_src_names`; do
265 if ipkg_require_list $src; then
266 # black magic...
267 sed -ne "
268 /^Package:/{
269 s/^Package:[[:space:]]*\<\([a-z0-9.+-]*$1[a-z0-9.+-]*\).*/\1/
272 /^Description:/{
273 s/^Description:[[:space:]]*\(.*\)/\1/
276 s/\\
277 / - /
280 " $IPKG_LISTS_DIR/$src
282 done
285 ipkg_extract_paragraph() {
286 local pkg="$1"
287 sed -ne "/Package:[[:space:]]*$pkg[[:space:]]*\$/,/^\$/p"
290 ipkg_extract_field() {
291 local field="$1"
292 # blacker magic...
293 sed -ne "
294 : TOP
295 /^$field:/{
298 b FIELD
301 : FIELD
302 /^$/b TOP
303 /^[^[:space:]]/b TOP
306 b FIELD
310 ipkg_extract_value() {
311 sed -e "s/^[^:]*:[[:space:]]*//"
314 ipkg_require_list() {
315 [ $# -lt 1 ] && return 1
316 local src="$1"
317 if [ ! -f "$IPKG_LISTS_DIR/$src" ]; then
318 echo "ERROR: File not found: $IPKG_LISTS_DIR/$src" >&2
319 echo " You probably want to run \`ipkg update'" >&2
320 return 1
322 return 0
325 ipkg_info() {
326 for src in `ipkg_src_names`; do
327 if ipkg_require_list $src; then
328 case $# in
330 cat $IPKG_LISTS_DIR/$src
333 ipkg_extract_paragraph $1 < $IPKG_LISTS_DIR/$src
336 ipkg_extract_paragraph $1 < $IPKG_LISTS_DIR/$src | ipkg_extract_field $2
338 esac
340 done
343 ipkg_status_sd() {
344 [ $# -lt 1 ] && return 0
345 sd="$1"
346 shift
347 if [ -f $sd/status ]; then
348 case $# in
350 cat $sd/status
353 ipkg_extract_paragraph $1 < $sd/status
356 ipkg_extract_paragraph $1 < $sd/status | ipkg_extract_field $2
358 esac
360 return 0
363 ipkg_status_all() {
364 for sd in `ipkg_state_dirs`; do
365 ipkg_status_sd $sd $*
366 done
369 ipkg_status() {
370 if [ -n "$DEST_NAME" ]; then
371 ipkg_status_sd $IPKG_STATE_DIR $*
372 else
373 ipkg_status_all $*
377 ipkg_status_matching_sd() {
378 local sd="$1"
379 local re="$2"
380 if [ -f $sd/status ]; then
381 sed -ne "
382 : TOP
383 /^Package:/{
384 s/^Package:[[:space:]]*//
385 s/[[:space:]]*$//
388 /$re/{
391 b NEXT
394 : NEXT
395 /^$/b TOP
397 b NEXT
398 " < $sd/status
400 return 0
403 ipkg_status_matching_all() {
404 for sd in `ipkg_state_dirs`; do
405 ipkg_status_matching_sd $sd $*
406 done
409 ipkg_status_matching() {
410 if [ -n "$DEST_NAME" ]; then
411 ipkg_status_matching_sd $IPKG_STATE_DIR $*
412 else
413 ipkg_status_matching_all $*
417 ipkg_status_installed_sd() {
418 local sd="$1"
419 local pkg="$2"
420 ipkg_status_sd $sd $pkg Status | grep -q "Status: install ok installed"
423 ipkg_status_installed_all() {
424 local ret=1
425 for sd in `ipkg_state_dirs`; do
426 if `ipkg_status_installed_sd $sd $*`; then
427 ret=0
429 done
430 return $ret
433 ipkg_status_mentioned_sd() {
434 local sd="$1"
435 local pkg="$2"
436 [ -n "`ipkg_status_sd $sd $pkg Status`" ]
439 ipkg_files() {
440 local pkg="$1"
441 if [ -n "$DEST_NAME" ]; then
442 dests=$IPKG_ROOT
443 else
444 dests=`ipkg_dests_all`
446 for dest in $dests; do
447 if [ -f $dest/$IPKG_DIR_PREFIX/info/$pkg.list ]; then
448 dest_sed=`echo $dest | ipkg_protect_slashes`
449 sed -e "s/^/$dest_sed/" < $dest/$IPKG_DIR_PREFIX/info/$pkg.list
451 done
454 ipkg_search() {
455 local pattern="$1"
457 for dest_name in `ipkg_dest_names`; do
458 dest=`ipkg_dest_byname $dest_name`
459 dest_sed=`echo $dest | ipkg_protect_slashes`
461 set +o noglob
462 local list_files=`ls -1 $dest/$IPKG_DIR_PREFIX/info/*.list 2>/dev/null`
463 set -o noglob
464 for file in $list_files; do
465 if sed "s/^/$dest_sed/" $file | grep -q $pattern; then
466 local pkg=`echo $file | sed "s/^.*\/\(.*\)\.list/\1/"`
467 [ "$dest_name" != `ipkg_dest_default_name` ] && pkg="$pkg ($dest_name)"
468 sed "s/^/$dest_sed/" $file | grep $pattern | sed "s/^/$pkg: /"
470 done
471 done
474 ipkg_status_remove_sd() {
475 local sd="$1"
476 local pkg="$2"
478 if [ ! -f $sd/status ]; then
479 mkdir -p $sd
480 touch $sd/status
482 sed -ne "/Package:[[:space:]]*$pkg[[:space:]]*\$/,/^\$/!p" < $sd/status > $sd/status.new
483 mv $sd/status.new $sd/status
486 ipkg_status_remove_all() {
487 for sd in `ipkg_state_dirs`; do
488 ipkg_status_remove_sd $sd $*
489 done
492 ipkg_status_remove() {
493 if [ -n "$DEST_NAME" ]; then
494 ipkg_status_remove_sd $IPKG_STATE_DIR $*
495 else
496 ipkg_status_remove_all $*
500 ipkg_status_update_sd() {
501 local sd="$1"
502 local pkg="$2"
504 ipkg_status_remove_sd $sd $pkg
505 ipkg_extract_field "$IPKG_STATUS_FIELDS" >> $sd/status
506 echo "" >> $sd/status
509 ipkg_status_update() {
510 ipkg_status_update_sd $IPKG_STATE_DIR $*
513 ipkg_unsatisfied_dependences() {
514 local pkg=$1
515 local deps=`ipkg_get_depends $pkg`
516 local remaining_deps=
517 for dep in $deps; do
518 local installed=`ipkg_get_installed $dep`
519 if [ "$installed" != "installed" ] ; then
520 remaining_deps="$remaining_deps $dep"
522 done
523 ## echo "ipkg_unsatisfied_dependences pkg=$pkg $remaining_deps" > /dev/console
524 echo $remaining_deps
527 ipkg_safe_pkg_name() {
528 local pkg=$1
529 local spkg=`echo pkg_$pkg | sed -e y/-+./___/`
530 echo $spkg
533 ipkg_set_depends() {
534 local pkg=$1; shift
535 local new_deps="$*"
536 pkg=`ipkg_safe_pkg_name $pkg`
537 ## setvar ${pkg}_depends "$new_deps"
538 echo $new_deps > /tmp/ipkg/${pkg}.depends
541 ipkg_get_depends() {
542 local pkg=$1
543 pkg=`ipkg_safe_pkg_name $pkg`
544 cat /tmp/ipkg/${pkg}.depends
545 ## eval "echo \$${pkg}_depends"
548 ipkg_set_installed() {
549 local pkg=$1
550 pkg=`ipkg_safe_pkg_name $pkg`
551 echo installed > /tmp/ipkg/${pkg}.installed
552 ## setvar ${pkg}_installed "installed"
555 ipkg_set_uninstalled() {
556 local pkg=$1
557 pkg=`ipkg_safe_pkg_name $pkg`
558 ### echo ipkg_set_uninstalled $pkg > /dev/console
559 echo uninstalled > /tmp/ipkg/${pkg}.installed
560 ## setvar ${pkg}_installed "uninstalled"
563 ipkg_get_installed() {
564 local pkg=$1
565 pkg=`ipkg_safe_pkg_name $pkg`
566 if [ -f /tmp/ipkg/${pkg}.installed ]; then
567 cat /tmp/ipkg/${pkg}.installed
569 ## eval "echo \$${pkg}_installed"
572 ipkg_depends() {
573 local new_pkgs="$*"
574 local all_deps=
575 local installed_pkgs=`ipkg_status_matching_all 'Status:.*[[:space:]]installed'`
576 for pkg in $installed_pkgs; do
577 ipkg_set_installed $pkg
578 done
579 while [ -n "$new_pkgs" ]; do
580 all_deps="$all_deps $new_pkgs"
581 local new_deps=
582 for pkg in $new_pkgs; do
583 if echo $pkg | grep -q '[^a-z0-9.+-]'; then
584 echo "ipkg_depends: ERROR: Package name $pkg contains illegal characters (should be [a-z0-9.+-])" >&2
585 return 1
587 # TODO: Fix this. For now I am ignoring versions and alternations in dependencies.
588 new_deps="$new_deps "`ipkg_info $pkg '\(Pre-\)\?Depends' | ipkg_extract_value | sed -e 's/([^)]*)//g
589 s/\(|[[:space:]]*[a-z0-9.+-]\+[[:space:]]*\)\+//g
590 s/,/ /g
591 s/ \+/ /g'`
592 ipkg_set_depends $pkg $new_deps
593 done
595 new_deps=`echo $new_deps | sed -e 's/[[:space:]]\+/\\
596 /g'`
598 local maybe_new_pkgs=
599 for pkg in $new_deps; do
600 if ! echo $installed_pkgs | grep -q "\<$pkg\>"; then
601 maybe_new_pkgs="$maybe_new_pkgs $pkg"
603 done
605 new_pkgs=
606 for pkg in $maybe_new_pkgs; do
607 if ! echo $all_deps | grep -q "\<$pkg\>"; then
608 if [ -z "`ipkg_info $pkg`" ]; then
609 echo "ipkg_depends: Warning: $pkg mentioned in dependency but no package found in $IPKG_LISTS_DIR" >&2
610 ipkg_set_installed $pkg
611 else
612 new_pkgs="$new_pkgs $pkg"
613 ipkg_set_uninstalled $pkg
615 else
616 ipkg_set_uninstalled $pkg
618 done
619 done
621 echo $all_deps
624 ipkg_get_install_dest() {
625 local dest="$1"
626 shift
627 local sd=$dest/$IPKG_DIR_PREFIX
628 local info_dir=$sd/info
630 local requested_pkgs="$*"
631 local pkgs=`ipkg_depends $*`
633 mkdir -p $info_dir
634 for pkg in $pkgs; do
635 if ! ipkg_status_mentioned_sd $sd $pkg; then
636 echo "Package: $pkg
637 Status: install ok not-installed" | ipkg_status_update_sd $sd $pkg
639 done
640 ## mark the packages that we were directly requested to install as uninstalled
641 for pkg in $requested_pkgs; do ipkg_set_uninstalled $pkg; done
643 local new_pkgs=
644 local pkgs_installed=0
645 while [ -n "pkgs" ]; do
646 curcheck=0
647 ## echo "pkgs to install: {$pkgs}" > /dev/console
648 for pkg in $pkgs; do
649 curcheck=`expr $curcheck + 1`
650 local is_installed=`ipkg_get_installed $pkg`
651 if [ "$is_installed" = "installed" ]; then
652 echo "$pkg is installed" > /dev/console
653 continue
656 local remaining_deps=`ipkg_unsatisfied_dependences $pkg`
657 if [ -n "$remaining_deps" ]; then
658 new_pkgs="$new_pkgs $pkg"
659 ### echo "Dependences not satisfied for $pkg: $remaining_deps"
660 if [ $curcheck -ne `echo $pkgs|wc -w` ]; then
661 continue
665 local filename=
666 for src in `ipkg_src_names`; do
667 if ipkg_require_list $src; then
668 filename=`ipkg_extract_paragraph $pkg < $IPKG_LISTS_DIR/$src | ipkg_extract_field Filename | ipkg_extract_value`
669 [ -n "$filename" ] && break
671 done
673 if [ -z "$filename" ]; then
674 echo "ipkg_get_install: ERROR: Cannot find package $pkg in $IPKG_LISTS_DIR"
675 echo "ipkg_get_install: Check the spelling and maybe run \`ipkg update'."
676 ipkg_status_remove_sd $sd $pkg
677 return 1;
680 [ -e "$IPKG_TMP" ] || mkdir -p $IPKG_TMP
682 echo ""
683 local tmp_pkg_file="$IPKG_TMP/"`ipkg_file_part $filename`
684 if ! ipkg_download `ipkg_src_byname $src`/$filename $tmp_pkg_file; then
685 echo "ipkg_get_install: Perhaps you need to run \`ipkg update'?"
686 return 1
689 if ! ipkg_install_file_dest $dest $tmp_pkg_file; then
690 echo "ipkg_get_install: ERROR: Failed to install $tmp_pkg_file"
691 echo "ipkg_get_install: I'll leave it there for you to try a manual installation"
692 return 1
695 ipkg_set_installed $pkg
696 pkgs_installed=`expr $pkgs_installed + 1`
697 rm $tmp_pkg_file
698 done
699 ### echo "Installed $pkgs_installed package(s) this round"
700 if [ $pkgs_installed -eq 0 ]; then
701 if [ -z "$new_pkgs" ]; then
702 break
705 pkgs_installed=0
706 pkgs="$new_pkgs"
707 new_pkgs=
708 curcheck=0
709 done
712 ipkg_get_install() {
713 ipkg_get_install_dest $IPKG_ROOT $*
716 ipkg_install_file_dest() {
717 local dest="$1"
718 local filename="$2"
719 local sd=$dest/$IPKG_DIR_PREFIX
720 local info_dir=$sd/info
722 if [ ! -f "$filename" ]; then
723 echo "ipkg_install_file: ERROR: File $filename not found"
724 return 1
727 local pkg=`ipkg_file_part $filename | sed 's/\([a-z0-9.+-]\+\)_.*/\1/'`
728 local ext=`echo $filename | sed 's/.*\.//'`
729 local pkg_extract_stdout
730 if [ "$ext" = "ipk" ]; then
731 pkg_extract_stdout="tar -xzOf"
732 elif [ "$ext" = "deb" ]; then
733 pkg_extract_stdout="ar p"
734 else
735 echo "ipkg_install_file: ERROR: File $filename has unknown extension $ext (not .ipk or .deb)"
736 return 1
739 # Check dependencies
740 local depends=`ipkg_depends $pkg | sed -e "s/\<$pkg\>//"`
742 # Don't worry about deps that are scheduled for installation
743 local missing_deps=
744 for dep in $depends; do
745 if ! ipkg_status_all $dep | grep -q 'Status:[[:space:]]install'; then
746 missing_deps="$missing_deps $dep"
748 done
750 if [ ! -z "$missing_deps" ]; then
751 if [ -n "$FORCE_DEPENDS" ]; then
752 echo "ipkg_install_file: Warning: $pkg depends on the following uninstalled programs: $missing_deps"
753 else
754 echo "ipkg_install_file: ERROR: $pkg depends on the following uninstalled programs:
755 $missing_deps"
756 echo "ipkg_install_file: You may want to use \`ipkg install' to install these."
757 return 1
761 mkdir -p $IPKG_TMP/$pkg/control
762 mkdir -p $IPKG_TMP/$pkg/data
763 mkdir -p $info_dir
765 if ! $pkg_extract_stdout $filename ./control.tar.gz | (cd $IPKG_TMP/$pkg/control; tar -xzf - ) ; then
766 echo "ipkg_install_file: ERROR unpacking control.tar.gz from $filename"
767 return 1
770 if [ -n "$IPKG_OFFLINE_ROOT" ]; then
771 if grep -q '^InstallsOffline:[[:space:]]*no' $IPKG_TMP/$pkg/control/control; then
772 echo "*** Warning: Package $pkg may not be installed in offline mode"
773 echo "*** Warning: Scheduling $filename for pending installation (installing into $IPKG_PENDING_DIR)"
774 echo "Package: $pkg
775 Status: install ok pending" | ipkg_status_update_sd $sd $pkg
776 mkdir -p $IPKG_PENDING_DIR
777 cp $filename $IPKG_PENDING_DIR
778 rm -r $IPKG_TMP/$pkg/control
779 rm -r $IPKG_TMP/$pkg/data
780 rmdir $IPKG_TMP/$pkg
781 return 0
786 echo -n "Unpacking $pkg..."
787 set +o noglob
788 for file in $IPKG_TMP/$pkg/control/*; do
789 local base_file=`ipkg_file_part $file`
790 mv $file $info_dir/$pkg.$base_file
791 done
792 set -o noglob
793 rm -r $IPKG_TMP/$pkg/control
795 if ! $pkg_extract_stdout $filename ./data.tar.gz | (cd $IPKG_TMP/$pkg/data; tar -xzf - ) ; then
796 echo "ipkg_install_file: ERROR unpacking data.tar.gz from $filename"
797 return 1
799 echo "Done."
801 echo -n "Configuring $pkg..."
802 export PKG_ROOT=$dest
803 if [ -x "$info_dir/$pkg.preinst" ]; then
804 if ! $info_dir/$pkg.preinst install; then
805 echo "$info_dir/$pkg.preinst failed. Aborting installation of $pkg"
806 rm -rf $IPKG_TMP/$pkg/data
807 rmdir $IPKG_TMP/$pkg
808 return 1
812 local old_conffiles=`ipkg_status_sd $sd $pkg Conffiles | ipkg_extract_value`
813 local new_conffiles=
814 if [ -f "$info_dir/$pkg.conffiles" ]; then
815 for conffile in `cat $info_dir/$pkg.conffiles`; do
816 if [ -f "$dest/$conffile" ] && ! echo " $old_conffiles " | grep -q " $conffile "`md5sum $dest/$conffile | sed 's/ .*//'`; then
817 local use_maintainers_conffile=
818 if [ -z "$FORCE_DEFAULTS" ]; then
819 while true; do
820 echo -n "Configuration file \`$conffile'
821 ==> File on system created by you or by a script.
822 ==> File also in package provided by package maintainer.
823 What would you like to do about it ? Your options are:
824 Y or I : install the package maintainer's version
825 N or O : keep your currently-installed version
826 D : show the differences between the versions (if diff is installed)
827 The default action is to keep your current version.
828 *** `ipkg_file_part $conffile` (Y/I/N/O/D) [default=N] ? "
829 read response
830 case "$response" in
831 [YyIi] | [Yy][Ee][Ss])
832 use_maintainers_conffile=t
833 break
835 [Dd])
836 echo "
837 diff -u $dest/$conffile $IPKG_TMP/$pkg/data/$conffile"
838 diff -u $dest/$conffile $IPKG_TMP/$pkg/data/$conffile || true
839 echo "[Press ENTER to continue]"
840 read junk
843 break
845 esac
846 done
848 if [ -n "$use_maintainers_conffile" ]; then
849 local md5sum=`md5sum $IPKG_TMP/$pkg/data/$conffile | sed 's/ .*//'`
850 new_conffiles="$new_conffiles $conffile $md5sum"
851 else
852 new_conffiles="$new_conffiles $conffile <custom>"
853 rm $IPKG_TMP/$pkg/data/$conffile
855 else
856 md5sum=`md5sum $IPKG_TMP/$pkg/data/$conffile | sed 's/ .*//'`
857 new_conffiles="$new_conffiles $conffile $md5sum"
859 done
862 local owd=`pwd`
863 (cd $IPKG_TMP/$pkg/data/; tar cf - . | (cd $owd; cd $dest; tar xf -))
864 rm -rf $IPKG_TMP/$pkg/data
865 rmdir $IPKG_TMP/$pkg
866 $pkg_extract_stdout $filename ./data.tar.gz | tar tzf - | sed -e 's/^\.//' > $info_dir/$pkg.list
868 if [ -x "$info_dir/$pkg.postinst" ]; then
869 $info_dir/$pkg.postinst configure
872 if [ -n "$new_conffiles" ]; then
873 new_conffiles='Conffiles: '`echo $new_conffiles | ipkg_protect_slashes`
875 local sed_safe_root=`echo $dest | sed -e "s/^${IPKG_OFFLINE_ROOT}//" | ipkg_protect_slashes`
876 sed -e "s/\(Package:.*\)/\1\\
877 Status: install ok installed\\
878 Root: ${sed_safe_root}\\
879 ${new_conffiles}/" $info_dir/$pkg.control | ipkg_status_update_sd $sd $pkg
881 rm -f $info_dir/$pkg.control
882 rm -f $info_dir/$pkg.conffiles
883 rm -f $info_dir/$pkg.preinst
884 rm -f $info_dir/$pkg.postinst
886 echo "Done."
889 ipkg_install_file() {
890 ipkg_install_file_dest $IPKG_ROOT $*
893 ipkg_install() {
895 while [ $# -gt 0 ]; do
896 local pkg="$1"
897 shift
899 case "$pkg" in
900 http://* | ftp://*)
901 local tmp_pkg_file="$IPKG_TMP/"`ipkg_file_part $pkg`
902 if ipkg_download $pkg $tmp_pkg_file; then
903 ipkg_install_file $tmp_pkg_file
904 rm $tmp_pkg_file
907 file:/*.ipk | file://*.deb)
908 local ipkg_filename="`echo $pkg|sed 's/^file://'`"
909 ipkg_install_file $ipkg_filename
911 *.ipk | *.deb)
912 if [ -f "$pkg" ]; then
913 ipkg_install_file $pkg
914 else
915 echo "File not found $pkg" >&2
919 ipkg_get_install $pkg || true
921 esac
922 done
925 ipkg_install_pending() {
926 [ -n "$IPKG_OFFLINE_ROOT" ] && return 0
928 if [ -d "$IPKG_PENDING_DIR" ]; then
929 set +o noglob
930 local pending=`ls -1d $IPKG_PENDING_DIR/*.ipk 2> /dev/null` || true
931 set -o noglob
932 if [ -n "$pending" ]; then
933 echo "The following packages in $IPKG_PENDING_DIR will now be installed:"
934 echo $pending
935 for filename in $pending; do
936 if ipkg_install_file $filename; then
937 rm $filename
939 done
942 return 0
945 ipkg_install_wanted() {
946 local wanted=`ipkg_status_matching 'Status:[[:space:]]*install.*not-installed'`
948 if [ -n "$wanted" ]; then
949 echo "The following package were previously requested but have not been installed:"
950 echo $wanted
952 if [ -n "$FORCE_DEFAULTS" ]; then
953 echo "Installing them now."
954 else
955 echo -n "Install them now [Y/n] ? "
956 read response
957 case "$response" in
958 [Nn] | [Nn][Oo])
959 return 0
961 esac
964 ipkg_install $wanted
967 return 0
970 ipkg_upgrade_pkg() {
971 local pkg="$1"
972 local avail_ver=`ipkg_info $pkg Version | ipkg_extract_value | head -1`
974 is_installed=
975 for dest_name in `ipkg_dest_names`; do
976 local dest=`ipkg_dest_byname $dest_name`
977 local sd=$dest/$IPKG_DIR_PREFIX
978 local inst_ver=`ipkg_status_sd $sd $pkg Version | ipkg_extract_value`
979 if [ -n "$inst_ver" ]; then
980 is_installed=t
982 if [ -z "$avail_ver" ]; then
983 echo "Assuming locally installed package $pkg ($inst_ver) is up to date"
984 return 0
987 if [ "$avail_ver" = "$inst_ver" ]; then
988 echo "Package $pkg ($inst_ver) installed in $dest_name is up to date"
989 elif ipkg-compare-versions $avail_ver '>>' $inst_ver; then
990 echo "Upgrading $pkg ($dest_name) from $inst_ver to $avail_ver"
991 ipkg_get_install_dest $dest $pkg
992 else
993 echo "Not downgrading package $pkg from $inst_ver to $avail_ver"
996 done
998 if [ -z "$is_installed" ]; then
999 echo "Package $pkg does not appear to be installed"
1000 return 0
1005 ipkg_upgrade() {
1006 if [ $# -lt 1 ]; then
1007 local pkgs=`ipkg_status_matching 'Status:.*[[:space:]]installed'`
1008 else
1009 pkgs="$*"
1012 for pkg in $pkgs; do
1013 ipkg_upgrade_pkg $pkg
1014 done
1017 ipkg_remove_pkg_dest() {
1018 local dest="$1"
1019 local pkg="$2"
1020 local sd=$dest/$IPKG_DIR_PREFIX
1021 local info_dir=$sd/info
1023 if ! ipkg_status_installed_sd $sd $pkg; then
1024 echo "ipkg_remove: Package $pkg does not appear to be installed in $dest"
1025 if ipkg_status_mentioned_sd $sd $pkg; then
1026 echo "Purging mention of $pkg from the ipkg database"
1027 ipkg_status_remove_sd $sd $pkg
1029 return 1
1032 echo "ipkg_remove: Removing $pkg... "
1034 local files=`cat $info_dir/$pkg.list`
1036 export PKG_ROOT=$dest
1037 if [ -x "$info_dir/$pkg.prerm" ]; then
1038 $info_dir/$pkg.prerm remove
1041 local conffiles=`ipkg_status_sd $sd $pkg Conffiles | ipkg_extract_value`
1043 local dirs_to_remove=
1044 for file in $files; do
1045 if [ -d "$dest/$file" ]; then
1046 dirs_to_remove="$dirs_to_remove $dest/$file"
1047 else
1048 if echo " $conffiles " | grep -q " $file "; then
1049 if echo " $conffiles " | grep -q " $file "`md5sum $dest/$file | sed 's/ .*//'`; then
1050 rm -f $dest/$file
1052 else
1053 rm -f $dest/$file
1056 done
1058 local removed_a_dir=t
1059 while [ -n "$removed_a_dir" ]; do
1060 removed_a_dir=
1061 local new_dirs_to_remove=
1062 for dir in $dirs_to_remove; do
1063 if rmdir $dir >/dev/null 2>&1; then
1064 removed_a_dir=t
1065 else
1066 new_dirs_to_remove="$new_dirs_to_remove $dir"
1068 done
1069 dirs_to_remove="$new_dirs_to_remove"
1070 done
1072 if [ -n "$dirs_to_remove" ]; then
1073 echo "ipkg_remove: Warning: Not removing the following directories since they are not empty:" >&2
1074 echo "$dirs_to_remove" | sed -e 's/\/[/]\+/\//g' >&2
1077 if [ -x "$info_dir/$pkg.postrm" ]; then
1078 $info_dir/$pkg.postrm remove
1081 ipkg_status_remove_sd $sd $pkg
1082 set +o noglob
1083 rm -f $info_dir/$pkg.*
1084 set -o noglob
1086 echo "Done."
1089 ipkg_remove_pkg() {
1090 local pkg="$1"
1091 for dest in `ipkg_dests_all`; do
1092 local sd=$dest/$IPKG_DIR_PREFIX
1093 if ipkg_status_mentioned_sd $sd $pkg; then
1094 ipkg_remove_pkg_dest $dest $pkg
1096 done
1099 ipkg_remove() {
1100 while [ $# -gt 0 ]; do
1101 local pkg="$1"
1102 shift
1103 if [ -n "$DEST_NAME" ]; then
1104 ipkg_remove_pkg_dest $IPKG_ROOT $pkg
1105 else
1106 ipkg_remove_pkg $pkg
1108 done
1111 ###########
1112 # ipkg main
1113 ###########
1115 # Parse options
1116 while [ $# -gt 0 ]; do
1117 arg="$1"
1118 case $arg in
1119 -d | -dest)
1120 [ $# -gt 1 ] || ipkg_usage "option $arg requires an argument"
1121 DEST_NAME="$2"
1122 shift
1124 -o | -offline)
1125 [ $# -gt 1 ] || ipkg_usage "option $arg requires an argument"
1126 IPKG_OFFLINE_ROOT="$2"
1127 shift
1129 -force-depends)
1130 FORCE_DEPENDS=t
1132 -force-defaults)
1133 FORCE_DEFAULTS=t
1136 ipkg_usage "unknown option $arg"
1139 break
1141 esac
1142 shift
1143 done
1145 [ $# -lt 1 ] && ipkg_usage "ipkg must have one sub-command argument"
1146 cmd="$1"
1147 shift
1149 ipkg_load_configuration
1150 mkdir -p /tmp/ipkg
1152 case "$cmd" in
1153 update|upgrade|list|info|status|install_pending)
1155 install|depends|remove|files|search)
1156 [ $# -lt 1 ] && ipkg_usage "ERROR: the \`\`$cmd'' command requires an argument"
1159 echo "ERROR: unknown sub-command \`$cmd'"
1160 ipkg_usage
1162 esac
1164 # Only install pending if we have an interactive sub-command
1165 case "$cmd" in
1166 upgrade|install)
1167 ipkg_install_pending
1168 ipkg_install_wanted
1170 esac
1172 ipkg_$cmd $*
1173 for a in `ls $IPKG_TMP`; do
1174 rm -f $IPKG_TMP/$a
1175 done