# Copyright (c) 2006 bivio Software, Inc. All Rights Reserved. # # Visit http://www.bivio.biz for more info. # # This library is free software; you can redistribute it and/or modify # it under the terms of the GNU Lesser General Public License as # published by the Free Software Foundation; either version 2.1 of the # License, or (at your option) any later version. # # This library is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # Lesser General Public License for more details. # # You should have received a copy of the GNU Lesser General Public # License along with this library; If not, you may get a copy from: # http://www.opensource.org/licenses/lgpl-license.html # # $Id: DarwinConfig.pm,v 1.3 2006/05/23 14:51:57 nagler Exp $ package Bivio::Util::DarwinConfig; use strict; use base 'Bivio::Util::LinuxConfig'; our($VERSION) = sprintf('%d.%02d', q$Revision: 1.3 $ =~ /\d+/g); sub USAGE { return <<'EOF' . shift->SUPER::USAGE(@_); usage: b-darwin-config [options] command [args..] commands: add_launch_daemon - Add enable a launch daemon EOF } sub add_launch_daemon { my($self, $vars) = shift->name_parameters([qw(Label ProgramArguments)], \@_); $self->usage_error( $vars->{Label}, ': label must be of the form com.company.daemon' ) unless $vars->{Label} =~ /^[a-z0-9]+\.[a-z0-9]+\.[a-z0-9]+$/; return $self->replace_file( "/Library/LaunchDaemons/$vars->{Label}.plist", qw(root wheel), 0644, _map_xml_vars(<<'EOF', $vars), ServiceIPC OnDemand Label $Label ProgramArguments @ProgramArguments EOF ); } sub _map_xml_vars { my($text, $vars) = @_; return join('', map({ my($line) = "$_\n"; $line =~ s/\$(\w+)/$vars->{$1} || die("$1: no such variable")/eg; my($array) = $line =~ /\@(\w+)/; $array ? map( { (my $l = $line) =~ s/[\@]$array/$_/ or die('@' . $array . ': not found'); $l; } @{ref($vars->{$array}) ? $vars->{$array} : defined($vars->{$array}) ? [split(' ', $vars->{$array})] : die("$array: no such array variable")}, ) : $line; } split(/\n/, $text))); } 1;