diff options
author | William Hubbs <williamh@gentoo.org> | 2014-03-10 19:47:21 +0000 |
---|---|---|
committer | William Hubbs <williamh@gentoo.org> | 2014-03-10 19:47:21 +0000 |
commit | 264e4abfe939fea4aeb8351dcb1874fca46b033f (patch) | |
tree | 809c978e1e0eed982990026a07c844c18c908c41 /sys-apps | |
parent | x86 stable, bug #492904 (diff) | |
download | gentoo-2-264e4abfe939fea4aeb8351dcb1874fca46b033f.tar.gz gentoo-2-264e4abfe939fea4aeb8351dcb1874fca46b033f.tar.bz2 gentoo-2-264e4abfe939fea4aeb8351dcb1874fca46b033f.zip |
Initial commit of gentoo functions for bug #373219.
(Portage version: 2.2.8-r1/cvs/Linux x86_64, signed Manifest commit with key 0x8568F528)
Diffstat (limited to 'sys-apps')
-rw-r--r-- | sys-apps/gentoo-functions/ChangeLog | 10 | ||||
-rw-r--r-- | sys-apps/gentoo-functions/Manifest | 4 | ||||
-rw-r--r-- | sys-apps/gentoo-functions/files/gentoo-functions-0.sh | 464 | ||||
-rw-r--r-- | sys-apps/gentoo-functions/gentoo-functions-0.ebuild | 25 | ||||
-rw-r--r-- | sys-apps/gentoo-functions/metadata.xml | 13 |
5 files changed, 516 insertions, 0 deletions
diff --git a/sys-apps/gentoo-functions/ChangeLog b/sys-apps/gentoo-functions/ChangeLog new file mode 100644 index 000000000000..5ef3f5308d25 --- /dev/null +++ b/sys-apps/gentoo-functions/ChangeLog @@ -0,0 +1,10 @@ +# ChangeLog for sys-apps/gentoo-functions +# Copyright 1999-2014 Gentoo Foundation; Distributed under the GPL v2 +# $Header: /var/cvsroot/gentoo-x86/sys-apps/gentoo-functions/ChangeLog,v 1.1 2014/03/10 19:47:21 williamh Exp $ + +*gentoo-functions-0 (10 Mar 2014) + + 10 Mar 2014; William Hubbs <williamh@gentoo.org> +gentoo-functions-0.ebuild, + +files/gentoo-functions-0.sh, +metadata.xml: + initial commit of gentoo functions for bug #373219. + diff --git a/sys-apps/gentoo-functions/Manifest b/sys-apps/gentoo-functions/Manifest new file mode 100644 index 000000000000..bb13f616d993 --- /dev/null +++ b/sys-apps/gentoo-functions/Manifest @@ -0,0 +1,4 @@ +AUX gentoo-functions-0.sh 8440 SHA256 d3f038fe159d81ce9c5e57b2910ae5cd1fc826e7ca83c7fe8b3814fa90be917a SHA512 cfeef8dbcb8541d91f9db9aba9caa07e1a4081f5e3511eb27810883941784f1151e6502bfb5a271c3fe3f993ab621df90f48f62a9a13113232d48972bcabbc39 WHIRLPOOL ead49ff61d02f65adb285c5e3bb669f43060b482ff04e42d7094370a6a25562647ccc9a42d1c74a9dc6374ac2e3430b9759386b8dbff104096b4e743db856e00 +EBUILD gentoo-functions-0.ebuild 542 SHA256 56591603f14de458d3ed9572b3591647d8acda7f1118fd8af8d4cd910db54902 SHA512 0176b70e2c94c97e9485e534245b750bb948cfe31068c13c8564c3493bfff698436f2b036308bba0c7743bc1c80736e477feb37dd05bea8c0a7d17b2a0799cfe WHIRLPOOL 7f83701a5416092ce9d8de8bbfa1cf313303e360af59d7bbc1a720414281c7492f69906c08b368749a37884d0b1dd17695841c73ceaec0104d3c0e05a13f3d33 +MISC ChangeLog 342 SHA256 91229ada2ccae18d4686ca2cb22cbedd573a0699a4045a123112b18055d45b66 SHA512 c80c4c3643b3345e4ffc86664728bdc32290027b946fc52d8e34c81f59c37306c6abb8a38b79c76d604ebc868e954398525356ea502a50a83137fbc8b6a7a03d WHIRLPOOL ae72c2f6aad1af841ab608717c1634356969dae65e2c9d9d662b397a63230d32b5bf33b3be828df4ab5e620b6060f5d3982bb82ecc64fea319dbd0385b60a27f +MISC metadata.xml 409 SHA256 c0f71c047e51b21d6870b41f8cd475c4d6bfedd8342e522916fdcf429634b7f9 SHA512 55b830e0219eb6d5ee1d30f5e93046bcebf06811b61e87ff4e6edf434b1580d063e81e9d0781099a058e4e2dbc4f5c6b491385d2296c35cc91fa327ea0fe8ce6 WHIRLPOOL 5fdb6255e00a573304980158bcbd48e22e208b7bd5bb6496d9a36dc740beacb0098c1a62299b6e8c0430428b2bbb127c30953d6da05e578574bdd11dba3495b7 diff --git a/sys-apps/gentoo-functions/files/gentoo-functions-0.sh b/sys-apps/gentoo-functions/files/gentoo-functions-0.sh new file mode 100644 index 000000000000..815a73df9648 --- /dev/null +++ b/sys-apps/gentoo-functions/files/gentoo-functions-0.sh @@ -0,0 +1,464 @@ +# Copyright 1999-2014 Gentoo Foundation +# Distributed under the terms of the GNU General Public License v2 + +# +# All functions in this file should be written in POSIX sh. Please do +# not use bashisms. +# + +RC_GOT_FUNCTIONS="yes" + +# +# hard set the indent used for e-commands. +# num defaults to 0 +# This is a private function. +# +_esetdent() +{ + local i="$1" + [ -z "$i" ] || [ "$i" -lt 0 ] && i=0 + RC_INDENTATION=$(printf "%${i}s" '') +} + +# +# increase the indent used for e-commands. +# +eindent() +{ + local i="$1" + [ -n "$i" ] && [ "$i" -gt 0 ] || i=$RC_DEFAULT_INDENT + _esetdent $(( ${#RC_INDENTATION} + i )) +} + +# +# decrease the indent used for e-commands. +# +eoutdent() +{ + local i="$1" + [ -n "$i" ] && [ "$i" -gt 0 ] || i=$RC_DEFAULT_INDENT + _esetdent $(( ${#RC_INDENTATION} - i )) +} + +# +# this function was lifted from OpenRC. It returns 0 if the argument or +# the value of the argument is "yes", "true", "on", or "1" or 1 +# otherwise. +# +yesno() +{ + [ -z "$1" ] && return 1 + + case "$1" in + [Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]|[Oo][Nn]|1) return 0;; + [Nn][Oo]|[Ff][Aa][Ll][Ss][Ee]|[Oo][Ff][Ff]|0) return 1;; + esac + + local value= + eval value=\$${1} + case "$value" in + [Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]|[Oo][Nn]|1) return 0;; + [Nn][Oo]|[Ff][Aa][Ll][Ss][Ee]|[Oo][Ff][Ff]|0) return 1;; + *) vewarn "\$$1 is not set properly"; return 1;; + esac +} + +# +# use the system logger to log a message +# +esyslog() +{ + local pri= + local tag= + + if command -v logger > /dev/null 2>&1; then + pri="$1" + tag="$2" + + shift 2 + [ -z "$*" ] && return 0 + + logger -p "${pri}" -t "${tag}" -- "$*" + fi + + return 0 +} + +# +# show an informative message (without a newline) +# +einfon() +{ + if yesno "${EINFO_QUIET}"; then + return 0 + fi + if ! yesno "${RC_ENDCOL}" && [ "${LAST_E_CMD}" = "ebegin" ]; then + printf "\n" + fi + printf " ${GOOD}*${NORMAL} ${RC_INDENTATION}$*" + LAST_E_CMD="einfon" + return 0 +} + +# +# show an informative message (with a newline) +# +einfo() +{ + einfon "$*\n" + LAST_E_CMD="einfo" + return 0 +} + +# +# show a warning message (without a newline) and log it +# +ewarnn() +{ + if yesno "${EINFO_QUIET}"; then + printf " $*" + else + if ! yesno "${RC_ENDCOL}" && [ ${LAST_E_CMD} = "ebegin" ]; then + printf "\n" + fi + printf " ${WARN}*${NORMAL} ${RC_INDENTATION}$*" + fi + + local name="${0##*/}" + # Log warnings to system log + esyslog "daemon.warning" "${name}" "$*" + + LAST_E_CMD="ewarnn" + return 0 +} + +# +# show a warning message (with a newline) and log it +# +ewarn() +{ + if yesno "${EINFO_QUIET}"; then + printf " $*\n" + else + if ! yesno "${RC_ENDCOL}" && [ ${LAST_E_CMD} = "ebegin" ]; then + printf "\n" + fi + printf " ${WARN}*${NORMAL} ${RC_INDENTATION}$*\n" + fi + + local name="${0##*/}" + # Log warnings to system log + esyslog "daemon.warning" "${name}" "$*" + + LAST_E_CMD="ewarn" + return 0 +} + +# +# show an error message (without a newline) and log it +# +eerrorn() +{ + if yesno "${EINFO_QUIET}"; then + printf " $*" >/dev/stderr + else + if ! yesno "${RC_ENDCOL}" && [ "${LAST_E_CMD}" = "ebegin" ]; then + printf "\n" + fi + printf " ${BAD}*${NORMAL} ${RC_INDENTATION}$*" + fi + + local name="${0##*/}" + # Log errors to system log + esyslog "daemon.err" "rc-scripts" "$*" + + LAST_E_CMD="eerrorn" + return 0 +} + +# +# show an error message (with a newline) and log it +# +eerror() +{ + if yesno "${EINFO_QUIET}"; then + printf " $*\n" >/dev/stderr + else + if ! yesno "${RC_ENDCOL}" && [ "${LAST_E_CMD}" = "ebegin" ]; then + printf "\n" + fi + printf " ${BAD}*${NORMAL} ${RC_INDENTATION}$*\n" + fi + + local name="${0##*/}" + # Log errors to system log + esyslog "daemon.err" "rc-scripts" "$*" + + LAST_E_CMD="eerror" + return 0 +} + +# +# show a message indicating the start of a process +# +ebegin() +{ + local msg="$*" + if yesno "${EINFO_QUIET}"; then + return 0 + fi + + msg="${msg} ..." + einfon "${msg}" + if yesno "${RC_ENDCOL}"; then + printf "\n" + fi + + LAST_E_LEN="$(( 3 + ${#RC_INDENTATION} + ${#msg} ))" + LAST_E_CMD="ebegin" + return 0 +} + +# +# indicate the completion of process, called from eend/ewend +# if error, show errstr via efunc +# +# This function is private to functions.sh. Do not call it from a +# script. +# +_eend() +{ + local retval="${1:-0}" efunc="${2:-eerror}" msg + shift 2 + + if [ "${retval}" = "0" ]; then + yesno "${EINFO_QUIET}" && return 0 + msg="${BRACKET}[ ${GOOD}ok${BRACKET} ]${NORMAL}" + else + if [ -c /dev/null ] ; then + rc_splash "stop" >/dev/null 2>&1 & + else + rc_splash "stop" & + fi + if [ -n "$*" ] ; then + ${efunc} "$*" + fi + msg="${BRACKET}[ ${BAD}!!${BRACKET} ]${NORMAL}" + fi + + if yesno "${RC_ENDCOL}"; then + printf "${ENDCOL} ${msg}\n" + else + [ "${LAST_E_CMD}" = ebegin ] || LAST_E_LEN=0 + printf "%$(( COLS - LAST_E_LEN - 6 ))s%b\n" '' "${msg}" + fi + + return ${retval} +} + +# +# indicate the completion of process +# if error, show errstr via eerror +# +eend() +{ + local retval="${1:-0}" + shift + + _eend "${retval}" eerror "$*" + + LAST_E_CMD="eend" + return ${retval} +} + +# +# indicate the completion of process +# if error, show errstr via ewarn +# +ewend() +{ + local retval="${1:-0}" + shift + + _eend "${retval}" ewarn "$*" + + LAST_E_CMD="ewend" + return ${retval} +} + +# v-e-commands honor EINFO_VERBOSE which defaults to no. +# The condition is negated so the return value will be zero. +veinfo() +{ + yesno "${EINFO_VERBOSE}" && einfo "$@" +} + +veinfon() +{ + yesno "${EINFO_VERBOSE}" && einfon "$@" +} + +vewarn() +{ + yesno "${EINFO_VERBOSE}" && ewarn "$@" +} + +veerror() +{ + yesno "${EINFO_VERBOSE}" && eerror "$@" +} + +vebegin() +{ + yesno "${EINFO_VERBOSE}" && ebegin "$@" +} + +veend() +{ + yesno "${EINFO_VERBOSE}" && { eend "$@"; return $?; } + return ${1:-0} +} + +vewend() +{ + yesno "${EINFO_VERBOSE}" && { ewend "$@"; return $?; } + return ${1:-0} +} + +veindent() +{ + yesno "${EINFO_VERBOSE}" && eindent +} + +veoutdent() +{ + yesno "${EINFO_VERBOSE}" && eoutdent +} + +# +# prints the current libdir {lib,lib32,lib64} +# +get_libdir() +{ + if [ -n "${CONF_LIBDIR_OVERRIDE}" ] ; then + CONF_LIBDIR="${CONF_LIBDIR_OVERRIDE}" + elif [ -x /usr/bin/portageq ] ; then + CONF_LIBDIR="$(/usr/bin/portageq envvar CONF_LIBDIR)" + fi + printf "${CONF_LIBDIR:=lib}\n" +} + +# +# return 0 if gentoo=param was passed to the kernel +# +# EXAMPLE: if get_bootparam "nodevfs" ; then .... +# +get_bootparam() +{ + local x copt params retval=1 + + [ ! -r /proc/cmdline ] && return 1 + + read copts < /proc/cmdline + for copt in $copts ; do + if [ "${copt%=*}" = "gentoo" ] ; then + params=$(gawk -v PARAMS="${copt##*=}" ' + BEGIN { + split(PARAMS, nodes, ",") + for (x in nodes) + print nodes[x] + }') + + # Parse gentoo option + for x in ${params} ; do + if [ "${x}" = "$1" ] ; then +# echo "YES" + retval=0 + fi + done + fi + done + + return ${retval} +} + +# +# return 0 if any of the files/dirs are newer than +# the reference file +# +# EXAMPLE: if is_older_than a.out *.o ; then ... +is_older_than() +{ + local x= + local ref="$1" + shift + + for x in "$@" ; do + [ "${x}" -nt "${ref}" ] && return 0 + [ -d "${x}" ] && is_older_than "${ref}" "${x}"/* && return 0 + done + + return 1 +} + +# This is the main script, please add all functions above this point! + +# Dont output to stdout? +EINFO_QUIET="${EINFO_QUIET:-no}" +EINFO_VERBOSE="${EINFO_VERBOSE:-no}" + +# Should we use color? +RC_NOCOLOR="${RC_NOCOLOR:-no}" +# Can the terminal handle endcols? +RC_ENDCOL="yes" + +# Default values for e-message indentation and dots +RC_INDENTATION='' +RC_DEFAULT_INDENT=2 +RC_DOT_PATTERN='' + +# Cache the CONSOLETYPE - this is important as backgrounded shells don't +# have a TTY. rc unsets it at the end of running so it shouldn't hang +# around +if [ -z "${CONSOLETYPE}" ] ; then + CONSOLETYPE="$( /sbin/consoletype 2>/dev/null )"; export CONSOLETYPE +fi +if [ "${CONSOLETYPE}" = "serial" ] ; then + RC_NOCOLOR="yes" + RC_ENDCOL="no" +fi + +for arg in "$@" ; do + case "${arg}" in + # Lastly check if the user disabled it with --nocolor argument + --nocolor|-nc) + RC_NOCOLOR="yes" + ;; + esac +done + +# Setup COLS and ENDCOL so eend can line up the [ ok ] +COLS="${COLUMNS:-0}" # bash's internal COLUMNS variable +[ "$COLS" -eq 0 ] && \ + COLS="$(set -- $(stty size 2>/dev/null) ; printf "$2\n")" +[ "$COLS" -gt 0 ] || COLS=80 # width of [ ok ] == 7 + +if yesno "${RC_ENDCOL}"; then + ENDCOL='\033[A\033['$(( COLS - 8 ))'C' +else + ENDCOL='' +fi + +# Setup the colors so our messages all look pretty +if yesno "${RC_NOCOLOR}"; then + unset GOOD WARN BAD NORMAL HILITE BRACKET +else + GOOD='\033[32;01m' + WARN='\033[33;01m' + BAD='\033[31;01m' + HILITE='\033[36;01m' + BRACKET='\033[34;01m' + NORMAL='\033[0m' +fi + +# vim:ts=4 diff --git a/sys-apps/gentoo-functions/gentoo-functions-0.ebuild b/sys-apps/gentoo-functions/gentoo-functions-0.ebuild new file mode 100644 index 000000000000..cf5a25a27ac1 --- /dev/null +++ b/sys-apps/gentoo-functions/gentoo-functions-0.ebuild @@ -0,0 +1,25 @@ +# Copyright 1999-2014 Gentoo Foundation +# Distributed under the terms of the GNU General Public License v2 +# $Header: /var/cvsroot/gentoo-x86/sys-apps/gentoo-functions/gentoo-functions-0.ebuild,v 1.1 2014/03/10 19:47:21 williamh Exp $ + +EAPI=5 + +DESCRIPTION="base shell functions required by all gentoo systems" +HOMEPAGE="http://www.gentoo.org" +SRC_URI="" + +LICENSE="GPL-2" +SLOT="0" +KEYWORDS="~alpha ~amd64 ~arm ~arm64 ~hppa ~ia64 ~m68k ~mips ~ppc ~ppc64 ~s390 ~sh ~sparc ~x86 ~amd64-fbsd ~sparc-fbsd ~x86-fbsd" +IUSE="" + +DEPEND="" +RDEPEND="" + +S="${WORKDIR}" + +src_install() { + dodir /lib/gentoo + insinto /lib/gentoo + newins "${FILESDIR}"/${P}.sh functions.sh +} diff --git a/sys-apps/gentoo-functions/metadata.xml b/sys-apps/gentoo-functions/metadata.xml new file mode 100644 index 000000000000..0a4b4a1b7343 --- /dev/null +++ b/sys-apps/gentoo-functions/metadata.xml @@ -0,0 +1,13 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE pkgmetadata SYSTEM "http://www.gentoo.org/dtd/metadata.dtd"> +<pkgmetadata> + <maintainer> + <email>williamh@gentoo.org</email> + <name>William Hubbs</name> + </maintainer> + <herd>base-system@gentoo.org</herd> + <longdescription lang="en"> + This package contains base shell functions which are required by + all Gentoo systems. + </longdescription> +</pkgmetadata> |