summaryrefslogtreecommitdiff
path: root/update-openssh-known-hosts
diff options
context:
space:
mode:
authorTimo Weingärtner <timo@tiwe.de>2012-02-25 21:17:00 +0100
committerTimo Weingärtner <timo@tiwe.de>2012-02-25 21:17:00 +0100
commit4b444020fa50e4f22a427b981c582b35cdb4efb1 (patch)
treea7e31424e72b3a98053ca5b11206831cfd3322e2 /update-openssh-known-hosts
parent8f32f842b33bdc6617b41dc9f18b222fd3013e21 (diff)
downloadopenssh-known-hosts-4b444020fa50e4f22a427b981c582b35cdb4efb1.tar.gz
Imported Debian version 0.2debian/0.2
Diffstat (limited to 'update-openssh-known-hosts')
-rwxr-xr-xupdate-openssh-known-hosts76
1 files changed, 76 insertions, 0 deletions
diff --git a/update-openssh-known-hosts b/update-openssh-known-hosts
new file mode 100755
index 0000000..136535a
--- /dev/null
+++ b/update-openssh-known-hosts
@@ -0,0 +1,76 @@
+#!/bin/dash
+
+set -euC
+
+CONFDIR=/etc/openssh-known-hosts
+PLUGIN_PATH=/usr/share/openssh-known-hosts/plugins:/usr/local/share/openssh-known-hosts/plugins
+CACHEDIR=/var/cache/openssh-known-hosts
+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
+ fi
+}
+
+lockfile-create "${LOCK}"
+lockfile-touch "${LOCK}" &
+LOCKPID="$!"
+
+mkdir -p "${CACHEDIR}"
+cd "${CACHEDIR}"
+
+find -mindepth 2 -maxdepth 2 -type f -name new -delete
+
+run-parts --list "${CONFDIR}/sources/" | while read sourcefile; do
+ source=`basename ${sourcefile}`
+ mkdir -p ${source}
+ (
+ set -a
+ cd ${source}
+ . "${sourcefile}"
+ `path_search "$PLUGIN" "$PLUGIN_PATH"` >| log 2>&1 || {
+ exitcode=$?
+ rm -f new
+ ignore=''
+ for e in ${EXIT_IGNORE:-0}; do
+ if [ "$e" = "$exitcode" ]; then
+ ignore=1
+ break
+ fi
+ done
+ if [ ! "$ignore" ]; then
+ echo "${source} exited with code ${exitcode}, log follows:"
+ cat log
+ echo
+ fi
+ }
+ )
+ if [ -e ${source}/new ]; then
+ mv ${source}/new ${source}/current
+ fi
+ if [ -e ${source}/current ]; then
+ cat ${source}/current >&3
+ fi
+done 3>| "${OUTFILE}.new"
+
+mv "${OUTFILE}.new" "${OUTFILE}"
+
+# clean up cache dirs of vanished sources
+for d in *; do
+ [ -d $d ] || continue
+ [ -e "${CONFDIR}/sources/$d" ] || rm -fr $d
+done
+
+kill "${LOCKPID}"
+lockfile-remove "${LOCK}"
+
+# vim:set ft=sh: