3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov# Miscellaneous routines.
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov# Copyright (C) 2014 Red Hat
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov# This program is free software; you can redistribute it and/or modify
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov# it under the terms of the GNU General Public License as published by
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov# the Free Software Foundation; either version 3 of the License, or
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov# (at your option) any later version.
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov# This program is distributed in the hope that it will be useful,
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov# but WITHOUT ANY WARRANTY; without even the implied warranty of
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov# GNU General Public License for more details.
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov# You should have received a copy of the GNU General Public License
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov# along with this program. If not, see <http://www.gnu.org/licenses/>.
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashovif [ -z ${_MISC_SH+set} ]; then
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov# Remove files and directories recursively, forcing write permissions on
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov# Args: path...
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov# Extract line and function coverage percentage from a "genhtml" or "lcov
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov# --summary" output.
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov# Input: "genhtml" or "lcov --summary" output
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov# Output: lines funcs
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov sed -ne 's/^ *\(lines\|functions\)\.*: \([0-9]\+\).*$/ \2/p' |
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov# Check if a "genhtml" or "lcov --summary" output has a minimum coverage
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov# percentage of lines and functions.
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov# Input: "genhtml" or "lcov --summary" output
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov# Args: min_lines min_funcs
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov ((lines >= min_lines && funcs >= min_funcs)) && return 0 || return 1
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov# Check if the current user belongs to a group.
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov# Args: group_name
3ce85a5f5264e7118beb6524e120fd8b53a13da4Nikolai Kondrashov group_id=`getent group "$group_name" | cut -d: -f3` || return 1