net-fs/openafs-kernel: remove vulnerable versions
[gentoo.git] / eclass / fixheadtails.eclass
1 # Copyright 1999-2014 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3 # $Id$
4
5 # @ECLASS: fixheadtails.eclass
6 # @MAINTAINER:
7 # base-system@gentoo.org
8 # @AUTHOR:
9 # Original author John Mylchreest <johnm@gentoo.org>
10 # @BLURB: functions to replace obsolete head/tail with POSIX compliant ones
11
12 DEPEND=">=sys-apps/sed-4"
13
14 _do_sed_fix() {
15         einfo " - fixed $1"
16         sed -i \
17                 -e 's/head \+-\([0-9]\)/head -n \1/g' \
18                 -e 's/tail \+\([-+][0-9]\+\)c/tail -c \1/g' \
19                 -e 's/tail \+\([-+][0-9]\)/tail -n \1/g' ${1} || \
20                         die "sed ${1} failed"
21 }
22
23 # @FUNCTION: ht_fix_file
24 # @USAGE: <files>
25 # @DESCRIPTION:
26 # Fix all the specified files.
27 ht_fix_file() {
28         local i
29         einfo "Replacing obsolete head/tail with POSIX compliant ones"
30         for i in "$@" ; do
31                 _do_sed_fix "$i"
32         done
33 }
34
35 # @FUNCTION: ht_fix_all
36 # @DESCRIPTION:
37 # Find and fix all files in the current directory as needed.
38 ht_fix_all() {
39         local MATCHES
40         MATCHES=$(grep -l -s -i -R -e "head -[ 0-9]" -e "tail [+-][ 0-9]" * | sort -u)
41         [[ -n ${MATCHES} ]] \
42                 && ht_fix_file ${MATCHES} \
43                 || einfo "No need for ht_fix_all anymore !"
44 }