[PC-BSD Commits] r9491 - in pcbsd/current/src-sh/pbi-manager: . man

svn at pcbsd.org svn at pcbsd.org
Fri Mar 4 11:30:44 PST 2011


Author: kris
Date: 2011-03-04 11:30:44 -0800 (Fri, 04 Mar 2011)
New Revision: 9491

Modified:
   pcbsd/current/src-sh/pbi-manager/man/pbi_update.1
   pcbsd/current/src-sh/pbi-manager/pbi-manager
Log:

Update to pbi-manager, now allow auto-updating via the PBID daemon, can
be set with pbi_update --enable-auto / --disable-auto



Modified: pcbsd/current/src-sh/pbi-manager/man/pbi_update.1
===================================================================
--- pcbsd/current/src-sh/pbi-manager/man/pbi_update.1	2011-03-04 16:47:17 UTC (rev 9490)
+++ pcbsd/current/src-sh/pbi-manager/man/pbi_update.1	2011-03-04 19:30:44 UTC (rev 9491)
@@ -8,7 +8,8 @@
 .Nm
 .Op Fl c
 .Op Fl -check-all
-.Op Fl -update-all
+.Op Fl -disable-auto
+.Op Fl -enable-auto
 .Op Fl u
 .Op Ar pbi
 .Sh DESCRIPTION
@@ -23,6 +24,10 @@
 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 -disable-auto
+Disable auto-updating of the target PBI
+.It Fl -enable-auto
+Enable auto-updating of the target PBI. Will only auto-update if the PBI is associated with a valid repository. 
 .It Fl -update-all
 Update all installed PBIs to the latest versions available.
 .Sh SEE ALSO

Modified: pcbsd/current/src-sh/pbi-manager/pbi-manager
===================================================================
--- pcbsd/current/src-sh/pbi-manager/pbi-manager	2011-03-04 16:47:17 UTC (rev 9490)
+++ pcbsd/current/src-sh/pbi-manager/pbi-manager	2011-03-04 19:30:44 UTC (rev 9491)
@@ -333,9 +333,11 @@
 usage: `basename $0` [options] pbi
 
 Options:
-  -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
+  -c              -- Check-only, do not update target PBI
+  --check-all     -- Perform a full check of all PBIs for updates
+  --disable-auto  -- Disable auto-updating for the target PBI
+  --enable-auto   -- Enable auto-updating for the target PBI
+  --update-all    -- Update all PBIs to latest versions
 
 EOF
         exit_trap
@@ -1142,6 +1144,8 @@
                 case "$1" in
                 -c)	PBI_UPCHECK="YES" ;; 
        --check-all)	PBI_UPCHECK="ALL" ;; 
+    --disable-auto)	PBI_UPENABLEAUTO="NO" ;; 
+     --enable-auto)	PBI_UPENABLEAUTO="YES" ;; 
       --update-all)	PBI_UPDATEAPP="ALL" ;; 
                  *)     if [ $# -gt 1 ]; then usage_update_pbi; fi
 			if [ ! -z "$PBI_UPDATEAPP" ] ; then usage_update_pbi ; fi
@@ -1158,6 +1162,14 @@
                 usage_update_pbi
         fi
 
+	# Make sure we aren't trying to enable auto-updating for ALL
+	if [ "${PBI_UPDATEAPP}" = "ALL" -a ! -z "${PBI_UPENABLEAUTO}" ] ; then
+                usage_update_pbi
+        fi
+	if [ -z "${PBI_UPDATEAPP}" -a ! -z "${PBI_UPENABLEAUTO}" ] ; then
+                usage_update_pbi
+        fi
+
         if [ -z "${PBI_UPDATEAPP}" -a "${PBI_UPCHECK}" != "ALL" ]; then
                 usage_update_pbi
         fi
@@ -2474,6 +2486,13 @@
 		_rID=`basename $_rID | cut -d '.' -f 1`
 		echo "Associated Repo: ${_rID} (${_rDesc})"
 	fi
+	
+	# Check if autoupdate is enable or not
+	if [ "${PBI_ENABLEAUTOUPDATE}" = "YES" ] ; then
+		echo "AutoUpdate: YES"
+	else
+		echo "AutoUpdate: NO"
+	fi
 
 	# See if we have any XDG stuff
 	if [ -e "${PBI_ORIGPROGDIRPATH}/.xdg-desktop/install-desktop-icons.sh" ] ; then
@@ -2606,6 +2625,7 @@
         PBI_APPCREATEVER=""
         PBI_ARCHIVE_CHECKSUM=""
         PBI_ARCHIVE_COUNT=""
+	PBI_ENABLEAUTOUPDATE=""
         PBI_FBSDVER=""
 	PBI_ORIGPROGDIRPATH=""
 	PBI_PATCHVERSION=""
@@ -2629,6 +2649,11 @@
         PBI_APPCREATEVER="`cat ${1}/pbi_createver 2>/dev/null`"
         PBI_ARCHIVE_COUNT="`cat ${1}/pbi_archivecount 2>/dev/null`"
         PBI_ARCHIVE_CHECKSUM="`cat ${1}/pbi_archivesum 2>/dev/null`"
+
+	# Check if auto-update is enabled
+	if [ -e "${1}/autoupdate-enable" ] ; then
+		PBI_ENABLEAUTOUPDATE="YES"
+	fi
 	
 	# Check if this is a patch file
 	if [ -e "${1}/pbi_patchfile" ] ; then
@@ -3952,6 +3977,9 @@
 		# Check if we have a dirty hash-dir to cleanup
 		check_clean_hashdir "$_pbid_log" "$_redir"
 
+		# Check if we have any PBIs to auto-update
+		check_autoupdate_pbis "$_pbid_log" "$_redir"
+
 		# Check if we need to merge files into the hashdir
 		if [ ! -z "`ls ${PBI_DBHASHQUEUEDIR}`" ] ; then
 			init_tmpdir
@@ -3988,6 +4016,57 @@
 
 }
 
+# Check if there are any PBIs which are flagged for auto-updates
+check_autoupdate_pbis() {
+
+	for i in `ls ${PBI_DBAPPDIR}/ 2>/dev/null`
+	do
+		if [ ! -e "${PBI_DBAPPDIR}/${i}/autoupdate-enable" ] ; then
+			continue 
+		fi
+
+		# Check if this app is already updating
+		if [ -e "${PBI_DBAPPDIR}/${i}/.updating" ] ; then
+			ps -p `cat ${PBI_DBAPPDIR}/${i}/.updating` >/dev/null 2>/dev/null
+			if [ "$?" != "0" ] ; then
+				rm "${PBI_DBAPPDIR}/${PBI_UPDATEAPP}/.updating"
+			else
+				continue 
+			fi
+		fi
+
+		# Found an auto-update enabled APP, see if it needs upping
+		PBI_UPDATEAPP="$i"
+
+		# Load the details about this app
+		load_info_from_dir "${PBI_DBAPPDIR}/${PBI_UPDATEAPP}"
+		if [ -z "${PBI_REPO}" ]; then
+			pbi_checksig_repomatch "${PBI_DBAPPDIR}/${PBI_UPDATEAPP}"
+		fi
+		if [ -z "${PBI_REPO}" ]; then continue ; fi
+		local _repoID=`ls ${PBI_DBREPODIR}/*.${PBI_REPO} | cut -d '.' -f 1 | sed "s|${PBI_DBREPODIR}/||g"`
+
+		# Does this need an update?
+		check_pbi_update "$PBI_UPDATEAPP" "nodisplay" \
+			"$PBI_PROGNAME" "current" \
+			"$PBI_FBSDVER" "$PBI_APPARCH" "$_repoID"
+		if [ "$?" != "0" ] ; then
+			continue
+		fi
+		
+		# Its Update Time!
+		echo "Starting Auto-Update of ${PBI_UPDATEAPP}: `date`" >>${_pbid_log}
+		start_pbi_updateapp "all" "${_pbid_log}" >/dev/null 2>/dev/null
+		if [ "$?" = "0" ] ; then
+			echo "Success! Update of ${PBI_UPDATEAPP}: `date`" >>${_pbid_log}
+		else
+			echo "Failed! Update of ${PBI_UPDATEAPP}: `date`" >>${_pbid_log}
+		fi
+
+		rm "${PBI_DBAPPDIR}/${i}/.updating" >/dev/null 2>/dev/null
+	done
+}
+
 check_clean_hashdir() {
 	if [ ! -e "${PBI_DBDIRTYFILE}" ] ; then return ; fi
 
@@ -4249,7 +4328,13 @@
 
   	parse_update_pbi_cmdline "$@"
 
+	check_enable_disable_auto
+
+	# Stop here if we are just enabling / disabling auto-update
+	if [ ! -z "$PBI_UPENABLEAUTO" ] ; then return 0 ; fi
+
 	start_update_checks
+	if [ "$?" != "0" ] ; then exit 1 ; fi
 
 	# Stop here if only doing update checks
 	if [ ! -z "${PBI_UPCHECK}" ]; then return 0 ; fi
@@ -4259,6 +4344,20 @@
 	do_pbi_update
 }
 
+# Check if we are enabling / disabling auto-updating
+check_enable_disable_auto()
+{
+	if [ -z "$PBI_UPENABLEAUTO" ] ; then return ; fi
+	if [ ! -d "${PBI_DBAPPDIR}/${PBI_UPDATEAPP}" ] ; then return ; fi
+
+	# Enable / disable auto-updating now
+	if [ "$PBI_UPENABLEAUTO" = "YES" ]; then
+		touch ${PBI_DBAPPDIR}/${PBI_UPDATEAPP}/autoupdate-enable
+	else
+		rm ${PBI_DBAPPDIR}/${PBI_UPDATEAPP}/autoupdate-enable >/dev/null 2>/dev/null
+	fi
+}
+
 # Function which checks the digital signature of a PBI to match it to a particular repo
 pbi_checksig_repomatch() {
   	if [ `id -u` != "0" ] ; then return ; fi
@@ -4284,7 +4383,7 @@
 			pbi_checksig_repomatch "${PBI_DBAPPDIR}/${PBI_UPDATEAPP}"
 		fi
 		if [ -z "${PBI_REPO}" ]; then
-			return
+			return 1
 		else
 			local _repoID=`ls ${PBI_DBREPODIR}/*.${PBI_REPO} | cut -d '.' -f 1 | sed "s|${PBI_DBREPODIR}/||g"`
 		fi
@@ -4292,6 +4391,7 @@
 		check_pbi_update "$PBI_UPDATEAPP" "display" \
 	 	 "$PBI_PROGNAME" "current" \
 	 	 "$PBI_FBSDVER" "$PBI_APPARCH" "$_repoID"
+		return $?
 	else
 		# Loop and check all PBIs for updates
 		for i in `ls ${PBI_DBAPPDIR}/ 2>/dev/null`
@@ -4312,6 +4412,7 @@
 				 "$PBI_FBSDVER" "$PBI_APPARCH" "$_repoID"
                         fi
                 done
+		return 0
 	fi
 
 }
@@ -4488,11 +4589,14 @@
 	# If no new version
 	if [ -z "$PBI_UPNVER" ] ; then return 1 ; fi
 
-	# If this is a load only, don't display details
-	if [ "$_udisp" != "display" ] ; then return 0 ; fi
 
 	if [ "$PBI_UPNVER" != "$PBI_PROGVERSION" ] ; then
-		echo "${_upbi} - Available: ${PBI_UPNVER}"
+		if [ "$_udisp" = "display" ] ; then 
+			echo "${_upbi} - Available: ${PBI_UPNVER}"
+		fi
+		return 0
+	else
+		return 1
 	fi
 }
 
@@ -4504,12 +4608,26 @@
 		# Loop and check all PBIs for updates
 		for i in `ls ${PBI_DBAPPDIR}/ 2>/dev/null`
                 do
+			if [ -e "${PBI_DBAPPDIR}/${i}/.updating" ] ; then
+				ps -p `cat ${PBI_DBAPPDIR}/${PBI_UPDATEAPP}/.updating` >/dev/null 2>/dev/null
+				if [ "$?" = "0" ] ; then
+					continue
+				fi
+				rm "${PBI_DBAPPDIR}/${PBI_UPDATEAPP}/.updating"
+			fi
                         if [ -e "${PBI_DBAPPDIR}/${i}/pbi_name" ] ; then
 				PBI_UPDATEAPP="${i}"
 				start_pbi_updateapp "all"
                         fi
 		done
 	else
+		if [ -e "${PBI_DBAPPDIR}/${PBI_UPDATEAPP}/.updating" ] ; then
+			ps -p `cat ${PBI_DBAPPDIR}/${PBI_UPDATEAPP}/.updating` >/dev/null 2>/dev/null
+			if [ "$?" = "0" ] ; then
+				exit_err "This application is currently updating."
+			fi
+			rm "${PBI_DBAPPDIR}/${PBI_UPDATEAPP}/.updating"
+		fi
 		start_pbi_updateapp "single"
 	fi
 }
@@ -4548,13 +4666,21 @@
 # Update the targed PBI
 start_pbi_updateapp() {
 	_upact="${1}"
+	if [ "$2" = "pbid" ] ; then 
+		_pbidlog="$2"
+	else
+		_pbidlog=""
+	fi
 
+	echo "$$" > "${PBI_DBAPPDIR}/${PBI_UPDATEAPP}/.updating"
+
 	# Check for update to this app, and exit or return if not available
 	load_info_from_dir "${PBI_DBAPPDIR}/${PBI_UPDATEAPP}"
 	if [ -z "${PBI_REPO}" ]; then
 		pbi_checksig_repomatch "${PBI_DBAPPDIR}/${PBI_UPDATEAPP}"
 	fi
 	if [ -z "${PBI_REPO}" ]; then
+		rm "${PBI_DBAPPDIR}/${PBI_UPDATEAPP}/.updating"
 		return
 	else
 		local _repoID=`ls ${PBI_DBREPODIR}/*.${PBI_REPO} | cut -d '.' -f 1 | sed "s|${PBI_DBREPODIR}/||g"`
@@ -4564,6 +4690,7 @@
 	 "$PBI_PROGNAME" "current" \
 	 "$PBI_FBSDVER" "$PBI_APPARCH" "$_repoID"
 	if [ "$?" != "0" ] ; then 
+		rm "${PBI_DBAPPDIR}/${PBI_UPDATEAPP}/.updating"
 		if [ "$_upact" = "single" ] ; then
 			exit_err "$PBI_UPDATEAPP - no update available!"
 		else
@@ -4572,40 +4699,52 @@
 	fi
 	
 	
+	echo "Starting update of ${PBI_UPDATEAPP} to ${PBI_UPNVER}..."
+	_pbilow="`echo ${PBI_PROGNAME} | tr '[:upper:]' '[:lower:]' | sed 's| ||g'`"
+
 	# Check if there is a possible patch file for this update
-	echo "${PBI_UPPATCHES}" | grep "$PBI_PROGVERSION" >/dev/null 2>/dev/null
+	# new filename to download
+	_pFile="${_pbilow}-${PBI_PROGVERSION}_to_${PBI_UPNVER}-${PBI_APPARCH}.pbp"
+
+	# Try downloading the patch file
+	echo "Trying update via patchfile..."
+	pbi_update_dl "$_pFile"
 	if [ "$?" = "0" ] ; then
-		# new filename to download
-		_pbilow="`echo ${PBI_PROGNAME} | tr '[:upper:]' '[:lower:]' | sed 's| ||g'`"
-		_pFile="${_pbilow}-${PBI_PROGVERSION}_to_${PBI_UPNVER}-${PBI_APPARCH}.pbp"
-
-		# Try downloading the patch file
-		pbi_update_dl "$_pFile"
-		if [ "$?" = "0" ] ; then
-			# We had a good patch download, try applying it now
-			echo "Updating via patch file..."
-			pbi_patch --licagree "$PBI_UPDLFILE" >/dev/null 2>/dev/null
-			if [ "$?" != "0" ] ; then
-				# Patching failed, we'll grab a fresh copy next
-				echo "Failed to install PBI: ${PBI_UPDLFILE}"
-			else
-				echo "Patch successful!"
-				rm "${PBI_UPDLFILE}"
-				exit_trap
-			fi
+		# We had a good patch download, try applying it now
+		echo "Updating via patch file..."
+		pbi_patch --licagree "$PBI_UPDLFILE" >/dev/null 2>/dev/null
+		if [ "$?" != "0" ] ; then
+			# Patching failed, we'll grab a fresh copy next
+			echo "Failed to patch with ${PBI_UPDLFILE}"
+			echo "Will try full file update"
+		else
+			echo "Patch successful!"
+			rm "${PBI_DBAPPDIR}/${PBI_UPDATEAPP}/.updating"
+			rm "${PBI_UPDLFILE}"
+			return 0
+		fi
 			
-		fi
 	fi
 
 	# No patch file, grab the full app
-	pbi_update_dl
+	echo "Trying update via full-file..."
+	pbi_update_dl 
 	if [ "$?" != "0" ] ; then
-		exit_err "Failed downloading update!"
+		if [ "$_upact" = "single" ] ; then
+			rm "${PBI_DBAPPDIR}/${PBI_UPDATEAPP}/.updating"
+			exit_err "Failed downloading update!"
+		fi
 	fi
 
 	echo " "
+
+	# Save the auto-update status
+	if [ -e "${PBI_DBAPPDIR}/${PBI_UPDATEAPP}/autoupdate-enable" ] ; then
+		_autoUpEnable="YES"
+	else
+		_autoUpEnable="NO"
+	fi
 	
-	# Delete the old version, prepare for new
 	echo -e "Removing old version...\c"
 	pbi_delete "${PBI_UPDATEAPP}"
 	echo "Done"
@@ -4615,10 +4754,18 @@
 	pbi_add --licagree -f "$PBI_UPDLFILE" >/dev/null 2>/dev/null
 	if [ "$?" != "0" ] ; then
 		echo "Failed to install PBI: ${PBI_UPDLFILE}"
+		rm "${PBI_UPDLFILE}"
+		rm "${PBI_DBAPPDIR}/${PBI_UPDATEAPP}/.updating" 2>/dev/null
+		return 1
 	else
+		if [ "$_autoUpEnable" = "YES" ] ; then
+		 	touch "${PBI_DBAPPDIR}/${_pbilow}-${PBI_UPNVER}-${PBI_APPARCH}/autoupdate-enable"
+		fi
 		echo "Done"
+		rm "${PBI_UPDLFILE}"
+		rm "${PBI_DBAPPDIR}/${PBI_UPDATEAPP}/.updating" 2>/dev/null
+		return 0
 	fi	
-	rm "${PBI_UPDLFILE}"
 }
 
 # Start downloading the update



More information about the Commits mailing list