Subject: Re: install/10935: update install should remember which X you use
To: None <dmcmahill@netbsd.org>
From: Hubert Feyrer <feyrer@rfhs8012.fh-regensburg.de>
List: tech-install
Date: 09/02/2000 14:58:23
On Fri, 1 Sep 2000 dmcmahill@netbsd.org wrote:
> I just used sysinst to update a i386 from 1.4.2 to 1.5_ALPHA2.  It would be nice if the link
> from /usr/X11R6/bin/X to Xwhatever_is_was_I_had_before was remembered.  Doesn't have to be remade,
> but at least recorded somewhere (like the way /etc is saved to /etc.old

Here is a patch that moves X aside, and back. 
It's untested. I also don't know what "X" is installed on non-i386. 
Someone please tell me if this is ok!!!

Index: msg.mi.en
===================================================================
RCS file: /cvsroot/basesrc/distrib/utils/sysinst/msg.mi.en,v
retrieving revision 1.65
diff -u -r1.65 msg.mi.en
--- msg.mi.en	2000/08/15 01:08:00	1.65
+++ msg.mi.en	2000/09/02 12:54:27
@@ -625,6 +625,20 @@
 
 Aborting upgrade.}
 
+message X_oldexists
+{I cannot save /usr/X11R6/bin/X as /usr/X11R6/bin/X.old, because the
+target disk already has an /usr/X11R6/bin/X.old. Please fix this before
+continuing.
+
+One way is to start a shell from the Utilities menu, examine the
+target /usr/X11R6/bin/X and /usr/X11R6/bin/X.old.  If
+/usr/X11R6/bin/X.old is from a completed upgrade, you can rm -f
+/usr/X11R6/bin/X.old and restart.  Or if /usr/X11R6/bin/X.old is from
+a recent, incomplete upgrade, you can rm -f /usr/X11R6/bin/X and mv
+/usr/X11R6/bin/X.old to /usr/X11R6/bin/X.
+
+Aborting upgrade.}
+
 message netnotup
 {There was a problem in setting up the network.  Either your gateway
 or your nameserver was not reachable by a ping.  Do you want to
Index: target.c
===================================================================
RCS file: /cvsroot/basesrc/distrib/utils/sysinst/target.c,v
retrieving revision 1.22
diff -u -r1.22 target.c
--- target.c	1999/06/20 06:08:15	1.22
+++ target.c	2000/09/02 12:54:29
@@ -541,7 +541,8 @@
 /*
  * Do a mv where both pathnames are  within the target filesystem.
  */
-void mv_within_target_or_die(frompath, topath)
+void
+mv_within_target_or_die(frompath, topath)
 	const char *frompath;
 	const char *topath;
 {
@@ -724,6 +725,14 @@
  	return target_test("-f", path);
 }
 
+int
+target_test_symlink(path)
+	const char *path;
+{
+
+ 	return target_test("-h", path);
+}
+
 int target_file_exists_p(path)
 	const char *path;
 {
@@ -736,4 +745,11 @@
 {
 
 	return (target_test_dir(path) == 0);
+}
+
+int target_symlink_exists_p(path)
+	const char *path;
+{
+
+	return (target_test_symlink(path) == 0);
 }
Index: upgrade.c
===================================================================
RCS file: /cvsroot/basesrc/distrib/utils/sysinst/upgrade.c,v
retrieving revision 1.20
diff -u -r1.20 upgrade.c
--- upgrade.c	1999/06/22 06:57:01	1.20
+++ upgrade.c	2000/09/02 12:54:29
@@ -51,6 +51,8 @@
 void 	check_prereqs __P((void));
 int	save_etc __P((void));
 int	merge_etc __P((void));
+int	save_X __P((void));
+int	merge_X __P((void));
 
 /*
  * Do the system upgrade.
@@ -88,6 +90,11 @@
 	if (save_etc())
 		return;
 
+	/*
+	 * Save X symlink, ...
+	 */
+	if (save_X())
+		return;
 
 	/* Do any md updating of the file systems ... e.g. bootblocks,
 	   copy file systems ... */
@@ -106,6 +113,7 @@
 
 	/* Copy back any files we should restore after the upgrade.*/
 	merge_etc();
+	merge_X();
 
 	sanity_check();
 }
@@ -169,6 +177,32 @@
 }
 
 /*
+ * Save X symlink to X.old so it can be recovered later
+ */
+int
+save_X()
+{
+	/* Only care for X if it's a symlink */
+	if (target_symlink_exists_p("/usr/X11R6/bin/X")) {
+		if (target_symlink_exists_p("/usr/X11R6/bin/X.old")) {
+			msg_display(MSG_X_oldexists);
+			process_menu(MENU_ok);
+			return EEXIST;
+		}
+
+#ifdef DEBUG
+		printf("saving /usr/X11R6/bin/X as .../X.old ...");
+#endif
+
+		/* Move target .../X to .../X.old.  Abort on error. */
+		mv_within_target_or_die("/usr/X11R6/bin/X",
+					"/usr/X11R6/bin/X.old");
+	}
+
+	return 0;
+}
+
+/*
  * Merge back saved target /etc files after unpacking the new
  * sets has completed.
  */
@@ -178,6 +212,23 @@
 
 	/* just move back fstab, so we can boot cleanly.  */
 	cp_within_target("/etc.old/fstab", "/etc/");
+
+	return 0;	
+}
+
+/*
+ * Merge back saved target X files after unpacking the new
+ * sets has completed.
+ */
+int
+merge_X()
+{
+	if (target_symlink_exists_p("/usr/X11R6/bin/X.old")) {
+		/* Only move back X if it's a symlink - we don't want
+		 * to restore old binaries */
+		mv_within_target_or_die("/usr/X11R6/bin/X.old",
+					"/usr/X11R6/bin/X");
+	}
 
 	return 0;	
 }



> write it down your self, or have sysinst save it somewhere.  Also, the Xservers file
> gets stomped on.

Which file is this, I'm not familiar with it.


 - Hubert

-- 
NetBSD - because Unix isn't just #include <linux.h>, i386, ILP32, ELF, ...!