#
plural()
{
- if [ $1 -ne 1 ]
+ if [ "$1" -a "$1" -ne 1 ]
then
- echo 's'
+ echo s
fi
}
#
- # Prints error and exists.
+ # Prints error and exits.
#
error()
{
#
cleanexit()
{
- local file
-
-
if [ ! "$LOCKFILE" ]
then
error 'internal error: $LOCKFILE is empty'
fi
- #if [ ! "$TEMP_PREFIX" ]
- #then
- # notice 'internal error: $TEMP_PREFIX is empty'
- #
- #else
- # for file in "$TEMP_PREFIX."???
- # do
- # unlink_file "$file"
- # done
- #fi
-
-
exit ${1:-0}
}
return 1
fi
+
echo
echo "> $1"
}
#
checkyesno()
{
+ if [ ! "$1" ]
+ then
+ return 1
+ fi
+
+
eval local value=\$$1
- case $value
+ case "$value"
in
[Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]|[Oo][Nn]|1)
+
+ unset value
+
return 0
;;
[Nn][Oo]|[Ff][Aa][Ll][Ss][Ee]|[Oo][Ff][Ff]|0)
+
+ unset value
+
return 1
;;
*)
- error "variable $1 is not set properly in $CONFIG_FILE"
- return 1
+ error "variable '$1' is not set properly in '$CONFIG_FILE'"
;;
esac
}
fi
- mktemp "$TEMP_PREFIX.XXX" || \
- error 'mktemp error'
+ mktemp "$TEMP_PREFIX.XXX" || error 'mktemp error'
}
#
show_dialog()
{
- local name text options type options_tempfile exitcode selected_options
-
-
if [ $# -ne 3 -a $# -ne 4 ]
then
return 1
fi
- name="$1"
- text="$2"
- options="$3"
+ local name text options type options_tempfile exitcode selected_options
+
+ name=$1
+ text=$2
+ options=$3
+
type=checklist
- case "$4"
+ case $4
in
''|checklist)
+
options_tempfile=`make_temp`
;;
+
menu)
- type="$4"
+ type=$4
;;
+
*)
+ unset name text options type options_tempfile exitcode selected_options
+
return 1
;;
esac
eval selopt_${name}_exitcode=\$exitcode
+ unset text options exitcode
+
if [ "$type" = checklist ]
then
selected_options=`sed 's|"||g' < "$options_tempfile"`
unlink_file "$options_tempfile"
+ unset options_tempfile
+
eval selopt_${name}_values="\$selected_options"
+
+ unset selected_options
fi
+
+ unset name type
}
#
- # Shows package deinstall dialog.
+ # Shows confirm dialog.
#
- package_deinstall()
+ show_confirm()
{
- local package NUM DIALOG_OPTIONS PACKAGES
+ if [ $# -ne 2 -a "$1" -a "$2" ]
+ then
+ return 1
+ fi
- PACKAGES="$1"
+ local type package packages count dialog_options confirm_message cancel_message
- if [ ! "$PACKAGES" ]
+ type=$1
+ packages=$2
+
+
+ for package in $packages
+ do
+ count=$(($count + 1))
+
+ dialog_options="$dialog_options '$package' ' '"
+ done
+
+ unset package packages
+
+
+ case $type
+ in
+ upgrade)
+ confirm_message="Upgrade $count package`plural $count`?"
+
+ cancel_message='Upgrade cancelled'
+ ;;
+
+ deinstall)
+ confirm_message="Deinstall $count package`plural $count`?\nARE YOU SURE?"
+
+ cancel_message='Deinstall cancelled'
+ ;;
+
+ install)
+ confirm_message="Install $count package`plural $count`?"
+
+ cancel_message='Install cancelled'
+ ;;
+
+ *)
+ error "show_confirm: internal error: invalid type '$type'"
+ ;;
+ esac
+
+ unset type count
+
+
+ show_dialog confirm "$confirm_message" "$dialog_options" menu
+
+ unset dialog_options confirm_message
+
+
+ if cmd_failed $selopt_confirm_exitcode
then
echo
- echo 'No packages selected for deinstall'
+ echo "$cancel_message"
echo
cleanexit
fi
+ unset cancel_message
+ }
+
+
+ #
+ # Shows package deinstall dialog.
+ #
+ package_deinstall()
+ {
+ local packages command exitcode
- for package in $PACKAGES
- do
- DIALOG_OPTIONS="$DIALOG_OPTIONS '$package' ' '"
-
- NUM=$(($NUM + 1))
- done
+ packages=$1
- show_dialog deinstall "Deinstall $NUM package`plural $NUM`?\nARE YOU SURE?" "$DIALOG_OPTIONS" menu
- unset NUM DIALOG_OPTIONS
-
-
- if cmd_failed $selopt_deinstall_exitcode
+ if [ ! "$packages" ]
then
echo
- echo 'Deinstall cancelled'
+ echo 'No packages selected for deinstall'
echo
cleanexit
fi
- PKG_DEINSTALL_COMMAND="pkg_deinstall $PACKAGES"
+ show_confirm deinstall "$packages"
+ command="pkg_deinstall $packages"
+
+ unset packages
+
+
if ! checkyesno enable_real_deinstall
then
cat <<- EOF
Execute that manually:
- $PKG_DEINSTALL_COMMAND
+ $command
EOF
fi
- showcmd "$PKG_DEINSTALL_COMMAND"
+ showcmd "$command"
- $PKG_DEINSTALL_COMMAND
+ $command
- if cmd_failed $?
- then
- exitcode "$PKG_DEINSTALL_COMMAND" $?
+ exitcode=$?
+ if cmd_failed $exitcode
+ then
+ exitcode "$command" $exitcode
else
+ unset command exitcode
+
if checkyesno listup_after_deinstall
then
echo
fi
fi
+
cleanexit
}
#
do_list()
{
- local tempfile count PORTVERSION_COMMAND exitcode
+ local tempfile command exitcode count
tempfile=`make_temp`
- PORTVERSION_COMMAND="portversion -vl <"
+ command='portversion -vl <'
- showcmd "$PORTVERSION_COMMAND"
+ showcmd "$command"
- $PORTVERSION_COMMAND > "$tempfile"
+ $command > "$tempfile"
exitcode=$?
then
unlink_file "$tempfile"
- exitcode "$PORTVERSION_COMMAND" $exitcode
+ exitcode "$command" $exitcode
fi
+ unset command exitcode
- sed 's|<||; s|needs updating (port has ||; s|) *$||' \
+
+ sed 's|<||; s|needs updating (port has ||; s|) *$||; s|) (| |' \
< "$tempfile" \
> "$status_file"
unlink_file "$tempfile"
fi
+ unset tempfile
+
count=`wc -l "$status_file" | awk '{print $1}'`
echo
echo "Found $count outdated package`plural $count`"
echo '-----------------------------------'
+
if [ "$count" -eq 0 -a "$1" = exit-if-none ]
then
cleanexit
fi
+ unset count
+
+
echo
}
#
do_csup()
{
- local old_wd CSUP_COMMAND PORTSDB_COMMAND
+ local command exitcode
check_supfile "$csup_supfile"
- CSUP_COMMAND="csup $csup_args $csup_supfile"
+ command="csup $csup_args $csup_supfile"
- showcmd "$CSUP_COMMAND"
+ showcmd "$command"
- $CSUP_COMMAND
+ $command
- if cmd_failed $?
+ exitcode=$?
+
+ if cmd_failed $exitcode
then
- exitcode "$CSUP_COMMAND" $?
+ exitcode "$command" $exitcode
fi
+ command='portsdb -Fu'
+
echo
- showcmd "cd $PORTS_PATH && make fetchindex"
+ showcmd "$command"
- old_wd=`pwd`
+ $command
- cd $PORTS_PATH && make fetchindex && \
- cd "$old_wd" || cleanexit 1
+ exitcode=$?
- PORTSDB_COMMAND="portsdb -u"
+ if cmd_failed $exitcode
+ then
+ exitcode "$command" $exitcode
+ fi
+ unset command exitcode
+
+
echo
- showcmd "$PORTSDB_COMMAND"
+ do_list
+ }
+
+
+ #
+ # Command:
+ # updates ports tree using portsnap(8).
+ #
+ do_portsnap()
+ {
+ local command exitcode
- $PORTSDB_COMMAND
+ command='portsnap fetch'
- if cmd_failed $?
+ showcmd "$command"
+
+ $command
+
+
+ exitcode=$?
+
+ if cmd_failed $exitcode
then
- exitcode "$PORTSDB_COMMAND" $?
+ exitcode "$command" $exitcode
fi
+ command='portsnap update'
+
echo
+ showcmd "$command"
+
+ $command
+
+
+ exitcode=$?
+
+ if cmd_failed $exitcode
+ then
+ exitcode "$command" $exitcode
+ fi
+
+
+ command='portsdb -u'
+
+ echo
+ showcmd "$command"
+
+ $command
+
+
+ exitcode=$?
+
+ if cmd_failed $exitcode
+ then
+ exitcode "$command" $exitcode
+ fi
+
+ unset command exitcode
+
+
+ echo
do_list
}
#
do_fixdb()
{
- local PKGDB_COMMAND
+ local command exitcode
- PKGDB_COMMAND="pkgdb -F"
+ command='pkgdb -F'
- showcmd "$PKGDB_COMMAND"
+ showcmd "$command"
- $PKGDB_COMMAND
+ $command
- if cmd_failed $?
+ exitcode=$?
+
+ if cmd_failed $exitcode
then
- exitcode "$PKGDB_COMMAND" $?
+ exitcode "$command" $exitcode
fi
+ unset command exitcode
+
echo
cleanexit
#
do_find()
{
- local string type
+ local search_string type
- string="$1"
+ search_string=$1
type=name
- case "$1"
+ case $search_string
in
name|key)
if [ ! "$2" ]
fi
- string="$2"
+ search_string=$2
- type="$1"
+ type=$1
;;
esac
- if [ ! "$string" ]
+ if [ ! "$search_string" ]
then
error 'empty search string'
fi
- showcmd "cd $PORTS_PATH && make search $type=$string"
+ showcmd "cd $PORTS_PATH && make search $type=$search_string"
- cd $PORTS_PATH || cleanexit 1
+ cd "$PORTS_PATH" || cleanexit 1
- make search "$type=$string" | $PAGER_PROGRAM
+ make search "$type=$search_string" | "$PAGER_PROGRAM"
+ unset search_string type
+
cleanexit
}
#
# Command:
+ # does search in ports tree
+ # and shows install dialog.
+ #
+ do_find_install()
+ {
+ local tempfile search_string index_file name comments count dialog_options
+
+
+ search_string=$1
+
+
+ if [ -f "$PORTS_PATH/INDEX-6" ]
+ then
+ index_file="$PORTS_PATH/INDEX-6"
+
+ elif [ -f "$PORTS_PATH/INDEX" ]
+ then
+ index_file="$PORTS_PATH/INDEX"
+
+ else
+ error 'no valid INDEX found'
+ fi
+
+
+ if [ ! "$search_string" ]
+ then
+ error 'search regex is required'
+ fi
+
+
+ tempfile=`make_temp`
+
+ grep -iE "$search_string" "$index_file" | cut -d '|' -f 1,4 | tr '|' ' ' > "$tempfile"
+
+ unset index_file
+
+
+ if [ ! -s "$tempfile" ]
+ then
+ unlink_file "$tempfile"
+
+ error "no packages matching '$search_string' found"
+ fi
+
+ unset search_string
+
+
+ while read name comments
+ do
+ count=$(($count + 1))
+
+ dialog_options="$dialog_options '$name' '`echo "$comments" | awk '{print substr($0, 0, 26)}'`...' OFF"
+ done \
+ < "$tempfile"
+
+ unlink_file "$tempfile"
+
+ unset name comments tempfile
+
+
+ show_dialog find "Found $count package`plural $count`.\nSelect one`plural $count` you want to install" "$dialog_options" checklist
+
+ unset count dialog_options
+
+
+ if [ ! "$selopt_find_values" ]
+ then
+ echo
+ echo 'No packages selected for install'
+ echo
+
+ cleanexit
+ fi
+
+
+ show_confirm install "$selopt_find_values"
+
+
+ do_portinstall_portupgrade portinstall $selopt_find_values
+ }
+
+
+ #
+ # Command:
# searches for local packages.
#
do_ls()
{
- local string="$1"
+ local search_string=$1
- if [ ! "$string" ]
+ if [ ! "$search_string" ]
then
error 'search regex is required'
fi
- ls -1 $PKGDB_PATH | \
- grep -v '^pkgdb\.' | \
- grep -iE "$string"
+ ls -1 "$PKGDB_PATH" | \
+ grep -v ^pkgdb\. | \
+ grep -iE "$search_string"
if cmd_failed $?
then
- error "no packages matching '$string' found"
+ error "no packages matching '$search_string' found"
fi
+ unset search_string
+
cleanexit
}
#
do_notreq()
{
- local old_wd name NUM DIALOG_OPTIONS PACKAGES
+ local old_wd name count dialog_options
old_wd=`pwd`
- cd $PKGDB_PATH || cleanexit 1
+ cd "$PKGDB_PATH" || cleanexit 1
for name in *
do
- if [ ! "$name" = pkgdb.db -a ! -f "$name/+REQUIRED_BY" ]
+ if [ ! $name = pkgdb.db -a ! -f $name/+REQUIRED_BY ]
then
- DIALOG_OPTIONS="$DIALOG_OPTIONS '$name' 'no +REQUIRED_BY' OFF"
+ count=$(($count + 1))
- NUM=$(($NUM + 1))
+ dialog_options="$dialog_options '$name' 'no +REQUIRED_BY' OFF"
fi
done
cd "$old_wd" || cleanexit 1
+ unset old_wd name
- show_dialog notrequired "$NUM not required package`plural $NUM`" "$DIALOG_OPTIONS"
- unset NUM DIALOG_OPTIONS
+ show_dialog notrequired "Found $count not required package`plural $count`\nSelect one`plural $count` you want to deinstall" "$dialog_options"
+ unset count dialog_options
+
package_deinstall "$selopt_notrequired_values"
}
#
do_deinst()
{
- local old_wd name NUM DIALOG_OPTIONS PACKAGES
+ local old_wd name count dialog_options
old_wd=`pwd`
- cd $PKGDB_PATH || cleanexit 1
+ cd "$PKGDB_PATH" || cleanexit 1
for name in *
do
- if [ ! "$name" = pkgdb.db ]
+ if [ ! $name = pkgdb.db ]
then
- DIALOG_OPTIONS="$DIALOG_OPTIONS '$name' ' ' OFF"
+ count=$(($count + 1))
- NUM=$(($NUM + 1))
+ dialog_options="$dialog_options '$name' ' ' OFF"
fi
done
cd "$old_wd" || cleanexit 1
+ unset old_wd name
- show_dialog deinstall "Found $NUM package`plural $NUM`.\nSelect one(s) you want to deinstall" "$DIALOG_OPTIONS"
- unset NUM DIALOG_OPTIONS
+ show_dialog deinstall "Found $count package`plural $count`.\nSelect one`plural $count` you want to deinstall" "$dialog_options"
+ unset count dialog_options
+
package_deinstall "$selopt_deinstall_values"
}
#
do_padb()
{
- local PORTAUDIT_COMMAND
+ local command exitcode
- PORTAUDIT_COMMAND="portaudit -Fd"
+ command="portaudit -Fd"
- showcmd "$PORTAUDIT_COMMAND"
+ showcmd "$command"
- $PORTAUDIT_COMMAND
+ $command
- if cmd_failed $?
+ exitcode=$?
+
+ if cmd_failed $exitcode
then
- exitcode "$PORTAUDIT_COMMAND" $?
+ exitcode "$command" $exitcode
fi
+ unset command exitcode
+
echo
}
#
# Command:
+ # runs portinstall(1) or portupgrade(1) with
+ # verbose mode and additional arguments.
+ #
+ do_portinstall_portupgrade()
+ {
+ local program command exitcode
+
+
+ program=$1
+
+ shift
+
+
+ case $program
+ in
+ portinstall|portupgrade)
+ ;;
+ *)
+ error "do_portinstall_portupgrade: internal error: invalid program '$program'"
+ ;;
+ esac
+
+
+ if checkyesno update_portaudit_db
+ then
+ echo
+ do_padb
+ fi
+
+
+ command="$program -v $portupgrade_args $*"
+
+ showcmd "$command"
+
+ $command
+
+
+ exitcode=$?
+
+ if cmd_failed $exitcode
+ then
+ exitcode "$command" $exitcode
+
+ elif [ $program = portupgrade ]
+ then
+ if checkyesno listup_after_upgrade
+ then
+ echo
+ do_list
+ fi
+ fi
+
+ unset program command exitcode
+
+
+ echo
+
+ cleanexit
+ }
+
+
+ #
+ # Command:
# checks for existence of required programs.
#
do_checkbinaries()
for binary in portupgrade portversion \
dialog csup portsdb pkgdb portaudit \
pkg_deinstall $PAGER_PROGRAM \
- sed grep cat touch id uname
+ sed grep cat touch id uname cut portsnap
do
which "$binary" > /dev/null
fi
done
+ unset binary
+
cleanexit $exitcode
}
check_lockfile
- trap 'cleanexit 1' 2
+ trap 'cleanexit 1' 2 15
##################################################
- case "$1"
+ case $1
in
listup|list)
+
do_list
cleanexit
;;
cvsup|cvs|csup)
+
do_csup
cleanexit
;;
+ portsnap|snap)
+
+ do_portsnap
+ cleanexit
+ ;;
+
fixdb|fix)
+
do_fixdb
;;
find|portfind)
+
do_find "$2" "$3"
;;
+ findi|findv)
+
+ do_find_install "$2"
+ ;;
+
ls|lspkg)
+
do_ls "$2"
;;
chkreq|notreq|noreq)
+
do_notreq
;;
deinst|deins)
+
do_deinst
;;
;;
listup+run|list+run)
+
do_list
;;
+ install|i)
+
+ shift
+ do_portinstall_portupgrade portinstall $*
+ ;;
+
+ upgrade|u)
+
+ shift
+ do_portinstall_portupgrade portupgrade $*
+ ;;
+
chkbin)
do_checkbinaries
;;
while read name comments
do
- DIALOG_OPTIONS="$DIALOG_OPTIONS '$name' '< $comments' OFF"
+ count=$(($count + 1))
- NUM=$(($NUM + 1))
+ dialog_options="$dialog_options '$name' '< $comments' OFF"
+ done \
+ < "$status_file"
- done < \
- "$status_file"
+ unset name comments
- show_dialog list "Found $NUM outdated package`plural $NUM`" "$DIALOG_OPTIONS"
+ show_dialog list "Found $count outdated package`plural $count`\nSelect one`plural $count` you want to upgrade" "$dialog_options"
- unset name comments NUM DIALOG_OPTIONS
+ unset count dialog_options
- PACKAGES="$selopt_list_values"
-
- if [ ! "$PACKAGES" ]
+ if [ ! "$selopt_list_values" ]
then
echo
echo 'No packages selected for upgrade'
fi
- for package in $PACKAGES
- do
- DIALOG_OPTIONS="$DIALOG_OPTIONS '$package' ' '"
-
- NUM=$(($NUM + 1))
- done
+ show_confirm upgrade "$selopt_list_values"
- show_dialog upgrade "Upgrade $NUM package`plural $NUM`?" "$DIALOG_OPTIONS" menu
+ do_portinstall_portupgrade portupgrade $selopt_list_values
- unset package NUM DIALOG_OPTIONS
-
- if cmd_failed $selopt_upgrade_exitcode
- then
- echo
- echo 'Upgrade cancelled'
- echo
-
- cleanexit
- fi
-
-
- if checkyesno update_portaudit_db
- then
- echo
- do_padb
- fi
-
-
- PORTUPGRADE_COMMAND="portupgrade -v $portupgrade_args $PACKAGES"
-
- showcmd "$PORTUPGRADE_COMMAND"
-
- $PORTUPGRADE_COMMAND
-
-
- exitcode=$?
-
- if cmd_failed $exitcode
- then
- exitcode "$PORTUPGRADE_COMMAND" $exitcode
-
- else
- if checkyesno listup_after_upgrade
- then
- echo
- do_list
- fi
- fi
-
- cleanexit
-
-
#__HELP__
# Package Frontend help
#-----------------------
# using "portversion -vl <"
#
#%P% cvs Update ports tree using csup
- # Run "make fetchindex" in %PORTS_PATH%
- # Run "portsdb -u"
+ # Run "portsdb -Fu"
# Run %P% list
#
+ #%P% snap Update ports tree using portsnap
+ # Run %P% list
+ #
#%P% all Run %P% cvs
# Run %P%
#
+ #%P% snap+run Run %P% snap
+ # Run %P%
+ #
#%P% list+run Run %P% list
# Run %P%
#
#
#%P% find Run "make search" in %PORTS_PATH%
#
+ #%P% findi Search for packages and show install dialog
+ #
#%P% ls Search packages in %PKGDB_PATH%
#
#%P% noreq Check for not required packages
#%P% deins Deinstall package(s) by name
#
#%P% padb Update portaudit database, using "portaudit -Fd"
+ #
+ #%P% i Run portinstall with -v $portupgrade_args
+ #
+ #%P% u Run portupgrade with -v $portupgrade_args
#
#%P% chkbin Check for existence of required programs
#