iOS 7: Read BundleIdentifier from Info.plist and use during install/upgrade
diff --git a/src/ideviceinstaller.c b/src/ideviceinstaller.c
index 3aac8ae..0877c86 100644
--- a/src/ideviceinstaller.c
+++ b/src/ideviceinstaller.c
@@ -858,12 +858,20 @@
 			}
 
 			char *bundleexecutable = NULL;
+			char *bundleidentifier = NULL;
 
 			plist_t bname = plist_dict_get_item(info, "CFBundleExecutable");
 			if (bname) {
 				plist_get_string_val(bname, &bundleexecutable);
 			}
+
+			bname = plist_dict_get_item(info, "CFBundleIdentifier");
+			if (bname) {
+				plist_get_string_val(bname, &bundleidentifier);
+				printf("Installing bundle %s.\n", bundleidentifier);
+			}
 			plist_free(info);
+			info = NULL;
 
 			if (!bundleexecutable) {
 				fprintf(stderr, "Could not determine value for CFBundleExecutable!\n");
@@ -892,7 +900,7 @@
 
 			/* copy archive to device */
 			pkgname = NULL;
-			if (asprintf(&pkgname, "%s/%s", PKG_PATH, basename(appid)) < 0) {
+			if (asprintf(&pkgname, "%s/%s", PKG_PATH, bundleidentifier) < 0) {
 				fprintf(stderr, "Out of memory!?\n");
 				goto leave_cleanup;
 			}
@@ -906,6 +914,9 @@
 
 			printf("done.\n");
 
+			if (bundleidentifier) {
+				instproxy_client_options_add(client_opts, "CFBundleIdentifier", bundleidentifier, NULL);
+			}
 			if (sinf) {
 				instproxy_client_options_add(client_opts, "ApplicationSINF", sinf, NULL);
 			}