The Script File

The script file is what SDM interprets and run to install or uninstall a package.

The script is, basically, a Groovy file that extends BinaryPackage and implements one or more of the following methods:

        void fetch(final String url);
        void extract(final String artifactName);
        void prepare();
        void verify();
        void install();
        
        void uninstall(final String path);

Phases

These are the installation phases, in the order they are executed:

  • Fetch: downloads the components of the package. The URL is passed as a parameter to the phase method.
  • Extract: extracts the artifact of the package. The full path to the artifact is passed as a parameter to the method
  • Prepare: runs any pre-build preparation steps.
  • Builds: builds the package, if necessary.
  • Verify: verify the build, if necessary.
  • Install: installs the package, from the work dir to the install dir.
  • Uninstall: this phase is run during package removal. It responsible for cleaning up the package installation.

Variables

The following variables are exposed to the scripts:

  • $installDir: this is the installation directory. By default, it is set to $HOME/software, however this can be set in sdm.properties and point to whatever the user want.
  • $workDir: this is the work directory - the path where the files are downloaded and extracted. By default it points to the $TMPDIR/work and can also be set in the sdm.properties file.

    When writing the script, three other variables must be defined as well:

  • version: the version of the package
  • name: the name of the package (must match the package directory name)
  • url: the URL to the download. Ideally, it should use $name and $version to reference the package name and version, so it's easier to bump them when new versions are released.

The API

You can check the API docs here.

Unpack

By default, SDM will try to unpack the file for you. It considers that the package will unpack itself to $workDir/$name-$version (ie.: /tmp/work/groovy-2.1.1). If that's not the case for your package, then you need to implement your own unpack method. For instance, a package that extracts the files in the same directory would end up with their files in $workDir instead of $workDir/$name-$version. To resolve this, you would have to create the dir, and then call unpack into that directory. Here's an example:

        void extract(String artifactName) {
                def tempWorkDir = "${workDir}/${name}-${version}"
                
                
                // Creates the ${workDir}/${name}-${version}
                mkdir("${tempWorkDir}")
                
                // Unpacks the artifact straight into the ${workDir}/${name}-${version}
                unpack(artifactName, ${tempWorkDir}")
        }

Install

Install copies the files from $workDir/$name-$version into the $installDir. Ideally, it would also create symlinks if required and any other installation step.

Uninstall

The uninstall should cleanup the steps done during install. For instance, if symlinks were created, then they should be removed.

Sample Script

This is what a script looks like:

import net.orpiske.sdm.packages.BinaryPackage;

import static net.orpiske.sdm.lib.OsUtils.*;
import static net.orpiske.sdm.lib.io.IOUtil.*;
import static net.orpiske.sdm.lib.Core.*;
import static net.orpiske.sdm.lib.Executable.*;

class ApacheMaven extends BinaryPackage {
        def version = "3.0.5"
        def name = "apache-maven"
        def url = "http://apache.mirror.pop-sc.rnp.br/apache/maven/maven-3/${version}/binaries/apache-maven-${version}-bin.tar.gz"
        
        void install() {
                // Protects the file from being overwritten during reinstall
                shield("${installDir}/${name}-${version}/conf/settings.xml")            
                
                
                // Installs ${workDir}/${name}-${version} into ${workDir}
                performInstall("${name}", "${version}")
                
                // If is a Unix-like system ...
                if (isNix()) {
                
                        // ... then create symlinks
                        println "Creating symlinks"
                        exec("ln", "-sf ${installDir}/${name}-${version} ${installDir}/${name}")
                }
        }
        
        void uninstall(String path) {
                if (isNix()) {
                        println "Removing symlinks"
                        exec("unlink", "${installDir}/${name}")
                }
        }
}