116 lines
3.0 KiB
Bash
116 lines
3.0 KiB
Bash
#! /bin/bash
|
|
#
|
|
# This is the update-reader.conf script for Debian GNU/Linux.
|
|
# Written by Ludovic Rousseau <ludovic.rousseau@free.fr>
|
|
# Based on update-modules written by Wichert Akkerman <wakkerma@debian.org>
|
|
# Copyright (C) 2001 Software in the Public Interest
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
# it under the terms of the GNU General Public License as published by
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
# (at your option) any later version.
|
|
#
|
|
# This program is distributed in the hope that it will be useful,
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
# GNU General Public License for more details.
|
|
#
|
|
# You should have received a copy of the GNU General Public License
|
|
# along with this program; if not, write to the Free Software
|
|
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
|
|
# $Id: update-reader.conf,v 1.4 2005-03-24 13:17:57 rousseau Exp $
|
|
|
|
OLDCFGFILE=/etc/reader.conf
|
|
CFGDIR=/var/lib/pcscd
|
|
CFGFILE="$CFGDIR/reader.conf"
|
|
TMPFILE=`mktemp /tmp/reader.conf.XXXXXX`
|
|
HEADER="### This file is automatically generated by update-reader.conf"
|
|
|
|
trap "rm -f $TMPFILE; exit" INT TERM EXIT
|
|
set -e
|
|
|
|
# Reset the sorting order since we depend on it
|
|
LC_COLLATE=C
|
|
export LC_COLLATE
|
|
|
|
# Avoid side effects with LC_ALL. See #567764
|
|
unset LC_ALL
|
|
|
|
if [ 0 -ne "`id -u`" ]; then
|
|
echo "You have to be root to run $0"
|
|
exit 2
|
|
fi
|
|
|
|
if [ ! -d "$CFGDIR" ]; then
|
|
mkdir "$CFGDIR"
|
|
fi
|
|
|
|
if [ -e "$OLDCFGFILE" ]; then
|
|
echo "moving the old configuration file $OLDCFGFILE to its new location: $CFGFILE"
|
|
mv "$OLDCFGFILE" "$CFGFILE"
|
|
if [ -e "$OLDCFGFILE".old ]; then
|
|
mv "$OLDCFGFILE".old "$CFGFILE".old
|
|
fi
|
|
fi
|
|
|
|
needforce=0
|
|
if [ -f "$CFGFILE" ]; then
|
|
FIRSTLINE=$(head -1 "$CFGFILE")
|
|
if [ "$FIRSTLINE" != "$HEADER" ]; then
|
|
#echo "new format or manual"
|
|
sha=$(echo "$FIRSTLINE" | cut -f2 -d' ')
|
|
#echo $sha
|
|
if [ ${#sha} -ne 40 ]; then
|
|
echo "Error: file $CFGFILE is not automatically generated."
|
|
needforce=1
|
|
else
|
|
sha2=$(tail --lines=+2 "$CFGFILE" | sha1sum | cut -f1 -d' ')
|
|
#echo $sha2
|
|
if [ $sha != $sha2 ]; then
|
|
echo "Error: file $CFGFILE was manually edited."
|
|
needforce=1
|
|
fi
|
|
fi
|
|
fi
|
|
fi
|
|
|
|
if [ "$1" = "force" ]; then
|
|
echo "force specified, (re)generating file anyway."
|
|
needforce=0
|
|
fi
|
|
|
|
if [ $needforce -eq 1 ]; then
|
|
echo "Use \"update-reader.conf force\" to force (re)generation."
|
|
exit 1
|
|
fi
|
|
|
|
if [ -e "$CFGFILE" ]; then
|
|
cp -f "$CFGFILE" "${CFGFILE}.old"
|
|
fi
|
|
|
|
for cfg in /etc/reader.conf.d/* ; do
|
|
if ! echo "$cfg" | grep -q '\(\.dpkg-[a-z]*\|~\)$' ; then
|
|
echo "### update-reader.conf: start processing $cfg" >> "$TMPFILE"
|
|
echo >> "$TMPFILE"
|
|
if [ -x "$cfg" ]; then
|
|
"$cfg" >> "$TMPFILE"
|
|
else
|
|
cat "$cfg" >> "$TMPFILE"
|
|
fi
|
|
echo >> "$TMPFILE"
|
|
echo "### update-reader.conf: end processing $cfg" >> "$TMPFILE"
|
|
echo >> "$TMPFILE"
|
|
fi
|
|
done
|
|
|
|
echo -n "#SHA1 " > "$CFGFILE"
|
|
sha1sum "$TMPFILE" >> "$CFGFILE"
|
|
cat "$TMPFILE" >> "$CFGFILE"
|
|
chmod 644 "$CFGFILE"
|
|
|
|
rm -f "$TMPFILE"
|
|
|