Scripting - Chapter 1: Getting to know Bash
Contents
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:
#!/usr/bin/env playonlinux-bash #--~~~~ Needs update [ "$PLAYONLINUX" = "" ] && exit 0 source "$PLAYONLINUX/lib/sources" POL_SetupWindow_Init POL_SetupWindow_Close 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.
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.
Script 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).
PlayOnLinux Wizard Run a local script
Warning!!
The signature of the script you are trying to run is NOT valid.
PlayOnLinux has not approved this script and will not be responsible for it. Please ensure you know what you are doing!
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).
PlayOnLinux Wizard Run a local script
Here is the source code of the script. Check it carefully:
#!/usr/bin/env playonlinux-bash [ "$PLAYONLINUX" = "" ] && exit 0 source "$PLAYONLINUX/lib/sources" POL_SetupWindow_Init POL_SetupWindow_Close exit