InstallAnywhere White Paper Unix Installations

9
WHITE PAPER Shell vs. Java: Overcoming the Challenges of Shell Scripting for UNIX Installations

description

InstallAnywhere White Paper Unix Installations

Transcript of InstallAnywhere White Paper Unix Installations

Page 1: InstallAnywhere White Paper Unix Installations

WH

ITE

PA

PE

R Shell vs. Java: Overcoming the Challenges of Shell Scripting for UNIX Installations

Page 2: InstallAnywhere White Paper Unix Installations

Shell vs. Java: Overcoming the Challenges of Shell Script ing for UNIX Installat ionsIntroduct ionA shell is a command-line interpreter that takes and executes commands, and in doing so, implements a programming language commonly referred to as “shell script ing.” Shell script ing is tradit ionally used by UNIX system administrators to automate the execut ion of system tasks, but developers also use shell scripts to create enterprise-level software installat ions, and that is where problems occur.

This white paper highlights the major difficult ies with attempting to develop UNIX installat ions using shell scripts. It focuses on shell script ing as a language and how it is used in the context of UNIX installat ion development. It also discusses how Java is being used as a successful alternat ive to shell script ing for enterprise installat ions.

Finally, this white paper details how the tools in InstallAnywhere®, the mult i-plat form installat ion tool from Flexera Software, can help developers overcome the inherent problems with shell script ing and create high-quality mult i-plat form installat ions ideal for enterprise environments.

UNIX Installat ions: The Tar-Ball ArchiveMost UNIX shell-based installat ions are constructed using a “tar-ball” (tar archive) paradigm. A tar file is delivered whose contents include a shell script and the files to be installed. For the most part the files are stored in a structure mimicking that of their final dest inat ion. This potent ially means that a single copy (cp) command is invoked to copy the ent ire directory to the home directory. All necessary configurat ions are done with the help of commands such as “sed”, “awk”, and so on. The user interface provided is console only.

By and large, the above scenario is acceptable for simple applicat ions. However, it becomes very hard to follow when even the most straightforward enterprise installat ions are attempted. If the installat ion you are attempting to construct is required to configure applicat ion servers, databases, or

Web servers, shell-based installat ions are rarely a viable delivery option. This delivery mechanism becomes more difficult when you reanalyze how the tar archive is built. The configurat ion management team has to produce a directory structure that will mimic the final dest inat ion.

In addit ion, it is well known that tar-ball installat ions are not user-friendly to regular users. This is due to the absence of visually guided installat ions, as is the accepted standard for Windows applicat ions. As a result, they often introduce barriers to user adoption of applicat ions, and may even cause problems with the installat ion and maintenance of the applicat ions.

UNIX Installat ions: The Way They Ought to BeInstallat ions, regardless of the targeted operat ing system, should be easier to implement. The “tar-ball” file archive structure should not be decided upon by the build system. This should be loosely packaged so that the installat ion can make the final decision on how the final file structure should look.

The installat ion technology used should be based on a more robust language with built-in parsing capabilit ies for XML, Java propert ies files, and so on. Finally, the installat ion should give the user the option of running the installat ion in a graphical mode.

Ult imately, customers and installat ion developers want the same thing, a robust installat ion system. However, their perspect ive is different. The customer cares about the final product, whereas the developer cares about the development environment needed to produce UNIX installat ions. The following lists are a subset of requirements as demanded by customers and installat ion developers.

For customers: • Ease of use – Most customers want an easy way to

interact with an installat ion, preferably one that is visually guided, such as those offered by Windows.

2 Flexera Software: InstallAnywhere White Paper Series

Page 3: InstallAnywhere White Paper Unix Installations

Shell vs. Java: Overcoming t he Challenges of Shell Script ing for UNIX Installat ions

3Flexera Software: InstallAnywhere White Paper Series

• Single point of init iat ion – An end user attempting to invoke your installat ion should not be confronted by a plethora of installat ion options. A single nat ive launcher should suffice.

• Native look and feel – It is important that users receive an installat ion that looks and feels like any other applicat ion targeted for that part icular operat ing system.

• Get the product installed – The ult imate goal of the installat ion is to get the product installed and configured.

For installat ion developers:

• Single point of development – A true cross-plat form development plat form that would allow the developer to maintain a single code base for numerous plat forms.

• The development environment should use a familiar language, preferably object oriented – To allow extensibility, the installat ion development tool should enable the developer to extend it.

• Operating system abstract ion – When developing cross-plat form installat ions, the developer should focus on product installat ion and configurat ion tasks and not how each operat ing system works.

Analyzing the Shell Script ing EnvironmentThe concept of shell script ing was introduced to help system administrators automate low-level shell commands. For a long t ime most companies have used shell scripts as delivery mechanisms (that is, installat ions), which, for the most part, worked well. Since shell scripts are delivered in clear, readable ASCII, they can potent ially expose implementat ions that can pose as security holes.

Unfortunately, that is not the only weakness shell script ing exposes. The following sect ions highlight why shell script ing does not scale when enterprises attempt to use it as an installat ion development plat form. The Development EnvironmentShell is littered with hard-to-understand regular expressions and lacks a true integrated development environment (IDE). It often takes a truly senior UNIX developers to properly handle such complex script ing environments. Consider the following syntax:

CURRENT_USER=`whoami | awk ‘{print $1}’` if [ “$CURRENTUSER” != “root” ] && [ “$CURRENT_USER” != “admin” ]; then printf “To install, you need admin rights\n” | tee -a install.log fi

If you take a closer look, you will not ice how awkward the if-statement really is. If you play with the white-spacing in the if-statement, you may receive an error similar to this one:

./install.sh: line 2: [CURRENT_USER: command not found]

Although this may not seem like a big problem, imagine what would happen if someone in the field ran your

installat ion and received the same error. Only this t ime the error occurs at line 4559. Debugging is not available unless you type:

% sh -x install.sh

The above does not yield results that someone with limited shell-script ing knowledge can understand.

The problem is worsened when the script contains a statement similar to myvar=`cat $1`. If $1 is not init ialized, the script will be stuck. Of course, a diligent programmer doesn’t allow this to happen, but if it does happen, debugging can be a nightmare.

Other issues with the script come to light when you consider the problems associated with localizat ion and permissions (“To install, you need admin rights\n”), and dealing with a nonstandard logging (to install.log) mechanism.

The point of this exercise was to show how difficult it can be to develop elaborate enterprise installat ions using shell.

InteroperabilityEven though shell was never intended for large development, shell script ing is sometimes used to create large installat ion projects, such as enterprise installat ions. These installat ions need to direct ly communicate configurat ion sett ings to the product being installed. For shell-based installat ions, this is done using input files or the command line. Error handling, for the most part, is done using return codes.

Unfortunately, return codes are not always reliable. Sometimes a command may return 0 when in fact it should return anything but 0. Extra steps need to be taken to ensure reliability, which can turn into unnecessary complex if-statements that make interoperability all the more difficult.

Sharing CodeWhen developing large-scale enterprise installat ions, you can expect more than one developer to work on the same code. Your plan, of course, is to develop reusable libraries that can be used across the installat ion system. However, shell was not designed with that in mind. Shell is for the most part used to automate administrat ion tasks such as “empty the temp space” or “manage users.” It was designed to deal with low-level tasks, not code sharing.

PortabilityNot all UNIX environments are created equal. Some commands work in every UNIX environment; some do not. Sometimes commands such as “pidof” do not exist in environments other than Linux. Furthermore, some ut ilit ies do not share the same command-line arguments across all UNIX implementat ions. Besides, would you like to learn all the command-line options offered by UNIX commands such as “ls”? To account for portability, a great deal of code must be written.

Page 4: InstallAnywhere White Paper Unix Installations

Shell vs. Java: Overcoming t he Challenges of Shell Script ing for UNIX Installat ions

Flexera Software: InstallAnywhere White Paper Series4

Parsing AbilityShell was written long before SGML technologies such as XML were available. Therefore, its abilit ies for parsing such formats are based on regular expressions. For the most part, regular expressions are hard to write and even harder to debug. To consider writ ing regular expressions for parsing XML would put you in the business of building XML parsers from scratch. Modern languages such as Java and C++ have XML parsers built-in.

Parsing becomes more of a problem when unknown formats are met. New regular expressions must be built, or you could write a native executable using C/C++ to do the job. Once again, interoperability becomes quest ionable.

The Linux FactorWith the introduct ion of Linux, a large number of non-UNIX users entered the UNIX arena. From a strategic point of view, it gives a large number of users the chance to diversify. On the other hand, most of these new users come from GUI-driven operat ing systems, and they want everything be done with graphical tools. But shell-based installat ions are made to be console-driven – no graphical interface.

Mac OS XMac OS X is further proof that UNIX is becoming more accepted as a graphical operat ing system. Besides making Mac OS X the most opt imized UNIX environment to run Java, Apple has made Java an integral part of Mac OS X, which is good news if your strategy is to create Java-based installat ions. But shell-based installat ions must once again take a back seat. Java-Based Installat ions If not shell script ing, what then is a feasible alternat ive technology for developing cross-plat form installat ions? What about Java? Its “write once, run everywhere” makes it an ideal technology for target ing platforms such as UNIX. Java transforms the installat ion development into a more robust environment.

To appreciate the power of Java to extend an installat ion, consider an example. The following is a simple Java class that computes a t ime stamp and stores the result in a custom InstallAnywhere variable.

import com.zerog.ia.api.pub.*; import java.ut il.*;

public class GenerateTimeStamp extends CustomCodeAction {

public void install(InstallerProxy ip) {

// compute t ime stamp with Java... String now = new Date( ).toString( ); // ...and set a custom variable to the value ip.setVariable(“$NOW$”, now);

}

public String getInstallStatusMessage( ) { return “Computing t ime stamp...”; }

public void uninstall(UninstallerProxy up) { /* do nothing on uninstall */ }

public String getUninstallStatusMessage( ) { return “...”; } }

First and foremost, the above code is standard Java code. In addit ion to being able to use standard Java funct ionality, Java code can use JNI to call in to nat ive code. The interest ing thing about JNI is the fact that as far as the Java developer is concerned, the JNI call is just another Java call.

Worth not icing is also the exception handling offered by Java. Logging is another powerful Java feature. To facilitate readability, logging information can be categorized by severity and the output can be formatted as XML, which in turn can be transformed into HTML so that customers can view install logs in a readable format.

Java has emerged as a very popular technology, and for good reasons. Most educators have embraced Java as their teaching language of choice, creat ing a large pool of Java developers. The attract iveness of Java as a “write once, run everywhere” language has certainly been another contribut ing factor to its popularity.

Another strong support ing argument for Java-based installat ions is that numerous companies deploy applicat ion servers such as IBM® WebSphere®, BEA® WebLogic®, Sun® Java Enterprise System, or JBoss. For scalability and reliability purposes, these are most ly deployed on the UNIX platform and are Java-based.

Most applicat ion servers expose Java configurat ion APIs. This allows for a seamless integrat ion strategy that can ult imately give users an out-of-the-box delivery solut ion. The interest ing point here is that “write once, run everywhere” becomes an attainable reality.

As an alternat ive to shell script ing, however, Java requires addit ional help before it can be considered as a logical successor. A reliable, user-friendly Windows-like setup experience would be a great thing to have for UNIX developers. The ability to target UNIX and Windows plat forms with a Java-based applicat ion install would be even better, especially given how difficult it is to accomplish this with shell script ing.

For the developer with lots of experience with tar-balls and crypt ic script commands, any alternat ive needs to offer clear and compelling benefits. The balance of this paper will offer just such an argument, based on the capabilit ies of InstallAnywhere from Flexera Software.

Page 5: InstallAnywhere White Paper Unix Installations

Shell vs. Java: Overcoming t he Challenges of Shell Script ing for UNIX Installat ions

5Flexera Software: InstallAnywhere White Paper Series

Building Mult i-Platform Installat ions with InstallAnywhereInstallAnywhere from Flexera Software provides an out-of-the-box Java-based installat ion solut ion. Developing cross-plat form installat ions with Java and InstallAnywhere’s mult i-platform installat ion IDE provides many benefits, including making it easy to:

• Tight ly integrate installat ion development into the development department

• Conceal code so that proprietary implementat ions are kept safe

• Create installat ions that can be extended and developed using Java technologies

With InstallAnywhere, developers can build installers for all supported platforms from a single project. InstallAnywhere’s capabilit ies (highlighted below) make it the ideal tool for quickly developing industrial-strength installers.

Rapid Prototyping with the Project WizardDevelopers can build their first installer in less than five minutes with InstallAnywhere’s six-step Project Wizard. This intuit ive design tool also sets the class path and finds the main class for a Java applicat ion automatically. When you complete the Project Wizard steps, the result is an installer project that targets a number of major operat ing systems.

This working prototype is inline with management demands that prototypes be produced early in the development process. The development process demands that the installat ion be integrated early so that test ing can be performed in a more realist ic environment.

This, for the most part, means that the installat ion should have the capability to run in graphical mode and have a consistent look and feel regardless of the operat ing system. InstallAnywhere contains many tools that make rapid prototyping a reality.

Customizing Projects in the Advanced DesignerThe InstallAnywhere Advanced Designer has an intuit ive,

graphical interface, which allows developers to manage all aspects of their installer project. All the features of InstallAnywhere are available in this easy to use integrated development environment.

Advanced Designer TasksThe Advanced Designer is divided into tasks that are represented by tabs found along the left-hand side of the window. Each of the following tabs represents tasks and sett ings specific to each installat ion project:

• Project: Sett ings related to your specific project. These include general sett ings, file sett ings, and localizat ion sett ings.

• Installer UI: Set the look and feel for the installer by adding background images, billboards, and other graphical components.

• Organization: Manages Install Sets, Features, Components, and Merge Modules.

• Pre-Install: An ordered sequence of panels and actions that occur before file installat ion.

• Install: Manage File installat ion tree and install t ime act ions.

• Post-Install: An ordered sequence of panels and act ions that occur after file installat ion.

• Pre-Uninstall: An ordered sequence of panels and actions that occur before file uninstallat ion.

• Post-Uninstall: An ordered sequence of panels and actions that occur after file uninstallat ion.

• Build: Manage build sett ings, including bundling of a Java Virtual Machine.

Each Advanced Designer task contains sub-tabs that offer greater fine-tuning of InstallAnywhere’s features.

Action-Based InstallersActions, which represent the operat ions the installer performs, are the fundamental elements of InstallAnywhere installers. InstallAnywhere supports an extensible act ion architecture that provides the ability to perform addit ional operat ions during installat ion, such as installing files and folders, creat ing shortcuts, execut ing custom code, or extract ing the contents of a compressed file. Some frequent ly used act ions include Install File, Create Folder, Create Alias, Link, Shortcut, Execute Target File, Execute Command, and Expand Archive.

Learn More about InstallAnywhereIf you wish to learn more about the capabilit ies of InstallAnywhere, please visit the Flexera Software Web site at www.flexerasoftware.com/installanywhere.

Page 6: InstallAnywhere White Paper Unix Installations

Shell vs. Java: Overcoming t he Challenges of Shell Script ing for UNIX Installat ions

Flexera Software: InstallAnywhere White Paper Series6

Components, Features, and Install SetsComponents, features, and install sets are organizational concepts in the InstallAnywhere IDE. They allow installer developers to add structure to the files and act ions their installers employ and determine what feature choices end users have during the install.

Components are an organization unit installer developers can use to group files and act ions; however, components are internal organization units that are never shown to the end user. Conversely, features can group one or more components, files, and act ions into combinations from which the installer end users can choose. And groups of features can be combined into install sets—a convention that allows end users to choose options like Minimal, Typical, or Full Install.

While developers working with relat ively simple installers can rely on InstallAnywhere to generate basic components, features, and install sets automatically, more advanced developers take control of components, features, and install sets to organize their installer resources in the Advanced Designer.

Rules and VariablesInstallAnywhere keeps track of dynamic values using variables. Almost every dynamic value in InstallAnywhere is represented by an InstallAnywhere variable. Variables may be modified or accessed in order to affect the design or output of an installer; they can also be modified during the progress of the installer in order to change the installer’s behavior.

InstallAnywhere uses variable-based Boolean rules to control most aspects of installer behavior. Rules can be applied to any act ion within the InstallAnywhere installer, as well as to organizational units such as Install Sets, Features, and Components. Rules commonly direct the execut ion of plat form-specific act ions on the target system, but they may check other condit ions such as system architecture, file and folder attributes, and user-chosen language. Rules can also be used to compare the values of two InstallAnywhere variables, match a regular expression, or to execute a custom coded rule. (InstallAnywhere Enterprise edit ion also includes rules specific to System i (i5/OS).)

Build and TryInstallAnywhere users can quickly examine the results of their project changes by building installers from the project and running the result ing installer with the click of a button. In addit ion, InstallAnywhere includes several built in features for previewing and debugging your installers and installer panels.

Get User Input PanelsInstallAnywhere provides many panels for displaying information to the user and collect ing user information. Moreover, InstallAnywhere includes the Get User Input - Simple and Get User Input - Advanced panel act ions. These act ions enable you to build custom panels by insert ing text-display and user-input controls into the Get User Input panel.

InstallAnywhere provides the architecture to capture the user input from these panels to InstallAnywhere variables. For requirements that exceed the Get User Input panel’s features, you can code custom panels that share the dimensions, images, navigation buttons, and other elements used by built-in panels.

LaunchAnywhere LaunchersCreate launchers that look and behave like the operat ing system your installat ion is running on. Your end users are accustomed to a part icular behavior. Windows users are quite familiar with the ubiquitous installer.exe concept. InstallAnywhere LaunchAnywhere launchers extend that philosophy to all of its supported platforms.

Page 7: InstallAnywhere White Paper Unix Installations

Shell vs. Java: Overcoming t he Challenges of Shell Script ing for UNIX Installat ions

7Flexera Software: InstallAnywhere White Paper Series

A LaunchAnywhere launcher is a unique executable that launches a Java applicat ion on Windows, UNIX (including Solaris, Linux, HP-UX, AIX, BSD, and others), and Mac OS X platforms. On Windows, LaunchAnywhere technology creates double-clickable icons that invoke a Java applicat ion. For Mac OS X, it generates applicat ion bundles. On UNIX platforms, end users type a simple command to launch the applicat ion.

LaunchAnywhere technology sets the classpath, redirects stdout and stderr, passes in system propert ies and command-line parameters, and performs other configurat ion funct ions. For graphical users a Web-based applet installat ion is also available. This further simplifies the distribut ion model of your product.

Customizing and Extending InstallAnywhereAdvanced installer developers or development teams that need to build complex installers can take advantage of a host of enterprise-strength features:

• Merge Modules: Essent ially installer sub-projects that can be created independent ly of one another and later merged together, merge module are reusable collect ions of installat ion funct ionality. A Merge Module is just like an installer, complete with features, components, panels, act ions, and files. However, a Merge Module cannot be installed without being part of an InstallAnywhere project; instead, use Merge Modules to include the funct ionality of one installer within another installer.

• Support for Deployment to Applicat ion Servers and Database Servers: InstallAnywhere supports installers that target applicat ion servers (such as Geronimo, JBoss, Resin, Sun Applicat ion Server, Tomcat, WebLogic, and WebSphere) and database servers (such as MySQL, Oracle, MS SQL Server, and DB2).

• Team Development Features: InstallAnywhere supports team-based installer development with source paths. Source paths allow developers to reference file resources using variable paths instead of absolute paths. This allows team members to share a project file even when file resources are located at different paths on their development systems.

• Custom Code: With InstallAnywhere’s API, developers can write custom Java code that runs in the same Java VM as InstallAnywhere, creat ing custom act ions,

custom panels, custom consoles, and custom rules that interact with and extend InstallAnywhere funct ionality.

Custom Dialog BoxesInstallAnywhere provides many built-in dialog boxes for displaying information to the user and collect ing user information. Moreover, InstallAnywhere’s Get User Input panels enable you to build up custom dialog boxes by insert ing text-display and user-input components into a standard dialog box frame. For more sophist icated user-interface requirements, you can create custom panels that share the dimensions, images, navigation buttons, and other elements used by built-in panels.

Shell RevisitedAs mentioned earlier, shell script ing was intended for system administrat ion. To that end, some scripts are worth keeping. InstallAnywhere facilitates launching exist ing shell scripts (even the ones that take command line arguments). Since most shell scripts are processed through /bin/sh (the first line in a shell script, the shebang—i.e., #!/bin/sh—tells you who is going to process the script), shell scripts can also be launched through Runt ime.exec. This command returns a Process object, which in turn can return the exit value from the sh process.

Powered by JavaInstallAnywhere is powered by Java. Java is a full-fledged, object-oriented language. Its cross-plat form capabilit ies make it the perfect engine for InstallAnywhere.

Besides the common tasks supplied by InstallAnywhere, you might want to add custom tasks that do not fit the ordinary. Since InstallAnywhere is powered by Java, you can extend its funct ionality in a number of ways.

• Create your own custom Java plug-ins: InstallAnywhere enables you to create custom act ions written in Java. You can refer to your custom code in a single project, or package it as an InstallAnywhere plug-in that can be used in mult iple projects.

• Use InstallAnywhere services: In addit ion to being able to call Java code from your custom code act ions, you can call methods from InstallAnywhere services. These services extend Java funct ionality with underlying native code. Example services are the System Utility Service, for working with environment variables and system startup commands; the Security Service, for working with users and groups; and the Win32 and Win32 Registry Services, for programmatically manipulat ing Windows services and the Windows registry.

• Java Native Interface (JNI): Although Java is a powerful language, some operat ing system APIs have not been mapped into the core language. JNI is intended to breach that gap. If necessary, you can implement custom funct ionality in a native library (a Windows DLL or UNIX shared library, for example) and call the native code from an InstallAnywhere custom code act ion.

Page 8: InstallAnywhere White Paper Unix Installations

Shell vs. Java: Overcoming t he Challenges of Shell Script ing for UNIX Installat ions

Flexera Software: InstallAnywhere White Paper Series8

Custom code development in Java is enhanced further when you consider the following:

• XML parsing: Java provides out-of-the-box XML parsing through standard parsing technologies such as DOM or SAX.

• Use any Java IDE: When writ ing InstallAnywhere custom code, you can use your own Java IDE.

• Unit test ing with JUnit: JUnit is a popular regression-test ing framework, and InstallAnywhere provides classes for integrat ing with JUnit.

• Coding standards: Create or extend exist ing common coding standards to accommodate the development of InstallAnywhere custom code.

SummaryThough shell script ing is being crit icized for its installat ion development capabilit ies, this white paper considers shell script ing a sound technology for UNIX system administrat ion. But for software development, shell scripts lack the robustness needed to create plat form independent installat ions. Java as a technology has matured to the point that creat ing Java-based installat ions has become the preferred method. Furthermore, technologies such as JDBC, CORBA, JNDI, and RMI, make Java-based installat ions the better candidate for target ing platforms such as UNIX.

Begin a Free Evaluat ion of InstallAnywhereYou can download a free trial version of InstallAnywhere from the Flexera Software Web site at: www.flexerasoftware.com/installanywhere/eval.

Want to learn more best pract ices for building quality installat ions? Join an InstallAnywhere training class – visit www.flexerasoftware.com/training for available classes.

Page 9: InstallAnywhere White Paper Unix Installations

WH

ITE

PA

PE

R

Flexera Software LLC1000 East Woodfield Road, Suite 400Schaumburg, IL 60173 USA

Schaumburg (Global Headquarters):+1 800-809-5659

United Kingdom (Europe, Middle East Headquarters):+44 870-871-1111+44 870-873-6300

Japan (Asia, Pacific Headquarters):+81 3-4360-8291

For more office locat ions visit:www.flexerasoftware.com

Copyright © 2011 Flexera Software LLC. All other brand and product names ment ioned herein may be the trademarks and registered trademarks of their respect ive owners. IA_WP_Shell_Oct11