<!-- 
The contents of this Documentation are subject to the Public Documentation
License Version 1.01 (the "License"); you may only use this Documentation if
you comply with the terms of this License. A copy of the License is
available at http://www.opensolaris.org/os/community/documentation/license.
-->

<chapter id="ips_dev_tasks"><title>Advanced Packaging Tasks</title><highlights><para>This section provides information for developers who are interested
in creating their own OpenSolaris repositories, and creating and publishing
IPS packages and <literal>SVR4</literal> packages.</para>
</highlights><sect1 id="ipsdev"><title>Creating Repositories</title><itemizedlist><para>The IPS software in the 2009.06 release of OpenSolaris enables developers
to perform a variety of tasks related to creating and publishing packages.
The following tasks are supported for the 2009.06 release.</para><listitem><para><olink type="auto-generated" targetptr="createrepo1" remap="internal">How to Create Your Own OpenSolaris Repository Using <command>pkg.depotd(1)</command> Command.</olink></para>
</listitem><listitem><para><olink type="auto-generated" targetptr="createrepo2" remap="internal">How to Create Your Own OpenSolaris Repository Using <command>SMF</command> Commands</olink></para>
</listitem>
</itemizedlist><task id="createrepo1"><title>How to Create Your Own OpenSolaris Repository
Using <citerefentry><refentrytitle>pkg.depotd</refentrytitle></citerefentry> Command</title><procedure><step><para>Type the following command to create your repository:</para><para><command>$ /usr/lib/pkg.depotd <option>d</option> <replaceable>repository_directory </replaceable> <option>p</option> <replaceable>port_value</replaceable></command></para><note><para>If the <replaceable>repository_directory</replaceable> you have
specified does not exist, it will be created for you.</para>
</note>
</step><step><para>To confirm that the repository has been created, open your browser
and type the following URL in the URL field: <literal>http://localhost:<replaceable>port_v</replaceable></literal>.</para><para>If the depot server is running
correctly, a message is displayed in the browser.</para>
</step><step><para>Check the contents of the repository.</para><para><command>$ ls <replaceable>repository_directory</replaceable></command></para>
</step>
</procedure><example><title>Creating Your Own Repository Using <command>pkg.depotd</command></title><para>This example creates an OpenSolaris repository <emphasis>repository1</emphasis> with
a port value of <emphasis>11000</emphasis> and shows the contents of the repository.</para><screen>$ /usr/lib/pkg.depotd -d /tmp/testrepo -p 11000 
[06/Nov/2008:13:43:26] INDEX Search Available
[06/Nov/2008:13:43:26] ENGINE Listening for SIGHUP.
[06/Nov/2008:13:43:26] ENGINE Listening for SIGTERM.
[06/Nov/2008:13:43:26] ENGINE Listening for SIGUSR1.
[06/Nov/2008:13:43:26] ENGINE Bus STARTING
[06/Nov/2008:13:43:26] ENGINE Started monitor thread '_TimeoutMonitor'.
[06/Nov/2008:13:43:26] ENGINE Serving on 0.0.0.0:11000
[06/Nov/2008:13:43:26] ENGINE Bus STARTED</screen><screen>$ ls /export/home/user1/repository1</screen><screen>catalog file pkg search.dir search.pag trans updatelog</screen>
</example>
</task><task id="createrepo2"><title>How to Create Your Own OpenSolaris Repository
Using SMF Commands</title><procedure><step><para>Become superuser.</para>
</step><step><para>Enable the SMF service. You need to do this only the first time
you start the service.</para><para><command># svcadm enable application/pkg/server</command></para>
</step><step><para>Set the value of the port.</para><para><command># svccfg <option>s</option> application/pkg/server
setprop pkg/port=<replaceable>port_value</replaceable></command></para>
</step><step><para>Set the value of the repository.</para><para><command># svccfg <option>s</option> application/pkg/server setprop pkg/inst_root=<replaceable>repository_directory</replaceable></command></para>
</step><step><para>Refresh the repository.</para><para><command># svcadm refresh
application/pkg/server</command></para>
</step><step><para>Restart the repository.</para><para><command># svcadm restart
application/pkg/server</command></para>
</step><step><para>Open your browser and type <literal>http://localhost:<replaceable>port_value</replaceable></literal> in the URL field to confirm that the repository has
been created.</para>
</step><step><para>Check the contents of the repository.</para><para><command># ls <replaceable>repository_directory</replaceable></command></para>
</step>
</procedure><example><title>Creating Your OpenSolaris Repository Using <command>SMF</command> Commands</title><para>This example creates an OpenSolaris repository, <replaceable>repository2</replaceable> with
a port value of <replaceable>8000</replaceable> and shows the contents of
the repository.</para><screen># svccfg -s application/pkg/server setprop pkg/port=8000
# svccfg -s application/pkg/server setprop pkg/inst_root=/export/home/user1/repository2
# svcadm refresh application/pkg/server
# svcadm restart application/pkg/server</screen><screen># ls /export/home/user1/repository2</screen><screen>catalog file pkg search.dir search.pag trans updatelog</screen>
</example>
</task>
</sect1><sect1 id="giikg"><title>Creating and Publishing Packages to a Repository</title><task id="createipspkg"><title>How to Create and Publish an IPS Package</title><tasksummary><para>You can create several different types of IPS packages. As mentioned
previously, a package is a collection of files, directories, drivers, and
dependencies in a defined format. This task shows how to create a package
that consists of a directory, a file, a dependency, and a name attribute.
The package is then published to the repository by using the <citerefentry><refentrytitle>pkgsend</refentrytitle><manvolnum>1</manvolnum></citerefentry> command.</para><note><para>This example publishes the packages to the default repository, <literal>http://localhost:10000</literal>. If you are publishing a package to a repository
other than the default repository, ensure that the repository is created and
use the <option>s</option> option with the <citerefentry><refentrytitle>pkgsend</refentrytitle><manvolnum>1</manvolnum></citerefentry> command to specify the repository. </para>
</note>
</tasksummary><taskprerequisites><para>Read the section <olink type="auto-generated" targetptr="actions" remap="internal">Actions in IPS</olink> and become familiar with actions
and the attributes of each action.</para>
</taskprerequisites><procedure><step><para>Create a temporary directory on your system.</para><para><command>$
mkdir <replaceable>my_tmp</replaceable></command></para>
</step><step><para>Change the directory to the temporary directory.</para><para><command>$ cd / <replaceable>my_tmp</replaceable></command></para>
</step><step><para>Create a directory called <replaceable>my_package</replaceable>.</para><para><command>$ mkdir <replaceable>my_package</replaceable></command></para>
</step><step><para>Change the directory to <replaceable>my_package</replaceable>.</para><para><command>$ cd <replaceable>my_package</replaceable></command></para>
</step><step><para>Create a text file under the directory <replaceable>my_package</replaceable>.</para><para><command>$ vi <replaceable>my_text_file</replaceable></command></para><note><para>The files can be of any type. This example uses a text file.</para>
</note>
</step><step><para>Export the directory <replaceable>my_package</replaceable>. Specify
a version number and a sub-version number for the package. In this example,
the <replaceable>my_package</replaceable> has a version number of 1.0 and
a sub-version number of 1. Note the <emphasis>back quotes</emphasis> used
in this command.</para><para><command>$ eval `pkgsend open <replaceable>my_package@1.0-1`</replaceable></command></para><note><para>Specify the package name, version number and sub-version number
correctly. This cannot be changed afterward.</para>
</note>
</step><step><para>Add attributes to the package. In this task you add a directory
action with attributes of mode, owner, group, and path. Path is the key attribute
for the directory action and must be specified.</para><para><command>$ pkgsend
add dir mode=<replaceable>0555</replaceable> owner=<replaceable>root</replaceable> group=<replaceable>bin</replaceable> path=<replaceable>/etc/my_package</replaceable></command></para>
</step><step><para>Add the file <replaceable>my_text_file</replaceable> under the <replaceable>my_package</replaceable> directory.</para><para><command>$ pkgsend add file <replaceable>my_package/my_text_file</replaceable></command></para>
</step><step><para>Add attributes to the file. In this example, you add the file
action with the attributes of mode, owner, group, and path. Path is the key
attribute for the file action and has to be specified.</para><para><command>$
pkgsend add file <replaceable>my_package/my_text_file</replaceable> mode=<replaceable>0555</replaceable> owner=<replaceable>root</replaceable> group=<replaceable>bin</replaceable> path=<replaceable>/etc/my_package</replaceable></command></para><note><para>Actions can also be included in a file. This file can then be <emphasis>added</emphasis> to the current transaction by using the <command>pkgsend
include</command> command.</para>
</note><note><para>The <literal>path</literal> attribute specifies the directory
where the file will be created. This path should exist on the IPS client,
although it can be different from the file's location on the IPS server.</para>
</note>
</step><step><para>You have now created a package, <replaceable>my_package</replaceable>,
consisting of a directory and a file.</para>
</step><step><para>Add a dependency for this package and set a <literal>name</literal> attribute.</para><para><command>$ pkgsend add depend fmri=pkg:/depends_on_this_package@1.0-1
type=require</command></para><para><command>$ pkgsend add set name=description value="Example Package"</command></para><note><para>If the resources have been specified in a file, use the <command>pkgsend
include <replaceable>resource_filename</replaceable></command> command <emphasis role="strong">instead</emphasis> of the <command>pkgsend add</command> command
to add the resources to the current transaction.</para>
</note>
</step><step><para>Use the following option to close the transaction.</para><para><command>$ pkgsend close</command></para>
</step>
</procedure><example><title>Creating and Publishing a Simple Package</title><para>This example uses the <command>pkgsend</command> command to create and
publish a package.</para><screen>$ eval `pkgsend open my_package@1.0-1`
$ pkgsend add file my_package mode=0555 owner=root group=bin\
 path=/usr/bin/my_package
$ pkgsend close</screen>
</example><taskrelated-custom><title>Tagging Your XML Manifest File</title><para>If you have specified the actions and resources for a package in an
XML file, also called the manifest, you can <emphasis>tag</emphasis> the manifest
file to instruct additional services either before or after the package is
installed.</para><para>For example, you can instruct a package to start an SMF service when
it is installed and stop the SMF service when the package is uninstalled.
Use the <command>pkgsend</command> command to tag your xml manifest file in
the following way:</para><para><command>$ pkgsend add set restart_fmri=svc:/system/manifest-import:default <replaceable>xml_manifest</replaceable></command></para>
</taskrelated-custom>
</task><task id="pubpkg2"><title>How to Publish SVR4 Packages to Your Repository</title><tasksummary><para><literal>SVR4</literal> packages can be installed directly on your system
by using <citerefentry><refentrytitle>pkgadd</refentrytitle><manvolnum>1M</manvolnum></citerefentry> and related commands. To learn more about the <literal>SVR4</literal> packaging
commands, see the <ulink url="http://docs.sun.com/app/docs/doc/817-0406" type="text"><citetitle>Application Packaging Programmer's Guide</citetitle></ulink>.</para><para> <literal>SVR4</literal> packages can be published to the IPS repository
by using the <command>pkgsend(1)</command> command.</para><note><para>This examples publishes the packages to the default repository, <literal>http://localhost:10000</literal>. If you are publishing a package to a repository
other than the default repository, ensure that the repository is created and
use the <option>s</option> option with the <command>pkgsend(1)</command> command
to specify the repository. </para>
</note>
</tasksummary><taskprerequisites><para>To become familiar with the extent and limitations of the command, see <olink type="auto-generated" targetptr="pkgsend" remap="internal">pkgsend(1)</olink>.</para>
</taskprerequisites><procedure><step><para>Open the transaction.</para><para>eval `<command>pkgsend open <replaceable>svr4pkg</replaceable></command>`</para>
</step><step><para>Include the manifest associated with the SVR4 package.</para><para><command>pkgsend include <replaceable>ips-manifest-with-metadata</replaceable></command> </para>
</step><step><para>Import the package.</para><para><command>pkgsend import <replaceable>svr4pkg</replaceable></command> </para>
</step><step><para>Close the transaction.</para><para><command>pkgsend close</command></para>
</step>
</procedure>
</task>
</sect1>
</chapter>