Scripting - Chapter 1: Getting to know Bash

From PlayOnLinux
Revision as of 20:35, 26 February 2015 by RoninDusette (talk | contribs)
Jump to: navigation, search

Introduction

You would like to create your own scripts for PlayOnLinux but you don't know squat about programming? This tutorial will explain the basics and you'll soon be a pro in playonlinuxian Bash.

Bash?

Bash is a command interpretor (or "shell") in GNU/Linux and Mac OS X. It's the one appearing when you launch a terminal. It also allows you to make scripts. A script is a list of commands that your shell will execute one after the other. PlayOnLinux has advanced functions in Bash to make the scripting process easier. Let's get acquainted with them.

Requirements of every script

Every PlayOnLinux script must contain this boilerplate code:


  1. #!/bin/bash
  2. [ "$PLAYONLINUX" = "" ] && exit 0
  3. source "$PLAYONLINUX/lib/sources"
  4. POL_SetupWindow_Init
  5. POL_SetupWindow_Close
  6. exit


The above code may not make sense to you yet. We will explain what it does as we go.

During this tutorial, I will not repeat this code over and over in the examples, as you will need it in every script. Remember to always include it, otherwise your script won't work.

NOTE: Do not copy the line numbers to the script. It is recommended to type it out by hand while learning, as opposed to copying and pasting, so as to become more familiar with the scripting language.

Executing your script

Ask your favourite text editor to save your script, then use the function Run a local script from the Tools menu of PlayOnLinux.

Scripts signing

PlayOnLinux uses digital signing (authentication) on scripts to certify that scripts have been validated by PlayOnLinux scripters. All the scripts available from the Install window of PlayOnLinux are validated. Each time you will try to run a script that has not been validated by PlayOnLinux scripters, you will get a warning message telling you that the script has no valid signature (see screenshot below).

ch01-01.en.png

You must click on Next button to get PlayOnLinux to show you the script source, then click on the I Agree checkbox, before you can (finally) run the script (see screenshot below).

ch01-02.en.png