diff options
author | Dave Reisner <dreisner@archlinux.org> | 2011-07-24 15:04:36 -0400 |
---|---|---|
committer | Dave Reisner <dreisner@archlinux.org> | 2011-07-24 16:07:41 -0400 |
commit | 370dd6573143fb9b9a7d368badbd3f2bb40ad6cf (patch) | |
tree | c8344316c5b60436f9b47ec726e327cfa3f1e226 | |
parent | 7e39dc717edd4690772059ad4d5a7550dbf65019 (diff) |
arch-tmpfiles: add cmdline parameters
Categorize actions as 'create' or 'remove', for finer control.
Signed-off-by: Dave Reisner <dreisner@archlinux.org>
-rwxr-xr-x | arch-tmpfiles | 37 | ||||
-rw-r--r-- | functions | 2 |
2 files changed, 33 insertions, 6 deletions
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 @@ -426,7 +426,7 @@ remove_leftover() { find /var/run/ \! -type d -delete ln -s /run/daemons /var/run/daemons fi - /usr/lib/initscripts/arch-tmpfiles && stat_done || stat_fail + /usr/lib/initscripts/arch-tmpfiles --create --remove && stat_done || stat_fail } bootlogd_stop() { |