在 Alpine 3.9 上使用带有 运行-parts 的正则表达式

Using regex with run-parts on Alpine 3.9

我正在创建 Docker 图片 FROM alpine:3.9.2,我需要 运行 run-parts。我过去在 ubuntu:16.04 上使用下面的脚本没有问题。

 run-parts --verbose --regex '\.sh$' "$DIR"

然而,这一次,我在传递给它的选项上遇到了错误。即

run-parts: unrecognized option: verbose

run-parts: unrecognized option: regex

根据我的理解,Alpine 3.9.2 使用 run-parts 4.8.6 https://pkgs.alpinelinux.org/package/edge/main/x86/run-parts which should come from the debianutils https://manpages.debian.org/testing/debianutils/run-parts.8.en.html 并支持 verboseregex

我在这里遗漏了什么吗?

如何在 Alpine 3.9.2 上 运行 所有以 .sh 结尾的文件?

默认情况下,alpine 图像中有 run-parts 的非常切割版本。是busybox一:

/ # which run-parts
/bin/run-parts
/ # run-parts --help
BusyBox v1.29.3 (2019-01-24 07:45:07 UTC) multi-call binary.

Usage: run-parts [-a ARG]... [-u UMASK] [--reverse] [--test] [--exit-on-error] DIRECTORY

Run a bunch of scripts in DIRECTORY

    -a ARG      Pass ARG as argument to scripts
    -u UMASK    Set UMASK before running scripts
    --reverse   Reverse execution order
    --test      Dry run
    --exit-on-error Exit if a script exits with non-zero

目录下只能运行一堆脚本

如果你想使用 debianutils 包中未切割的 run-parts,你需要先将它安装到 alpine 镜像:

/ # apk add --no-cache run-parts
fetch http://dl-cdn.alpinelinux.org/alpine/v3.9/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.9/community/x86_64/APKINDEX.tar.gz
(1/1) Installing run-parts (4.8.6-r0)
Executing busybox-1.29.3-r10.trigger
OK: 6 MiB in 15 packages

现在,alpine 实例中有 run-parts 的完整版本:

/ # which run-parts
/usr/bin/run-parts
/ # run-parts --help
Usage: run-parts [OPTION]... DIRECTORY
      --test          print script names which would run, but don't run them.
      --list          print names of all valid files (can not be used with
                      --test)
  -v, --verbose       print script names before running them.
      --report        print script names if they produce output.
      --reverse       reverse execution order of scripts.
      --exit-on-error exit as soon as a script returns with a non-zero exit
                      code.
      --lsbsysinit    validate filenames based on LSB sysinit specs.
      --new-session   run each script in a separate process session
      --regex=PATTERN validate filenames based on POSIX ERE pattern PATTERN.
  -u, --umask=UMASK   sets umask to UMASK (octal), default is 022.
  -a, --arg=ARGUMENT  pass ARGUMENT to scripts, use once for each argument.
  -V, --version       output version information and exit.
  -h, --help          display this help and exit.