Difference between revisions of "Scripting - Chapter 8: My First Real Script"

From PlayOnLinux
Jump to: navigation, search
(Installation methods)
(Remove POL_Debug_Init from example script, it is secondary to the example and only introduced in next chapter)
(Tag: visualeditor)
 
(6 intermediate revisions by 2 users not shown)
Line 11: Line 11:
 
Since Mozilla Firefox must be downloaded from mirror servers, I'll give you the address of the mirror server you should use:
 
Since Mozilla Firefox must be downloaded from mirror servers, I'll give you the address of the mirror server you should use:
  
<pre>
+
http://ftp.mozilla.org/pub/mozilla.org/firefox/releases/36.0/win32/en-US/Firefox%20Setup%2036.0.exe
http://mirror3.mirrors.tds.net/pub/mozilla.org/firefox/releases/latest/win32/en-US/Firefox Setup 7.0.exe
 
</pre>
 
  
You just have to replace the version number just before '''.exe''' with the current version (as found on this page).
+
''This link will download Firefox version 36.0.''
  
 
=== Name of the executable ===
 
=== Name of the executable ===
Line 26: Line 24:
  
 
<pre class="playonlinux code">
 
<pre class="playonlinux code">
#!/bin/bash
+
#!/usr/bin/env playonlinux-bash
 
[ "$PLAYONLINUX" = "" ] && exit 0
 
[ "$PLAYONLINUX" = "" ] && exit 0
 
source "$PLAYONLINUX/lib/sources"
 
source "$PLAYONLINUX/lib/sources"
 
POL_SetupWindow_Init
 
POL_SetupWindow_Init
+
 
 
POL_SetupWindow_presentation
 
POL_SetupWindow_presentation
POL_Wine_SelectPrefix
 
POL_Wine_PrefixCreate
 
 
POL_System_TmpCreate
 
POL_System_TmpCreate
 
POL_SetupWindow_InstallMethod
 
POL_SetupWindow_InstallMethod
Line 39: Line 35:
 
then
 
then
 
     POL_SetupWindow_browse
 
     POL_SetupWindow_browse
    POL_SetupWindow_wait
 
    POL_Wine
 
 
elif [ "$INSTALL_METHOD" = "DOWNLOAD" ]
 
elif [ "$INSTALL_METHOD" = "DOWNLOAD" ]
 
then
 
then
 
     cd
 
     cd
 
     POL_Download
 
     POL_Download
    POL_SetupWindow_wait
 
    POL_Wine
 
 
fi
 
fi
 +
POL_Wine_SelectPrefix
 +
POL_Wine_PrefixCreate
 +
POL_SetupWindow_wait
 +
POL_Wine
 
POL_System_TmpDelete
 
POL_System_TmpDelete
 
POL_Shortcut
 
POL_Shortcut
Line 64: Line 60:
  
 
<pre class="playonlinux code">
 
<pre class="playonlinux code">
#!/bin/bash
+
#!/usr/bin/env playonlinux-bash
 
[ "$PLAYONLINUX" = "" ] && exit 0
 
[ "$PLAYONLINUX" = "" ] && exit 0
 
source "$PLAYONLINUX/lib/sources"
 
source "$PLAYONLINUX/lib/sources"
+
 
 
POL_SetupWindow_Init
 
POL_SetupWindow_Init
+
 
 
POL_SetupWindow_presentation "Mozilla Firefox" "Mozilla" "http://www.mozilla.com" "YourNickname" "MozillaFirefox"
 
POL_SetupWindow_presentation "Mozilla Firefox" "Mozilla" "http://www.mozilla.com" "YourNickname" "MozillaFirefox"
+
 
POL_Wine_SelectPrefix "MozillaFirefox"
 
POL_Wine_PrefixCreate
 
 
 
POL_System_TmpCreate "MozillaFirefox"
 
POL_System_TmpCreate "MozillaFirefox"
+
 
 
POL_SetupWindow_InstallMethod "LOCAL,DOWNLOAD"
 
POL_SetupWindow_InstallMethod "LOCAL,DOWNLOAD"
+
 
 
if [ "$INSTALL_METHOD" = "LOCAL" ]
 
if [ "$INSTALL_METHOD" = "LOCAL" ]
 
then
 
then
 
     POL_SetupWindow_browse "Please select the installation file to run." "Mozilla Firefox installation"
 
     POL_SetupWindow_browse "Please select the installation file to run." "Mozilla Firefox installation"
     POL_SetupWindow_wait "Installation in progress." "Mozilla Firefox installation"
+
     INSTALLER="$APP_ANSWER"
    POL_Wine start /unix "$APP_ANSWER"
 
 
elif [ "$INSTALL_METHOD" = "DOWNLOAD" ]
 
elif [ "$INSTALL_METHOD" = "DOWNLOAD" ]
 
then
 
then
 
     cd "$POL_System_TmpDir"
 
     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_Download "http://ftp.mozilla.org/pub/mozilla.org/firefox/releases/36.0/win32/en-US/Firefox%20Setup%2036.0.exe"
     POL_SetupWindow_wait "Installation in progress." "Mozilla Firefox installation"
+
     INSTALLER="$POL_System_TmpDir/Firefox Setup 36.0.exe"
    POL_Wine start /unix "$POL_System_TmpDir/Firefox Setup 7.0.exe"
 
 
fi
 
fi
+
 
 +
POL_Wine_SelectPrefix "MozillaFirefox"
 +
POL_Wine_PrefixCreate
 +
 
 +
POL_SetupWindow_wait "Installation in progress." "Mozilla Firefox installation"
 +
POL_Wine "$INSTALLER"
 +
 
 
POL_System_TmpDelete
 
POL_System_TmpDelete
+
 
 
POL_Shortcut "firefox.exe" "Mozilla Firefox"
 
POL_Shortcut "firefox.exe" "Mozilla Firefox"
+
 
 
POL_SetupWindow_Close
 
POL_SetupWindow_Close
 
exit
 
exit

Latest revision as of 17:17, 22 March 2015

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.

Instructions:

For this exercise, we will work on Mozilla Firefox (Windows version). It is 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://ftp.mozilla.org/pub/mozilla.org/firefox/releases/36.0/win32/en-US/Firefox%20Setup%2036.0.exe

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.

Correction

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

Next: Chapter 9: Standardization