Skip to content

Instantly share code, notes, and snippets.

@RomanHargrave
Created December 15, 2020 06:39
Show Gist options
  • Save RomanHargrave/25098f5479dc8874169e10a5cd5887b7 to your computer and use it in GitHub Desktop.
Save RomanHargrave/25098f5479dc8874169e10a5cd5887b7 to your computer and use it in GitHub Desktop.
#!/usr/bin/perl
use Getopt::Long;
my $cmd = '/usr/bin/steam';
my $rt_run = 0;
GetOptions(
'c|cmd=s' => \$cmd,
'rt' => \$rt_run,
);
my $uid = getpwnam($ENV{USER});
my @bind_rw = (
'/proc',
'/sys',
'/dev',
'/dev/shm',
'/dev/pts',
'/home',
'/tmp',
'/var/lib/dbus',
'/mnt/lfs0/roman/Steam',
'/run',
"/run/user/$uid",
);
my %set_env = (
'STEAMOS' => ''
);
my @unset_env = (
'LD_LIBRARY_PATH',
'LD_PRELOAD',
'PATH'
);
my @generated = ();
push @generated, ('--dev-bind', $_, $_) for @bind_rw;
push @generated, ('--unsetenv', $_) for @unset_env;
push @generated, ('--setenv', $_, $set_env{$_}) for keys %set_env;
my $restart_request_code = -1;
# Special case
if ($cmd eq 'steam') {
my $steam = $ENV{STEAM_HOME};
my $platform = 'ubuntu12_32';
my $rt = "$steam/$platform/steam-runtime";
my $rt_scr = "$rt/run.sh";
if (-d $rt) {
if ($rt_run) {
$cmd = $rt_scr;
} else {
$cmd = "$steam/$platform/steam";
$restart_request_code = 42;
# see: detect_platform() in steam.sh
$ENV{STEAM_RUNTIME} = $rt;
$ENV{SYSTEM_LD_LIBRARY_PATH} = $ENV{LD_LIBRARY_PATH};
$ENV{STEAM_RUNTIME_LIBRARY_PATH} = `$rt/run.sh --print-steam-runtime-library-paths`;
$ENV{LD_LIBRARY_PATH} = ${STEAM_RUNTIME_LIBRARY_PATH};
$ENV{STEAMSCRIPT} = '/usr/bin/steam';
$ENV{TEXTDOMAIN} = 'steam';
}
} else {
if ($rt_run) {
die "runtime not found";
} else {
warn "runtime not found, not performing fast launch";
}
}
}
my @exec = (
'bwrap',
'--share-net',
'--bind', '/srv/chroot/steam', '/',
'--proc', '/proc',
@generated,
# add a one-off bind because i need my music in proton apps
'--ro-bind', '/mnt/lfs0/roman/Music', '/home/roman/Music',
'--chdir', $ENV{HOME},
'--', $cmd, @ARGV,
);
print("command: " . join(' ', @exec) . "\n");
my $r = $restart_request_code;
$r = system(@exec) while $r == $restart_request_code; # steam exits with 42 when it wants to restart
exit $r;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment