#!/bin/sh -e
# Copyright (C) 2013-2014 Michael Gilbert <mgilbert@debian.org>
# License: MIT

config=$HOME/.steam
ubuntu32=$config/ubuntu12_32
steam=$ubuntu32/steam
runtime=$ubuntu32/steam-runtime

real=/usr/games/steam.real

# do an initial update when expected pieces are missing
test ! -d $config && rm -rf $config && mkdir -p $config || true
test ! -x $config/steam.sh && rm -rf $config/package $steam || true
test ! -d $ubuntu32 && rm -rf $ubuntu32 && mkdir -p $ubuntu32 || true
test ! -x $steam && rm -rf $steam && cp $real $steam && $steam || true
test ! -e $runtime.tar.xz && cat $runtime.tar.xz.part* > $runtime.tar.xz || true
test ! -d $runtime && cd $ubuntu32 && tar xf steam-runtime.tar.xz && \
    md5sum steam-runtime.tar.xz > steam-runtime/checksum || true

# remove steam-runtime's libstdc++, which is incompatible with newer mesa drivers
# (https://bugs.freedesktop.org/78242)
rm -f $ubuntu32/steam-runtime/i386/usr/lib/i386-linux-gnu/libstdc++.so.6*
rm -f $ubuntu32/steam-runtime/amd64/usr/lib/x86_64-linux-gnu/libstdc++.so.6*

# launch the Valve run script
test -x $config/steam.sh && $config/steam.sh "$@" 2>$config/error.log
