[PC-BSD Commits] r7577 - pcbsd/current/src-qt4/pbi-manager

svn at pcbsd.org svn at pcbsd.org
Thu Sep 16 12:25:16 PDT 2010


Author: kris
Date: 2010-09-16 12:25:16 -0700 (Thu, 16 Sep 2010)
New Revision: 7577

Modified:
   pcbsd/current/src-qt4/pbi-manager/pbi-manager
Log:

Initial import of the pbi_patch command, now you can take a .PBP patch file and use it to
upgrade a PBI without needing to re-download the entire archive again. (Patch files are much smaller, up to %85 to %95 smaller in most cases.)

Also fixed several usage bugs, improved how we generate install menu/desktop/mime scripts, so they can
be run stand-alone now by the user, or another GUI directly. 



Modified: pcbsd/current/src-qt4/pbi-manager/pbi-manager
===================================================================
--- pcbsd/current/src-qt4/pbi-manager/pbi-manager	2010-09-16 14:25:10 UTC (rev 7576)
+++ pcbsd/current/src-qt4/pbi-manager/pbi-manager	2010-09-16 19:25:16 UTC (rev 7577)
@@ -44,7 +44,7 @@
   --no-hash      -- Disable using shared hash folder for PBI
 
 EOF
-        exit 0
+        exit_trap
 }
 
 usage_autob_pbi() {
@@ -62,7 +62,7 @@
   --sign key   -- Sign the PBI(s) with specified openssl key
 
 EOF
-        exit 0
+        exit_trap
 }
 
 
@@ -84,7 +84,7 @@
   --sign key   -- Sign the PBI with specified openssl key
 
 EOF
-        exit 0
+        exit_trap
 }
 
 usage_delete_pbi() {
@@ -97,7 +97,7 @@
   --no-hash      -- Skip cleaning the hash dir
 
 EOF
-        exit 0
+        exit_trap
 }
 
 usage_make_pbi() {
@@ -115,7 +115,7 @@
   --sign key   -- Sign the PBI with specified openssl key
 
 EOF
-        exit 0
+        exit_trap
 }
 
 usage_info_pbi() {
@@ -127,7 +127,7 @@
   -v             -- Enable verbose output
 
 EOF
-        exit 0
+        exit_trap
 }
 
 usage_makepatch_pbi() {
@@ -139,7 +139,7 @@
   --sign key   -- Sign the PBI with specified openssl key
 
 EOF
-        exit 0
+        exit_trap
 }
 
 usage_patch_pbi() {
@@ -156,7 +156,7 @@
   --no-hash      -- Disable using shared hash folder for PBI
 
 EOF
-        exit 0
+        exit_trap
 }
 
 # update usage
@@ -170,7 +170,7 @@
   --update-all   -- Update all PBIs to latest versions
 
 EOF
-        exit 0
+        exit_trap
 }
 
 # Parse the command line for info
@@ -181,8 +181,7 @@
                         ;;
          --no-hash)     PBI_DISABLEHASHDIR="YES" ;;
       --clean-hdir)     pbi_clean_hashdir
-			rm_tmpdir
-			exit 0 
+			exit_trap
 			;;
                  *)     if [ $# -gt 1 ]; then usage_delete_pbi; fi
 			if [ ! -e "${PBI_DBDIR}/${1}" ] ; then
@@ -272,9 +271,14 @@
                 shift
         done
 
-
         if [ -z "${PBI_FILENAME}" ]; then usage_patch_pbi ; fi
 
+	# Get the absolute patch to the file
+        get_abspath "$PBI_FILENAME"
+	PBI_FILENAME="$_ABSPATH"
+
+        if [ ! -e "${PBI_FILENAME}" ]; then usage_patch_pbi ; fi
+
         # Load all the information about this PBI / PBP
         load_info_from_header
 
@@ -658,6 +662,7 @@
 	PBI_LICAGREE="NO"
 	PBI_LICENSEFILE="LICENSE"
 	PBI_PATCHVERSION=""
+	PBI_PATCHTARGET=""
 	PBI_REMOTEFETCH=""
 	PBI_RESOURCE_DIR="resources"
 	PBI_SS_ICON="__PBI_ICON__"
@@ -908,7 +913,7 @@
 require_root() {
   if [ `id -u` != "0" ] ; then
      echo "`basename ${0}`: Must be run as root!"
-     exit 1
+     exit_trap
   fi 
 }
 
@@ -935,7 +940,7 @@
 	check_pbi_license_display
 	if [ "$PBI_ADD_GUIDISPLAY" = "YES" -o "$PBI_ADD_INFODISPLAY" = "YES" -o "$PBI_CHECKSCRIPTS" = "YES" -o "${PBI_ADD_LICDISPLAY}" = "YES" ] 
 	then 
-		exit 0 
+		exit_trap
 	fi
 
 	# Try to apply this patch file
@@ -944,14 +949,220 @@
 
 # Start the PBI patch process
 do_pbi_patch() {
+	
+	# Verify the target PBI is installed
+	verify_pbi_update_target
+	
+
         pbi_verify_signatures
         pbi_verify_archivesum
         
+	# Extract the archive contents
         mk_pbi_extract_dir
         pbi_extract_archive
 
+	set_patch_wrkdir
+
+	init_tmpdir
+
+	# Run the uninstall script
+	if [ -e "${PBI_PATCHWRKDIR}/.sbin/.pbi-uninstall.sh" ] ; then
+		echo "Removing old xdg data..."
+		sh "${PBI_PATCHWRKDIR}/.sbin/.pbi-uninstall.sh"	>/dev/null 2>/dev/null
+	fi
+
+	# Remove old files from the installed PBI
+	patch_rm_old_files
+	
+	# Extract the new files
+	patch_extract_new_files
+
+	# Merge in the bsdiffs
+	patch_merge_bsdiffs
+
+	# Make sure we have good permissions on this PBI
+	patch_apply_chmod
+
+	# Update the hashdir
+	pbi_add_update_hashdir "${PBI_PATCHWRKDIR}"
+	pbi_clean_hashdir
+
+	# Run the install script
+	if [ -e "${PBI_PATCHWRKDIR}/.sbin/.pbi-install.sh" ] ; then
+		echo "Adding new xdg data..."
+		sh "${PBI_PATCHWRKDIR}/.sbin/.pbi-install.sh"	>/dev/null 2>/dev/null
+	fi
+
+	# Update the registered version of the PBI
+	_pbilow="`echo ${PBI_PROGNAME} | tr '[:upper:]' '[:lower:]' | sed 's| ||g'`"
+        oldDir="${PBI_DBDIR}/${_pbilow}-${PBI_PATCHTARGET}-${PBI_APPARCH}"
+        newDir="${PBI_DBDIR}/${_pbilow}-${PBI_PATCHVERSION}-${PBI_APPARCH}"
+	mv "$oldDir" "$newDir"
+	rm ${newDir}/*.sha1 >/dev/null 2>/dev/null
+	pbi_add_register_app	
+
+	# Cleanup after our selves
+	if [ -d "$PBI_EXTRACTDIR" ] ; then
+		echo "Cleaning up..."
+		rm -rf "$PBI_EXTRACTDIR"
+	fi
+
+	echo "Finished patching ${_pbilow}: $PBI_PATCHTARGET -> $PBI_PATCHVERSION"
 }
 
+# Do any chmod stuff after patching
+patch_apply_chmod()
+{
+	if [ ! -e "${PBI_EXTRACTDIR}/PBI-permList" ] ; then return; fi
+
+	cuDir=`pwd`
+
+	cd "${PBI_PATCHWRKDIR}"
+	echo "Applying updated permissions..."
+	while read chLine
+	do
+		$chLine >/dev/null 2>/dev/null
+	done < "${PBI_EXTRACTDIR}/PBI-permList"
+
+	cd "$cuDir"
+}
+
+# Function which does the merge of bsdiff files
+patch_merge_bsdiffs()
+{
+	echo "Applying patch data..."
+	find ${PBI_EXTRACTDIR} | grep '.bsdiff' | sed "s|${PBI_EXTRACTDIR}/||g" > /tmp/.PBI.bspatch.$$
+
+	while read pLine
+	do
+		if [ -z "$pLine" ] ; then continue; fi
+		_tFile="`echo $pLine | sed 's|.bsdiff$||g'`"
+		
+		if [ ! -e "${PBI_EXTRACTDIR}/${_tFile}.sha256" ] ; then
+			exit_err "Missing checksums for \"${_tFile}\" this patch is corrupt"
+		fi
+
+		if [ ! -e "${PBI_PATCHWRKDIR}/${_tFile}" ] ; then
+			echo "Warning: Missing target file for patching: $_tFile"
+			continue
+		fi
+		
+		# Make sure we really are trying to patch the same file
+		sha1="`sha256 -q ${PBI_PATCHWRKDIR}/${_tFile}`"
+		sha2="`cat ${PBI_EXTRACTDIR}/${_tFile}.sha256`"
+		if [ "$sha1" != "$sha2" ] ; then
+			echo "Warning: Checksum failed for ${_tFile}, skipping."
+			continue
+		fi
+
+		_fPerm=`stat -f %Op "${PBI_PATCHWRKDIR}/${_tFile}"  | cut -c 3-6`
+
+		# See if we have a hard-link to take care of first
+		get_hard_link_count "${PBI_PATCHWRKDIR}/${_tFile}"
+       	 	if [ "$HLINKS" != "1" ] ; then
+			mv "${PBI_PATCHWRKDIR}/${_tFile}" "${PBI_PATCHWRKDIR}/${_tFile}.patch.$$"
+			cp "${PBI_PATCHWRKDIR}/${_tFile}.patch.$$" "${PBI_PATCHWRKDIR}/${_tFile}"
+			rm "${PBI_PATCHWRKDIR}/${_tFile}.patch.$$"
+        	fi
+		
+		# Now do the patching
+	 	#echo "Patching $_tFile"	
+		mv "${PBI_PATCHWRKDIR}/${_tFile}" "${PBI_PATCHWRKDIR}/${_tFile}.patch.$$"
+		bspatch "${PBI_PATCHWRKDIR}/${_tFile}.patch.$$" \
+			"${PBI_PATCHWRKDIR}/${_tFile}" \
+			"${PBI_EXTRACTDIR}/$pLine" >/dev/null 2>/dev/null
+		if [ "$?" != "0" ] ; then
+			echo "Warning: Failed to apply patch to \"$_tFile\""
+		fi
+
+		# Re-apply the same permissions to the new file
+		chmod $_fPerm "${PBI_PATCHWRKDIR}/${_tFile}"
+
+		# Remove the old file
+		rm "${PBI_PATCHWRKDIR}/${_tFile}.patch.$$"
+
+	done < "/tmp/.PBI.bspatch.$$"
+
+	rm /tmp/.PBI.bspatch.$$
+}
+
+# Function which does the new file extraction for this PBI
+patch_extract_new_files()
+{
+	if [ ! -e "${PBI_EXTRACTDIR}/PBI-newFiles.tar" ] ; then return; fi
+	echo "Installing new files..."
+	tar xvf "${PBI_EXTRACTDIR}/PBI-newFiles.tar" -C "${PBI_PATCHWRKDIR}" >/dev/null 2>/dev/null 
+	if [ "$?" != "0" ] ; then
+		echo "Warning: Error during new file extraction, PBI may not function correctly."
+	fi
+}
+
+# Function which removes files that no longer exist in this updated PBI
+patch_rm_old_files()
+{
+	if [ ! -e "${PBI_EXTRACTDIR}/PBI-rmList" ] ; then return; fi
+	
+	echo "Removing old files..."
+	while read rmLine
+	do
+		if [ -z "$rmLine" ] ; then continue ; fi
+		if [ ! -e "${PBI_PATCHWRKDIR}/$rmLine" ] ; then
+			continue
+		fi
+
+		rm -rf "${PBI_PATCHWRKDIR}/${rmLine}"
+	done < "${PBI_EXTRACTDIR}/PBI-rmList"
+
+}
+
+# Sets the workdir of the target PBI we are patching
+set_patch_wrkdir()
+{
+	_pbilow="`echo ${PBI_PROGNAME} | tr '[:upper:]' '[:lower:]' | sed 's| ||g'`"
+        oldDir="${PBI_DBDIR}/${_pbilow}-${PBI_PATCHTARGET}-${PBI_APPARCH}"
+
+	if [ ! -e "${oldDir}/pbi_defaultpath" ] ; then
+        	exit_err "Can not fild default path for \"$PBI_PROGNAME\"!"
+        fi
+
+	PBI_PATCHWRKDIR="`cat ${oldDir}/pbi_defaultpath`"
+
+	if [ ! -d "$PBI_PATCHWRKDIR" ] ; then
+        	exit_err "Path for \"$PBI_PROGNAME\" does not exist!"
+	fi
+}
+
+# Confirms that the target PBI for this patch is installed
+# Exits if not and we are not doing a extract only
+verify_pbi_update_target()
+{
+	if [ "${PBI_EXTRACTONLY}" = "YES" ] ; then return ; fi
+	
+	# Make sure the target PBI is installed
+	_pbilow="`echo ${PBI_PROGNAME} | tr '[:upper:]' '[:lower:]' | sed 's| ||g'`"
+        oldDir="${PBI_DBDIR}/${_pbilow}-${PBI_PATCHTARGET}-${PBI_APPARCH}"
+
+	if [ ! -e "${oldDir}" ] ; then
+        	exit_err "\"${_pbilow}\" does not appear to be installed!"
+        fi
+
+	# Check the arch type
+	if [ "`cat ${oldDir}/pbi_arch`" != "$PBI_APPARCH" ] ; then
+     		exit_err "Installed \"${PBI_PROGNAME}\" is not compiled for $PBI_APPARCH"
+	fi
+
+	# Check the taret version
+	if [ "`cat ${oldDir}/pbi_version`" != "$PBI_PATCHTARGET" ] ; then
+     		exit_err "\"${_pbilow}\" patch is for \"$PBI_PROGVERSION\" only!"
+	fi
+
+	# Check the fbsd version
+	if [ "`cat ${oldDir}/pbi_fbsdver`" != "$PBI_FBSDVER" ] ; then
+     		exit_err "\"${_pbilow}\" patch is for FreeBSD \"$PBI_FBSDVER\" only!"
+	fi
+}
+
+# Start the pbi_add process
 pbi_add_init() {
 	parse_add_pbi_cmdline "$@"
 
@@ -965,7 +1176,7 @@
 	if [ "$PBI_ADD_GUIDISPLAY" = "YES" -o "$PBI_ADD_INFODISPLAY" = "YES" -o "$PBI_CHECKSCRIPTS" = "YES" -o "${PBI_ADD_LICDISPLAY}" = "YES" ] 
 	then 
 		clean_remote_dl
-		exit 0 
+		exit_trap
 	fi
 
 	check_agree_lic
@@ -976,6 +1187,7 @@
 # Check if this PBI exists and exit if so
 check_existing_pbi() {
 	if [ "${PBI_FORCEADD}" = "YES" ] ; then return 0; fi
+	if [ "${PBI_EXTRACTONLY}" = "YES" ] ; then return 0; fi
 	get_dbdir
 	dir="${APPDBDIR}"
 	if [ -d "$dir" ]; then
@@ -1033,7 +1245,7 @@
 	echo "Name: ${PBI_PROGNAME}"
 
 	if [ ! -z "$PBI_PATCHVERSION" ] ; then
-		echo "PatchTarget: `echo $PBI_PATCHVERSION | cut -d ':' -f 1`"
+		echo "PatchTarget: $PBI_PATCHTARGET"
 	fi
 
 	echo "Version: ${PBI_PROGVERSION}"
@@ -1100,10 +1312,11 @@
 }
 
 open_header_tmp() {
+	init_tmpdir
 
 	# If we have a custom extract dir, use it
 	if [ -z "$1" ] ; then
-		PBI_HEADER_TMPDIR=".PBI-header.$$"
+		PBI_HEADER_TMPDIR="${PBI_TMPDIR}/.PBI-header.$$"
 	else
 		PBI_HEADER_TMPDIR="${1}/.PBI-header.$$"
 	fi
@@ -1176,6 +1389,7 @@
         PBI_ARCHIVE_CHECKSUM=""
 	PBI_SIGVALID=""
 	PBI_PATCHVERSION=""
+	PBI_PATCHTARGET=""
 
 	PBI_ORIGPROGDIRPATH="`cat ${1}/pbi_defaultpath`"
         PBI_PROGNAME="`cat ${1}/pbi_name`"
@@ -1191,7 +1405,8 @@
 	
 	# Check if this is a patch file
 	if [ -e "${1}/pbi_patchfile" ] ; then
-        	PBI_PATCHVERSION=`cat ${1}/pbi_patchfile`
+        	PBI_PATCHVERSION=`cat ${1}/pbi_patchfile | cut -d ':' -f 2`
+		PBI_PATCHTARGET=`cat ${1}/pbi_patchfile | cut -d ':' -f 1`
 	fi
 
 	# See if this PBI was signed
@@ -1220,7 +1435,7 @@
 	pbi_add_run_script
 	check_postinstall_script
 
-	pbi_add_update_hashdir	
+	pbi_add_update_hashdir "${PBI_PROGDIRPATH}"
 
 	pbi_add_register_app
 
@@ -1242,10 +1457,10 @@
 # If we need to, update the hashdir
 pbi_add_update_hashdir() {
 	if [ "${PBI_NOHASHDIR}" = "YES" ] ; then return 0 ; fi
-	if [ ! -e "${PBI_PROGDIRPATH}/${PBI_HASHLIST}" ] ; then return 0; fi
+	if [ ! -e "${1}/${PBI_HASHLIST}" ] ; then return 0; fi
 
 	if [ "$PBI_VERBOSE" = "YES" ] ; then
-		echo "HASHCOUNT: `wc -l ${PBI_PROGDIRPATH}/${PBI_HASHLIST} | tr -d ' ' | cut -d '/' -f 1`"
+		echo "HASHCOUNT: `wc -l ${1}/${PBI_HASHLIST} | tr -d ' ' | cut -d '/' -f 1`"
 	else
 	
 		echo -e "Merging with hashdir...\c"
@@ -1259,14 +1474,14 @@
 		tfile="${file}:::${hash}"
 		
 		# We dont need no stinking sym-links
-		if [ -h "${PBI_PROGDIRPATH}/${file}" ] ; then continue ; fi
+		if [ -h "${1}/${file}" ] ; then continue ; fi
 
 		if [ -f "${PBI_HASHDIR}/${tfile}" ] ; then
-			use_hashfile "${tfile}" "$file" "$hash"
+			use_hashfile "${tfile}" "${1}/$file" "$hash"
 		else
-			mv_ln_hashfile "${tfile}" "$file" "$hash"
+			mv_ln_hashfile "${tfile}" "${1}/$file" "$hash"
 		fi
-	done < ${PBI_PROGDIRPATH}/${PBI_HASHLIST}
+	done < "${1}/${PBI_HASHLIST}"
 
 	if [ "$PBI_VERBOSE" = "YES" ] ; then 
 		echo "HASHDONE"
@@ -1280,15 +1495,15 @@
 	tfile="$1"
 	file="$2"
 	hash="$3"
-	dir="`dirname ${file}`"
+	dir="`dirname ${tfile}`"
 	if [ ! -d "${PBI_HASHDIR}/${dir}" ] ; then
 		mkdir -p ${PBI_HASHDIR}/${dir}
 	fi
 	# Confirm that the files are the same
-	diff "${PBI_PROGDIRPATH}/${file}" "${PBI_HASHDIR}/${tfile}" >/dev/null 2>/dev/null
+	diff "${file}" "${PBI_HASHDIR}/${tfile}" >/dev/null 2>/dev/null
 	if [ "$?" = "0" ] ; then
 		if [ "$PBI_VERBOSE" = "YES" ] ; then echo "." ; fi
-		ln -f "${PBI_HASHDIR}/${tfile}" "${PBI_PROGDIRPATH}/${file}"
+		ln -f "${PBI_HASHDIR}/${tfile}" "${file}"
 		if [ "$?" != "0" ] ; then exit_err "Critical failure, exiting..."; fi
 	else
 		if [ "$PBI_VERBOSE" = "YES" ] ; then echo "X" ; fi
@@ -1303,14 +1518,14 @@
 	tfile="$1"
 	file="$2"
 	hash="$3"
-	dir="`dirname ${file}`"
+	dir="`dirname ${tfile}`"
 	if [ ! -d "${PBI_HASHDIR}/${dir}" ] ; then
 		mkdir -p ${PBI_HASHDIR}/${dir}
 	fi
 
-	mv "${PBI_PROGDIRPATH}/${file}" "${PBI_HASHDIR}/${tfile}"
+	mv "${file}" "${PBI_HASHDIR}/${tfile}"
 	if [ "$?" != "0" ] ; then exit_err "Critical failure, exiting..."; fi
-	ln -f "${PBI_HASHDIR}/${tfile}" "${PBI_PROGDIRPATH}/${file}"
+	ln -f "${PBI_HASHDIR}/${tfile}" "${file}"
 	if [ "$?" != "0" ] ; then exit_err "Critical failure, exiting..."; fi
 	if [ "$PBI_VERBOSE" = "YES" ] ; then echo "L" ; fi
 }
@@ -1333,6 +1548,11 @@
 
 	echo "${PBI_PROGDIRPATH}" >${dir}/pbi_installedpath
 
+	# Dont need any patch version info
+	if [ -e "${dir}/pbi_patchfile" ] ; then
+		rm "${dir}/pbi_patchfile"
+	fi
+
 	# Remove any duplicate ldconfig entry
         # KPM - 08172010 - Disable until we get a patch to BSD to support hints via path
 	#cat "${PBI_LDCONFIGFILE}" 2>/dev/null | grep "^${PBI_PROGDIRPATH}" >/dev/null 2>/dev/null
@@ -1345,7 +1565,7 @@
         delete_header_tmp
 
 	# Re-gen the ldconfig hints files
-	${PBI_LDCONFIGRC} onestart >/dev/null 2>/dev/null
+	#${PBI_LDCONFIGRC} onestart >/dev/null 2>/dev/null
 
 	echo "Installed: ${PBI_PROGNAME}-${PBI_PROGVERSION}"
 }
@@ -1417,7 +1637,7 @@
 # Verify if the archive checksum is good
 pbi_verify_archivesum() {
 	if [ "${PBI_SKIPCHECKSUM}" = "YES" ] ; then return 0 ; fi
-	echo -e "Verifying CheckSum...\c"
+	echo -e "Verifying Checksum...\c"
 
         pbi_find_archive_header
 	sum=`tail +$PBI_SKIP_ARCHLINES "${PBI_FILENAME}" | sha256 -q`
@@ -1473,7 +1693,7 @@
 	if [ "$PBI_VERBOSE" = "YES" ] ; then echo "Extraction Finished!" ; fi
 
 	# If this is an extract only, do it and exit
-	if [ "${PBI_EXTRACTONLY}" = "YES" ] ; then exit 0 ; fi
+	if [ "${PBI_EXTRACTONLY}" = "YES" ] ; then exit_trap ; fi
 }
 	
 
@@ -1633,12 +1853,12 @@
 			else
 				# Make our link commands
 				if [ "$_keep" = "YES" ] ; then _lop="-fs"; else _lop="-s"; fi
-				echo "ln ${_lop} \$PBI_PROGDIRPATH/${src} \$SYS_LOCALBASE/${tar}" \
+				echo "ln ${_lop} $PBI_PROGDIRPATH/${src} \$SYS_LOCALBASE/${tar}" \
 					>> "${dir}/${PBI_INS_PATHSCRIPT}"
 			fi
 
 			# Make the uninstall command
-			echo "ls -al \"\$SYS_LOCALBASE/$tar\" | grep \"> \$PBI_PROGDIRPATH\" >/dev/null 2>/dev/null " \
+			echo "ls -al \"\$SYS_LOCALBASE/$tar\" | grep \"> $PBI_PROGDIRPATH\" >/dev/null 2>/dev/null " \
 				>> "${dir}/${PBI_UNINS_PATHSCRIPT}"
 			echo "if [ \"\$?\" = \"0\" ] ; then" >> "${dir}/${PBI_UNINS_PATHSCRIPT}"
 			echo "	rm \"\$SYS_LOCALBASE/${tar}\"" >> "${dir}/${PBI_UNINS_PATHSCRIPT}"
@@ -1656,7 +1876,6 @@
 
 	chmod 755 "${dir}/${PBI_INS_PATHSCRIPT}"
 	chmod 755 "${dir}/${PBI_UNINS_PATHSCRIPT}"
-	rm_tmpdir
 }
 
 
@@ -1676,7 +1895,7 @@
 
 	# Make our link to the system localbase if its not a wrapper only
  	if [ "$onlywrap" != "YES" ] ; then	
-		echo "ln -fs \$PBI_PROGDIRPATH/${PBI_FAKEBIN_DIR}/${fbin} \$SYS_LOCALBASE/${tar}" \
+		echo "ln -fs $PBI_PROGDIRPATH/${PBI_FAKEBIN_DIR}/${fbin} \$SYS_LOCALBASE/${tar}" \
 			>> "${dir}/${PBI_INS_PATHSCRIPT}"
 	fi
 
@@ -1764,7 +1983,7 @@
 		> "${dir}/PBI-${i}"
 		#cp "${i}" "${dir}/PBI-${i}"
 
-		ifi="\$PBI_PROGDIRPATH/${PBI_APPDESK_DIR}/PBI-${i}"
+		ifi="$PBI_PROGDIRPATH/${PBI_APPDESK_DIR}/PBI-${i}"
 
 		echo "xdg-desktop-icon install --novendor ${ifi}" \
 			 >> "${dir}/${PBI_INS_DESKSCRIPT}"
@@ -1795,7 +2014,7 @@
 		| sed "s|%%PBI_APPDIR%%|$PBI_PROGDIRPATH|g" \
 		> "${dir}/PBI-${i}"
 
-		ifi="\$PBI_PROGDIRPATH/${PBI_APPMENU_DIR}/PBI-${i}"
+		ifi="$PBI_PROGDIRPATH/${PBI_APPMENU_DIR}/PBI-${i}"
 
 		# Check for a .directory file associated with this .desktop
 		ifd=""
@@ -1806,7 +2025,7 @@
 			| sed "s|%%PBI_APPDIR%%|$PBI_PROGDIRPATH|g" \
 			> "${dir}/PBI-${dirfile}.directory"
 			#cp "${dirfile}.directory" "${dir}/PBI-${dirfile}.directory"
-			ifd="\$PBI_PROGDIRPATH/${PBI_APPMENU_DIR}/PBI-${dirfile}.directory "	
+			ifd="$PBI_PROGDIRPATH/${PBI_APPMENU_DIR}/PBI-${dirfile}.directory "	
 		fi
 
 		echo "xdg-desktop-menu install --novendor ${ifd}${ifi}" \
@@ -1834,14 +2053,14 @@
   	for i in `ls *.xml 2>/dev/null`
   	do
 		cp "${i}" "${dir}/PBI-${i}"
-		ifi="\$PBI_PROGDIRPATH/${PBI_APPMIME_DIR}/PBI-${i}"
+		ifi="$PBI_PROGDIRPATH/${PBI_APPMIME_DIR}/PBI-${i}"
 
 		# Check for a .directory file associated with this .desktop
 		ifp=""
 		iconfile="`basename -s .xml ${i}`"
 		if [ -e "${iconfile}.png" ] ; then
 			cp "${iconfile}.png" "${dir}/${iconfile}.png"
-			ifp="\$PBI_PROGDIRPATH/${PBI_APPMIME_DIR}/${iconfile}.png"
+			ifp="$PBI_PROGDIRPATH/${PBI_APPMIME_DIR}/${iconfile}.png"
 			mi=`cat "$i" | grep '<mime-type' | cut -d '"' -f 2 | sed 's|/|-|g'`
 			echo "xdg-icon-resource install --novendor --context mimetypes ${ifp} --size 64 $mi" \
 				 >> "${dir}/${PBI_INS_MIMESCRIPT}"
@@ -1887,18 +2106,15 @@
 
 	# Add the binary wrapper sym-links
         if [ -e "${PBI_STAGEDIR}/${PBI_FAKEBIN_DIR}/${PBI_INS_PATHSCRIPT}" ] ; then
-		echo "\$PBI_PROGDIRPATH/${PBI_FAKEBIN_DIR}/${PBI_INS_PATHSCRIPT}" >>${insc}
+		echo "$PBI_PROGDIRPATH/${PBI_FAKEBIN_DIR}/${PBI_INS_PATHSCRIPT}" >>${insc}
 	fi
 
 	# Look for any XDG scripts
         if [ -e "${PBI_STAGEDIR}/${PBI_APPMIME_DIR}/${PBI_INS_MIMESCRIPT}" ] ; then
-		echo "\$PBI_PROGDIRPATH/${PBI_APPMIME_DIR}/${PBI_INS_MIMESCRIPT}" >>${insc}
+		echo "$PBI_PROGDIRPATH/${PBI_APPMIME_DIR}/${PBI_INS_MIMESCRIPT}" >>${insc}
 	fi
-        if [ -e "${PBI_STAGEDIR}/${PBI_APPDESK_DIR}/${PBI_INS_DESKSCRIPT}" ] ; then
-		echo "su \$USER \$PBI_PROGDIRPATH/${PBI_APPDESK_DIR}/${PBI_INS_DESKSCRIPT}" >>${insc}
-	fi
         if [ -e "${PBI_STAGEDIR}/${PBI_APPMENU_DIR}/${PBI_INS_MENUSCRIPT}" ] ; then
-		echo "\$PBI_PROGDIRPATH/${PBI_APPMENU_DIR}/${PBI_INS_MENUSCRIPT}" >>${insc}
+		echo "$PBI_PROGDIRPATH/${PBI_APPMENU_DIR}/${PBI_INS_MENUSCRIPT}" >>${insc}
 	fi
 
 	chmod 755 "${insc}"
@@ -1913,18 +2129,15 @@
 
 	# Remove the binary wrapper sym-links
         if [ -e "${PBI_STAGEDIR}/${PBI_FAKEBIN_DIR}/${PBI_UNINS_PATHSCRIPT}" ] ; then
-		echo "\$PBI_PROGDIRPATH/${PBI_FAKEBIN_DIR}/${PBI_UNINS_PATHSCRIPT}" >>${uisc}
+		echo "$PBI_PROGDIRPATH/${PBI_FAKEBIN_DIR}/${PBI_UNINS_PATHSCRIPT}" >>${uisc}
 	fi
 
 	# Look for any XDG scripts
         if [ -e "${PBI_STAGEDIR}/${PBI_APPMIME_DIR}/${PBI_UNINS_MIMESCRIPT}" ] ; then
-		echo "\$PBI_PROGDIRPATH/${PBI_APPMIME_DIR}/${PBI_UNINS_MIMESCRIPT}" >>${uisc}
+		echo "$PBI_PROGDIRPATH/${PBI_APPMIME_DIR}/${PBI_UNINS_MIMESCRIPT}" >>${uisc}
 	fi
-        if [ -e "${PBI_STAGEDIR}/${PBI_APPDESK_DIR}/${PBI_UNINS_DESKSCRIPT}" ] ; then
-		echo "su $USER \$PBI_PROGDIRPATH/${PBI_APPDESK_DIR}/${PBI_UNINS_DESKSCRIPT}" >>${uisc}
-	fi
         if [ -e "${PBI_STAGEDIR}/${PBI_APPMENU_DIR}/${PBI_UNINS_MENUSCRIPT}" ] ; then
-		echo "\$PBI_PROGDIRPATH/${PBI_APPMENU_DIR}/${PBI_UNINS_MENUSCRIPT}" >>${uisc}
+		echo "$PBI_PROGDIRPATH/${PBI_APPMENU_DIR}/${PBI_UNINS_MENUSCRIPT}" >>${uisc}
 	fi
 	chmod 755 "${uisc}"
 }
@@ -2124,7 +2337,6 @@
 	parse_delete_pbi_cmdline "$@"
   	require_root
 	do_pbi_delete
-	rm_tmpdir
 }
 
 # Delete this PBI
@@ -2186,7 +2398,7 @@
 # Read through and clean the entire hashdir
 pbi_clean_hashdir() {
         if [ ! -d "${PBI_HASHDIR}" ] ; then return 0 ; fi
-	echo "Cleaning shared-hash dir: ${PBI_HASHDIR}"
+	echo "Cleaning shared-hash dir..."
 	cd ${PBI_HASHDIR}
 	tmphashlist="${PBI_TMPDIR}/.pbi-hashdir.$$"
 	find * -type f > "${tmphashlist}" 2>/dev/null
@@ -2479,9 +2691,6 @@
                 done
 	fi
 
-	# Bye Bye!
-	rm_tmpdir
-
 }
 
 # Check if we need to pull down the updated INDEX file
@@ -2551,9 +2760,6 @@
 
 	# Uncomment to see details from update server
 	#cat ${PBI_TMPDIR}/.upcheck$$
-
-	# Bye Bye!
-	rm_tmpdir
 }
 
 # Check a specific PBI for updates
@@ -2595,9 +2801,6 @@
 	if [ "$PBI_UPNVER" != "$PBI_PROGVERSION" ] ; then
 		echo "${_upbi} - Available: ${PBI_UPNVER}"
 	fi
-
-	# Bye Bye!
-	rm_tmpdir
 }
 
 # Start PBI update process
@@ -2794,8 +2997,6 @@
 
 	done < ${PBI_TMPDIR}/.autob.$$
 	rm "${PBI_TMPDIR}/.autob.$$"
-
-	rm_tmpdir
 }
 
 # Prune any outdir files which don't have matching modules
@@ -3123,18 +3324,22 @@
 		if [ -b "${1}/$line" ] ; then continue ; fi
 		if [ -c "${1}/$line" ] ; then continue ; fi
 
-		diff -q ${1}/$line ${2}/$line >/dev/null 2>/dev/null
-		if [ $? != 0 ] ; then
+		# Check sha256 of each file, see if we have differences
+		sha1="`sha256 -q ${1}/${line}`" 
+		sha2="`sha256 -q ${2}/${line}`"
+		if [ "$sha1" != "$sha2" ] ; then
 			# These files differ, get a binary patch made of them
 			_tDir="${3}/`dirname $line`"
 			_bName=`basename $line`
 			if [ ! -d "$_tDir" ] ; then mkdir -p "$_tDir" ; fi
 			
-			#echo "Making patch for $line"
-			bsdiff ${2}/${line} ${1}/${line} ${_tDir}/${_bName}.bsdiff
+			bsdiff "${2}/${line}" "${1}/${line}" "${_tDir}/${_bName}.bsdiff"
 			if [ "$?" != "0" ] ; then
 				exit_err "Failed creating bsdiff patch for $line"
 			fi
+
+			# Save the sha256 of the file to be modified
+			sha256 -q "${2}/${line}" > "${_tDir}/${_bName}.sha256"
 		fi
 
 	done < /tmp/.pbi.nDir.$$
@@ -3339,13 +3544,12 @@
 	mk_auto_ext_linksfile
 
   	# Break here if we are only doing a build
-	if [ "${PBI_BUILDONLY}" = "YES" ] ; then rm_tmpdir ; exit 0; fi
+	if [ "${PBI_BUILDONLY}" = "YES" ] ; then exit_trap; fi
 
 	# Start creation of PBI
 	do_pbi_create
 
 	# Clean the tmpdir
-	rm_tmpdir
 	rm_buildfiles
 }
 
@@ -3447,6 +3651,7 @@
 # Cleanup after caught exit
 exit_trap() {
 	rm_tmpdir
+	exit 0
 }
 
 # Read in the global pbi.conf
@@ -3525,7 +3730,8 @@
    pbi_patch) pbi_patch_init "$@" ;;
    pbi_update) pbi_update_init "$@" ;;
    pbi-crashhandler) pbi_crash_init "$@" ;;
-   *) echo "Error: Called with invalid basename!" ; exit 1 ;;
+   *) echo "Error: Called with invalid basename!" ; exit_trap ;;
 esac
 
+rm_tmpdir
 exit 0



More information about the Commits mailing list