From 550c2f513a05899566ca90a1e859218ee44a8ac7 Mon Sep 17 00:00:00 2001 From: Timo Weingärtner Date: Sat, 25 Feb 2012 21:17:02 +0100 Subject: Imported Debian version 0.3 --- update-openssh-known-hosts | 51 ++++++++++++++++++++++++++++++++-------------- 1 file changed, 36 insertions(+), 15 deletions(-) (limited to 'update-openssh-known-hosts') diff --git a/update-openssh-known-hosts b/update-openssh-known-hosts index 136535a..63df1e3 100755 --- a/update-openssh-known-hosts +++ b/update-openssh-known-hosts @@ -1,4 +1,4 @@ -#!/bin/dash +#!/bin/bash set -euC @@ -9,18 +9,39 @@ LOCK=/var/lock/openssh-known-hosts OUTFILE=/var/lib/openssh-known-hosts/ssh_known_hosts path_search () { - if [ "${1}" != "${1#*/}" ]; then - echo $1 - else - echo "$2" | tr ':' '\n' | while read -r path; do - if [ -f "${path}/${1}" ]; then - echo "${path}/${1}" - break - fi - done + search="$1" + shift + local IFS + IFS=: + set -- $@ + if [ "${search}" != "${search#*/}" ]; then + echo "${search}" + return 0 fi + for path; do + if [ -f "${path}/${search}" ]; then + echo "${path}/${search}" + return 0 + fi + done + echo "'${search}' not found in '$@'!" >&2 + exit 127 +} + +cleanup () { + rm -f "${OUTFILE}.new" + kill "${LOCKPID}" + lockfile-remove "${LOCK}" } +if [ $# = 1 ] && [ "$1" = "-f" ]; then + fail=1 +else + fail='' +fi + +trap cleanup EXIT + lockfile-create "${LOCK}" lockfile-touch "${LOCK}" & LOCKPID="$!" @@ -47,13 +68,16 @@ run-parts --list "${CONFDIR}/sources/" | while read sourcefile; do break fi done - if [ ! "$ignore" ]; then + if [ "$ignore" != "1" -o "$fail" = "1" ]; then echo "${source} exited with code ${exitcode}, log follows:" cat log echo fi + if [ "$fail" = "1" ]; then + exit 1 + fi } - ) + ) || exit 1 if [ -e ${source}/new ]; then mv ${source}/new ${source}/current fi @@ -70,7 +94,4 @@ for d in *; do [ -e "${CONFDIR}/sources/$d" ] || rm -fr $d done -kill "${LOCKPID}" -lockfile-remove "${LOCK}" - # vim:set ft=sh: -- cgit v1.2.3