Bladeren bron

Factor out tool check to lib.sh.in

Michael Aldridge 7 jaren geleden
bovenliggende
commit
b531fae80b
2 gewijzigde bestanden met toevoegingen van 40 en 19 verwijderingen
  1. 34 1
      lib.sh.in
  2. 6 18
      mkrootfs.sh.in

+ 34 - 1
lib.sh.in

@@ -1,5 +1,10 @@
 #!/bin/sh
 
+# This contains the COMPLETE list of binaries that this script needs
+# to function.  The only exception is the QEMU binary since it is not
+# known in advance which one wil be required.
+readonly LIBTOOLS="cp echo cat printf which mountpoint mount umount modprobe"
+
 info_msg() {
     # This function handles the printing that is bold within all
     # scripts.  This is a convenience function so that the rather ugly
@@ -17,6 +22,24 @@ die() {
     exit 1
 }
 
+check_tools() {
+    # All scripts within mklive declare the tools they will use in a
+    # variable called "REQTOOLS".  This function checks that these
+    # tools are available and prints out the path to each tool that
+    # will be used.  This can be useful to figure out what is broken
+    # if a different version of something is used than was expected.
+    for tool in $LIBTOOLS $REQTOOLS ; do
+        if ! which "$tool" > /dev/null ; then
+            die "Required tool $f is not available on this system!"
+        fi
+    done
+
+    info_msg "The following tools will be used:"
+    for tool in $LIBTOOLS $REQTOOLS ; do
+        which "$tool"
+    done
+}
+
 mount_pseudofs() {
     # This function ensures that the psuedofs mountpoints are present
     # in the chroot.  Strictly they are not necessary to have for many
@@ -159,7 +182,7 @@ register_binfmt() {
     if [ "$QEMU_BIN" = "NATIVE" ] ; then
         return
     fi
-    
+
     # For builds that do not match the host architecture, the correct
     # qemu binary will be required.
     if ! $QEMU_BIN -version >/dev/null 2>&1; then
@@ -189,3 +212,13 @@ register_binfmt() {
             die "Could not install $QEMU_BIN to $ROOTFS/usr/bin/"
     fi
 }
+
+# These should all resolve even if they won't have the appropriate
+# repodata files for the selected architecture.
+: "${XBPS_REPOSITORY:=--repository=http://repo.voidlinux.eu/current \
+                      --repository=http://repo.voidlinux.eu/current/musl \
+                      --repository=http://repo.voidlinux.eu/current/aarch64}"
+
+# The package artifacts are cacheable, but they need to be isolated
+# from the host cache.
+: "${XBPS_CACHEDIR:=--cachedir=$PWD/xbps-cache/${XBPS_TARGET_ARCH}}"

+ 6 - 18
mkrootfs.sh.in

@@ -27,6 +27,7 @@
 
 readonly PROGNAME=$(basename "$0")
 readonly ARCH=$(uname -m)
+readonly REQTOOLS="xbps-install xbps-reconfigure tar xz"
 
 # This source pulls in all the functions from lib.sh.  This set of
 # functions makes it much easier to work with chroots and abstracts
@@ -88,6 +89,11 @@ if [ "$(id -u)" -ne 0 ]; then
     die "need root perms to continue, exiting."
 fi
 
+# Before going any further, check that the tools that are needed are
+# present.  If we delayed this we could check for the QEMU binary, but
+# its a reasonable tradeoff to just bail out now.
+check_tools
+
 # If the arch wasn't set let's bail out now, nothing else in this
 # script will work without knowing what we're trying to build for.
 if [ -z "$XBPS_TARGET_ARCH" ]; then
@@ -95,24 +101,6 @@ if [ -z "$XBPS_TARGET_ARCH" ]; then
     usage; exit 1
 fi
 
-# If the repository hasn't already been set, we set it to a sane value
-# here.  These should all resolve even if they won't have the
-# appropriate repodata files for the selected architecture.
-: "${XBPS_REPOSITORY:=--repository=http://repo.voidlinux.eu/current \
-                      --repository=http://repo.voidlinux.eu/current/musl \
-                      --repository=http://repo.voidlinux.eu/current/aarch64}"
-
-# The package artifacts are cacheable, but they need to be isolated
-# from the host cache.
-: "${XBPS_CACHEDIR:=--cachedir=$PWD/xbps-cache/${XBPS_TARGET_ARCH}}"
-
-# The following binaries are required to proceed
-for f in chroot tar xbps-install xbps-reconfigure xbps-query; do
-    if ! which $f >/dev/null ; then
-        die "$f binary is missing in your system, exiting."
-    fi
-done
-
 # We need to operate on a tempdir, if this fails to create, it is
 # absolutely crucial to bail out so that we don't hose the system that
 # is running the script.