[PC-BSD Commits] r6867 - in pcbsd-projects/pbi-manager: . man
svn at pcbsd.org
svn at pcbsd.org
Fri Jun 4 08:41:32 PDT 2010
Author: kris
Date: 2010-06-04 08:41:32 -0700 (Fri, 04 Jun 2010)
New Revision: 6867
Modified:
pcbsd-projects/pbi-manager/man/pbi_update.1
pcbsd-projects/pbi-manager/pbi-manager
Log:
Wrap up the updater functionality for PBI9.
Now we can upgrade a specified PBI, or run one command to update everything.
Modified: pcbsd-projects/pbi-manager/man/pbi_update.1
===================================================================
--- pcbsd-projects/pbi-manager/man/pbi_update.1 2010-06-04 14:56:44 UTC (rev 6866)
+++ pcbsd-projects/pbi-manager/man/pbi_update.1 2010-06-04 15:41:32 UTC (rev 6867)
@@ -8,6 +8,7 @@
.Nm
.Op Fl c
.Op Fl -check-all
+.Op Fl -update-all
.Op Fl u
.Op Ar pbi
.Sh DESCRIPTION
@@ -19,11 +20,11 @@
.Sh OPTIONS
.Bl -tag -width indent
.It Fl c
-Check the specified PBI for updates.
-.It Fl u
-Update the specified PBI to the latest version.
+Check-only of the specified PBI for available updates.
.It Fl -check-all
Run a full check of all installed PBIs, and display list of available updates.
+.It Fl -update-all
+Update all installed PBIs to the latest versions available.
.Sh SEE ALSO
.Xr pbi_add 1 ,
.Xr pbi_create 1 ,
Modified: pcbsd-projects/pbi-manager/pbi-manager
===================================================================
--- pcbsd-projects/pbi-manager/pbi-manager 2010-06-04 14:56:44 UTC (rev 6866)
+++ pcbsd-projects/pbi-manager/pbi-manager 2010-06-04 15:41:32 UTC (rev 6867)
@@ -132,9 +132,9 @@
usage: `basename $0` [options] pbi
Options:
- -c -- Check the specified PBI for updates
- -u -- Update the specified PBI
+ -c -- Check-only, do not update specified PBI
--check-all -- Perform a full check of all PBIs for updates
+ --update-all -- Update all PBIs to latest versions
EOF
exit 0
@@ -429,9 +429,10 @@
while [ $# -gt 0 ]; do
case "$1" in
-c) PBI_UPCHECK="YES" ;;
- -u) PBI_DOUPDATE="YES" ;;
--check-all) PBI_UPCHECK="ALL" ;;
+ --update-all) PBI_UPDATEAPP="ALL" ;;
*) if [ $# -gt 1 ]; then usage_update_pbi; fi
+ if [ ! -z "$PBI_UPDATEAPP" ] ; then usage_update_pbi ; fi
if [ ! -e "${PBI_DBDIR}/${1}" ] ; then
exit_err "can't find installed pbi (${1})"
fi
@@ -441,6 +442,10 @@
shift
done
+ if [ "${PBI_UPDATEAPP}" = "ALL" -a ! -z "${PBI_UPCHECK}" ] ; then
+ usage_update_pbi
+ fi
+
if [ -z "${PBI_UPDATEAPP}" -a "${PBI_UPCHECK}" != "ALL" ]; then
usage_update_pbi
fi
@@ -500,7 +505,6 @@
PBI_APPMENU_DIR=".${MOD_XDGMENU_DIR}"
PBI_APPMIME_DIR=".${MOD_XDGMIME_DIR}"
PBI_DELETENAME=""
- PBI_DOUPDATE=""
PBI_FAKEBIN_DIR=".sbin"
PBI_FILENAME=""
PBI_FORCEADD="NO"
@@ -2192,10 +2196,15 @@
# Bye Bye!
rm_tmpdir
+
}
# Check a specific PBI for updates
check_pbi_update() {
+
+ # Init the tmpdir
+ init_tmpdir
+
_upbi="${1}"
load_info_from_dir "${PBI_DBDIR}/${_upbi}"
if [ -z "${PBI_UPDATEURL}" ] ; then return ; fi
@@ -2210,40 +2219,161 @@
"${PBI_UPDATEURL}" >/dev/null 2>/dev/null
# Uncomment to see details from update server
- cat ${PBI_TMPDIR}/.upcheck$$
- _nver="`cat ${PBI_TMPDIR}/.upcheck$$ | grep 'NewVer: ' | sed 's|NewVer: ||g'`"
+ #cat ${PBI_TMPDIR}/.upcheck$$
+
+ PBI_UPNVER=""
+ PBI_UPMIRROR1=""
+ PBI_UPMIRROR2=""
+ PBI_UPMIRROR3=""
+ PBI_UPFILE=""
+ PBI_UPCSUM=""
+ PBI_UPMDATE=""
+
+ # Load some variables from the update check
+ PBI_UPNVER="`cat ${PBI_TMPDIR}/.upcheck$$ | grep 'NewVer: ' | sed 's|NewVer: ||g'`"
+ PBI_UPMIRROR1="`cat ${PBI_TMPDIR}/.upcheck$$ | grep 'Mirror1: ' | sed 's|Mirror1: ||g'`"
+ PBI_UPMIRROR2="`cat ${PBI_TMPDIR}/.upcheck$$ | grep 'Mirror2: ' | sed 's|Mirror2: ||g'`"
+ PBI_UPMIRROR3="`cat ${PBI_TMPDIR}/.upcheck$$ | grep 'Mirror3: ' | sed 's|Mirror3: ||g'`"
+ PBI_UPFILE="`cat ${PBI_TMPDIR}/.upcheck$$ | grep 'FileLoc: ' | sed 's|FileLoc: ||g'`"
+ PBI_UPCSUM="`cat ${PBI_TMPDIR}/.upcheck$$ | grep 'MD5: ' | sed 's|MD5: ||g'`"
+ PBI_UPMDATE="`cat ${PBI_TMPDIR}/.upcheck$$ | grep 'MDATE: ' | sed 's|MDATE: ||g'`"
+
rm ${PBI_TMPDIR}/.upcheck$$
# If no new version
- if [ -z "$_nver" ] ; then return 0 ; fi
+ if [ -z "$PBI_UPNVER" ] ; then return 1 ; fi
# If this is a load only, don't display details
if [ "$2" != "display" ] ; then return 0 ; fi
- if [ "$_nver" != "$PBI_PROGVERSION" ] ; then
- echo "${_upbi} - Available: ${_nver}"
+ if [ "$PBI_UPNVER" != "$PBI_PROGVERSION" ] ; then
+ echo "${_upbi} - Available: ${PBI_UPNVER}"
fi
+
+ # Bye Bye!
+ rm_tmpdir
}
# Start PBI update process
do_pbi_update() {
- if [ "${PBI_DOUPDATE}" != "YES" ]; then return 0 ; fi
+ if [ ! -z "${PBI_UPCHECK}" ]; then return 0 ; fi
+
+ if [ "$PBI_UPDATEAPP" = "ALL" ] ; then
+ # Loop and check all PBIs for updates
+ for i in `ls ${PBI_DBDIR}/ 2>/dev/null`
+ do
+ if [ -e "${PBI_DBDIR}/${i}/pbi_name" ] ; then
+ PBI_UPDATEAPP="${i}"
+ start_pbi_updateapp "all"
+ fi
+ done
+ else
+ start_pbi_updateapp "single"
+ fi
+}
+
+# Update the targed PBI
+start_pbi_updateapp() {
+ _upact="${1}"
+
+ # Check for update to this app, and exit or return if not available
check_pbi_update "${PBI_UPDATEAPP}" "nodisplay"
- if [ "$?" != "0" ] ; then exit_err "$PBI_UPDATEAPP - no update available!" ; fi
+ if [ "$?" != "0" ] ; then
+ if [ "$_upact" = "single" ] ; then
+ exit_err "$PBI_UPDATEAPP - no update available!"
+ else
+ return 1
+ fi
+ fi
# We've gotten this far, now download the updated PBI
+ pbi_update_dl
+ echo " "
- # KPM KPM KPM
# Delete the old version, prepare for new
- pbi_delete "${NO_UPDATEAPP}"
+ echo -e "Removing old version...\c"
+ pbi_delete "${PBI_UPDATEAPP}"
+ echo "Done"
# Now install new PBI
- # pbi_add
+ echo -e "Installing new version...\c"
+ pbi_add --licagree -f "$PBI_UPDLFILE" >/dev/null 2>/dev/null
+ if [ "$?" != "0" ] ; then
+ echo "Failed to install PBI: ${PBI_UPDLFILE}"
+ else
+ echo "Done"
+ fi
+ rm "${PBI_UPDLFILE}"
+}
+
+# Start downloading the update
+pbi_update_dl() {
+ # Set local download location
+ _dl_loc="${PBI_APPDIR}/.`basename $PBI_UPFILE`.$$"
+ if [ ! -z "$PBI_MIRROR" ] ; then
+ # Start download from default mirror
+ _furl="`echo $PBI_MIRROR | sed 's/\/*$//'`${PBI_UPFILE}"
+ echo "Downloading ${_furl}"
+ pbi_get_file "$_furl" "$_dl_loc"
+ if [ "$?" != "0" ] ; then
+ rm "${_dl_loc}" >/dev/null 2>/dev/null
+ exit_err "Download Failed: ${_furl}"
+ fi
+ _upcsum=`sha256 -q "$_dl_loc"`
+ if [ "$_upcsum" != "$PBI_UPCSUM" ] ; then
+ rm "${_dl_loc}" >/dev/null 2>/dev/null
+ exit_err "Download Failed: ${_furl}"
+ fi
+
+ else
+ # Loop through the provided mirrors until we get a good dl or fail
+ _upattempt="1"
+ _gooddl="no"
+ while [ "$_upattempt" -lt 4 ]
+ do
+ # Do download from updater mirrors
+ case $_upattempt in
+ 1) _furl="`echo $PBI_UPMIRROR1 | sed 's/\/*$//'`${PBI_UPFILE}" ;;
+ 2) _furl="`echo $PBI_UPMIRROR2 | sed 's/\/*$//'`${PBI_UPFILE}" ;;
+ 3) _furl="`echo $PBI_UPMIRROR3 | sed 's/\/*$//'`${PBI_UPFILE}" ;;
+ esac
+ echo "Downloading ${_furl}"
+ pbi_get_file "$_furl" "$_dl_loc"
+ if [ "$?" != "0" ] ; then
+ rm "${_dl_loc}" >/dev/null 2>/dev/null
+ fi
+ _upcsum=`sha256 -q "$_dl_loc"`
+ if [ "$_upcsum" != "$PBI_UPCSUM" ] ; then
+ rm "${_dl_loc}" >/dev/null 2>/dev/null
+ else
+ _gooddl="yes"
+ break
+ fi
+ _upattempt="`expr $_upattempt + 1`"
+ done
+ if [ "$_gooddl" != "yes" ] ; then
+ exit_err "Download Failed: ${_furl}"
+ fi
+ fi
+
+ # If we get this far, we have a good file!
+ PBI_UPDLFILE="$_dl_loc"
+ sync
}
+# Function to download a file from remote using curl
+pbi_get_file() {
+ _rf="${1}"
+ _lf="${2}"
+ if [ -e "${_lf}" ] ; then rm "$_lf" ; fi
+
+ curl -# -o "${_lf}" "${_rf}"
+ return $?
+}
+
# start processing autobuild
pbi_autob_init() {
@@ -2506,6 +2636,7 @@
if [ ! -e "${PBI_ETCCONF}" ] ; then return 0 ; fi
PBI_UPDATEURL="`cat ${PBI_ETCCONF} | grep 'PBI_UPDATEURL: ' | sed 's|PBI_UPDATEURL: ||g'`"
PBI_PUBKEYS="`cat ${PBI_ETCCONF} | grep 'PBI_PUBKEYS: ' | sed 's|PBI_PUBKEYS: ||g'`"
+ PBI_MIRROR="`cat ${PBI_ETCCONF} | grep 'PBI_MIRROR: ' | sed 's|PBI_MIRROR: ||g'`"
}
# Main program operation
More information about the Commits
mailing list