#!/bin/sh # NOTE: file derived from etckeeper/update-ignore.d/01update-ignore set -e if [ "$VCS" = git ]; then dir=.git file=.gitignore elif [ "$VCS" = hg ]; then dir=.hg file=.hgignore elif [ "$VCS" = bzr ]; then dir=.bzr file=.bzrignore elif [ "$VCS" = darcs ]; then dir=_darcs file=.darcsignore else echo "etckeeper: unsupported VCS $VCS" >&2 exit 1 fi if [ ! -d "$dir" ]; then exit 0 fi managed_by_etckeeper="managed by update-ignore.d/02custom-ignore" nl() { echo >>"$file" } comment() { comment="$1" echo "# $comment" >>"$file" } ignore() { glob="$1" case "$VCS" in git) # escape "#" in ignores, as otherwise it may # be considered a comment echo "$glob" | sed 's/#/\\#/g' >>"$file" ;; bzr) echo "$glob" >>"$file" ;; hg) # rather than converting the glob to a regexp, just # configure hg to use globs if [ -z "$hg_syntax_printed" ]; then comment "use glob syntax" echo "syntax: glob" >>"$file" nl hg_syntax_printed=1 fi echo "$glob" | sed 's/#/\\#/g' >>"$file" ;; darcs) # darcs doesn't understand globs, so we need to # translate them into regexs. Not a complete converter, # but suitable for given globs. if [ "${glob%\*}" != "$glob" ]; then glob="${glob%\*}" else glob="$glob"'($|/)' fi if [ "${glob#\*}" != "$glob" ]; then glob="${glob#\*}" else glob='(^|/)'"$glob" fi glob="$( printf %s $glob | sed -e 's/\./\\./g;s/\*/[^\/]*/g;s/\?/[^\/]/g' )" echo "$glob" >>"$file" esac } writefile () { comment "begin section $managed_by_etckeeper (do not edit this section by hand)" nl ignore "aliases.db" ignore "postfix/*.db" nl comment "end section $managed_by_etckeeper" } if [ -e "$file" ]; then if ! grep -q "$managed_by_etckeeper" "$file"; then if [ "$1" != "-a" ]; then echo "etckeeper: "$file" does not contain \"$managed_by_etckeeper\" comment; not updating" exit 1 else echo "etckeeper: "$file" exists but does not contain \"$managed_by_etckeeper\" comment; updating" writefile exit 0 fi fi realfile="$file" if [ -n "`type -p tempfile`" ]; then tempfile="tempfile" elif [ -n "`type -p mktemp`" ]; then tempfile="mktemp" else echo "etckeeper warning: can't find tempfile or mktemp" >&2 fi file=$($tempfile) ( skipping= while read line; do if echo "$line" | grep -q "$managed_by_etckeeper"; then if [ ! "$skipping" ]; then skipping=1 else skipping= writefile fi elif [ ! "$skipping" ]; then echo "$line" >> "$file" fi done if [ "$skipping" ]; then # reached end of file w/o ending block writefile fi ) <"$realfile" mv -f "$file" "$realfile" else writefile fi