[debian-edu-commits] [Git][debian-edu/debian-edu-install][master] Add systemd service files equivalent to xdebian-edu-firstboot init script

Mike Gabriel (@sunweaver) gitlab at salsa.debian.org
Thu Sep 14 15:12:07 BST 2023



Mike Gabriel pushed to branch master at Debian Edu / debian-edu-install


Commits:
c80e9b30 by Guido Berhoerster at 2023-09-12T07:47:28+02:00
Add systemd service files equivalent to xdebian-edu-firstboot init script

The init script performs two tasks on the first boot after installation.
Firstly, it starts the run-at-firstboot script from debian-edu-config.
Secondly, it runs tests via the debian-edu-test-install script provided by
debian-edu-config if requested by the user via the testinstall argument on the
kernel command line.  Any errors found will be mailed to the first user and
success or failure will be signaled through a graphical dialog on top of the
display manager.
Factor out the test runner into a separate script debian-edu-testsuite.  This
script is then run by the xdebian-edu-firstboot sysvinit script.  Create two
systemd service files, one which runs the run-at-firstboot script and another
one for running debian-edu-testsuite.
Remove unsupported update-rc.d options.

- - - - -


6 changed files:

- Makefile
- + debian-edu-testsuite
- + debian/debian-edu-install.debian-edu-testsuite.service
- debian/debian-edu-install.xdebian-edu-firstboot.init
- + debian/debian-edu-install.xdebian-edu-firstboot.service
- debian/rules


Changes:

=====================================
Makefile
=====================================
@@ -4,10 +4,13 @@
 
 INSTALL     = install
 INSTALL_DATA= install -m 644
+INSTALL_BIN = install -m 755
 
 libdir      = /usr/lib
 templatedir = /usr/share/debconf/templates
 pkglibdir   = $(libdir)/debian-edu-install
+libexecdir  = /usr/lib
+pkglibexecdir = $(libexecdir)/debian-edu-install
 sbindir     = /usr/sbin
 sysconfdir  = /etc
 
@@ -45,6 +48,7 @@ install:
 	    $(INSTALL_DATA) preseed-values/defaults.$$profile $(DESTDIR)$(pkglibdir)/; \
 	done
 	$(INSTALL_DATA) version $(DESTDIR)$(pkglibdir)
+	$(INSTALL_BIN) debian-edu-testsuite $(DESTDIR)$(pkglibexecdir)
 
 debian-edu-profile.templates: debian/debian-edu-profile-udeb.templates
 	(cd debian; po2debconf debian-edu-profile-udeb.templates) > $@


=====================================
debian-edu-testsuite
=====================================
@@ -0,0 +1,167 @@
+#!/bin/sh
+#
+# debian-edu-testsuite - Check the Debian Edu installation after first boot
+#
+# Run the self test and report any errors found.
+#
+# Author: Petter Reinholdtsen
+#
+
+info() {
+    logger -t debian-edu-install "info: $@"
+}
+
+error() {
+    logger -t debian-edu-install "error: $@"
+}
+
+at_exit() {
+    error "script $0 terminated unexpectedly."
+}
+disable_exception() { trap - INT TERM EXIT; }
+trap at_exit INT TERM EXIT
+
+run_testsuite() {
+    logfile=/var/log/installer/debian-edu-install-testsuite
+
+    temp_dir=$(mktemp -d)
+    errfile=$temp_dir/errors
+
+    nice debian-edu-test-install > $logfile 2>&1
+
+    # find error and partition resize messages in the d-i log and the
+    # self test
+    if [ -f /var/log/installer/syslog  ] ; then
+        # remove syslog prefix
+        # Ignore normal errors from wget commands used to test if
+        # mirrors are available [pere 2010-07-22].
+        # Ignore also samba-ad-dc error (unused atm) [schweer 2018-11-05].
+        grep -E 'error:|fsautoresize' /var/log/installer/syslog | \
+	    grep -v 'wget: server returned error: HTTP/1.0 404 Not Found' | \
+	    grep -v 'wget: server returned error: HTTP/1.1 404 Not Found' | \
+	    grep -v 'samba-ad' | \
+	sed 's/.*error: /error: /g' > $errfile
+    fi
+    # The a param is now needed to find all errors [schweer 2018-11-05].
+    grep -a error: $logfile >> $errfile || true
+
+    if [ -s $errfile ] ; then
+    content=$(cat $errfile)
+    # Send error report via mail to first user (who has uid 1000 by default).
+    firstuser=$(getent passwd | grep 1000 | cut -d':' -f1)
+    username=$(getent passwd | grep 1000 | cut -d':' -f5)
+
+            cat << EOF | /usr/lib/sendmail $firstuser
+Subject: Test status
+
+Hello $username,
+
+these are the test results you requested by adding 'testinstall' as
+additional kernel commandline parameter. They have been collected by running
+the testsuite and searching in the /var/log/installer directory.
+
+$content
+
+(Sent from the Debian Edu first boot script.)
+
+EOF
+
+        $0 report-errors $errfile || true
+    else
+        $0 report-success || true
+    fi
+    rm $errfile
+    rmdir $temp_dir
+}
+
+prepare_debconf() {
+    # Try to get debconf to pop up the dialog on top of the display
+    # manager.  Need to do this before starting debconf.
+    if [ ! "$DEBIAN_HAS_FRONTEND" ] ; then
+        # This is generated by sddm
+	candidate="$(ls -tr /var/run/sddm/* 2>/dev/null|tail -1)"
+        # lightdm
+	candidate="$candidate /var/lib/lightdm/.Xauthority"
+
+	XAUTHORITY=
+	for f in $candidate ; do
+	    if XAUTHORITY=$f DISPLAY=:0 xauth list >/dev/null 2>&1 &&
+		XAUTHORITY=$f DISPLAY=:0 xhost > /dev/null 2>&1 ; then
+		XAUTHORITY=$f
+		break
+	    fi
+	done
+
+	if [ "$XAUTHORITY" ] ; then
+            info "found X authority file $XAUTHORITY, trying to start debconf with X frontend."
+            # Try to use gnome frontend (requires libgtk3-perl) or kde frontend
+            # (requires debconf-kde-helper). debconf will fall back to dialog if
+            # either frontend fails to start. The frontend needs to be set
+            # before confmodule is sourced to have effect.
+            DISPLAY=:0
+            # TODO: find graphical variant that works with dialog frontend?
+            if perl -MGtk3 -e 'exit 0' ; then
+               # use gnome frontend
+		export DEBIAN_FRONTEND=gnome
+            elif [ -x /usr/bin/debconf-kde-helper ] ; then
+               # use kde frontend
+		export DEBIAN_FRONTEND=kde
+            else
+		info "unable to find usable debconf X frontend"
+            fi
+            export XAUTHORITY DISPLAY
+	else
+            info "no X detected, not showing test status, send email"
+            return 1
+	fi
+    fi
+    . /usr/share/debconf/confmodule
+}
+
+report_errors() {
+    errfile="$2"
+
+    prepare_debconf $@ || return
+
+    # Quick fix to make sure all error entries at least are
+    # displayed.  The correct fix is to find out how to replace a
+    # debconf variable with multiline content.  not sure why I
+    # need to change this in to one long line
+    errors=`cat $errfile | sed 's/$/, /g' | tr -d "\n" | sed 's/, $//'`
+
+    # Take a look at how CURRENT_CONFIG is built up in
+    # partman/partman-lvm/choose_partition/lvm/do_option
+
+    db_subst debian-edu-install/errors-found ERRORS "$errors"
+
+    db_fset debian-edu-install/errors-found seen false
+    db_input critical debian-edu-install/errors-found || [ $? -eq 30 ]
+    db_go
+}
+
+report_success() {
+    prepare_debconf $@ || return
+
+    db_input critical debian-edu-install/no-errors-found || [ $? -eq 30 ]
+    db_go
+}
+
+case "$1" in
+    run)
+        run_testsuite
+        ;;
+    report-errors)
+        # Need to pass all arguments, to get debconf re-exec to work
+        report_errors $@
+        ;;
+    report-success)
+        # Need to pass all arguments, to get debconf re-exec to work
+        report_success $@
+	;;
+    *)
+        echo "Usage: $0 {run|report-errors|report-success}"
+        disable_exception
+        exit 1
+        ;;
+esac
+disable_exception


=====================================
debian/debian-edu-install.debian-edu-testsuite.service
=====================================
@@ -0,0 +1,18 @@
+[Unit]
+Description=Check the Debian Edu installation after first boot
+After=xdebian-edu-firstboot.service graphical.target
+Requisite=xdebian-edu-firstboot.service
+ConditionPathExists=!/etc/debian-edu/debian-edu-testsuite
+
+[Service]
+EnvironmentFile=-/etc/debian-edu/config
+Type=oneshot
+ExecCondition=test ${TESTINSTALL} = true
+ExecStart=/usr/lib/debian-edu-install/debian-edu-testsuite run
+ExecStartPost=touch /etc/debian-edu/debian-edu-testsuite
+# Do not try to run after first boot even if condition failed
+ExecStopPost=touch /etc/debian-edu/debian-edu-testsuite
+RemainAfterExit=true
+
+[Install]
+WantedBy=multi-user.target


=====================================
debian/debian-edu-install.xdebian-edu-firstboot.init
=====================================
@@ -25,81 +25,6 @@ firstboot_file=/etc/debian-edu/xdebian-edu-firstboot
 
 set -e
 
-info() {
-    logger -t debian-edu-install "info: $@"
-}
-
-error() {
-    logger -t debian-edu-install "error: $@"
-}
-
-at_exit() {
-    error "script $0 terminated unexpectedly."
-}
-disable_exception() { trap - INT TERM EXIT; }
-trap at_exit INT TERM EXIT
-
-run_testsuite() {
-    log_begin_msg "Collecting testsuite results"
-    logfile=/var/log/installer/debian-edu-install-testsuite
-
-    temp_dir=$(mktemp -d)
-    errfile=$temp_dir/errors
-
-    nice debian-edu-test-install > $logfile 2>&1
-
-    # find error and partition resize messages in the d-i log and the
-    # self test
-    if [ -f /var/log/installer/syslog  ] ; then
-        # remove syslog prefix
-        # Ignore normal errors from wget commands used to test if
-        # mirrors are available [pere 2010-07-22].
-        # Ignore also samba-ad-dc error (unused atm) [schweer 2018-11-05].
-        egrep 'error:|fsautoresize' /var/log/installer/syslog | \
-	    grep -v 'wget: server returned error: HTTP/1.0 404 Not Found' | \
-	    grep -v 'wget: server returned error: HTTP/1.1 404 Not Found' | \
-	    grep -v 'samba-ad' | \
-	sed 's/.*error: /error: /g' > $errfile
-    fi
-    # The a param is now needed to find all errors [schweer 2018-11-05].
-    grep -a error: $logfile >> $errfile || true
-
-    if [ -s $errfile ] ; then
-    content=$(cat $errfile)
-    # Send error report via mail to first user (who has uid 1000 by default).
-    firstuser=$(getent passwd | grep 1000 | cut -d':' -f1)
-    username=$(getent passwd | grep 1000 | cut -d':' -f5)
-
-            cat << EOF | /usr/lib/sendmail $firstuser
-Subject: Test status
-
-Hello $username,
-
-these are the test results you requested by adding 'testinstall' as
-additional kernel commandline parameter. They have been collected by running
-the testsuite and searching in the /var/log/installer directory.
-
-$content
-
-(Sent from the Debian Edu first boot script.)
-
-EOF
-
-        log_end_msg 1 || true
-        log_begin_msg "Reporting errors found"
-        if $0 report-errors $errfile ; then
-            log_end_msg 0 || true
-        else
-            log_end_msg 1 || true
-        fi
-    else
-        log_end_msg 0 || true
-        $0 report-success || true
-    fi
-    rm $errfile
-    rmdir $temp_dir
-}
-
 do_start() {
     logger -t debian-edu-install "Executing xdebian-edu-firstboot"
 
@@ -118,89 +43,15 @@ do_start() {
     # command line param 'testinstall'.
     if [ -f /etc/debian-edu/config ] ; then . /etc/debian-edu/config ; fi
     if [ true = "$TESTINSTALL" ]; then
-	run_testsuite
+	log_begin_msg "Collecting testsuite results"
+	/usr/share/debian-edu-install/debian-edu-testsuite
+	log_end_msg $? || true
     else
 	log_begin_msg "Not collecting testsuite results"
 	log_end_msg 0 || true
     fi
 }
 
-prepare_debconf() {
-    # Try to get debconf to pop up the dialog on top of the display
-    # manager.  Need to do this before starting debconf.
-    if [ ! "$DEBIAN_HAS_FRONTEND" ] ; then
-        # This is generated by sddm
-	candidate="$(ls -tr /var/run/sddm/* 2>/dev/null|tail -1)"
-        # lightdm
-	candidate="$candidate /var/lib/lightdm/.Xauthority"
-
-	XAUTHORITY=
-	for f in $candidate ; do
-	    if XAUTHORITY=$f DISPLAY=:0 xauth list >/dev/null 2>&1 &&
-		XAUTHORITY=$f DISPLAY=:0 xhost > /dev/null 2>&1 ; then
-		XAUTHORITY=$f
-		break
-	    fi
-	done
-
-	if [ "$XAUTHORITY" ] ; then
-            info "found X authority file $XAUTHORITY, trying to start debconf with X frontend."
-            # Try to use gnome frontend (requires libgtk3-perl) or kde frontend
-            # (requires debconf-kde-helper). debconf will fall back to dialog if
-            # either frontend fails to start. The frontend needs to be set
-            # before confmodule is sourced to have effect.
-            DISPLAY=:0
-            # TODO: find graphical variant that works with dialog frontend?
-            if perl -MGtk3 -e 'exit 0' ; then
-               # use gnome frontend
-		export DEBIAN_FRONTEND=gnome
-            elif [ -x /usr/bin/debconf-kde-helper ] ; then
-               # use kde frontend
-		export DEBIAN_FRONTEND=kde
-            else
-		info "unable to find usable debconf X frontend"
-            fi
-            export XAUTHORITY DISPLAY
-	else
-            info "no X detected, not showing test status, send email"
-            return 1
-	fi
-    fi
-    . /usr/share/debconf/confmodule
-}
-
-report_errors() {
-    errfile="$2"
-
-    prepare_debconf $@ || return
-
-    # Quick fix to make sure all error entries at least are
-    # displayed.  The correct fix is to find out how to replace a
-    # debconf variable with multiline content.  not sure why I
-    # need to change this in to one long line
-    errors=`cat $errfile | sed 's/$/, /g' | tr -d "\n" | sed 's/, $//'`
-
-    # Take a look at how CURRENT_CONFIG is built up in
-    # partman/partman-lvm/choose_partition/lvm/do_option
-
-    db_subst debian-edu-install/errors-found ERRORS "$errors"
-
-    db_fset debian-edu-install/errors-found seen false
-    db_input critical debian-edu-install/errors-found || [ $? -eq 30 ]
-    db_go
-}
-
-report_success() {
-    prepare_debconf $@ || return
-
-    log_begin_msg "Reporting successful installation"
-
-    db_input critical debian-edu-install/no-errors-found || [ $? -eq 30 ]
-    db_go
-
-    log_end_msg 0 || true
-}
-
 case "$1" in
     start)
         if [ ! -f "$firstboot_file" ]; then
@@ -209,14 +60,6 @@ case "$1" in
         ;;
     stop|force-reload|restart)
         ;;
-    report-errors)
-        # Need to pass all arguments, to get debconf re-exec to work
-        report_errors $@
-        ;;
-    report-success)
-        # Need to pass all arguments, to get debconf re-exec to work
-        report_success $@
-	;;
     *)
         echo "Usage: /etc/init.d/xdebian-edu-firstboot {start|stop|restart|force-reload}"
         disable_exception
@@ -224,5 +67,4 @@ case "$1" in
         ;;
 esac
 
-disable_exception
 exit 0


=====================================
debian/debian-edu-install.xdebian-edu-firstboot.service
=====================================
@@ -0,0 +1,14 @@
+[Unit]
+Description=Run various tasks on the first boot after installation
+After=remote-fs.target network-online.target
+Wants=remote-fs.target
+ConditionPathExists=!/etc/debian-edu/xdebian-edu-firstboot
+
+[Service]
+Type=oneshot
+ExecStart=/usr/share/debian-edu-config/tools/run-at-firstboot
+ExecStartPost=touch /etc/debian-edu/xdebian-edu-firstboot
+RemainAfterExit=true
+
+[Install]
+WantedBy=multi-user.target


=====================================
debian/rules
=====================================
@@ -34,5 +34,8 @@ override_dh_auto_install:
 	cp debian-edu-profile $(CURDIR)/debian/debian-edu-profile-udeb/usr/bin
 
 override_dh_installinit:
-	# Use prefix 99x* to make sure it is the very last script in the boot sequence.
-	dh_installinit -pdebian-edu-install --name=xdebian-edu-firstboot --no-start -u"start 99 2 3 4 5 ."
+	dh_installinit -pdebian-edu-install --name=xdebian-edu-firstboot --no-start
+
+override_dh_installsystemd:
+	dh_installsystemd -pdebian-edu-install --no-start --name=xdebian-edu-firstboot
+	dh_installsystemd -pdebian-edu-install --no-start --name=debian-edu-testsuite



View it on GitLab: https://salsa.debian.org/debian-edu/debian-edu-install/-/commit/c80e9b3027105fbfda140a814b60bd4395ec1435

-- 
View it on GitLab: https://salsa.debian.org/debian-edu/debian-edu-install/-/commit/c80e9b3027105fbfda140a814b60bd4395ec1435
You're receiving this email because of your account on salsa.debian.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://alioth-lists.debian.net/pipermail/debian-edu-commits/attachments/20230914/3ea8f915/attachment-0001.htm>


More information about the debian-edu-commits mailing list