I am looking for help trying to create a .sh file to run steam games through wines windows player - bash

I have a computer running Ubuntu with retropie (emulationstation) which i can create .sh files to run linux based steam games through as they can be directly installed onto the computer. I have installed wine in order to play the windows based games and while I can run the files by going into windows steam and clicking play, I am looking for a way to create a .sh file that will allow me to play them through retropie. I can post some of the stuff ive tried i just am struggling with the formatting.
Let me know if i need to post anything else or fix something!
EDIT: Heres some of the code ive tried, the first i thinks should run the executable through wine but i cant get anything to output, the second is some code i found online which watches for the game to close as well so it can exit clean.
#!/bin/bash
wine ~/PlayOnLinux\'s\ virtual\ drives/Steam/drive_c/Program\
Files/Steam/steamapps/common/MortalKombat_KompleteEdition/DiscContentPC/MKKE.exe
#! /bin/bash
appid=$1
procname=$2
PREFIX=/home/rig-cade/PlayOnLinux\'s\ virtual\ drives
STEAM="/home/rig-cade/.wine-steam/drive_c/Program Files/Steam/Steam.exe"
export WINEDEBUG=-all
export WINEPREFIX=$PREFIX
if [[ ((`pgrep -f steam.exe -c` == 0)) && ((`pgrep -f Steam.exe -c` == 0)) ]]; then
optirun wine "$STEAM" -silent &
sleep 20
fi
echo "Running game"
wine "$STEAM" steam://rungameid/$appid &
sleep 15
echo "Starting checks"
status=`pgrep -f $procname -c`
if (( "$status" > 1 )); then
while (( "$status" > 1 )); do
sleep 5
status=`pgrep -f $procname -c`
done
wine "$STEAM" -shutdown &
fi
echo "Exiting"

I'm not 100% sure and I will test once I get done with work in a couple hours, but AFAIK the Steam URL protocol cannot be used with the command-line and so when you try this Steam is likely throwing a parsing error. If you add -console after -silent it should enable the Console tab and allow you to see an error message if you open the client.
Instead try one of
Only using the browser protocol without the "$STEAM" part so it's not trying to pass it as an argument to the client.
Using the Steam Command-line parameter -applaunch {appid},
where {appid} is replaced with the appid of the game to be run as you were already trying to do.

Related

Creating a Service with automator, caffeinate

First of all, sorry for my english, not a native speaker.
Since I'm a bit fed up opening Termninal and ^C I want to create a shortcut for activating caffeinate -d on my Mac OS X 10.11
I've been trying a simple Automator Service but with my noob skills it doesn't work.
This is the settings:
I chose Service as type of document
Library->Utilities->Run Shell Script
Service receives: no input
in: any application
Shell: /bin/bash
Pass input: to stdin
CAFFEINATECHECK=`ps | grep caffeinate | cut -d ' ' -f7,8`
if [ $CAFFEINATECHECK == 'caffeinate -d' ]; then
killall caffeinate
else
caffeinate -d
fi
Problem is that such a short scrip keeps running with no response and I have to stop it after a minute
I hope someone could give me any tips necessary
I got the solution in a duplicate on Ask Different
In short, just replacing mine code with a more elegant command lines:
if [[ $(pgrep caffeinate) == "" ]]; then
caffeinate -d &
else
pkill caffeinate
fi
The only change I made inside user3439894's solution was to remove the '&' (usually useful at the end of a command line to run it in background) because apparently Automator doesn't work well with it (shame I can't remember where I read/heard that..!) .
After saving the Service I just had to
Open System Preferences Keyboard->Shortcuts->Services
Bind my shortcut with my saved workflow found under ▼General in the right pannel
This way a cog gear wheel ⚙ appears on the menubar when caffeinate shortcut is activated and spins till I deactive it .

Why would this script work on Mac OS and not on Windows using Git Bash?

I wrote a site diagnostic script and have been testing it using iTerm2 on MacOS. A good portion of people that may consume this script use Windows and Git Bash (it's probably 50|50 Windows vs Mac OS): so not supporting Windows might not be an option.
I had someone here test out the script on their Windows PC and it immediately failed. Would anyone know why this function would succeed on Mac and fail on Windows?
_ping_test(){
# Define Error Codes & Messages Below:
local _success="0"
local _success_message="${_green}SUCCESS:${_reset_color} Ping Test Passed"
local _unknown_host="68"
local _unknown_host_message="${_red}ERROR:${_reset_color} Ping Test Failed on ${_url} - Unknown Host"
local _unrecognized_code="${_red}ERROR:${_reset_color} Ping Test Failed - Unrecognized Status Code${_ping_test} "
local _url="${1}.testdomain.net"
local _ping_url=$(ping -c 1 -q $_url &> /dev/null; echo $?)
if [ "${_ping_url}" == "${_success}" ] ; then
echo $_success_message
elif [ "${_ping_url}" == "${_unknown_host}" ] ; then
echo $_unknown_host_message
exit 1
elif true ; then
echo $_unrecognized_code
exit 1
fi
}
Running it returns the Unrecognized Code response on his computer, but given the same site is successful on my Mac.
I echo'd back $_url, and that returns the correct site. I also tried removing the &> /dev/null portion to hear back what the issue was, but it returned that it didn't recognize the command ping
Then I just ran the ping command directly in his Git Bash window, and that worked outside of the shell script.
I realize the ping test portion is a bit silly (it's used to exit the script if they input a bad URL), but the more valuable ssh commands that run later were also failing similarly
I managed to grab a Windows PC and TiL that the parameters you pass to ping follow a different paradigm based on OS:
-c means count on Mac OS
but
-c means compartmentalize on Windows which required admin access
fixed the params and then it worked

Troubleshooting a script for my RPI to toggle displays

So I have a Quimat LCD attached to my gpio.
included is a script which runs to switch to the display (LCD35-show), and another to switch back to the HDMI port (LCD-hdmi). This causes a reboot when done so any variable changes have to happen prior to this.
as this is for my mother who is afraid of touching command prompt, I am trying to set up a single icon to use to switch between video sources.
I am a novice at coding, most of my experience from dabbling in BASIC, and have spent a couple days searching and trying to set this up, but apparently am failing at how to search properly as I couldn't get it functioning.
What I have done so far is this:
Created text file state.txt to hold a variable stating what mode the device is in (HDMI or LCD)
My attempt was to read the variable, then use if then statement to determine which file to run, change the variable then run the file.
This is the code I ended up with.
!/bin/bash
read var < state.txt
if var == HDMI
then
echo LCD > state.txt
cd LCD-show/
sudo ./LCD35-show
else
echo HDMI > state.txt
cd LCD-show/
sudo ./LCD-hdmi
fi
I am hoping someone can show me what I did wrong, and hopefully explain what I missed in the process.
Be careful with your bash script comparisons.
Wrap strings in quotes (or some other method), so it's not a syntax error when string-vars evaluate to empty. You can use == for string comparisons in bash, but = works in bash and sh.
#! /bin/bash
EXE=`basename "$0"`
LCD_DIR="LCD-show"
STATE_FILE="state.txt"
if [ ! -d "$LCD_DIR" ]; then
echo "$EXE: $LCD_DIR does not exist"
exit 1
fi
read var < state.txt
if [ "$var" = "HDMI" ]; then
echo LCD > "$STATE_FILE"
cd "$LCD_DIR"
sudo ./LCD35-show
else
echo HDMI > "$STATE_FILE"
cd "$LCD_DIR"
sudo ./LCD-hdmi
fi
The difference between a good script and a great script is error handling.
What happens when the dir LCD-show does not exist? (for whatever reason).

In Mac, how do I determine in a script (sh/bash/applescript) if currently running via Apple Remote Desktop?

I am creating an application installer for Mac. The installer involves getting a code from the user on install. I used an Installer Plugin for the Code Input screen.
I have read (from this link) and verified that plugins do not work in the command line and Apple Remote Desktop. I can check if the installer is running from the command line using a variable ("$COMMAND_LINE_INSTALL").
My questions is, how can I programmatically check if it is running via Apple Remote Desktop?
If pstree is available, you can get a quick ancestry of the current process and see if Apple Remote Desktop is in it, something like pstree -p $$ in bash. Unfortunately, I installed pstree using brew, so this is most likely not going to be available for you, unless you distribute a binary yourself.
The other approach is to walk up the parent yourself. Here is a sample that I tested to be working to check if I am running inside iTerm (I used iTerm as a sample because I don't know what the pstree output would look like when running inside Apple Remote Desktop).
pid=$$
running_in_iterm=0
while [ $pid -ne 1 ]; do
command=$(ps -o command= -p $pid)
case "$command" in
*iTerm*)
running_in_iterm=1
break;;
esac
pid=$(ps -o ppid= -p $pid)
done
if [ $running_in_iterm -eq 1 ]; then
echo "Running in iTerm"
else
echo "Not running in iTerm"
fi
You can try running this script from both the built-in Terminal app as well as iTerm and see the difference.

checking if a streaming server is up using bash?

I use Ubuntu and am trying to write a script that makes the following:
-test if an audio stream works
-if not, send an email.
I have tried the following code (running as a cron job every 10 minutes), which 'works' if I supply the wrong pw e.g.(it sends an email then), but does nothing if the actual server is down (tested by killing the server). any ideas on how to fix the script?
Thanks in advance!
#!/bin/bash
#servertest.sh
username=user1
password=xyz
url="http://wwww.streamingaudioserver.com -passwd $password -user $username"
mplayer $url &
sleep 5
test=$(pgrep -c mplayer)
if [ $test = 0 ]; then
#server is down!
mailfile="downmail.txt"
/usr/sbin/ssmtp test#maildomain.com < "/home/test/$mailfile"
fi
killall mplayer
sleep 5
exit
Your problem is in this line:
$mailfile="downmail.txt"
remove the dollar sign and that should do it.
You should be getting error messages in your cron log or emails to the crontab owner complaining about a command not found or no such file.
Edit:
Does your script work if run from the command line (with the stream down) rather than cron?
Try using set -x (or #!/bin/bash -x) in the script to turn on tracing or use echo "PID: $$, value of \$test: $test" > /tmp/script.out after the assignment to see if you're getting the zero you're expecting.
Also, try an ssmtp command outside the if to make sure it's working (but I think you already said it is under some circumstances).
Try your script without ever starting mplayer.

Resources