Scripting - Chapter 8: My First Real Script
Do you feel ready to write your first complete script? Yes? Let's go! Your goal is to try to write this script by yourself.
For this exercise, we will work on Mozilla Firefox (Windows version). It is freely available for download.
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:
This link will download Firefox version 36.0.
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):
#!/usr/bin/env playonlinux-bash [ "$PLAYONLINUX" = "" ] && exit 0 source "$PLAYONLINUX/lib/sources" POL_SetupWindow_Init POL_SetupWindow_presentation POL_System_TmpCreate POL_SetupWindow_InstallMethod if [ "$INSTALL_METHOD" = "LOCAL" ] then POL_SetupWindow_browse elif [ "$INSTALL_METHOD" = "DOWNLOAD" ] then cd POL_Download fi POL_Wine_SelectPrefix POL_Wine_PrefixCreate POL_SetupWindow_wait POL_Wine 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 information 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.
Here's a working script:
#!/usr/bin/env playonlinux-bash [ "$PLAYONLINUX" = "" ] && exit 0 source "$PLAYONLINUX/lib/sources" POL_SetupWindow_Init POL_SetupWindow_presentation "Mozilla Firefox" "Mozilla" "http://www.mozilla.com" "YourNickname" "MozillaFirefox" 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" INSTALLER="$APP_ANSWER" elif [ "$INSTALL_METHOD" = "DOWNLOAD" ] then cd "$POL_System_TmpDir" POL_Download "http://ftp.mozilla.org/pub/mozilla.org/firefox/releases/36.0/win32/en-US/Firefox%20Setup%2036.0.exe" INSTALLER="$POL_System_TmpDir/Firefox Setup 36.0.exe" fi POL_Wine_SelectPrefix "MozillaFirefox" POL_Wine_PrefixCreate POL_SetupWindow_wait "Installation in progress." "Mozilla Firefox installation" POL_Wine "$INSTALLER" POL_System_TmpDelete POL_Shortcut "firefox.exe" "Mozilla Firefox" POL_SetupWindow_Close exit
The tighter the resemblance 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 additional 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 appdb.wineHQ.org may prove useful to you.
Ok, I'm done, can I write PlayOnLinux scripts now?
Sadly not yet, you've learned to write "basic" scripts, but additional requirements need to be taken care of, like allowing for localization or debugging. We'll see that in the next chapters.
Previous: Chapter 7: Installation Media