[bootlin/training-materials updates] master: Move the lab-data tarball generation logic to the Makefile (bbec2182)

Thomas Petazzoni thomas.petazzoni at bootlin.com
Thu Apr 25 12:12:57 CEST 2019


Repository : https://github.com/bootlin/training-materials
On branch  : master
Link       : https://github.com/bootlin/training-materials/commit/bbec218295c9be9533081a970b61384c981a2026

>---------------------------------------------------------------

commit bbec218295c9be9533081a970b61384c981a2026
Author: Thomas Petazzoni <thomas.petazzoni at bootlin.com>
Date:   Thu Apr 25 11:48:26 2019 +0200

    Move the lab-data tarball generation logic to the Makefile
    
    At the same time, use fakeroot instead of sudo to do the
    root-requiring steps.
    
    Signed-off-by: Thomas Petazzoni <thomas.petazzoni at bootlin.com>


>---------------------------------------------------------------

bbec218295c9be9533081a970b61384c981a2026
 Makefile                   | 16 +++++++++++
 common/process-lab-data.sh | 15 +++++++++++
 gen-lab-archive            | 67 ----------------------------------------------
 3 files changed, 31 insertions(+), 67 deletions(-)

diff --git a/Makefile b/Makefile
index d82f270c..657e992a 100644
--- a/Makefile
+++ b/Makefile
@@ -196,6 +196,20 @@ FORCE:
 	@$(MAKE) $@ LABS=$*
 endif
 
+#
+# Lab data archive generation
+#
+
+%-labs.tar.xz: LAB_DATA=$(patsubst %-labs.tar.xz,%,$@)
+%-labs.tar.xz: OUT_LAB_DATA=$(OUTDIR)/$(LAB_DATA)-labs
+%-labs.tar.xz:
+	rm -rf $(OUT_LAB_DATA)
+	rsync --exclude=.git -a -k --delete lab-data/$(LAB_DATA)/ $(OUT_LAB_DATA)
+	fakeroot common/process-lab-data.sh $(OUT_LAB_DATA)
+	find $(OUT_LAB_DATA) -name '*.xz' -exec unxz {} \;
+	(cd $(OUTDIR); tar Jcf $@ $(LAB_DATA)-labs)
+	mv $(OUTDIR)/$@ $@
+
 #
 # === Compilation of agendas ===
 #
@@ -283,6 +297,8 @@ help:
 		@printf " %-30s %s\n" "full-$(p)-slides.pdf" "Complete slides for the '$(p)' course"$(sep))
 	$(foreach p,$(ALL_TRAININGS),\
 		@printf " %-30s %s\n" "$(p)-agenda.pdf" "Agenda for the '$(p)' course"$(sep))
+	$(foreach p,$(ALL_TRAININGS),\
+		@printf " %-30s %s\n" "$(p)-labs.tar.xz" "Lab data for the '$(p)' course"$(sep))
 	@echo
 	@echo " <some-chapter>-slides.pdf      Slides for a particular chapter in slides/"
 	@echo " <some-chapter>-labs.pdf        Labs for a particular chapter in labs/"
diff --git a/common/process-lab-data.sh b/common/process-lab-data.sh
new file mode 100755
index 00000000..1ed88066
--- /dev/null
+++ b/common/process-lab-data.sh
@@ -0,0 +1,15 @@
+#!/bin/sh
+# This script is called under fakeroot
+
+OUT_LAB_DATA=$1
+
+tarball_extracted=no
+for f in `find ${OUT_LAB_DATA} -name "*.tar.xz"`; do
+	tar -C `dirname $f` -Jxf $f
+	rm -f $f
+	tarball_extracted=yes
+done
+
+if test "${tarball_extracted}" = "yes"; then
+    chown -R $USER.$USER ${OUT_LAB_DATA}
+fi
diff --git a/gen-lab-archive b/gen-lab-archive
deleted file mode 100755
index e058f847..00000000
--- a/gen-lab-archive
+++ /dev/null
@@ -1,67 +0,0 @@
-#!/bin/sh
-
-# Produces the lab archive that is published on
-# https://bootlin.com/labs/<session>-labs.tar.xz
-
-ECHO=/bin/echo
-GIT=/usr/bin/git
-RM=/bin/rm
-FIND=/usr/bin/find
-TAR=/bin/tar
-UNXZ=/usr/bin/unxz
-DIRNAME=/usr/bin/dirname
-RSYNC=/usr/bin/rsync
-SUDO=/usr/bin/sudo
-CHOWN=/bin/chown
-
-if [ ! -d lab-data ]; then
-   $ECHO "ERROR: this script need to be run in the training-materials git repository"
-   $ECHO "in the toplevel directory"
-   exit 1
-fi
-
-if [ -z $1 ]; then
-    $ECHO "ERROR: training name missing"
-    exit 1
-fi
-
-if ! ls lab-data | grep -q $1; then
-    $ECHO "ERROR: not a valid training name: $1"
-    exit 1
-fi
-
-FELABS=$1-labs
-
-# Updating repo
-
-$ECHO "Git repository update..."
-$GIT pull
-
-# Copy lab data
-
-$ECHO "Copying data from the git repository"
-$RSYNC --exclude=.git -a -k --delete lab-data/$1/ $FELABS
-
-# Uncompress compressed files
-
-$ECHO "Extracting tar.xz archives (root permissions needed for device files)"
-
-tarball_extracted=no
-for f in `$FIND $FELABS -name "*.tar.xz"`; do
-	$SUDO $TAR -C `dirname $f` -Jxf $f
-	$RM $f
-	tarball_extracted=yes
-done
-
-if test "${tarball_extracted}" = "yes"; then
-    $SUDO $CHOWN -R $USER.$USER $FELABS
-fi
-
-$ECHO "Uncompressing other .xz files"
-$FIND $FELABS -name "*.xz" -exec $UNXZ {} ';'
-
-# Create the final archive
-
-$ECHO "Creating the final archive..."
-$TAR Jcf ${FELABS}.tar.xz $FELABS
-




More information about the training-materials-updates mailing list