Skip to content

Instantly share code, notes, and snippets.

@rcg4u
Created March 6, 2013 15:24
Show Gist options
  • Save rcg4u/5100055 to your computer and use it in GitHub Desktop.
Save rcg4u/5100055 to your computer and use it in GitHub Desktop.
#!/usr/bin/perl
# This script will download and install the latest wine compatible version
# of the IMVUClient
# Be strict to avoid messy code
use strict;
# Use FindBin module to get script directory
use FindBin;
# Get script directory
my $cwd = $FindBin::Bin;
#fallback client url incase the check for new wine compatible client fails
my $fallback_client_url = "http://static-akm.imvu.com/imvufiles/installers/InstallIMVU_453.8.exe";
main();
sub main
{
#create some variables we will need
my $url;
my $counter;
#try to get the latest wine compatible imvu client url
$url = get_latest_wine_compatible_client_url();
#put testing to false to do an update or install on default wine location
my $istesting = "false";
# If --force argument is not provided
if ("@ARGV" =~ /--force/)
{
# Tell what we will do
print "--force applied!\nSkipping check for compatible wine version.\n\n";
}
else
{
# Tell what we will do
print "--force not applied!\nChecking for compatible wine version.\n\n";
# Run a check for compatible wine version
checkwine();
}
# Parse the passed parameters
for ($counter = 0; $counter < @ARGV; $counter++)
{
# if the --test {version} is passed then
if ($ARGV[$counter] =~ /--test/)
{
# Get the value passed
my @testversion = $ARGV[$counter+1];
#generate download link for the version passed
$url = "http://static-akm.imvu.com/imvufiles/installers/InstallIMVU_$testversion[-1].exe";
# Tell the user we are testing
print "But we are gonna run a test on\n$url\ninstead :)\n\n";
#put testing to true so we dont destroy our main imvu install
$istesting = "true";
}
}
#finnish off the installation by integrating imvu with linux by adding the url-handler protocol
integrate_with_linux();
#check if we are setting up a testing environment or not
if ($istesting =~ /true/)
{
# Get the location of Home Folder
my $HOME = $ENV{"HOME"};
# Backup old IMVU folder
backup_old_desktop_files();
#download and install in a test environment through x-terminal-emulator and then remove the installation file
system 'x-terminal-emulator -e "echo Downloading latest wine compatible version of IMVUClient && wget -O'.$cwd.'/InstallIMVU.exe '.$url.' && clear && mv \$HOME/.wine/dosdevices/c:/windows/winsxs/manifests/x86_microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.30729.4148_none_deadbeef.manifest \$HOME/.wine/dosdevices/c:/windows/winsxs/manifests/x86_microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.30729.4148_none_deadbeef.manifest.old && echo Installing IMVUClient using wine in the test environment\n$HOME/IMVU4Linux-test && '."WINEPREFIX=$HOME/IMVU4Linux-test/ wine $cwd/InstallIMVU.exe && WINEPREFIX=$HOME/IMVU4Linux-test/ wine taskmgr".' & clear && echo Please press enter when the install is done && read i && '."rm $cwd/InstallIMVU.exe\"";
# Fix the desktop files
fix_desktop_files();
}
else
{
#download and install through x-terminal-emulator and then remove the installation file
system 'x-terminal-emulator -e "echo Downloading latest wine compatible version of IMVUClient && wget -O'.$cwd.'/InstallIMVU.exe '.$url.' && clear && mv \$HOME/.wine/dosdevices/c:/windows/winsxs/manifests/x86_microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.30729.4148_none_deadbeef.manifest \$HOME/.wine/dosdevices/c:/windows/winsxs/manifests/x86_microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.30729.4148_none_deadbeef.manifest.old && echo Installing IMVUClient using wine && '."WINEDEBUG=-all wine $cwd/InstallIMVU.exe".' && clear && echo Please press enter when the install is done && read i && '."rm $cwd/InstallIMVU.exe\"";
}
}
#
#---------------------------------------- *** ----------------------------------------
#
sub checkwine
{
# get the wine version
my $wineversion = `wine --version`;
if ($wineversion =~ m/(wine-1.[01].*|[com])/)
{
die "Wine version too old, you need wine-1.2 or newer\nBut you can try at your own risk\nby starting this script with --force at the end\n\n";
}
}
#
#---------------------------------------- *** ----------------------------------------
#
sub integrate_with_linux
{
#get some variables we need for the integration
my $HOME = $ENV{"HOME"};
#get a variable from wine which we only need the last part of
my $APPDATA = `wine cmd /c echo "%APPDATA%"`;
#convert the appdata variable to unix path
$APPDATA =~ s/(C:\\|\\)/\//g;
#remove some stupid newlines in the variable(thanks alot windows!)
$APPDATA =~ s/(\r\n|\r|\n)//g;
#remove whitespace
$APPDATA =~ s/\s/\\\\\ /g;
##Integration with gnome2
#add imvu protocol to the url-hanlder in linux (xdg-open)
system "gconftool-2 --set --type=string /desktop/gnome/url-handlers/imvu/command 'wine $HOME/.wine/drive_c$APPDATA/IMVUClient/IMVUClient.exe %s'";
system "gconftool-2 --set --type=bool /desktop/gnome/url-handlers/imvu/enabled true";
system "gconftool-2 --set --type=bool /desktop/gnome/url-handlers/imvu/need-terminal false";
#now add the above commands to a script file $HOME/.local/bin/imvu-url-handler
system "mkdir -p $HOME/.local/bin";
system 'echo "#!/bin/sh"\\\\ngconftool-2 --set --type=string /desktop/gnome/url-handlers/imvu/command \\\'wine $HOME/.wine/drive_c$APPDATA/IMVUClient/IMVUClient.exe %s\\\'\\\\ngconftool-2 --set --type=bool /desktop/gnome/url-handlers/imvu/enabled true\\\\ngconftool-2 --set --type=bool /desktop/gnome/url-handlers/imvu/need-terminal false > $HOME/.local/bin/imvu-url-protocol && chmod 755 $HOME/.local/bin/imvu-url-protocol';
#now add the desktop file to add the above script to be executed at login(because gconf clears the setting at logout for some reason)
system "echo [Desktop Entry]\\\\nType=Application\\\\nExec=$HOME/.local/bin/imvu-url-protocol\\\\nName=Imvu Protocol Integration\\\\nTerminal=false\\\\nGenericName=Imvu Protocol Integration\\\\nStartupNotify=false > $HOME/.config/autostart/imvu-protocol.desktop";
##end of Integration with gnome2
##Integration with unity/gnome3
#make a .desktop file with MimeType=x-scheme-handler/imvu and then use xdg-mime default on it
system "echo [Desktop Entry]\\\\nNoDisplay=true\\\\nMimeType=x-scheme-handler/imvu\\\\nName=imvu-handler\\\\nExec=env wine $HOME/.wine/drive_c$APPDATA/IMVUClient/IMVUClient.exe %U\\\\nType=Application\\\\nStartupNotify=true > $HOME/.local/share/applications/IMVU-handler.desktop && xdg-mime default IMVU-handler.desktop x-scheme-handler/imvu";
##end of Integration with unity/gnome3
##Integration with xfce4/lxde (unfinished)
#system "mkdir -p $HOME/.local/share/xfce4/helpers";
#system "echo [Desktop Entry]\\\\nNoDisplay=true\\\\nMimeType=x-scheme-handler/imvu\\\\nName=imvu-handler\\\\nType=X-XFCE-Helper\\\\nX-XFCE-Binaries=wine $HOME/.wine/drive_c$APPDATA/IMVUClient/IMVUClient.exe\\\\nX-XFCE-Commands=wine $HOME/.wine/drive_c$APPDATA/IMVUClient/IMVUClient.exe\\\\nX-XFCE-CommandsWithParameter=wine $HOME/.wine/drive_c$APPDATA/IMVUClient/IMVUClient.exe \\\"%s\\\"\\\\nStartupNotify=true > $HOME/.local/share/xfce4/helpers/IMVU-handler.desktop";
##Integration with kde4
#add 1 extra \ to the appdata variable so KDE can use it from the protocol file
$APPDATA =~ s/\\/\\\\\\/g;
#make the kde directories incase they dont exist
system "mkdir -p $HOME/.kde/share/kde4/services/";
system "echo [Protocol]\\\\nexec=wine $HOME/.wine/drive_c$APPDATA/IMVUClient/IMVUClient.exe \\\"%u\\\"\\\\nprotocol=imvu\\\\ninput=none\\\\noutput=none\\\\nhelper=true\\\\nlisting=\\\\nreading=false\\\\nwriting=false\\\\nmakedir=false\\\\ndeleting=false\\\\nURIMode=rawuri > $HOME/.kde/share/kde4/services/imvu-handler.protocol";
##end of Integration with kde4
}
#
#---------------------------------------- *** ----------------------------------------
#
sub get_latest_wine_compatible_client_url
{
#url to the latest wine compatible client (link to latest wine compatible client is hosted on my dropbox account)
my $url = `wget -qO- http://dl.dropbox.com/u/11631899/imvu4linux/latest_imvu_wine.txt`;
#remove any newlines from the url
$url =~ s/(\r\n|\r|\n)//g;
#if we failed to get the url(due to some firewall) we will use a fallback client url
if ($url eq '')
{
#use fallback client url
$url = "$fallback_client_url";
#tell that we could not get the latest url and will use a fallback url
print "Failed to fetch the url to the latest wine compatible client, we will instead use this download url:\n$fallback_client_url\n\n";
}
else
{
print "Latest wine compatible imvu client is:\n$url\n\n";
}
#return download url
return $url
}
#
#---------------------------------------- *** ----------------------------------------
#
sub backup_old_desktop_files
{
# Find the imvu folder
my $imvufolder = `find ~/.local/share/applications/wine -name "IMVU"`;
# Remove unwanted newline and whitespace
$imvufolder =~ s/(\n|\s+)//g;
# Make a backup of it
system "mkdir $imvufolder"."-bak && cp $imvufolder/* $imvufolder"."-bak/";
}
#
#---------------------------------------- *** ----------------------------------------
#
sub fix_desktop_files
{
# Get the location of Home Folder
my $HOME = $ENV{"HOME"};
# Find the imvu folder
my $imvufolder = `find ~/.local/share/applications/wine -name "IMVU"`;
# Remove unwanted newline and whitespace
$imvufolder =~ s/(\n|\s+)//g;
# Move it to testfolder and Move the backup to its correct place
system "mkdir $HOME/IMVU4Linux-test/IMVU && rm $HOME/IMVU4Linux-test/IMVU/*";
system "mv $imvufolder/* $HOME/IMVU4Linux-test/IMVU/";
system "mv $imvufolder"."-bak/* $imvufolder/ && rmdir $imvufolder"."-bak";
# Symlink the desktop files for the test client
system "ln -s $HOME/IMVU4Linux-test/IMVU $HOME/IMVU4Linux-test/drive_c/users/\$USER/Desktop/IMVU4Linux-test && chmod 755 $HOME/IMVU4Linux-test/IMVU/* && rm $HOME/IMVU4Linux-test/IMVU/IMVU";
}
#
#---------------------------------------- *** ----------------------------------------
#
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment