Hello World Example

The following example demonstrates the basic life cycle of a package that is published and installed using the Image Packaging System. The example demonstrates how the pkgsend command can be used to publish a package, the pkg.depotd server can be used to house a repository containing the package and the pkg command can be used to both create an area in which to install the package and to install the package.

This example is for Unix platforms and assumes the use of bash(1) or ksh(1) or any other shell that supports export syntax of the form: export foobar=123. There are notes about running this example on Windows at the end of the page.

Get the Software

The toolkit download page page provides the file that is needed to run this example. Choose the pkg-toolkit-*.zip file for your desired platform and unzip the file into a directory of your choice. Within the toolkit image, you can find the commands referenced in the example in the pkg-toolkit-<platform>/pkg/bin directory.

Starting a Repository Server

Before running the series of pkgsend commands, you will need to run a repository server to receive and store the package that is being published. Assuming that you created an empty directory named myrepo/ to house the repository's content, the following command will start the repository server:

pkg.depotd -p 10000 -d myrepo

Where -p represents the port on which the repository server will listen and -d represents the directory in which the repository content is stored.

See the pkg.depotd(1m) documentation for details.

Publishing a Package

Let's create a package called helloworld that contains two files, foo.txt and bar.txt in a directory called hello. Also, assume that the source files come from the current directory in foo.txt and bar.txt. A shell script that will create a package from these files is as follows:

#!/bin/bash
export PATH=<pkg_install_path>/pkg/bin:$PATH
touch foo.txt
touch bar.txt
export PKG_REPO=http://localhost:10000/
eval `pkgsend open helloworld@1.0`
pkgsend add set name=pkg.summary value='HelloWorld Package'
pkgsend add dir mode=0755 owner=nobody group=nobody path=hello
pkgsend add file foo.txt mode=0644 owner=nobody group=nobody path=hello/foo.txt
pkgsend add file bar.txt mode=0644 owner=nobody group=nobody path=hello/bar.txt
pkgsend close

This series of pkgsend operations represents a publishing transaction bounded by the open and close operations.

See the pkgsend(1) documentation for details.

Installing the Package

Before installing the package from the repository, you must first ensure that an Image Packaging System installation image is available to receive the package.

To create an image that is associated with the repository, do the following:

pkg image-create -U -a myrepo=http://localhost:10000 myimage

Execution of this command will create a directory named myimage which represents a self-contained "user" image. This image is empty in that it does not yet contain any packages. However, it does contain control files and other information that associates this image with your repository. The -a option argument represents an arbitrary name "myrepo" the client uses to refer to the repository and the URL used to access the package repository.

Now let's install the helloworld package into this image:

pkg -R myimage install helloworld

Where -R represents the location of the installation image. (The -R option is not necessary when you run the pkg command anywhere within the image).

The list subcommand can be used to see what packages are in the repository:

pkg -R myimage list -a

When pkg is executed without any arguments, it prints a usage message with more subcommands. You can also refer to the pkg(1) documentation for details.

Uninstalling the Package

To uninstall the package, use the uninstall subcommand:

pkg -R myimage uninstall helloworld

Trying Out the Example

If you would like to try this example on your own system, you can either download the Image Packaging System binaries or, if you are running OpenSolaris, you can simply use the pkgsend, pkg.depotd and pkg tools that are part of OpenSolaris.

Running the Example on Windows

The example contains some constructs that are specific to a Unix shell.  If using a command prompt on Windows, those functions are not available so alternate syntax is required. 

When publishing a package, use the following syntax to set the transaction identifer that is returned by pkgsend open:

type foo > foo.txt
type bar > bar.txt
set PKG_REPO=http://localhost:10000/
pkgsend open -n helloworld@1.0 >trans.txt
set /P PKG_TRANS= <trans.txt
erase trans.txt
pkgsend add set name=pkg.summary value='HelloWorld Package'
pkgsend add dir mode=0755 owner=nobody group=nobody path=hello
pkgsend add file foo.txt mode=0644 owner=nobody group=nobody path=hello/foo.txt
pkgsend add file bar.txt mode=0644 owner=nobody group=nobody path=hello/bar.txt
pkgsend close

If you want to use this within a BAT script, then the pkgsend commands must be prefixed with "call" because pkgsend is itself a BAT script.

The remainder of the example works on Windows as well as Unix.

What Next?

Please see the Examples page for more examples. There is also documentation available for creating packages, assembling install bundles, and running repositories. This documentation contains information about other types of actions and on how to handle configuration.















Confluence User's Guide
Plugins Available

Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.
  1. Oct 10, 2008

    tj_yang says:

    minor editing to correct the errors. Let's create a package called helloworld ...

    minor editing to correct the errors.

    Let's create a package called helloworld that contains two files, foo and bar in a directory called hello. Also, assume that the source files come from the current directory in foo.txt and bar.txt. A shell script that will create a package from these files is as follows:

    mkdir hello
    touch hello/foo.txt
    touch hello/bar.txt
    export PKG_REPO=http://localhost:10000/
    eval `pkgsend open helloworld@1.0`
    pkgsend add set name=pkg.summary value='HelloWorld Package'
    pkgsend add dir mode=0755 owner=nobody group=nobody path=hello
    pkgsend add file hello/foo.txt mode=0644 owner=nobody group=nobody path=hello/foo.txt
    pkgsend add file hello/bar.txt mode=0644 owner=nobody group=nobody path=hello/bar.txt
    pkgsend close

    1. Jul 08

      TomMueller says:

      The existing example works without having the hello subdirectory. The source of...

      The existing example works without having the hello subdirectory. The source of the files for the pkgsend command does not have to be the same as the destination "path" that is specified in the file action.

      Was there a specific error that you encountered when running the example?

  2. Oct 10, 2008

    tj_yang says:

    please include a uninstall example, like following. -bash-3.2# pkg -R myimage ...

    please include a uninstall example, like following.

    -bash-3.2# pkg -R myimage uninstall helloworld
    PHASE ACTIONS
    Removal Phase 7/7
    PHASE ITEMS
    Reading Existing Index 9/9
    Indexing Packages 1/1
    -bash-3.2#

    1. Jul 08

      TomMueller says:

      To keep this example as simple as possible, I didn't show the output of any of t...

      To keep this example as simple as possible, I didn't show the output of any of the commands. There is an uninstall example now.

  3. Oct 13, 2008

    tj_yang says:

    Also we need more helloworld examples helloworld2: to demonstrate more actions...

    Also we need more helloworld examples
    helloworld2: to demonstrate more actions beside,set,dir and file.

    no-pkg-script is IPS's policy but please provide examples to show packager to achieve the same goal without writing personal pkg scripts.

    1. Jul 08

      TomMueller says:

      Please see the Examples pages for more examples. There is also documentation ava...

      Please see the Examples pages for more examples. There is also documentation available for creating packages, assembling install bundles, and running repositories. This documentation contains information about other types of actions and on how to handle configuration.

Sign up or Log in to add a comment or watch this page.


The individuals who post here are part of the extended Sun Microsystems community and they might not be employed or in any way formally affiliated with Sun Microsystems. The opinions expressed here are their own, are not necessarily reviewed in advance by anyone but the individual authors, and neither Sun nor any other party necessarily agrees with them.

Copyright 1994-2009 Sun Microsystems, Inc.
Powered by Atlassian Confluence
Sun Guidelines on Public Discourse Privacy Policy Terms of Use Trademarks Site Map Employment Investor Relations Contact