Need help with scripting for some tutorials

Questions about applications and software
Forum rules
Before you post please read this

Need help with scripting for some tutorials

Postby RedWagon on Tue Jan 05, 2010 7:40 am

I didn't know where exactly to post this, but I'm working on some pretty big tutorials for games and Linux and needed some help improving on a few things before I made them public. I am gearing up for the new Linux Mint Community portal and am planning doing my own little Linux gaming blog to help people run games in Wine, highlight some good open source games and give instructions on how to install and use them. I see a lot of tutorials for games and lists for good open source games, but it always seems like the authors only played the games for 10 minutes or so and didn't really get a good evaluation of them. Anyways, I hope to do a lot of tutorials and posts to help promote gaming on Linux but first I need to fine tune my Wine process.

Right now I compile Wine from source and run it from its source directory without installing it. This allows me to run multiple versions of wine at once and have as many as I want installed on my system. I also put similar programs in different Wine prefixes (not just .wine) so it's easier to back things up, I can change settings independently for different programs and if I botch an install I can delete a particular Wine prefix without having to worry about loosing anything.

The main problem I'm looking to fix is that this changes a simple
Code: Select all
wine setup.exe

to a very intimidating
Code: Select all
WINEPREFIX=/home/user/.wine_program/ /home/user/.wine-1.1.32/./wine setup.exe

I am looking for some way to create a custom Wine launcher that will let me pick a specific Wine prefix and wine version so I could have the users install wine, copy and paste a script and then run something like
Code: Select all
wine-steam setup.exe

I tried making my own scripts, but could never figure out how to pass the scripts options (the setup.exe at the end). It would really help me a lot if some of the more experienced Linux guys can take a good look at the tutorial I attached and give some suggestions on a more user-friendly way for people to manage these Wine installs.

A brief intro: This is a complete guide to running Source games on Linux. It covers everything you need to play Source games casually or competitively, including installing and configuring Wine, Steam, Ventrilo, Team Speak and your games. This tutorial (will) also include instructions for how to backup everything so you'll never have to setup everything again after data loss or upgrading your OS. For those of you not in the gaming scene, Source is a game engine created by Valve (confusing, yes I know) that powers Counter Strike Source, the Half Life 2 series, Portal, Team Fortress 2, Left 4 Dead (2) and countless others.

*There are no screenshots yet and the final product will be adapted for htlm later. I just threw everything in an .rtf for now to get everything down first.
Attachments
SourceInLinux.rtf
(84.64 KiB) Downloaded 93 times
User avatar
RedWagon
Level 5
Level 5
 
Posts: 644
Joined: Tue May 26, 2009 6:41 pm

Linux Mint is funded by ads and donations.
 

Re: Need help with scripting for some tutorials

Postby Husse on Thu Jan 07, 2010 9:58 am

Kingoverload, or ikey (the same guy) on the IRC channel could help you I think
He's been playing with games lately.... playing with - not playing :)
Image
Don't fix it if it ain't broken, don't break it if you can't fix it
Husse
Level 21
Level 21
 
Posts: 19710
Joined: Sun Feb 11, 2007 7:22 am
Location: Near Borås Sweden

Re: Need help with scripting for some tutorials

Postby RedWagon on Thu Jan 07, 2010 11:29 am

Thanks, I'll try to find him. The only thing is the parts I need help with isn't with the games, but with general BASH scripting. I think this thread was too vague, I need to make some more specific questions...
User avatar
RedWagon
Level 5
Level 5
 
Posts: 644
Joined: Tue May 26, 2009 6:41 pm

Re: Need help with scripting for some tutorials

Postby emorrp1 on Thu Jan 07, 2010 11:50 am

well, you could do something like this in .bashrc:
Code: Select all
WP=wine_program
WV=1.1.32
alias wine='WINEPREFIX=~/.$WP ~/.wine-$WV/wine'

that'd give you a default program dir and a default wine version, so that "wine setup.exe" is invisibly expanded to "WINEPREFIX=/home/user/.wine_program/ /home/user/.wine-1.1.32/wine setup.exe". You could then launch individual progs with specific wine versions like "WV=1.0.8; WP=my_prog; wine my_prog" which is invisible expanded to "WINEPREFIX=/home/user/.my_prog/ /home/user/.wine-1.0.8/wine my_prog" (note that this way these WV,WP values become the default for all future "wine" incantations, so be careful - "echo $WV" will tell you what the current value is). Therefore you can create new aliases e.g. "alias my_prog='WV=1.0.8; WP=my_prog; wine my_prog'" which allows you to do all that just by typing my_prog in the terminal. You can do some even more fancy things if you need to.
If you have a question that has been answered and solved, then please edit your original post and put a [SOLVED] at the end of your subject header
Hint - use a google search including the search term site:forums.linuxmint.com
emorrp1
Level 8
Level 8
 
Posts: 2322
Joined: Thu Feb 26, 2009 8:58 pm

Re: Need help with scripting for some tutorials

Postby RedWagon on Fri Jan 08, 2010 7:15 am

Thanks for the post emorrp1, that was exactly the type of thing I was looking for. I really like the idea of being able to do every thing from one file, the only problem is I can't seem to call aliases from other aliases. I asked Google but the only things I've found so far just say this should work.

Code: Select all
verdow@RedWagon ~ $ cat .bashrc
alias wine-1.1.30='/home/verdow/.wine-1.1.30/./wine'
alias wine-1.1.35='/home/verdow/.wine-1.1.35/./wine'

alias wine_steam='WINEPREFIX=/home/verdow/.wine_steam/ padsp wine-1.1.30'

alias Steam='
   wine_steam /home/verdow/.wine_steam/drive_c/Program\ Files/Steam/Steam.exe "$&" &;
   sleep 45;
   renice 19 `pidof Steam.exe`
'
verdow@RedWagon ~ $ wine-1.1.30
Usage: wine PROGRAM [ARGUMENTS...]   Run the specified program
       wine --help                   Display this help and exit
       wine --version                Output version information and exit
verdow@RedWagon ~ $ wine_steam
exec: 88: wine-1.1.30: not found
verdow@RedWagon ~ $
User avatar
RedWagon
Level 5
Level 5
 
Posts: 644
Joined: Tue May 26, 2009 6:41 pm

Re: Need help with scripting for some tutorials

Postby RedWagon on Fri Jan 08, 2010 8:10 am

While Googleing I discovered function which is a lot better for replacing scripts. I can now create multiple launcher functions that call wine_steam, but I still can't get wine_steam to call wine-1.1.30.

Code: Select all
verdow@RedWagon ~ $ cat .bashrc
alias wine-1.1.30='/home/verdow/.wine-1.1.30/./wine'
alias wine-1.1.35='/home/verdow/.wine-1.1.35/./wine'

alias wine_steam='WINEPREFIX=/home/verdow/.wine_steam/ padsp /home/verdow/.wine-1.1.30/./wine'

function Steam {
   wine_steam /home/verdow/.wine_steam/drive_c/Program\ Files/Steam/Steam.exe "$&" &
   sleep 45
   renice 19 `pidof Steam.exe`
}
verdow@RedWagon ~ $
User avatar
RedWagon
Level 5
Level 5
 
Posts: 644
Joined: Tue May 26, 2009 6:41 pm

Re: Need help with scripting for some tutorials

Postby emorrp1 on Fri Jan 08, 2010 8:27 am

EDIT: I took so long to investigate that you've replied since, having found the function, ah well, enjoy
  • using ${HOME} in the aliases in place of /home/verdow makes them more portable
  • dir/./wine is identical to dir/wine
  • your main problem is that aliases are for commands, whereas the command in the wine_steam line is padsp. You can either make a variable (WINE30=$HOME/.wine-1.1.30/wine) then use that with padsp, or you can add padsp to the original wine-1.1.30 alias (which is probably what you actually want)
  • you can't use argument expansion in an alias, use a function instead (replace "alias" with "function"; "=" with "()"; the quotes with braces "{" and "}")
  • you might want to create a function that takes the wine version as an argument, rather than creating many wine aliases. Aliases are expanded when executed, functions are expanded when defined.
  • you probably mean $@ rather than $&, let me know if I'm wrong
  • if you plan on using these aliases in a custom script, you have to add a line: "shopt -s expand_aliases"
  • you might need to check that the wine-ified Steam.exe still identifies itself to pidof as Steam.exe
  • you'll probably forget to use a capital S for steam

suggested replacement .bashrc:
Code: Select all
function winev {
  VER=$1; shift
  padsp $HOME/.wine-$VER/wine $@
}
alias wine_steam='WINEPREFIX=${HOME}/.wine_steam/ winev 1.1.30'
STEAMDIR=$HOME/.wine_steam/drive_c/Program\ Files/Steam/Steam.exe
function steam {
  wine_steam $STEAMDIR $@ &
  sleep 45
  renice 19 `pidof Steam.exe`
}
If you have a question that has been answered and solved, then please edit your original post and put a [SOLVED] at the end of your subject header
Hint - use a google search including the search term site:forums.linuxmint.com
emorrp1
Level 8
Level 8
 
Posts: 2322
Joined: Thu Feb 26, 2009 8:58 pm

Re: Need help with scripting for some tutorials

Postby RedWagon on Fri Jan 08, 2010 10:29 am

Really good info in your last post, the only problem now is I can't get past that @#!%ing space in Program Files. No matter what I try I get some form of "wine cannot find C:/Program" or "wine cannot find /home/verdow/.wine_steam/drive_c/Program". I even tried bypassing your wine function (wine_steam3) to see if that was the problem but I get the same results. Below is my .bashrc file, it should show you some of the stuff I've tried.

Code: Select all
function wine {
  VER=$1; shift
  padsp $HOME/.wine-$VER/wine $@
}

alias wine_steam='WINEPREFIX=$HOME/.wine_steam/ wine 1.1.30'
function wine_steam2 {
  WINEPREFIX=$HOME/.wine_steam/ wine 1.1.30 $@
}
alias wine_steam3='WINEPREFIX=$HOME/.wine_steam/ $HOME/.wine-1.1.30/./wine'

STEAMEXE=C:\\Program\ Files\\Steam\\Steam.exe
STEAMEXE2="C:\Program Files\Steam\Steam.exe"
STEAMEXE3=$HOME/.wine_steam/drive_c/Program\ Files/Steam/Steam.exe

function Steam {
  wine_steam3 $STEAMEXE3 &
  sleep 45
  renice 19 `pidof Steam.exe`
}
User avatar
RedWagon
Level 5
Level 5
 
Posts: 644
Joined: Tue May 26, 2009 6:41 pm

Re: Need help with scripting for some tutorials

Postby Husse on Fri Jan 08, 2010 6:35 pm

If it is Wine that has problems it should behave like Windows and in Windows Program Files is a well known problem in localized versions solved by editing the registry for the offending program so it reads
C:\"Program Files"\whatever
In Vista it's different but in a Swedish XP Program Files is Program - I've helped with this numerous times
Image
Don't fix it if it ain't broken, don't break it if you can't fix it
Husse
Level 21
Level 21
 
Posts: 19710
Joined: Sun Feb 11, 2007 7:22 am
Location: Near Borås Sweden

Re: Need help with scripting for some tutorials

Postby emorrp1 on Fri Jan 08, 2010 9:32 pm

Husse could be right, I don't have much experience with wine, but it seems to me it's a quoting issue. Unfortunately I played around with it a bit, but couldn't work out the correct quoting method, have you tried putting the contents of STEAMEXE3 inline, to bypass the issue? (wine_steam3 $HOME/.wine_steam/drive_c/Program\ Files/Steam/Steam.exe &) Also, I'm pretty sure you need to use '${HOME}' rather than '$HOME' inside an alias, but I could be wrong.
If you have a question that has been answered and solved, then please edit your original post and put a [SOLVED] at the end of your subject header
Hint - use a google search including the search term site:forums.linuxmint.com
emorrp1
Level 8
Level 8
 
Posts: 2322
Joined: Thu Feb 26, 2009 8:58 pm

Re: Need help with scripting for some tutorials

Postby RedWagon on Sat Jan 09, 2010 3:14 am

I found two fixes to the problem. The wine function emorrp1 seems to be where the problem is at with the space in Program Files. I forgot that the wine aliases weren't working and recreated them and for some reason they worked. I also found out that I can bypass the space issue by changing the directory first and then calling wine which also makes the script a little more readable.

Now everything is working except I can't get Steam to launch from the menu. When I have it setup as an Application nothing happens and when I try to run it as Application in Terminal I get a popup that says "There was an error creating the child process for this terminal"
I found this:
Just in case someone stumbles across this post with the same problem, here's the simple solution.
I ran nautilus <sudo nautilus>, navigated to the script I'd created, selected properties then the permissions tab, and selected "Allow executing file as program".
So it was a permissions error (obviously); a pretty simple one at that!

but I'm not sure how to apply that to a function in .bashrc.

My current (working) .bashrc:
Code: Select all
alias wine-1.1.30='$HOME/.wine-1.1.30/./wine'
alias wine-1.1.35='$HOME/.wine-1.1.35/./wine'

alias wine_steam='WINEPREFIX=$HOME/.wine_steam/ wine-1.1.30'

function Steam {
  cd $HOME/.wine_steam/drive_c/Program\ Files/Steam/
  padsp wine_steam Steam.exe &
  sleep 45
  renice 19 `pidof Steam.exe`
}
User avatar
RedWagon
Level 5
Level 5
 
Posts: 644
Joined: Tue May 26, 2009 6:41 pm

Re: Need help with scripting for some tutorials

Postby emorrp1 on Sat Jan 09, 2010 5:51 am

well, I tested the wine function quite thoroughly, but good call about cd first. Oh yeah, I forgot that you can put the alias in the function because it's expanded on function definition, so padsp will then work. Anyway, to make it work in the Menu and the terminal, you need to turn it into a script (you might need the shopt line I mentioned earlier, and don't forget to make it executable):
Code: Select all
#!/bin/bash
Steam
If you have a question that has been answered and solved, then please edit your original post and put a [SOLVED] at the end of your subject header
Hint - use a google search including the search term site:forums.linuxmint.com
emorrp1
Level 8
Level 8
 
Posts: 2322
Joined: Thu Feb 26, 2009 8:58 pm

Linux Mint is funded by ads and donations.
 

Return to Software & Applications

Who is online

Users browsing this forum: No registered users and 23 guests