[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#882851: [PATCH] introduce LIVE_UTC=auto to auto-detect windows-installations



... with os-prober, if that is available
---
 components/1120-util-linux | 48 +++++++++++++++++++++++++++++++-------
 1 file changed, 39 insertions(+), 9 deletions(-)

diff --git a/components/1120-util-linux b/components/1120-util-linux
index 8bb45e5..65aa1be 100755
--- a/components/1120-util-linux
+++ b/components/1120-util-linux
@@ -21,13 +21,21 @@ Cmdline ()
 				;;
 		esac
 	done
+
+	# If not explicitly given, auto-detect
+	if [ -n "${LIVE_UTC}" ]
+	then
+		LIVE_UTC="auto"
+	fi
+
 }

 Init ()
 {
 	# Checking if package is installed
 	if [ ! -e /var/lib/dpkg/info/util-linux.list ] || \
-	   [ -e /var/lib/live/config/util-linux ]
+	   # and wether previously configured or auto-detect mode active
+	   [ -e /var/lib/live/config/util-linux -a "${LIVE_UTC}" != "auto" ]
 	then
 		exit 0
 	fi
@@ -39,10 +47,20 @@ Config ()
 {
 	rm -f /etc/rc?.d/*hwclock*

-	if [ -n "${LIVE_UTC}" ]
+	# if os-prober is installed, use it to detect windows installations
+	if [ "${LIVE_UTC}" = "auto" ] && [ -x /usr/bin/os-prober ]
 	then
-		case "${LIVE_UTC}" in
-			yes)
+		if os-prober | grep -qsi windows
+		then
+			LIVE_UTC=no
+		else
+			LIVE_UTC=yes
+		fi
+
+	fi
+
+	case "${LIVE_UTC}" in
+		yes)

 cat > /etc/adjtime << EOF
 0.0 0 0.0
@@ -50,19 +68,31 @@ cat > /etc/adjtime << EOF
 UTC
 EOF

-				;;
+			;;

-			no)
+		no)

 cat > /etc/adjtime << EOF
 0.0 0 0.0
 0
 LOCAL
 EOF
+			# prevent "System clock time unset or jumped
+			# backwards, restoring from recorded timestamp"
+			# oh Lennart
+			pgrep systemd-timesyncd && SYSD=1
+			TIMEFILE=/var/lib/systemd/timesync/clock

-				;;
-		esac
-	fi
+			[ -e $TIMEFILE ] && rm -v $TIMEFILE
+			[ "$SYSD" = "1" ] && systemctl stop systemd-timesyncd
+
+			# tell kernel to set the timezone and
+			# reset the system clock to local time
+			hwclock --systz --localtime
+
+			[ "$SYSD" = "1" ] && systemctl start systemd-timesyncd
+			;;
+	esac

 	# Creating state file
 	touch /var/lib/live/config/util-linux
--
2.24.0


Reply to: