diff options
author | Peter Palfrader <peter@palfrader.org> | 2016-02-09 18:03:47 +0100 |
---|---|---|
committer | Peter Palfrader <peter@palfrader.org> | 2016-02-09 18:03:47 +0100 |
commit | d16f9b79c0eb8071ad8a9a33cc57f5bfe9636c9b (patch) | |
tree | f7e853029d99de5e2174b94a0d92542e62f8c37e /recvconf | |
parent | 39d1afc865759259a662ac14c426dc31a24575a2 (diff) |
whitespace cleanup
Diffstat (limited to 'recvconf')
-rwxr-xr-x | recvconf | 164 |
1 files changed, 82 insertions, 82 deletions
@@ -29,55 +29,55 @@ copy_and_runcommands() { file="$1"; perms="$2"; user="$3"; group="$4"; precommand="$5"; postcommand="$6" if [ -f "$file" ]; then - if [ -h "$file" ]; then # File should NOT be a symlink - printf "\`%s' is a symlink, aborting.\n" "$file" >&2 - return 1 - fi - - if ! [ "$file" -nt "/$file" ]; then - rm -f "$file" - return 0 - fi - - if [ -n "$precommand" ]; then - printf "Running precommand \`%s' for %s\n" "$precommand" "$file" >&2 - eval -- $precommand >&2 - fi - - if [ -n "$perms" ]; then - chmod -- "$perms" "$file" - else - printf "Warning, no perms defined for \`%s', assuming 0640.\n" "$file" >&2 - chmod 0640 "$file" - fi - if [ -n "$user" ]; then - chown -- "$user" "$file" - else - printf "Warning, no user defined for \`%s', assuming root.\n" "$file" >&2 - chown root "$file" - fi - if [ -n "$group" ]; then - chgrp -- "$group" "$file" - else - printf "Warning, no group defined for \`%s', assuming root.\n" "$file" >&2 - chgrp root "$file" - fi - - if [ ! -d "/$(dirname "$file")" ]; then - printf "Directory \`%s' does not exist, aborting.\n" "$(dirname "$file")" >&2 - exit 1 - fi - - cp -a -- "$file" "/$(dirname "$file")" >&2 - ls -l "/$(dirname "$file")/$(basename "$file")" >&2 - - if [ -n "$postcommand" ]; then - if ! grep -F -- "$postcommand" "$tempscript" > /dev/null 2>&1; then - printf "%s\n" "$postcommand" >> "$tempscript" - fi - fi - - rm -f -- "$file" + if [ -h "$file" ]; then # File should NOT be a symlink + printf "\`%s' is a symlink, aborting.\n" "$file" >&2 + return 1 + fi + + if ! [ "$file" -nt "/$file" ]; then + rm -f "$file" + return 0 + fi + + if [ -n "$precommand" ]; then + printf "Running precommand \`%s' for %s\n" "$precommand" "$file" >&2 + eval -- $precommand >&2 + fi + + if [ -n "$perms" ]; then + chmod -- "$perms" "$file" + else + printf "Warning, no perms defined for \`%s', assuming 0640.\n" "$file" >&2 + chmod 0640 "$file" + fi + if [ -n "$user" ]; then + chown -- "$user" "$file" + else + printf "Warning, no user defined for \`%s', assuming root.\n" "$file" >&2 + chown root "$file" + fi + if [ -n "$group" ]; then + chgrp -- "$group" "$file" + else + printf "Warning, no group defined for \`%s', assuming root.\n" "$file" >&2 + chgrp root "$file" + fi + + if [ ! -d "/$(dirname "$file")" ]; then + printf "Directory \`%s' does not exist, aborting.\n" "$(dirname "$file")" >&2 + exit 1 + fi + + cp -a -- "$file" "/$(dirname "$file")" >&2 + ls -l "/$(dirname "$file")/$(basename "$file")" >&2 + + if [ -n "$postcommand" ]; then + if ! grep -F -- "$postcommand" "$tempscript" > /dev/null 2>&1; then + printf "%s\n" "$postcommand" >> "$tempscript" + fi + fi + + rm -f -- "$file" fi } @@ -88,49 +88,49 @@ while read line; do linenum="$(($linenum + 1))" if printf "%s\n" "$line" | grep -E '^[[:space:]]*$' > /dev/null 2>&1; then - ## This line is an empty line; skip it - continue + ## This line is an empty line; skip it + continue elif printf "%s" "$line" | grep -E '^[[:space:]]*#' > /dev/null 2>&1; then - ## This line is a comment; skip it - continue + ## This line is a comment; skip it + continue fi ## IN=0, so we're out of a stanza: better get a file declaration next if [ "$IN" = "0" ] && ! printf "%s" "$line" | grep -E '^[[:space:]]*file[[:space:]]' > /dev/null 2>&1; then - printf "Error on line %s, file declaration expected. Got\n\t%s\n" "$linenum" "$line" >&2 - exit 1 + printf "Error on line %s, file declaration expected. Got\n\t%s\n" "$linenum" "$line" >&2 + exit 1 elif [ "$IN" = 0 ] && printf "%s" "$line" | grep -E '^[[:space:]]*file[[:space:]]' > /dev/null 2>&1; then - ## Okay, we're just starting out; set $file and move on - file="$(printf "%s" "$line" | sed -e 's/[[:space:]]*file[[:space:]]\+\([^[:space:]#]*\).*/\1/')" - IN=1 - continue + ## Okay, we're just starting out; set $file and move on + file="$(printf "%s" "$line" | sed -e 's/[[:space:]]*file[[:space:]]\+\([^[:space:]#]*\).*/\1/')" + IN=1 + continue elif [ "$IN" = 1 ] && printf "%s" "$line" | grep -E '^[[:space:]]*file[[:space:]]' > /dev/null 2>&1; then - ## Okay, not only are we at a file declaration, but this isn't our first one. Run the commands to process - ## the file, then set a $file to the new value and continue parsing. - [ -n "$file" ] && copy_and_runcommands "$file" "$perms" "$user" "$group" "$precommand" "$postcommand" - file="$(printf "%s" "$line" | sed -e 's/[[:space:]]*file[[:space:]]\+\([^[:space:]#]*\).*/\1/')" - perms=""; user=""; group=""; precommand=""; postcommand="" - continue + ## Okay, not only are we at a file declaration, but this isn't our first one. Run the commands to process + ## the file, then set a $file to the new value and continue parsing. + [ -n "$file" ] && copy_and_runcommands "$file" "$perms" "$user" "$group" "$precommand" "$postcommand" + file="$(printf "%s" "$line" | sed -e 's/[[:space:]]*file[[:space:]]\+\([^[:space:]#]*\).*/\1/')" + perms=""; user=""; group=""; precommand=""; postcommand="" + continue fi ## The last two if blocks weren't processed; thus this isn't a comment, a blank line, and we're in the middle of a stanza if printf "%s" "$line" | grep -E '^[[:space:]]*perms[[:space:]]' > /dev/null 2>&1; then - perms="$(printf "%s" "$line" | sed -e 's/[[:space:]]*perms[[:space:]]\+\([^[:space:]#]*\).*/\1/')" - continue + perms="$(printf "%s" "$line" | sed -e 's/[[:space:]]*perms[[:space:]]\+\([^[:space:]#]*\).*/\1/')" + continue elif printf "%s" "$line" | grep -E '^[[:space:]]*user[[:space:]]' > /dev/null 2>&1; then - user="$(printf "%s" "$line" | sed -e 's/[[:space:]]*user[[:space:]]\+\([^[:space:]#]*\).*/\1/')" - continue + user="$(printf "%s" "$line" | sed -e 's/[[:space:]]*user[[:space:]]\+\([^[:space:]#]*\).*/\1/')" + continue elif printf "%s" "$line" | grep -E '^[[:space:]]*group[[:space:]]' > /dev/null 2>&1; then - group="$(printf "%s" "$line" | sed -e 's/[[:space:]]*group[[:space:]]\+\([^[:space:]#]*\).*/\1/')" - continue + group="$(printf "%s" "$line" | sed -e 's/[[:space:]]*group[[:space:]]\+\([^[:space:]#]*\).*/\1/')" + continue elif printf "%s" "$line" | grep -E '^[[:space:]]*precommand[[:space:]]' > /dev/null 2>&1; then - precommand="$(printf "%s" "$line" | sed -e 's/[[:space:]]*precommand[[:space:]]\+\([^[:space:]#]*\)/\1/')" - continue + precommand="$(printf "%s" "$line" | sed -e 's/[[:space:]]*precommand[[:space:]]\+\([^[:space:]#]*\)/\1/')" + continue elif printf "%s" "$line" | grep -E '^[[:space:]]*postcommand[[:space:]]' > /dev/null 2>&1; then - postcommand="$(printf "%s" "$line" | sed -e 's/[[:space:]]*postcommand[[:space:]]\+\([^[:space:]#]*\)/\1/')" - continue + postcommand="$(printf "%s" "$line" | sed -e 's/[[:space:]]*postcommand[[:space:]]\+\([^[:space:]#]*\)/\1/')" + continue else - printf "Unknown token at line %s:\n\t%s\n" "$linenum" "$line" + printf "Unknown token at line %s:\n\t%s\n" "$linenum" "$line" fi done < "$FILELIST" @@ -142,12 +142,12 @@ if [ -s "$tempscript" ]; then tempoutput="$(mktemp)" ## Post-copying commands to be run, run them here. Only display output if they exit with $? > 0 while read command; do - printf "Running postcommand \`%s' on %s.\n" "$command" "$(hostname -s)" >&2 - if ! eval -- "(cd / && env -i $command)" > "$tempoutput" 2>&1; then - printf "Error, postcommand \`%s' on %s failed. Output follows:\n" "$command" "$(hostname -s)" >&2 - cat -- "$tempoutput" >&2 - exit 1 - fi + printf "Running postcommand \`%s' on %s.\n" "$command" "$(hostname -s)" >&2 + if ! eval -- "(cd / && env -i $command)" > "$tempoutput" 2>&1; then + printf "Error, postcommand \`%s' on %s failed. Output follows:\n" "$command" "$(hostname -s)" >&2 + cat -- "$tempoutput" >&2 + exit 1 + fi done < "$tempscript" fi |