From 370dd6573143fb9b9a7d368badbd3f2bb40ad6cf Mon Sep 17 00:00:00 2001 From: Dave Reisner Date: Sun, 24 Jul 2011 15:04:36 -0400 Subject: arch-tmpfiles: add cmdline parameters Categorize actions as 'create' or 'remove', for finer control. Signed-off-by: Dave Reisner --- arch-tmpfiles | 37 ++++++++++++++++++++++++++++++++----- 1 file changed, 32 insertions(+), 5 deletions(-) (limited to 'arch-tmpfiles') diff --git a/arch-tmpfiles b/arch-tmpfiles index 827bc54..c646ecd 100755 --- a/arch-tmpfiles +++ b/arch-tmpfiles @@ -41,6 +41,8 @@ _f() { # Create a file if it doesn't exist yet local path=$1 mode=$2 uid=$3 gid=$4 + (( CREATE )) || return 0 + if ! checkparams 4 "$@"; then warninvalid return @@ -55,6 +57,8 @@ _F() { # Create or truncate a file local path=$1 mode=$2 uid=$3 gid=$4 + (( CREATE )) || return 0 + if ! checkparams 4 "$@"; then warninvalid return @@ -67,6 +71,8 @@ _d() { # Create a directory if it doesn't exist yet local path=$1 mode=$2 uid=$3 gid=$4 + (( CREATE )) || return 0 + if ! checkparams 4 "$@"; then warninvalid return @@ -81,6 +87,8 @@ _D() { # Create or empty a directory local path=$1 mode=$2 uid=$3 gid=$4 + (( CREATE )) || return 0 + if ! checkparams 4 "$@"; then warninvalid return @@ -96,6 +104,8 @@ _p() { # Create a named pipe (FIFO) if it doesn't exist yet local path=$1 mode=$2 uid=$3 gid=$4 + (( CREATE )) || return 0 + if ! checkparams 4 "$@"; then warninvalid return @@ -123,6 +133,8 @@ _r() { local path local -a paths=($1) + (( REMOVE )) || return 0 + if ! checkparams 1 "$@"; then warninvalid return @@ -143,6 +155,8 @@ _R() { local path local -a paths=($1) + (( REMOVE )) || return 0 + if ! checkparams 1 "$@"; then warninvalid return @@ -155,11 +169,7 @@ _R() { shopt -s nullglob -# catch errors in functions so we can exit with something meaningful -set -E -trap '(( ++error ))' ERR - -declare -i error=0 LINENO=0 +declare -i CREATE=0 REMOVE=0 CLEAN=0 error=0 LINENO=0 declare FILE= declare -A fragments declare -a tmpfiles_d=( @@ -168,6 +178,19 @@ declare -a tmpfiles_d=( /run/tmpfiles.d/*.conf ) +while (( $# )); do + case $1 in + --create) CREATE=1 ;; + --remove) REMOVE=1 ;; + esac + shift +done + +if (( !(CREATE + REMOVE) )); then + printf 'usage: %s [--create] [--remove]\n' "${0##*/}" + exit 1 +fi + # directories declared later in the tmpfiles_d array will override earlier # directories, on a per file basis. # Example: `/etc/tmpfiles.d/foo.conf' supersedes `/usr/lib/tmpfiles.d/foo.conf'. @@ -175,6 +198,10 @@ for path in "${tmpfiles_d[@]}"; do [[ -f $path ]] && fragments[${path##*/}]=${path%/*} done +# catch errors in functions so we can exit with something meaningful +set -E +trap '(( ++error ))' ERR + # loop through the gathered fragments, sorted globally by filename. # `/run/tmpfiles/foo.conf' will always be read after `/etc/tmpfiles.d/bar.conf' while read -d '' fragment; do -- cgit v1.2.3