This repository has been archived on 2019-12-04. You can view files and clone it, but cannot push or open issues or pull requests.
wino/wino

129 lines
3.2 KiB
Perl

#!/usr/bin/perl -s
#
# wino v git
#
# WINO (WINO is not an organizer) is a simple script to help
# organize your wine installation into separate WINEPREFIX directories.
# This allows you to have multiple wine "containers", or virtual Windows
# installations, that are separated from each other.
# See 'wino --help' for information on available options
use strict;
use File::Path qw(make_path);
### User-editable fields go here
# The WINO_DIR is the directory wino will store all of its containers
# Do not include a / at the end of this, or things could break...
my $WINO_DIR = '~/opt/wino';
### No more user-editable data below
my $VERSION = "git";
my $HELP_MSG = "wino v $VERSION\n\tusage: wino --list | <prefix> [options] [command]\n\n" .
"Valid options:\n\n" .
"--config\t\tRun winecfg for the container\n" .
"--default <command>\tSet the command that will be run when no other command is given\n" .
"--trick <options>\tRun winetricks with the specified options\n" .
"--regedit\t\tRun regedit for the container\n";
my $winecmd = 'wine';
my $uname = `uname -i`;
chomp $uname;
if ($uname eq "x86_64" && -x "/usr/bin/wine32") { $winecmd = 'wine32'; }
foreach (@ARGV)
{
die $HELP_MSG if (/^(--help)|(-h)$/);
}
my $prefix = shift @ARGV;
my $command = shift @ARGV;
# Handle WINO_DIR having a ~
$WINO_DIR =~ s/~/$ENV{'HOME'}/;
# Check for WINO_DIR, make it if needed
unless (-d $WINO_DIR) { make_path $WINO_DIR; }
# We separate out the check for --list, since it uses $prefix and doesn't operate on a container
if ($prefix eq '--list')
{
print "Wino Containers:\n";
# List the installed wino containers
foreach (`ls -1 $WINO_DIR`)
{
s/^.*$WINO_DIR\///;
print;
}
exit;
}
# Set the container path
my $container_path = "$WINO_DIR/$prefix";
# Check for the special commands "--config", "--default", "--trick"
if ($command eq '--config')
{
# Run winecfg on the container
exec "WINEPREFIX=$container_path $winecmd winecfg"
}
elsif ($command eq '--default')
{
my $new_command = join(' ', @ARGV);
# Set the default command for the container
open(DEFAULT_FILE, ">$container_path/default") or die "Cannot open file to save default: $!";
print DEFAULT_FILE $new_command . "\n";
close DEFAULT_FILE;
print "Set default command: $new_command\n";
}
elsif ($command eq '--trick')
{
my $new_command = join(' ', @ARGV);
# Run winetricks with whatever came after it. No sanity checking, we'll let winetricks handle that
exec "WINEPREFIX=$container_path winetricks $new_command";
}
elsif ($command eq '--regedit')
{
exec "WINEPREFIX=$container_path regedit";
}
elsif ($command eq '--msi')
{
my $new_command = join(' ', @ARGV);
exec "WINEPREFIX=$container_path msiexec /i $new_command";
}
elsif ($command eq '--task')
{
exec "WINEPREFIX=$container_path taskmgr";
}
else
{
# Execute the command given, or the default command
if ($command eq '')
{
if (-e "$container_path/default")
{
$command=`cat $container_path/default`;
chomp $command;
exec "WINEPREFIX=$container_path $winecmd $command @ARGV";
}
else { die "No command given, and no default command found"; }
}
else
{
exec "WINEPREFIX=$container_path $winecmd \"$command\" @ARGV";
}
}