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);
These are the installation phases, in the order they are executed:
The following variables are exposed to the scripts:
When writing the script, three other variables must be defined as well:
You can check the API docs here.
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 copies the files from $workDir/$name-$version into the $installDir. Ideally, it would also create symlinks if required and any other installation step.
The uninstall should cleanup the steps done during install. For instance, if symlinks were created, then they should be removed.
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}") } } }