commit:     3092e310acd376fc626cc051549e02bcd7697aed
Author:     Mike Gilbert <floppym <AT> gentoo <DOT> org>
AuthorDate: Sat Mar 12 19:10:42 2016 +0000
Commit:     William Hubbs <williamh <AT> gentoo <DOT> org>
CommitDate: Mon Jul 25 20:37:18 2016 +0000
URL:        https://gitweb.gentoo.org/proj/openrc.git/commit/?id=3092e310

tmpfiles: Accept filenames as command line arguments

This brings us closer to being able to use tmpfiles.sh as a full
replacement for systemd-tmpfiles.

This closes #83.

 sh/tmpfiles.sh.in | 61 ++++++++++++++++++++++++++++++++-----------------------
 1 file changed, 36 insertions(+), 25 deletions(-)

diff --git a/sh/tmpfiles.sh.in b/sh/tmpfiles.sh.in
index 95b8b93..f7ee11b 100644
--- a/sh/tmpfiles.sh.in
+++ b/sh/tmpfiles.sh.in
@@ -264,6 +264,7 @@ _Z() {
 BOOT=0 CREATE=0 REMOVE=0 CLEAN=0 VERBOSE=0 DRYRUN=0 error=0 LINENO=0
 EXCLUDE=
 PREFIX=
+FILES=
 
 while [ $# -gt 0 ]; do
        case $1 in
@@ -276,6 +277,7 @@ while [ $# -gt 0 ]; do
                --exclude-prefix=*) EXCLUDE="${EXCLUDE}${1##--exclude-prefix=} 
" ;;
                --prefix=*) PREFIX="${PREFIX}${1##--prefix=} " ;;
                -*) invalid_option "$1" ;;
+               *) FILES="${FILES} $1"
        esac
        shift
 done
@@ -290,40 +292,49 @@ if [ "$CREATE$REMOVE" = '00' ]; then
        exit 1
 fi
 
-FILE=
-fragments=
 # XXX: The harcoding of /usr/lib/ is an explicit choice by upstream
-tmpfiles_dirs='/usr/lib/tmpfiles.d/ /run/tmpfiles.d/ /etc/tmpfiles.d/'
+tmpfiles_dirs='/usr/lib/tmpfiles.d /run/tmpfiles.d /etc/tmpfiles.d'
 tmpfiles_basenames=''
+
+if [ -z "${FILES}" ]; then
+       # Build a list of sorted unique basenames
+       # directories declared later in the tmpfiles_d array will override 
earlier
+       # directories, on a per file basename basis.
+       # `/etc/tmpfiles.d/foo.conf' supersedes `/usr/lib/tmpfiles.d/foo.conf'.
+       # `/run/tmpfiles/foo.conf' will always be read after 
`/etc/tmpfiles.d/bar.conf'
+       for d in ${tmpfiles_dirs} ; do
+               [ -d $d ] && for f in ${d}/*.conf ; do
+                       case "${f##*/}" in
+                               systemd.conf|systemd-*.conf) continue;;
+                       esac
+                       [ -f $f ] && 
tmpfiles_basenames="${tmpfiles_basenames}\n${f##*/}"
+               done # for f in ${d}
+       done # for d in ${tmpfiles_dirs}
+       FILES="$(printf "${tmpfiles_basenames}\n" | sort -u )"
+fi
+
 tmpfiles_d=''
-# Build a list of sorted unique basenames
-# directories declared later in the tmpfiles_d array will override earlier
-# directories, on a per file basename basis.
-# `/etc/tmpfiles.d/foo.conf' supersedes `/usr/lib/tmpfiles.d/foo.conf'.
-# `/run/tmpfiles/foo.conf' will always be read after `/etc/tmpfiles.d/bar.conf'
-for d in ${tmpfiles_dirs} ; do
-       [ -d $d ] && for f in ${d}/*.conf ; do
-               case "${f##*/}" in
-                       systemd.conf|systemd-*.conf) continue;;
-               esac
-               [ -f $f ] && 
tmpfiles_basenames="${tmpfiles_basenames}\n${f##*/}"
-       done # for f in ${d}
-done # for d in ${tmpfiles_dirs}
-tmpfiles_basenames="$(printf "${tmpfiles_basenames}\n" | sort -u )"
-
-for b in $tmpfiles_basenames ; do
-       real_f=''
-       for d in $tmpfiles_dirs ; do
-               f=${d}/${b}
-               [ -f "${f}" ] && real_f=$f
-       done
-       [ -f "${real_f}" ] && tmpfiles_d="${tmpfiles_d} ${real_f}"
+
+for b in ${FILES} ; do
+       if [ "${b##*/}" != "${b}" ]; then
+               # The user specified a path on the command line
+               # Just pass it through unaltered
+               tmpfiles_d="${tmpfiles_d} ${b}"
+       else
+               real_f=''
+               for d in $tmpfiles_dirs ; do
+                       f=${d}/${b}
+                       [ -f "${f}" ] && real_f=$f
+               done
+               [ -f "${real_f}" ] && tmpfiles_d="${tmpfiles_d} ${real_f}"
+       fi
 done
 
 error=0
 
 # loop through the gathered fragments, sorted globally by filename.
 # `/run/tmpfiles/foo.conf' will always be read after `/etc/tmpfiles.d/bar.conf'
+FILE=
 for FILE in $tmpfiles_d ; do
        LINENUM=0
 

Reply via email to