fr

Create a script for PlayOnMac - Chapter 8: My first real script

Do you feel ready to write your first complete script? Yes, so let's go!

Your goal is to try to write this script by yourself.

Instructions:

For this exercise, we will work on Mozilla Firefox (Windows version), that is easily and freely available for download.

Installation methods

Two methods of installation should be supported: LOCAL and DOWNLOAD

Since Mozilla Firefox must be downloaded from mirror servers, I'll give you the address of the mirror server you should use:

http://mirror3.mirrors.tds.net/pub/mozilla.org/firefox/releases/latest/win32/en-US/Firefox Setup 7.0.exe

You just have to replace the version number in red with the current version (as found on this page).

Name of the executable

The executable to pass to the POL_Shortcut command is: firefox.exe.

List of useful commands

To make your task easier, here are the commands that you'll need (in usage order):

#!/bin/bash
[ "$PLAYONLINUX" = "" ] && exit 0
source "$PLAYONLINUX/lib/sources"
POL_SetupWindow_Init

POL_SetupWindow_presentation
POL_Wine_SelectPrefix
POL_Wine_PrefixCreate
POL_System_TmpCreate
POL_SetupWindow_InstallMethod
if [ "$INSTALL_METHOD" = "LOCAL" ]
then
	POL_SetupWindow_browse
	POL_SetupWindow_wait
	POL_Wine
elif [ "$INSTALL_METHOD" = "DOWNLOAD" ]
then
	cd
	POL_Download
	POL_SetupWindow_wait
	POL_Wine
fi
POL_System_TmpDelete
POL_Shortcut

POL_SetupWindow_Close
exit

It's your turn now!

Additional arguments may be required, check the previous chapters.

You should now have all the necessary infomations to achieve this task. Try to complete the script as much as possible by yourself.

Once you're done, you can check the solution below.

Correction

Here's a working script:

#!/bin/bash
[ "$PLAYONLINUX" = "" ] && exit 0
source "$PLAYONLINUX/lib/sources"

POL_SetupWindow_Init

POL_SetupWindow_presentation "Mozilla Firefox" "Mozilla" "http://www.mozilla.com" "YourNickname" "MozillaFirefox"

POL_Wine_SelectPrefix "MozillaFirefox"
POL_Wine_PrefixCreate

POL_System_TmpCreate "MozillaFirefox"

POL_SetupWindow_InstallMethod "LOCAL,DOWNLOAD"

if [ "$INSTALL_METHOD" = "LOCAL" ]
then
	POL_SetupWindow_browse "Please select the installation file to run." "Mozilla Firefox installation"
	POL_SetupWindow_wait "Installation in progress." "Mozilla Firefox installation"
	POL_Wine start /unix "$APP_ANSWER"
elif [ "$INSTALL_METHOD" = "DOWNLOAD" ]
then
	cd "$POL_System_TmpDir"
	POL_Download "http://mirror3.mirrors.tds.net/pub/mozilla.org/firefox/releases/latest/win32/en-US/Firefox Setup 7.0.exe"
	POL_SetupWindow_wait "Installation in progress." "Mozilla Firefox installation"
	POL_Wine start /unix "$POL_System_TmpDir/Firefox Setup 7.0.exe"
fi

POL_System_TmpDelete

POL_Shortcut "firefox.exe" "Mozilla Firefox"

POL_SetupWindow_Close
exit

The tighter the ressemblance of your script with this one, the better your understanding of scripting. The exact messages used are not important, what matters is that you used all the functions in your own script.

You can try to adapt this code to the installation of other programs, but keep in mind that some programs do not work with the default settings of Wine, and that additionnal functions may be required. Wine technology is not perfect, so some programs may not work no matter how hard you will try.

The test reports available from WineHQ AppDB may prove useful to you.

Ok, I'm done, can I write PlayOnMac scripts now?

Sadly not yet, you've learned to write "basic" scripts, but additionnal requirements need to be taken care of, like allowing for localization or debugging. We'll see that in the next chapters.

Previous chapter - Next chapter

Il n'y a rien à voir ici