Script installs Windows apps in Wine.

For discussions about programming, programming questions/advice, and projects that don't really have anything to do with Puppy.
Post Reply
Message
Author
mos
Posts: 6
Joined: Sat 01 Oct 2016, 12:15

Script installs Windows apps in Wine.

#1 Post by mos »

Hello Puppy community ,this is my first writing , in this forum.I often read here the postings ,especially those about gtkdialog scripting.The thing is that i'm not good at bash scripting.So I need some help in this direction.
Now I want to create a script to automate the install of windows apps on linux through wine.So i thought that to accomplish this I need to create a script that makes a text file for every .exe and .msi file from a directory ,naming the text files after the apps.I used as source for this a topic from this area and I came up with this script ,that partially works:

Code: Select all

#!/bin/bash

HERE="$(dirname "$(readlink -f "${0}")")"

rm -f /tmp/txt

cd $HERE 

find . -maxdepth 1 -type f \( -name "*.exe" -o -name "*.msi" \) -print > /tmp/txt

fgs=/tmp/txt
while IFS='' read -r line || [[ -n "$line" ]]; do
    echo 'This is a test' > $line.txt
done < "$fgs"

I wanted to replace 'This is a test' with the second script code , but the resulting text was so compacted that it was useless.The second script:

Code: Select all

#!/bin/bash

env WINEPREFIX="/home/lns/.wine" /opt/wine-staging/bin/wine Z:\\\\tmp\\\\$line &

sleep 3
xdotool windowactivate
sleep 3
xdotool key Return
sleep 2
xdotool key space
sleep 2
xdotool key Return
sleep 2
xdotool key Down
sleep 2
xdotool key Tab
sleep 2
xdotool key Return
sleep 2
xdotool key Delete
sleep 2
xdotool type "C:\Program Files\VSTPlugins"
sleep 2
xdotool key Tab
sleep 2
xdotool key Return
sleep 2
xdotool key Tab
sleep 2
xdotool key Tab
sleep 2
xdotool key Tab
sleep 2
xdotool key Tab
sleep 2
xdotool key Return
sleep 2
xdotool key Return
sleep 2
xdotool key Return
Then I tried a different approach considering that will be easier just to put the second script in the directory with exe and msi apps and use another script (third) to make a copy of the second one for every exe,msi file and after that to rename those second script copies with the names of apps ,followed by txt extension to differentiate them from real apps.And finally to replace the $line variable from those copies with the name of corresponding exe and msi apps.But after surfing with no luck this forum and askubuntu in search of a way how to copy and rename files I finally gave up.So how could it be done?I really want to make this automate install of windows apps to work from some script.Thank in advance.

User avatar
MochiMoppel
Posts: 2084
Joined: Wed 26 Jan 2011, 09:06
Location: Japan

Re: Complex script

#2 Post by MochiMoppel »

Your script does not need to be complex. You don't need a tmp file when you put the output of the find command into a variable. You can echo the complete second script into the target file. No need for a line-by-line process. The only thing you have to take care of are quotations: If you put the complete string of the second script into double quotes, any double quote within the script has to be escaped (or replaced by single quotes if appropriate).

I hope that this is close to what you are trying to achieve:

Code: Select all

#!/bin/sh
HERE="$(dirname "$(readlink -f "${0}")")" 
cd $HERE 

LIST=$(find . -maxdepth 1 -type f \( -name "*.exe" -o -name "*.msi" \) )

IFS=$'\n'
for file in $LIST ; do 

echo -n "#!/bin/bash 
env WINEPREFIX=\"/home/lns/.wine\" /opt/wine-staging/bin/wine Z:\\\\tmp\\\\$line & 
sleep 3 
xdotool windowactivate 
sleep 3 
xdotool key Return 
sleep 2 
xdotool key space 
sleep 2 
xdotool key Return 
sleep 2 
xdotool key Down 
sleep 2 
xdotool key Tab 
sleep 2 
xdotool key Return 
sleep 2 
xdotool key Delete 
sleep 2 
xdotool type \"C:\Program Files\VSTPlugins\" 
sleep 2 
xdotool key Tab 
sleep 2 
xdotool key Return 
sleep 2 
xdotool key Tab 
sleep 2 
xdotool key Tab 
sleep 2 
xdotool key Tab 
sleep 2 
xdotool key Tab 
sleep 2 
xdotool key Return 
sleep 2 
xdotool key Return 
sleep 2 
xdotool key Return" > "${file}.txt"

done
This is even easier and probably what you asked for at the end of your post. Put your 2nd script into a file, then copy this file for each .exe. and .msi to files renamed <name.exe>.txt or <name.msi>.txt. This assumes that all files are located in the HERE directory, otherwise use full paths.

Code: Select all

#!/bin/sh
HERE="$(dirname "$(readlink -f "${0}")")" 
cd $HERE 

for file in *.{exe,msi} ; do 
cp secondscript.txt "$file".txt
done

mos
Posts: 6
Joined: Sat 01 Oct 2016, 12:15

#3 Post by mos »

Thank you Mochi.Your solutions are helpful but something isn't fully working in both situations(solutions).So here's what I've done :I created the script1 provided by you :

Code: Select all


#!/bin/bash
HERE="$(dirname "$(readlink -f "${0}")")"
cd $HERE

LIST=$(find . -maxdepth 1 -type f \( -name "*.exe" -o -name "*.msi" \) )

IFS=$'\n'
for file in $LIST ; do

echo -n "#!/bin/bash

env WINEPREFIX=\"/home/lns/.wine\" /opt/wine-staging/bin/wine Z:\\\\media\\\\SDA\\\\VST\\\\VSTe\\\\$file &

sleep 3
xdotool windowactivate
sleep 3
xdotool key Return
sleep 2
xdotool key space
sleep 2
xdotool key Return
sleep 2
xdotool key Down
sleep 2
xdotool key Tab
sleep 2
xdotool key Return
sleep 2
xdotool key Delete
sleep 2
xdotool type \"C:\Program Files\VSTPlugins\"
sleep 2
xdotool key Tab
sleep 2
xdotool key Return
sleep 2
xdotool key Tab
sleep 2
xdotool key Tab
sleep 2
xdotool key Tab
sleep 2
xdotool key Tab
sleep 2
xdotool key Return
sleep 2
xdotool key Return
sleep 2
xdotool key Return" > "${file}.txt"

done
When used ,it makes a *.txt file for every exe ,msi file ,with the names of exe,msi files.This is good.But for example the inside of one file looks like this:

Code: Select all

#!/bin/bash

env WINEPREFIX="/home/lns/.wine" /opt/wine-staging/bin/wine Z:\\media\\SDA\\VST\\VSTe\\./BlueCatFreewarePackVST3Setup.exe &

sleep 3
xdotool windowactivate
sleep 3
xdotool key Return
sleep 2
xdotool key space
sleep 2
xdotool key Return
sleep 2
xdotool key Down
sleep 2
xdotool key Tab
sleep 2
xdotool key Return
sleep 2
xdotool key Delete
sleep 2
xdotool type "C:\Program Files\VSTPlugins"
sleep 2
xdotool key Tab
sleep 2
xdotool key Return
sleep 2
xdotool key Tab
sleep 2
xdotool key Tab
sleep 2
xdotool key Tab
sleep 2
xdotool key Tab
sleep 2
xdotool key Return
sleep 2
xdotool key Return
sleep 2
xdotool key Return
The line:

Code: Select all

Z:\\media\\SDA\\VST\\VSTe\\./BlueCatFreewarePackVST3Setup.exe &
Is wrong because in has only 2 slashes in the path that wine reads and it has to be 4 of them to work.So in the script1 I doubled the number to 8 slashes.I don't know if it's a good thing but this solved the path problem.Another problem that I can't solve is this:

Code: Select all

./BlueCatFreewarePackVST3Setup.exe
In front of BlueCatFreewarePackVST3Setup.exe shouldn't be this "./"
I modified the slashes and now the script1 looks like this:

Code: Select all

#!/bin/bash
HERE="$(dirname "$(readlink -f "${0}")")"
cd $HERE

LIST=$(find . -maxdepth 1 -type f \( -name "*.exe" -o -name "*.msi" \) )

IFS=$'\n'
for file in $LIST ; do

echo -n "#!/bin/bash

env WINEPREFIX=\"/home/lns/.wine\" /opt/wine-staging/bin/wine Z:\\\\\\\\media\\\\\\\\SDA\\\\\\\\VST\\\\\\\\VSTe\\\\\\\\$file &

sleep 3
xdotool windowactivate
sleep 3
xdotool key Return
sleep 2
xdotool key space
sleep 2
xdotool key Return
sleep 2
xdotool key Down
sleep 2
xdotool key Tab
sleep 2
xdotool key Return
sleep 2
xdotool key Delete
sleep 2
xdotool type \"C:\Program Files\VSTPlugins\"
sleep 2
xdotool key Tab
sleep 2
xdotool key Return
sleep 2
xdotool key Tab
sleep 2
xdotool key Tab
sleep 2
xdotool key Tab
sleep 2
xdotool key Tab
sleep 2
xdotool key Return
sleep 2
xdotool key Return
sleep 2
xdotool key Return" > "${file}.txt"

done
The result of using it is this:

Code: Select all

#!/bin/bash

env WINEPREFIX="/home/lns/.wine" /opt/wine-staging/bin/wine Z:\\\\media\\\\SDA\\\\VST\\\\VSTe\\\\./BlueCatFreewarePackVST3Setup.exe &

sleep 3
xdotool windowactivate
sleep 3
xdotool key Return
sleep 2
xdotool key space
sleep 2
xdotool key Return
sleep 2
xdotool key Down
sleep 2
xdotool key Tab
sleep 2
xdotool key Return
sleep 2
xdotool key Delete
sleep 2
xdotool type "C:\Program Files\VSTPlugins"
sleep 2
xdotool key Tab
sleep 2
xdotool key Return
sleep 2
xdotool key Tab
sleep 2
xdotool key Tab
sleep 2
xdotool key Tab
sleep 2
xdotool key Tab
sleep 2
xdotool key Return
sleep 2
xdotool key Return
sleep 2
xdotool key Return
In front of BlueCatFreewarePackVST3Setup.exe still persists this "./"

Concerning the second script you wrote, this is how I adapted it:

Code: Select all

#!/bin/sh
HERE="$(dirname "$(readlink -f "${0}")")"
cd $HERE

for file in "*".{exe,msi} ; do
cp xdotool-vste "$file".txt
done
xdotool-vste is the name of the file that is copied.The result of using script2 is a single file not one for every exe,msi file and it's name is : *.{exe,msi}.txt .It's content is good but the variable $file is not modified so the result is this:

Code: Select all


#!/bin/bash

env WINEPREFIX="/home/a/.wine" /opt/wine-staging/bin/wine Z:\\\\media\\\\SDA\\\\VST\\\\VSTe\\\\$file &

sleep 3
xdotool windowactivate
sleep 3
xdotool key Return
sleep 2
xdotool key space
sleep 2
xdotool key Return
sleep 2
xdotool key Down
sleep 2
xdotool key Tab
sleep 2
xdotool key Return
sleep 2
xdotool key Delete
sleep 2
xdotool type "C:\Program Files\VSTPlugins"
sleep 2
xdotool key Tab
sleep 2
xdotool key Return
sleep 2
xdotool key Tab
sleep 2
xdotool key Tab
sleep 2
xdotool key Tab
sleep 2
xdotool key Tab
sleep 2
xdotool key Return
sleep 2
xdotool key Return
sleep 2
xdotool key Return
What should be done next?

User avatar
MochiMoppel
Posts: 2084
Joined: Wed 26 Jan 2011, 09:06
Location: Japan

#4 Post by MochiMoppel »

mos wrote:So in the script1 I doubled the number to 8 slashes.I don't know if it's a good thing but this solved the path problem.
Looks odd, but it is correct. Bash uses the backslash as an escape character, so when you need a literal backslash you need 2 of them.
Another problem that I can't solve is this:

Code: Select all

./BlueCatFreewarePackVST3Setup.exe
In front of BlueCatFreewarePackVST3Setup.exe shouldn't be this "./"
This is a result of your find command. I don't like the use of the find command here anyway.
Try this:

Code: Select all

#!/bin/sh
HERE="$(dirname "$(readlink -f "${0}")")" 
cd $HERE 

for file in *.{exe,msi} ; do
echo -n "#!/bin/bash 

env WINEPREFIX="/home/lns/.wine" /opt/wine-staging/bin/wine Z:\\\\\\\\media\\\\\\\\SDA\\\\\\\\VST\\\\\\\\VSTe\\\\\\\\$file &

sleep 3 
xdotool windowactivate 
sleep 3 
xdotool key Return 
sleep 2 
xdotool key space 
sleep 2 
xdotool key Return 
sleep 2 
xdotool key Down 
sleep 2 
xdotool key Tab 
sleep 2 
xdotool key Return 
sleep 2 
xdotool key Delete 
sleep 2 
xdotool type "C:\Program Files\VSTPlugins" 
sleep 2 
xdotool key Tab 
sleep 2 
xdotool key Return 
sleep 2 
xdotool key Tab 
sleep 2 
xdotool key Tab 
sleep 2 
xdotool key Tab 
sleep 2 
xdotool key Tab 
sleep 2 
xdotool key Return 
sleep 2 
xdotool key Return 
sleep 2 
xdotool key Return" > "${file}.txt" 

done

mos
Posts: 6
Joined: Sat 01 Oct 2016, 12:15

#5 Post by mos »

A huge thank you ,a big hug and a box of beers for you Mochi.It works.
Many thanks for your help.
Now , if I'm not asking too much ,how could I adapt your script or make a new one to include in a single text file, the names of all the .zip,.rar and .7z files from one directory and look like this:

Code: Select all

#!/bin/bash

echo -e "\n"
read -s -n1 -p " Press any key to continue"
echo -e "\n"
echo -e "\033[01;38;5;220m  \n                     * INSTALLING VSTi Bass * \033[0m"
echo -e "\n"

HVST=/media/SDA/VST/VSTi/Bass

mkdir ~/.wine/drive_c/Program\ Files/VSTPlugins/$file
cd ~/.wine/drive_c/Program\ Files/VSTPlugins/$file
7z x $HVST/$file.zip &&

mkdir ~/.wine/drive_c/Program\ Files/VSTPlugins/$file
cd ~/.wine/drive_c/Program\ Files/VSTPlugins/$file
7z x $HVST/$file.zip &&

mkdir ~/.wine/drive_c/Program\ Files/VSTPlugins/$file
cd ~/.wine/drive_c/Program\ Files/VSTPlugins/$file
7z x $HVST/$file.zip &&

.
.
.
.
.
.
.
.

mkdir ~/.wine/drive_c/Program\ Files/VSTPlugins/$file
cd ~/.wine/drive_c/Program\ Files/VSTPlugins/$file
7z x $HVST/$file.zip &&

echo -e "\n"
read -s -n1 -p " Press any key to Close"
How to tell bash to create a new entry on that text file in the form of:

Code: Select all

mkdir ~/.wine/drive_c/Program\ Files/VSTPlugins/$file
cd ~/.wine/drive_c/Program\ Files/VSTPlugins/$file
7z x $HVST/$file.zip &&
for every archive file ,and replace the $file with the name of the file ,without it's extension(.zip ,.rar or .7z)?
And ,how to tell bash to adapt the value of $HVST variable according to the path of the directory where i'll put the script that creates the text file?
So there will be two files in every directory that contains .zip.rar.7z files:first ,a script and second a text file.The script should create the text file that looks like in the first example above.

Post Reply