From 91c30f6ab242f86bfa71d8eda14283f90a992cd2 Mon Sep 17 00:00:00 2001 From: Clint Byrum Date: Thu, 14 Feb 2013 10:20:30 -0800 Subject: [PATCH] Use dib-run-parts for running scripts in target Also modified dib-run-parts to apply a more workable solution for filtering out unwanted files such as editor backups and VCS. The script is installed in its own element, depended on by the OS specific ubuntu element. This is because the ubuntu element (and later other OS's) are responsible for populating the root filesystem. If we try to install this in base, the root filesystem will look to be populated already and we will skip automatically choosing ubuntu. Change-Id: I017646748c1a8360299106289b57d976d45875a8 --- elements/dib-run-parts/root.d/90-base-dib-run-parts | 5 +++++ elements/{base/bin => dib-run-parts/root.d}/dib-run-parts | 7 +++++-- elements/ubuntu/element-deps | 1 + lib/img-functions | 2 +- 4 files changed, 12 insertions(+), 3 deletions(-) create mode 100755 elements/dib-run-parts/root.d/90-base-dib-run-parts rename elements/{base/bin => dib-run-parts/root.d}/dib-run-parts (82%) mode change 100755 => 100644 diff --git a/elements/dib-run-parts/root.d/90-base-dib-run-parts b/elements/dib-run-parts/root.d/90-base-dib-run-parts new file mode 100755 index 00000000..fe4ca43d --- /dev/null +++ b/elements/dib-run-parts/root.d/90-base-dib-run-parts @@ -0,0 +1,5 @@ +#!/bin/bash +home=$(dirname $0) +exec sudo install -m 0755 -o root -g root -D \ + $home/dib-run-parts \ + $TARGET_ROOT/usr/local/bin/dib-run-parts diff --git a/elements/base/bin/dib-run-parts b/elements/dib-run-parts/root.d/dib-run-parts old mode 100755 new mode 100644 similarity index 82% rename from elements/base/bin/dib-run-parts rename to elements/dib-run-parts/root.d/dib-run-parts index 365607ab..928c292d --- a/elements/base/bin/dib-run-parts +++ b/elements/dib-run-parts/root.d/dib-run-parts @@ -16,6 +16,8 @@ # License for the specific language governing permissions and limitations # under the License. +allowed_regex=${RUN_PARTS_REGEX:-"^[0-9A-Za-z_-]+$"} + set -ue name=$(basename $0) @@ -41,8 +43,9 @@ if ! [ -d $target_dir ] ; then fi # We specifically only want to sort *by the numbers*. -# Lexical sorting is not guaranteed. -targets=$(find $target_dir -type f -executable \! -name '.*' -printf '%f\n' | sort -n) +# Lexical sorting is not guaranteed, and identical numbers may be +# parallelized later +targets=$(find $target_dir -type f -executable -printf '%f\n' | grep -E "$allowed_regex" | LANG=C sort -n) for target in $targets ; do output "Running $target_dir/$target" diff --git a/elements/ubuntu/element-deps b/elements/ubuntu/element-deps index 6b0d9ace..16fd9fc7 100644 --- a/elements/ubuntu/element-deps +++ b/elements/ubuntu/element-deps @@ -1 +1,2 @@ dpkg +dib-run-parts diff --git a/lib/img-functions b/lib/img-functions index 38b1de95..ae55abf3 100644 --- a/lib/img-functions +++ b/lib/img-functions @@ -116,7 +116,7 @@ function run_d_in_target() { sudo mount --bind ${TMP_HOOKS_PATH} $TMP_MOUNT_PATH/tmp/in_target.d sudo mount -o remount,ro,bind ${TMP_HOOKS_PATH} $TMP_MOUNT_PATH/tmp/in_target.d check_break before-$1 run_in_target bash - run_in_target run-parts /tmp/in_target.d/$1.d + run_in_target dib-run-parts /tmp/in_target.d/$1.d check_break after-$1 run_in_target bash sudo umount -f $TMP_MOUNT_PATH/tmp/in_target.d sudo rmdir $TMP_MOUNT_PATH/tmp/in_target.d