From owner-svn-src-user@FreeBSD.ORG Sat Aug 7 19:27:37 2010 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id E4B0E1065676; Sat, 7 Aug 2010 19:27:36 +0000 (UTC) (envelope-from dougb@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id D373F8FC13; Sat, 7 Aug 2010 19:27:36 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id o77JRaGs033640; Sat, 7 Aug 2010 19:27:36 GMT (envelope-from dougb@svn.freebsd.org) Received: (from dougb@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id o77JRaRU033638; Sat, 7 Aug 2010 19:27:36 GMT (envelope-from dougb@svn.freebsd.org) Message-Id: <201008071927.o77JRaRU033638@svn.freebsd.org> From: Doug Barton Date: Sat, 7 Aug 2010 19:27:36 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r211034 - user/dougb/portmaster X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 07 Aug 2010 19:27:37 -0000 Author: dougb Date: Sat Aug 7 19:27:36 2010 New Revision: 211034 URL: http://svn.freebsd.org/changeset/base/211034 Log: Step 4 of the internal whitespace cleanup: * if/then/fi clauses with only 1 action get the && treatement * With multiple actions, they get real if/then/fi blocks (generally) * Re-wrap some of the heinously long lines [1] * Properly (4-space) indent lines continued after pipes [1] * Un-wrap some more short clauses (for, case, etc.) * Move the code to fetch distfiles from do_fetch() in line Tweaks to --clean-packages ========================== 1. Check first if a package matches an installed version and if not offer to delete it. 2. Sort the output of find 3. If there are empty directories to delete, notify the user, otherwise tell the user there is nothing to delete New Feature =========== Add the ability to ignore failed backup package creation by setting PM_IGNORE_FAILED_BACKUP_PACKAGE in the environment (rc file, etc.) General cleanups ================ 1. local'ize a couple more variables 2. Add some more tags to fi lines in long blocks 3. When taking user input, use a safer style of accepting the default answer. If the user types the matching option, or nothing, we accept it. Anything else, we don't. 4. Only run check_state() to see if a port is FORBIDDEN, etc. the first time through 5. In the package do_fetch, use meaninful strings for the flag variables instead of just 1 to make debugging easier Bug Fixes ========= 1. For the new logging feature, if $PM_LOG is not writable it needs to be unset so we don't try writing to it later; and fix one more \n from $INSTALLED_LIST 2. Inspired by: brucification [1] (thanks!) Modified: user/dougb/portmaster/portmaster Modified: user/dougb/portmaster/portmaster ============================================================================== --- user/dougb/portmaster/portmaster Sat Aug 7 19:08:39 2010 (r211033) +++ user/dougb/portmaster/portmaster Sat Aug 7 19:27:36 2010 (r211034) @@ -14,11 +14,7 @@ if [ -z "$PM_PARENT_PID" ]; then # /usr/local is needed in the path for make PATH=/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/bin:/usr/local/sbin [ -e /usr/X11R6 -a ! -L /usr/X11R6 ] && PATH=$PATH:/usr/X11R6/bin - if [ -n "$CCACHE_PATH" ]; then - if [ -z "$NOCCACHE" ]; then - PATH="/usr/local/libexec/ccache:$PATH" - fi - fi + [ -n "$CCACHE_PATH" -a -z "$NOCCACHE" ] && PATH="/usr/local/libexec/ccache:$PATH" export PM_PARENT_PID TMPDIR UPGRADE_TOOL PATH if [ -r /etc/portmaster.rc ]; then @@ -77,7 +73,8 @@ trap_exit () { if [ "$$" -eq "$PM_PARENT_PID" ]; then local n=0 - while ps -axo pid,ppid,command | grep -v egrep | egrep -q "(make -DBATCH checksum|/fetch |\[sh\])"; do + while ps -axo pid,ppid,command | grep -v egrep | + egrep -q "(make -DBATCH checksum|/fetch |\[sh\])"; do # Protect from infinite loop if there is another fetch [ $n -gt 9 ] && break n=$(( $n + 1 )) @@ -90,9 +87,7 @@ trap_exit () { if [ -n "$logs" ]; then echo '' echo "===>>> Build/Install logs available:" - for file in $logs; do - echo " $file" - done + for file in $logs; do echo " $file"; done fi [ -n "$logs" ] && echo '' fi @@ -105,31 +100,27 @@ kill_bad_children () { mypgid=`ps -o pgid -p $PM_PARENT_PID` ; mypgid=${mypgid##*PGID[^0-9]} - ps -axo pid,ppid,pgid,command | sed '1d' | - while read pid ppid pgid command; do + ps -axo pid,ppid,pgid,command | sed '1d' | while read pid ppid pgid command; do [ "$pid" -gt 25 ] || continue case "$ppid" in 1) case "$command" in *" $0 "*) pm_kill $pid ;; - *'make -DBATCH checksum'*|*'/fetch '*|\[sh\]) - pm_kill -9 $pid ;; + *'make -DBATCH checksum'*|*'/fetch '*|\[sh\]) pm_kill -9 $pid ;; esac ;; *) [ $pgid -eq $mypgid ] || continue case "$command" in *" $0 "*) [ $pid -ne $PM_PARENT_PID ] && pm_kill $pid ;; - *'make -DBATCH checksum'*|*'/fetch '*|\[sh\]) - pm_kill $pid ;; + *'make -DBATCH checksum'*|*'/fetch '*|\[sh\]) pm_kill $pid ;; esac ;; esac done } parent_exit () { - local files f show_list + local files f DISCARD show_list + + [ -s "$DI_FILES" ] && { grep -q '%%%%%%%%%%%%' $DI_FILES || kill_bad_children; } - if [ -s "$DI_FILES" ]; then - grep -q '%%%%%%%%%%%%' $DI_FILES || kill_bad_children - fi [ -n "$FETCH_ONLY" -a -z "$FETCH_ONLY_DONE" ] && kill_bad_children if [ -z "$1" ]; then @@ -174,7 +165,7 @@ parent_exit () { if [ -n "$INSTALLED_LIST" ]; then if [ -n "$UPDATE_ALL" -o -n "$PM_MULTI_PORTS" ]; then show_list=all - elif [ -z "$show_list" ]; then + else case "$INSTALLED_LIST" in *\\n\\t*) show_list=all ;; *\\n) show_list=one @@ -189,21 +180,22 @@ parent_exit () { echo '' >> $PM_LOG elif [ -e "$PM_LOG" -a ! -w "$PM_LOG" ]; then echo "===>>> Warning: $PM_LOG exists, but is not writable" + unset PM_LOG elif [ -e "$PM_LOG" -o -L "$PM_LOG" ]; then echo "===>>> Warning: $PM_LOG exists, but is not a regular file" + unset PM_LOG else local new_pm_log - new_pm_log=`pm_mktemp pm_log` && - mv $new_pm_log $PM_LOG + new_pm_log=`pm_mktemp pm_log` && mv $new_pm_log $PM_LOG fi - date >> $PM_LOG + [ -n "$PM_LOG" ] && date >> $PM_LOG fi [ -n "$PM_SU_VERBOSE" ] && echo '' case "$show_list" in all) echo "===>>> The following actions were performed:" echo -e $INSTALLED_LIST - [ -n "$PM_LOG" ] && echo -e ${INSTALLED_LIST%\n} >> $PM_LOG ;; + [ -n "$PM_LOG" ] && echo -e ${INSTALLED_LIST%\\n} >> $PM_LOG ;; one) echo "===>>> $ilist complete" ; echo '' [ -n "$PM_LOG" ] && echo " $ilist" >> $PM_LOG ;; esac @@ -239,14 +231,10 @@ safe_exit () { # Do these here so +IGNOREME can modify them echo "num_of_deps='$num_of_deps'" >> $IPC_SAVE echo "build_l='$build_l'" >> $IPC_SAVE - if [ -z "$NO_DEP_UPDATES" ]; then - echo 'unset NO_DEP_UPDATES' >> $IPC_SAVE - fi + [ -z "$NO_DEP_UPDATES" ] && echo 'unset NO_DEP_UPDATES' >> $IPC_SAVE fi - [ -z "$NO_BACKUP" -a -z "$BACKUP" ] && - echo "NB_DELETE='$NB_DELETE'" >> $IPC_SAVE - [ -n "$PM_MULTI_BUILT" ] && - echo "PM_MULTI_BUILT='$PM_MULTI_BUILT'" >> $IPC_SAVE + [ -z "$NO_BACKUP" -a -z "$BACKUP" ] && echo "NB_DELETE='$NB_DELETE'" >> $IPC_SAVE + [ -n "$PM_MULTI_BUILT" ] && echo "PM_MULTI_BUILT='$PM_MULTI_BUILT'" >> $IPC_SAVE if [ -n "$INTERACTIVE_UPDATE" ]; then echo "INTERACTIVE_YES='$INTERACTIVE_YES'" >> $IPC_SAVE echo "INTERACTIVE_NO='$INTERACTIVE_NO'" >> $IPC_SAVE @@ -402,8 +390,7 @@ pm_unlink () { /bin/test -e $1 && /bin/u # truncate, pkg_create, cp, /etc/rc.d/ldconfig, touch pm_find_s () { $PM_SU_CMD /usr/bin/find $*; } -pm_install_s () { $PM_SU_CMD /usr/bin/install -o root \ - -g wheel -m 644 $1 $2; } +pm_install_s () { $PM_SU_CMD /usr/bin/install -o root -g wheel -m 644 $1 $2; } pm_make_s () { ( unset -v CUR_DEPS INSTALLED_LIST PM_DEPTH build_l; unset -v MASTER_RB_LIST PM_FP_SEEN_LIST; $PM_SU_CMD /usr/bin/nice /usr/bin/make $PM_MAKE_ARGS $*; ); } @@ -604,10 +591,10 @@ if [ "$$" -eq "$PM_PARENT_PID" ]; then fi export pd pdb - if [ -z "$DISTDIR" -a "$PM_PACKAGES" != only -a -z "$CHECK_DEPENDS" -a \ - -z "$CHECK_PORT_DBDIR" -a -z "$LIST_ORIGINS" ]; then + [ -z "$DISTDIR" -a "$PM_PACKAGES" != only -a -z "$CHECK_DEPENDS" -a \ + -z "$CHECK_PORT_DBDIR" -a -z "$LIST_ORIGINS" ] && DISTDIR=`pm_make_b -f/usr/share/mk/bsd.port.mk -V DISTDIR 2>/dev/null` - fi + [ -n "$DISTDIR" ] && { DISTDIR="${DISTDIR%/}/"; export DISTDIR; } [ -z "$port_dbdir" -a -d /var/db/ports ] && port_dbdir=/var/db/ports @@ -641,6 +628,7 @@ iport_from_origin () { origin_from_pdb () { local o + o=`grep -m1 '@comment ORIGIN:' $pdb/$1/+CONTENTS 2>/dev/null` && { echo ${o#@comment ORIGIN:}; return 0; } @@ -681,8 +669,7 @@ check_dependency_files () { origin=$1 ; iport=$2 # egrep hates + in file names - case "$origin" in *+*) - origin=`echo $origin | sed 's#\+#\\\\+#g'` ;; esac + case "$origin" in *+*) origin=`echo $origin | sed 's#\+#\\\\+#g'` ;; esac case "$ro_opd" in '') ro_opd=a/a ;; *+*) ro_opd=`echo $ro_opd | sed 's#\+#\\\\+#g'` ;; esac @@ -690,7 +677,7 @@ check_dependency_files () { # Always rely on the grep'ed dependencies instead of +REQUIRED_BY grep_deps=`pm_mktemp grep-deps-${iport}` egrep -l "DEPORIGIN:($origin|$ro_opd)$" $pdb/*/+CONTENTS | - strip_to_iport | sort -u > $grep_deps + strip_to_iport | sort -u > $grep_deps if [ ! -s "$grep_deps" ]; then if [ -s "$pdb/$iport/+REQUIRED_BY" ]; then @@ -813,11 +800,11 @@ find_moved_port () { ${sf}\|\|*) [ -n "$iport" ] || iport=`iport_from_origin $sf` if [ -e "$pdb/$iport/+IGNOREME" ]; then if [ -n "$PM_VERBOSE" ]; then - echo '' - echo " ===>>> The $sf port has been deleted" - echo " ===>>> Reason: ${l##*|}" - echo " ===>>> Skipping it due to +IGNOREME file" - echo '' + echo '' + echo " ===>>> The $sf port has been deleted" + echo " ===>>> Reason: ${l##*|}" + echo " ===>>> Skipping it due to +IGNOREME file" + echo '' fi return 0 else @@ -846,11 +833,7 @@ find_moved_port () { echo '' [ -n "$iport" ] || iport=`iport_from_origin $sf` - if [ -e "$pdb/$iport/+IGNOREME" ]; then - return 0 - else - return 1 - fi + [ -e "$pdb/$iport/+IGNOREME" ] || return 1 fi return 0 } @@ -1057,8 +1040,8 @@ if [ -n "$CLEAN_DISTFILES" ]; then echo -n "===>>> Delete stale file: ${f}? y/n [y] " read answer case "$answer" in - [nN]*) continue ;; - *) pm_unlink $df ;; + [yY]|'') pm_unlink $df ;; + *) continue ;; esac fi fi @@ -1071,10 +1054,21 @@ fi if [ -n "$CLEAN_PACKAGES" ]; then init_packages_var - echo "===>>> Checking for stale packages" + echo "===>>> Checking for stale packages"; echo '' for package in `find $PACKAGES -type f | sort`; do - origin=`tar -O -zxvf $package '+CONTENTS' 2>/dev/null | grep '@comment ORIGIN:'` || { - fail Empty origin in $package; } + pkg_dir=${package##*/} ; pkg_dir=${pkg_dir%\.tbz} + if [ ! -d "${pdb}/${pkg_dir}" ]; then + echo "===>>> ${package##*/} is not currently installed" + echo -n " ===>>> Delete? y/n [y] " + read answer + case "$answer" in + [yY]|'') echo " ===>>> Deleting $package" + pm_unlink_s $package ; continue ;; + esac + fi + + origin=`tar -O -zxvf $package '+CONTENTS' 2>/dev/null | grep '@comment ORIGIN:'` || + fail Empty origin in $package origin=${origin#@comment ORIGIN:} if [ -z "$PM_INDEX" ]; then @@ -1100,7 +1094,7 @@ if [ -n "$CLEAN_PACKAGES" ]; then echo "===>>> Package version: ${package##*/} Latest version: $port_ver" - if [ -d "${pdb}/${package##*/}" ]; then + if [ -d "${pdb}/${pkg_dir}" ]; then echo " ===>>> ${package##*/} matches the installed version" else echo " ===>>> ${package##*/} is out of date" @@ -1113,28 +1107,36 @@ if [ -n "$CLEAN_PACKAGES" ]; then echo -n " ===>>> Delete stale package: ${package##*/}? y/n [y] " read answer case "$answer" in - [nN]*) continue ;; + [yY]|'') echo " ===>>> Deleting $package" + pm_unlink_s $package ;; esac fi - echo " ===>>> Deleting $package" - pm_unlink_s $package done echo '' ; echo "===>>> Deleting stale symlinks" pm_cd $PACKAGES || fail "Cannot cd to $PACKAGES" - for link in `find . -type l` ; do + for link in `find . -type l | sort` ; do if [ ! -e "$link" ]; then echo " ===>>> ${link#./}" $PM_SU_CMD /bin/unlink $link fi done - echo '' ; echo "===>>> Deleting empty directories (if any)" - pm_find_s . -type d -empty -delete + echo '' + empty_dirs=`find . -type d -empty -print | sort` + if [ -n "$empty_dirs" ]; then + echo "===>>> Deleting empty directories" + for dir in $empty_dirs; do + echo " ===>>> ${dir#\.\/}" + done + pm_find_s . -type d -empty -delete + else + echo "===>>> No empty directories in $PACKAGES" + fi safe_exit -fi +fi # [ -n "$CLEAN_PACKAGES" ] if [ -n "$CHECK_DEPENDS" ]; then d_orig_ok=':' @@ -1147,9 +1149,10 @@ IFS=' echo "===>>> Checking $iport" - [ -r "$pkg/+CONTENTS" ] || { - echo " ===>>> Warning: No +CONTENTS file!"; - continue; } + if [ ! -r "$pkg/+CONTENTS" ]; then + echo " ===>>> Warning: No +CONTENTS file!" + continue + fi origin=`origin_from_pdb $iport` || continue @@ -1174,8 +1177,7 @@ IFS=' pm_install_s $grep_deps $pkg/+REQUIRED_BY fi fi - [ -n "$grep_deps" ] && { - pm_unlink $grep_deps && unset grep_deps; } + [ -n "$grep_deps" ] && { pm_unlink $grep_deps && unset grep_deps; } update_contents $pkg/+CONTENTS done @@ -1205,9 +1207,10 @@ if [ -n "$CHECK_PORT_DBDIR" ]; then origin=$moved_npd fi - pm_cd $pd/$origin || { - echo " ===>>> $pd/$origin does not exist for $pkg"; - continue; } + if ! pm_cd $pd/$origin; then + echo " ===>>> $pd/$origin does not exist for $pkg" + continue + fi unique_name=`make -V UNIQUENAME` unique_list="${unique_list}${unique_name}:" done @@ -1420,8 +1423,8 @@ check_for_updates () { if [ -d "$pd/$origin" -a -z "$do_update" -a -z "$skip" ]; then if ! pm_cd $pd/$origin; then if [ -e "$pdb/$iport/+IGNOREME" ]; then - echo " ===>>> Warning: Unable to cd to $pd/$origin" - echo " ===>>> Continuing due to $pdb/$iport/+IGNOREME" + echo " ===>>> Warning: Unable to cd to $pd/$origin" + echo " ===>>> Continuing due to $pdb/$iport/+IGNOREME" return 0 else fail "Cannot cd to port directory: $pd/$origin" @@ -1449,8 +1452,7 @@ check_for_updates () { udf="$pdb/$iport/PM_UPGRADE_DONE_FLAG" if [ "$iport" = "$port_ver" ]; then if [ -n "$PM_FORCE" ]; then - check_restart_and_udf $udf $iport || - do_update=do_update_force + check_restart_and_udf $udf $iport || do_update=do_update_force elif [ -n "$URB_YES" ]; then case "$MASTER_RB_LIST" in *" $iport "*) if ! check_restart_and_udf $udf $iport; then @@ -1475,8 +1477,7 @@ check_for_updates () { fi fi - [ -z "$do_update" ] && { - CUR_DEPS="${CUR_DEPS}${iport}:${origin}:" ; return 0; } + [ -z "$do_update" ] && { CUR_DEPS="${CUR_DEPS}${iport}:${origin}:" ; return 0; } if [ -n "$list_only" ]; then if [ -z "$moved_npd" ]; then @@ -1520,7 +1521,7 @@ init_packages () { } pm_pkg_create () { - local pkgdir + local pkgdir backup init_packages @@ -1534,6 +1535,7 @@ pm_pkg_create () { else pkgdir=$1 ; echo '' echo "===>>> Creating a backup package for old version $2" + backup=backup fi pm_cd $pkgdir || fail "Cannot cd into $pkgdir to create a package" @@ -1565,13 +1567,16 @@ pm_pkg_create () { echo '' echo "===>>> Package creation failed for ${2}!" echo '' + + [ -n "$backup" -a -n "$PM_IGNORE_FAILED_BACKUP_PACKAGE" ] && return + echo "===>>> Ignore this error [i]" echo "===>>> Abort [a]" echo '' echo -n "===>>> How would you like to proceed? [i] " local answer ; read answer case "$answer" in - a) fail "Package creation failed for $2" ;; + [aA]) fail "Package creation failed for $2" ;; esac fi } @@ -1921,7 +1926,7 @@ if [ -n "$CLEAN_STALE" ]; then deplist=`grep -l DEPORIGIN:$origin$ $pdb/*/+CONTENTS` if [ -n "$deplist" ]; then echo '' - echo "===>>> Warning: Unrecorded dependencies on ${iport}:" + echo "===>>> Warning: Unrecorded dependencies on ${iport}:" for dep in $deplist; do dep=${dep%/+CON*} ; echo " ${dep##*/}" done @@ -1937,8 +1942,7 @@ if [ -n "$CLEAN_STALE" ]; then read answer case "$answer" in [yY]) [ -n "$BACKUP" ] && { init_packages ; pm_pkg_create $pbu $iport; } - [ -z "$DONT_SCRUB_DISTFILES" ] && - delete_all_distfiles $origin + [ -z "$DONT_SCRUB_DISTFILES" ] && delete_all_distfiles $origin delete_dist_list echo "===>>> Running pkg_delete -f $iport" @@ -1999,8 +2003,8 @@ check_interactive () { echo '' ; echo -n "===>>> Update ${1}${update_to}? y/n [y] " local answer ; read answer case "$answer" in - [nN]*) INTERACTIVE_NO="${INTERACTIVE_NO}${1}:" ; return 1 ;; - *) INTERACTIVE_YES="${INTERACTIVE_YES}${1}:" ;; + [yY]|'') INTERACTIVE_YES="${INTERACTIVE_YES}${1}:" ;; + *) INTERACTIVE_NO="${INTERACTIVE_NO}${1}:" ; return 1 ;; esac return 0 } @@ -2013,12 +2017,12 @@ check_exclude () { for pat in $PM_EXCL; do case "$1" in *${pat}*) - if [ -n "$PM_VERBOSE" ]; then - echo "===>>> Skipping $1" - echo " because it matches the pattern: *${pat}*" - echo '' - fi - return 1 ;; + if [ -n "$PM_VERBOSE" ]; then + echo "===>>> Skipping $1" + echo " because it matches the pattern: *${pat}*" + echo '' + fi + return 1 ;; esac done @@ -2109,9 +2113,7 @@ update_port () { echo " ${PM_DEPTH}>> ${1#$pd/}" term_printf " ${PM_DEPTH#* }>> ${1#$pd/}${deps}" else - if [ -n "$UPDATE_ALL" ]; then - term_printf " >> ${1#$pd/}${deps}" - fi + [ -n "$UPDATE_ALL" ] && term_printf " >> ${1#$pd/}${deps}" fi [ -n "$doing_dep_check" -o \( -n "$UPDATE_ALL" -a -n "$PM_FIRST_PASS" \) ] && @@ -2131,7 +2133,7 @@ update_port () { elif [ -n "$UPDATE_REQ_BYS" ]; then return 0 elif [ -n "$PM_FIRST_PASS" -a -z "$PM_PACKAGES" ]; then - echo "===>>> Continuing initial dependency check for $portdir" + echo "===>>> Continuing initial dependency check for $portdir" else term_printf " ${PM_DEPTH#* }${deps}" echo "===>>> Returning to dependency check for $portdir" @@ -2176,7 +2178,7 @@ gen_dep_list () { case "$*" in 'build-depends-list run-depends-list'|all-depends-list) - temp_list="`parse_index $portdir b-deps` `parse_index $portdir r-deps`" ;; + temp_list="`parse_index $portdir b-deps` `parse_index $portdir r-deps`" ;; build-depends-list) temp_list=`parse_index $portdir b-deps` ;; run-depends-list) temp_list=`parse_index $portdir r-deps` ;; esac @@ -2303,11 +2305,7 @@ dependency_check () { # In case d_port changed above origin="${d_port#$pd/}" ; iport=`iport_from_origin ${origin}` - if [ -n "$iport" ]; then - check_exclude $iport || continue - else - check_exclude $origin || continue - fi + check_exclude ${iport:-$origin} || continue udf="$pdb/$iport/PM_UPGRADE_DONE_FLAG" if [ -n "$PM_FORCE" -a -n "$iport" ]; then @@ -2404,7 +2402,8 @@ post_first_pass () { echo -n "===>>> Proceed? y/n [y] " read answer case "$answer" in - [nN]*) echo '' + [yY]|'') ;; + *) echo '' echo "===>>> If you would like to upgrade or install some, but not" echo " all of the above try adding '-i' to the command line." safe_exit 1 ;; @@ -2422,9 +2421,7 @@ post_first_pass () { action='build and/or install' fi - echo '' - echo "===>>> Starting $action for $* <<<===" - echo '' + echo ''; echo "===>>> Starting $action for $* <<<==="; echo '' unset PM_FP_SEEN_LIST PM_FIRST_PASS PM_NO_CONFIRM @@ -2445,7 +2442,7 @@ post_first_pass () { done [ "$real_rundep" = 'no' ] && - eval build_only_dl_g=\"${build_only_dl_g}\$${var}_p \" + eval build_only_dl_g=\"${build_only_dl_g}\$${var}_p \" eval unset $var ${var}_p done @@ -2478,7 +2475,7 @@ multiport () { local port worklist_temp worklist portlist numports num # Expand globs and check that the directories exist - for port in $@; do + for port in "$@"; do port=${port#$pdb/} case "$port" in */*) port=${port#$pd/} @@ -2524,8 +2521,7 @@ multiport () { for port in $worklist; do case "$port" in */*) run_dl_g="$run_dl_g ${pd}/${port} " ;; - *) - run_dl_g="$run_dl_g ${pd}/`origin_from_pdb $port` " ;; + *) run_dl_g="$run_dl_g ${pd}/`origin_from_pdb $port` " ;; esac done fi @@ -2576,7 +2572,6 @@ make_config () { urb_final () { # Global: URB_YES - local req_by export URB_YES=urb_yes_final @@ -2692,7 +2687,7 @@ if [ "$$" -eq "$PM_PARENT_PID" -a -z "$S [ -z "$DONT_SCRUB_DISTFILES" -a -z "$FETCH_ONLY" -a -z "$PM_PACKAGES" ] && export DI_FILES=`pm_mktemp DI-FILES` - [ $# -gt 1 -a -z "$REPLACE_ORIGIN" ] && multiport $@ + [ $# -gt 1 -a -z "$REPLACE_ORIGIN" ] && multiport "$@" elif [ -z "$SHOW_WORK" ]; then # Zero out this file so that we can save our data to it safely > $IPC_SAVE @@ -2703,7 +2698,7 @@ if [ -n "$UPDATE_ALL" ]; then all_first_pass () { local iport origin - for iport in $@; do + for iport in "$@"; do pm_v "===>>> $iport" case "$CUR_DEPS" in *:${iport}:*) continue ;; esac @@ -2798,10 +2793,10 @@ all_first_pass () { echo "===>>> Update check of installed ports complete" ; echo '' safe_exit -fi +fi # [ -n "$UPDATE_ALL" ] no_valid_port () { - echo "===>>> No valid installed port, or port directory given"; + echo "===>>> No valid installed port, or port directory given" echo "===>>> Try ${0##*/} --help" ; echo '' ; safe_exit 1 } @@ -2830,9 +2825,11 @@ if [ -z "$REPLACE_ORIGIN" ]; then fi else portdir="${1#$pd/}" ; portdir="${portdir%/}" - [ -d "$pd/$portdir" ] || { echo '' + if [ ! -d "$pd/$portdir" ]; then + echo '' echo "===>>> The first argument to -o must be a directory in $pd" - echo '' ; no_valid_port; } + echo '' ; no_valid_port + fi upg_port=`iport_from_origin $portdir` @@ -2865,8 +2862,7 @@ fi if [ -n "$upg_port" -a -z "$portdir" ]; then portdir=`origin_from_pdb $upg_port` || { case "$?" in - 3) echo '' - echo "===>>> BSDPAN ports cannot be upgraded with portmaster" + 3) echo ''; echo "===>>> BSDPAN ports cannot be upgraded with portmaster" echo " (${upg_port})"; echo ''; safe_exit 1 ;; 2) pm_v " ===>>> No ORIGIN for $upg_port, and +IGNOREME is present"; pm_v safe_exit 1 ;; @@ -2900,7 +2896,7 @@ if [ -e "$pdb/$upg_port/+IGNOREME" ]; th read answer case "$answer" in [yY]) ;; # Let it build - *) CUR_DEPS="${CUR_DEPS}${upg_port}:${portdir}:" + *) CUR_DEPS="${CUR_DEPS}${upg_port}:${portdir}:" if [ $dep_of_deps -gt 0 ]; then dep_of_deps=$(( $dep_of_deps - 1 )) if [ -n "$PM_FIRST_PASS" ]; then @@ -2943,8 +2939,7 @@ fi if [ -n "$PM_FIRST_PASS" -a "$$" -eq "$PM_PARENT_PID" ]; then if [ -n "$upg_port" ]; then update_build_l $upg_port - [ -n "$UPDATE_REQ_BYS" -a -n "$RESTART" ] && - check_for_updates $upg_port + [ -n "$UPDATE_REQ_BYS" -a -n "$RESTART" ] && check_for_updates $upg_port else update_build_l $portdir fi @@ -2957,29 +2952,16 @@ echo '' if [ -z "$PM_INDEX_ONLY" ]; then echo "===>>> Port directory: $pd/$portdir" - check_state || { - echo " ===>>> If you are sure you can build it, remove the"; - echo " $state line in the Makefile and try again."; - safe_exit 1; } - - # Do not start this in the background until we are sure we are going to build - [ "$$" -eq "$PM_PARENT_PID" -a -n "$DI_FILES" ] && { echo ''; (read_distinfos)& } - # Do these things first time through if [ -z "$PM_BUILDING" -a -z "$SHOW_WORK" -a -z "$NO_ACTION" ]; then - dofetch () { - local fetchlog allfiles + if ! check_state; then + echo " ===>>> If you are sure you can build it, remove the" + echo " $state line in the Makefile and try again." + safe_exit 1 + fi - echo "===>>> Launching 'make checksum' for $portdir in background" - fetchlog=`pm_mktemp fetchlog-${portdir#*/}` - (pm_make -DBATCH checksum >> $fetchlog 2>&1 && { - rm -f ${TMPDIR}/f-${PM_PARENT_PID}-*-${portdir#*/}.*; exit 0; } - allfiles=`pm_make -V ALLFILES` - pm_make delete-distfiles RESTRICTED_FILES="${allfiles}" >> $fetchlog 2>&1 && - echo "===>>> RE-STARTING FETCH <<<===" >> $fetchlog - pm_make -DBATCH checksum >> $fetchlog 2>&1; \ - rm -f ${TMPDIR}/f-${PM_PARENT_PID}-*-${portdir#*/}.* )& - } + # Do not start this in the background until we are sure we are going to build + [ "$$" -eq "$PM_PARENT_PID" -a -n "$DI_FILES" ] && { echo ''; (read_distinfos)& } # Handle the problem of manual fetching [ -z "$PM_PACKAGES" ] && master_sites=`pm_make_b -V MASTER_SITES` @@ -3003,9 +2985,20 @@ if [ -z "$PM_INDEX_ONLY" ]; then fi done - [ -z "$DONT_FETCH" -a -n "$distfiles" ] && dofetch + if [ -z "$DONT_FETCH" -a -n "$distfiles" ]; then + echo "===>>> Launching 'make checksum' for $portdir in background" + fetchlog=`pm_mktemp fetchlog-${portdir#*/}` + (pm_make -DBATCH checksum >> $fetchlog 2>&1 && { + rm -f ${TMPDIR}/f-${PM_PARENT_PID}-*-${portdir#*/}.*; exit 0; } + allfiles=`pm_make -V ALLFILES` + pm_make delete-distfiles RESTRICTED_FILES="${allfiles}" \ + >> $fetchlog 2>&1 && + echo "===>>> RE-STARTING FETCH <<<===" >> $fetchlog + pm_make -DBATCH checksum >> $fetchlog 2>&1 + rm -f ${TMPDIR}/f-${PM_PARENT_PID}-*-${portdir#*/}.* )& + fi + unset master_sites distfiles file DONT_FETCH fetchlog allfiles fi - unset master_sites distfiles file DONT_FETCH if [ -z "$FETCH_ONLY" -a ! "$PM_PACKAGES" = only ]; then TESTINT=`grep -l ^IS_INTERACTIVE Makefile` @@ -3022,7 +3015,7 @@ if [ -z "$PM_INDEX_ONLY" ]; then echo '' unset TESTINT DISCARD fi - fi + fi # [ -z "$PM_BUILDING" -a -z "$SHOW_WORK" -a -z "$NO_ACTION" ] fi # [ -z "$PM_INDEX_ONLY" ] if [ -n "$PM_FIRST_PASS" ]; then @@ -3083,7 +3076,7 @@ if [ -n "$PM_FIRST_PASS" ]; then else check_for_updates $req_by || fail 'Update failed' fi - echo "===>>> Returning to check of ports depending on $upg_port" + echo "===>>> Returning to check of ports depending on $upg_port" done echo '' echo "===>>> Done checking ports that depend on $upg_port" @@ -3102,8 +3095,8 @@ fi # [ -n "$PM_FIRST_PASS" ] if [ -n "$PM_BUILD_ONLY_LIST" ]; then case "$build_only_dl_g" in *" $pd/$portdir "*) - [ -n "$PM_PACKAGES_BUILD" ] && PM_PACKAGES_BUILD=doing_build_only_dep - [ -n "$PM_DEL_BUILD_ONLY" ] && PM_DEL_BUILD_ONLY=doing_build_only_dep ;; + [ -n "$PM_PACKAGES_BUILD" ] && PM_PACKAGES_BUILD=doing_build_only_dep + [ -n "$PM_DEL_BUILD_ONLY" ] && PM_DEL_BUILD_ONLY=doing_build_only_dep ;; *) [ -n "$PM_PACKAGES_BUILD" ] && PM_PACKAGES_BUILD=pmp_build [ -n "$PM_DEL_BUILD_ONLY" ] && PM_DEL_BUILD_ONLY=pm_dbo ;; esac @@ -3134,8 +3127,7 @@ if [ -z "$new_port" ]; then if [ -z "$PM_INDEX_ONLY" ]; then new_port=`pm_make -V PKGNAME` else - new_port=`parse_index $portdir name` || - fail "No INDEX entry for $origin" + new_port=`parse_index $portdir name` || fail "No INDEX entry for $origin" fi fi @@ -3151,10 +3143,7 @@ fetch_package () { export ppd fi - if [ ! -d "$ppd" ]; then - pm_sv Creating $ppd - pm_mkdir_s $ppd - fi + [ -d "$ppd" ] || { pm_sv Creating $ppd; pm_mkdir_s $ppd; } if [ -z "$FETCH_ARGS" ]; then FETCH_ARGS=`pm_make -f/usr/share/mk/bsd.port.mk -V FETCH_ARGS 2>/dev/null` @@ -3167,10 +3156,10 @@ fetch_package () { pm_v "===>>> Package exists, skipping fetch" return 0 else - do_fetch=1 + do_fetch=do_fetch_no_package fi else - do_fetch=1 + do_fetch=do_fetch_always_fetch fi if [ -n "$do_fetch" ]; then @@ -3183,9 +3172,10 @@ fetch_package () { fi pm_sv Fetching ${1}.tbz - $PM_SU_CMD fetch $FETCH_ARGS -o $ppd ${sitepath}${1}.tbz 2>/dev/null || { - pm_unlink_s ${ppd}/${1}.tbz; - $PM_SU_CMD fetch $FETCH_ARGS -o $ppd ${sitepath}${1}.tbz 2>/dev/null; } + if ! $PM_SU_CMD fetch $FETCH_ARGS -o $ppd ${sitepath}${1}.tbz 2>/dev/null; then + pm_unlink_s ${ppd}/${1}.tbz + $PM_SU_CMD fetch $FETCH_ARGS -o $ppd ${sitepath}${1}.tbz 2>/dev/null + fi fi } if [ -z "$PACKAGESITE" -a -z "$PM_PACKAGES_LOCAL" ]; then @@ -3220,14 +3210,14 @@ fetch_package () { local_package=${LOCAL_PACKAGEDIR}/All/${new_port}.tbz latest_pv=${local_package##*/} fi - if [ -z "$latest_pv" -a -z "$PM_INDEX_ONLY" ]; then + if [ -z "$latest_pv" -a -z "$PM_INDEX_ONLY" ]; then s=`pm_make -V LATEST_LINK` if [ -r "${LOCAL_PACKAGEDIR}/Latest/${s}.tbz" ]; then local_package=${LOCAL_PACKAGEDIR}/Latest/${s}.tbz latest_pv=`readlink ${LOCAL_PACKAGEDIR}/Latest/${s}.tbz` latest_pv=${latest_pv##*/} else - pm_v "===>>> No local package for $new_port exists, attempting fetch" + pm_v "===>>> No local package for ${new_port}, attempting fetch" fi fi fi @@ -3238,7 +3228,7 @@ fetch_package () { pm_unlink $dirlist # JIC dirlist=`pm_mktemp dl-${portdir%/*}` fetch -q -o - ${sitepath} 2>/dev/null | - sed -e "s#%2[cC]#,#g" -e "s#%2[bB]#+#g" > $dirlist + sed -e "s#%2[cC]#,#g" -e "s#%2[bB]#+#g" > $dirlist fi for s in ${new_port%\.*} ${new_port%%\.*} ${new_port%-*}; do @@ -3248,12 +3238,8 @@ fetch_package () { fi unset dirlist s - if [ -z "$latest_pv" -a -z "$PM_PACKAGES_LOCAL" ]; then - fetch_package $new_port try - if [ $? -eq 0 ]; then - latest_pv=$new_port - fi - fi + [ -z "$latest_pv" -a -z "$PM_PACKAGES_LOCAL" ] && { + fetch_package $new_port try && latest_pv=$new_port; } ponly_err="Try --packages-if-newer, or do not use -PP/--packages-only" @@ -3261,9 +3247,7 @@ fetch_package () { echo "===>>> Package and/or archive not found at:" if [ -n "$LOCAL_PACKAGEDIR" ]; then echo " $LOCAL_PACKAGEDIR" - if [ -z "$PM_PACKAGES_LOCAL" ]; then - echo ' or' - fi + [ -z "$PM_PACKAGES_LOCAL" ] && echo ' or' fi [ -z "$PM_PACKAGES_LOCAL" ] && echo " ${sitepath}" echo '' @@ -3282,7 +3266,6 @@ notnewer () { unset local_package } - if [ "$latest_pv" = "$new_port" ]; then use_package=up_equal pm_v "===>>> Available package ($latest_pv) matches the current version" @@ -3372,7 +3355,7 @@ if [ -z "$use_package" ]; then sleep=$(( $sleep + 1 )) fi done - unset sleep + unset sleep fl_read if [ -n "$HIDE_BUILD" ]; then port_log=`mktemp -t port_log-${PM_PARENT_PID}-${portdir#*/}` || @@ -3399,10 +3382,12 @@ if [ -n "$upg_port" -o -n "$ro_upg_port" if [ -n "$SAVE_SHARED" ]; then ldconfig_out=`pm_mktemp ldconfig` - ldconfig -r | sed 's#.* ##' | grep -v ^$LOCALBASE_COMPAT > $ldconfig_out + ldconfig -r | sed 's#.* ##' | + grep -v ^$LOCALBASE_COMPAT > $ldconfig_out unset temp - for file in `pkg_info -q -L $UPGRADE_PORT | sort - $ldconfig_out | uniq -d`; do + for file in `pkg_info -q -L $UPGRADE_PORT | + sort - $ldconfig_out | uniq -d`; do temp="${temp}$file " done if [ -n "$temp" ]; then @@ -3459,10 +3444,10 @@ install_failed () { if [ -z "$use_package" ]; then pm_sv Running make install - if [ -n "$PM_SU_UNSET_PORT_LOG_ARGS" ]; then - unset port_log_args - else + if [ -z "$PM_SU_UNSET_PORT_LOG_ARGS" ]; then [ -n "$HIDE_BUILD" ] && echo "===>>> Logging install to $port_log" + else + unset port_log_args fi # Defining NO_DEPENDS ensures that we will control the installation @@ -3473,9 +3458,10 @@ else echo "===>>> Installing package" if $PM_SU_CMD pkg_add --no-deps --force ${ppd}/${latest_pv}.tbz; then - [ -n "$PM_DELETE_PACKAGES" ] && { + if [ -n "$PM_DELETE_PACKAGES" ]; then pm_v "===>>> Deleting ${latest_pv}.tbz" - pm_unlink_s ${ppd}/${latest_pv}.tbz; } + pm_unlink_s ${ppd}/${latest_pv}.tbz + fi else install_failed ${latest_pv}.tbz fi @@ -3491,8 +3477,8 @@ temp=`find $LOCALBASE_COMPAT -type d -em if [ -z "$temp" -a -d "$LOCALBASE_COMPAT" ]; then unset files for file in `pkg_info -q -L $new_port`; do - [ -f "${LOCALBASE_COMPAT}/${file##*/}" ] && { - files="${files}${LOCALBASE_COMPAT}/${file##*/} "; } + [ -f "${LOCALBASE_COMPAT}/${file##*/}" ] && + files="${files}${LOCALBASE_COMPAT}/${file##*/} " done if [ -n "$files" ]; then @@ -3541,7 +3527,8 @@ if [ -n "$distfiles" ]; then size=`grep "^SIZE (${ds}${file})" $distinfo` sha256=`grep "^SHA256 (${ds}${file})" $distinfo` md5=`grep "^MD5 (${ds}${file})" $distinfo` - echo "DISTFILE:${ds}${file}:SIZE=${size##* }:SHA256=${sha256##* }:MD5=${md5##* }" >> $dist_list_temp + echo "DISTFILE:${ds}${file}:SIZE=${size##* }:SHA256=${sha256##* }:MD5=${md5##* }" \ + >> $dist_list_temp # Make sure any new distfiles get added to the list [ -z "$DONT_SCRUB_DISTFILES" -a ! "$$" -eq "$PM_PARENT_PID" ] && echo "${ds}$file" >> $DI_FILES @@ -3563,24 +3550,22 @@ fi if [ -n "$MAKE_PACKAGE" ]; then if [ -z "$use_package" ]; then echo "===>>> Creating a package for new version $new_port" - pm_make_s package >/dev/null || - fail "Package creation of $new_port failed" + pm_make_s package >/dev/null || fail "Package creation of $new_port failed" echo " ===>>> Package saved to $PACKAGES/All" ; echo '' else pm_pkg_create $PACKAGES $new_port fi fi -if [ -z "$use_package" ]; then - [ -z "$DONT_POST_CLEAN" ] && { - pm_sv Running \'make clean\' - pm_make_s clean NOCLEANDEPENDS=ncd2 ; echo ''; } +if [ -z "$use_package" -a -z "$DONT_POST_CLEAN" ]; then + pm_sv Running \'make clean\' + pm_make_s clean NOCLEANDEPENDS=ncd2 + echo '' fi check_dependency_files $portdir $new_port if [ -s "$grep_deps" ]; then - echo "===>>> Updating dependency entry for $new_port in each dependent port" - pm_v + echo "===>>> Updating dependency entry for $new_port in each dependent port"; pm_v while read d_port; do pm_v "===>>> $d_port" dp_cont=$pdb/$d_port/+CONTENTS @@ -3599,8 +3584,7 @@ if [ -s "$grep_deps" ]; then unset d_port dp_cont do_update if [ -e "$pdb/$new_port/+REQUIRED_BY" ]; then - sort $pdb/$new_port/+REQUIRED_BY | cmp -s $grep_deps - || - do_update=do_update + sort $pdb/$new_port/+REQUIRED_BY | cmp -s $grep_deps - || do_update=do_update check_regular_file $pdb/$new_port/+REQUIRED_BY else do_update=do_update2 @@ -3636,8 +3620,7 @@ CUR_DEPS="${CUR_DEPS}${new_port}:${portd [ -n "$HIDE_BUILD" -a -n "$port_log" ] && pm_unlink $port_log -[ -n "$URB_YES" -o -n "$UPDATE_REQ_BYS" ] && - URB_DONE_LIST="${URB_DONE_LIST}${new_port}:" +[ -n "$URB_YES" -o -n "$UPDATE_REQ_BYS" ] && URB_DONE_LIST="${URB_DONE_LIST}${new_port}:" [ -n "$URB_YES" -o -n "$UPDATE_REQ_BYS" -o -n "$PM_FORCE" ] && $PM_SU_CMD touch $pdb/$new_port/PM_UPGRADE_DONE_FLAG