# Copyright 1999-2004 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 # $Header: /var/cvsroot/gentoo-x86/eclass/x11.eclass,v 1.3 2004/10/29 07:11:35 spyderous Exp $ # # Author: Mamoru KOMACHI # # The darwin-daemon.eclass is designed to convert Gentoo init.d scripts # into Mac OS X compatible format. It should be called from src_install() # and will create necessary files in /Library/System/StartupItems. # # External function: # register-StartupItems # Internal functions: # create-plist # convert-initd # parse-Items # map-Items # fakeuse # fakeneed ECLASS=darwin-initd INHERITED="${INHERITED} ${ECLASS}" EXPORT_FUNCTIONS register-StartupItems # # Register StartupItems: # # register-StartupItems [StartupItem [init.d]] # register-StartupItems() { if [ -n "$1" ] ; then local StartupItem="$1" fi if [ -n "$2" ] ; then local INITD="$2" fi : ${StartupItem:=${PN}} : ${INITD:=/etc/init.d/${PN}} local StartupItemsDir=${D}/Library/StartupItems/${StartupItem} mkdir -p ${StartupItemsDir} || die "mkdir failed" create-plist "${INITD}" "${StartupItem}" > ${StartupItemsDir}/StartupParameters.plist || die "creating StartupParameters.plist failed" convert-initd "${INITD}" > ${StartupItemsDir}/${StartupItem} || die "creating Service failed" chmod +x ${StartupItemsDir}/${StartupItem} || die "chmod failed" } # # Function to create StartupParameters.plist # # create-plist path_to_init.d_script StartupItem # create-plist() { local INITD="$1" local StartupItem="$2" alias use=fakeuse alias need=fakeneed cat < ("foo") # parse-Items foo bar -> ("foo", "bar") # parse-Items() { echo -n "(" while [ "$#" -gt 1 ] ; do echo -n "\"$(map-Items $1)\", " shift done echo -n "\"$(map-Items $1)\"" echo -n ")" } # # Function to map Gentoo init.d naming convension to Mac OS X # StartupItems naming convension # map-Items() { local gen2mac sedlist # one line for one map gen2mac="net Network logger System Log netmount NFS dns Resolver portmap Portmap ypserv NIS domainname Network Configuration" echo "$gen2mac" | while read gen mac ; do sedlist="${sedlist} s:^${gen}\$:${mac}: " done if [ "$#" -eq 0 ] ; then sed -e "{ $sedlist }" else echo "$@" | sed -e "{ $sedlist }" fi }