svc-pkg-mirror revision 3156
06e46062ef4f5f4b687cbafb4518fb123fe23920jbeloro# CDDL HEADER START
06e46062ef4f5f4b687cbafb4518fb123fe23920jbeloro# The contents of this file are subject to the terms of the
06e46062ef4f5f4b687cbafb4518fb123fe23920jbeloro# Common Development and Distribution License (the "License").
06e46062ef4f5f4b687cbafb4518fb123fe23920jbeloro# You may not use this file except in compliance with the License.
06e46062ef4f5f4b687cbafb4518fb123fe23920jbeloro# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
06e46062ef4f5f4b687cbafb4518fb123fe23920jbeloro# See the License for the specific language governing permissions
06e46062ef4f5f4b687cbafb4518fb123fe23920jbeloro# and limitations under the License.
06e46062ef4f5f4b687cbafb4518fb123fe23920jbeloro# When distributing Covered Code, include this CDDL HEADER in each
06e46062ef4f5f4b687cbafb4518fb123fe23920jbeloro# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
06e46062ef4f5f4b687cbafb4518fb123fe23920jbeloro# If applicable, add the following below this CDDL HEADER, with the
06e46062ef4f5f4b687cbafb4518fb123fe23920jbeloro# fields enclosed by brackets "[]" replaced with your own identifying
06e46062ef4f5f4b687cbafb4518fb123fe23920jbeloro# information: Portions Copyright [yyyy] [name of copyright owner]
06e46062ef4f5f4b687cbafb4518fb123fe23920jbeloro# CDDL HEADER END
06e46062ef4f5f4b687cbafb4518fb123fe23920jbeloro# Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved.
06e46062ef4f5f4b687cbafb4518fb123fe23920jbeloro# This is the method script for the svc:/application/pkg/mirror service
06e46062ef4f5f4b687cbafb4518fb123fe23920jbeloro# When called using the 'start' or 'stop' SMF method script, it adds
06e46062ef4f5f4b687cbafb4518fb123fe23920jbeloro# or removes a crontab entry for the user running the service, pkg5srv
06e46062ef4f5f4b687cbafb4518fb123fe23920jbeloro# by default.
06e46062ef4f5f4b687cbafb4518fb123fe23920jbeloro# When called using the 'refresh' method, it runs pkgrecv(1) to update a
06e46062ef4f5f4b687cbafb4518fb123fe23920jbeloro# pkg(5) repository using configuration stored in the SMF instance.
06e46062ef4f5f4b687cbafb4518fb123fe23920jbeloro# The following SMF properties are used to configure the service:
06e46062ef4f5f4b687cbafb4518fb123fe23920jbeloro# config/repository the local pkg5 repository we update.
06e46062ef4f5f4b687cbafb4518fb123fe23920jbeloro# config/ref_image the reference pkg5 image that contains
06e46062ef4f5f4b687cbafb4518fb123fe23920jbeloro# origin information that we should update
06e46062ef4f5f4b687cbafb4518fb123fe23920jbeloro# config/publishers a comma-separated list of the publishers
06e46062ef4f5f4b687cbafb4518fb123fe23920jbeloro# from ref_image that we pkgrecv from.
06e46062ef4f5f4b687cbafb4518fb123fe23920jbeloro# config/crontab_period the first five fields of a crontab(4)
06e46062ef4f5f4b687cbafb4518fb123fe23920jbeloro# entry, with the 3rd field allowing the
06e46062ef4f5f4b687cbafb4518fb123fe23920jbeloro# special value 'random'.
06e46062ef4f5f4b687cbafb4518fb123fe23920jbeloro# config/debug a boolean, 'true' or 'false'; whether
06e46062ef4f5f4b687cbafb4518fb123fe23920jbeloro# to log more output when debugging.
06e46062ef4f5f4b687cbafb4518fb123fe23920jbeloro# Load SMF constants and functions
set -o noglob
# day, when configured with a 'config/crontab_period' containing a
print "config/crontab_period property must contain 5 " \
$SMF_FMRI exit
print $new_schedule
IFS=,
if [ ! -f $repo/pkg5.repository ]; then
check_failure $? \
check_failure $? \
typeset pub=$2
typeset SMF_FMRI=$1
if [ -f $lockfile ]; then
override, or check the SMF property 'config/crontab_period' to ensure
echo $$ > $lockfile
IFS=,
return $SMF_EXIT_FATAL
index=0
pub=${publishers[$i]}
$PKG -R $ref_image publisher -F tsv > /tmp/pkg.mirror.$$
configured for publisher $pub"
if [ $? -eq 0 ]; then
done < /tmp/pkg.mirror.$$
$RM /tmp/pkg.mirror.$$
http_proxy=${http_proxies[$i]}
https_proxy=${https_proxies[$i]}
check_failure $? \
if [ $? -ne 0 ]; then
EXIT=$?
return $EXIT
while read value; do
echo $value
typeset repo=$1
typeset origin=$2
typeset SMF_FMRI=$5
typeset cachedir=$6
typeset clone=$9
typeset publisher=${10}
export http_proxy=$http_proxy
export https_proxy=$https_proxy
>> $LOG
echo $cmd
EXIT=$?
return $EXIT
echo "Problem mirroring repository for $SMF_FMRI"
echo "Problem mirroring repository for $SMF_FMRI"
RET=$?
echo "Mirror refresh failed: see $LOG for more detail."
exit $result