From 4f2d7949f03e1c198bc888f2d05f421d35c57e21 Mon Sep 17 00:00:00 2001 From: V3n3RiX Date: Mon, 9 Oct 2017 18:53:29 +0100 Subject: reinit the tree, so we can have metadata --- eclass/fixheadtails.eclass | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 eclass/fixheadtails.eclass (limited to 'eclass/fixheadtails.eclass') diff --git a/eclass/fixheadtails.eclass b/eclass/fixheadtails.eclass new file mode 100644 index 000000000000..c19d33924aab --- /dev/null +++ b/eclass/fixheadtails.eclass @@ -0,0 +1,43 @@ +# Copyright 1999-2014 Gentoo Foundation +# Distributed under the terms of the GNU General Public License v2 + +# @ECLASS: fixheadtails.eclass +# @MAINTAINER: +# base-system@gentoo.org +# @AUTHOR: +# Original author John Mylchreest +# @BLURB: functions to replace obsolete head/tail with POSIX compliant ones + +DEPEND=">=sys-apps/sed-4" + +_do_sed_fix() { + einfo " - fixed $1" + sed -i \ + -e 's/head \+-\([0-9]\)/head -n \1/g' \ + -e 's/tail \+\([-+][0-9]\+\)c/tail -c \1/g' \ + -e 's/tail \+\([-+][0-9]\)/tail -n \1/g' ${1} || \ + die "sed ${1} failed" +} + +# @FUNCTION: ht_fix_file +# @USAGE: +# @DESCRIPTION: +# Fix all the specified files. +ht_fix_file() { + local i + einfo "Replacing obsolete head/tail with POSIX compliant ones" + for i in "$@" ; do + _do_sed_fix "$i" + done +} + +# @FUNCTION: ht_fix_all +# @DESCRIPTION: +# Find and fix all files in the current directory as needed. +ht_fix_all() { + local MATCHES + MATCHES=$(grep -l -s -i -R -e "head -[ 0-9]" -e "tail [+-][ 0-9]" * | sort -u) + [[ -n ${MATCHES} ]] \ + && ht_fix_file ${MATCHES} \ + || einfo "No need for ht_fix_all anymore !" +} -- cgit v1.2.3