Ubuntu – Steam install can erase the home. How to prevent it


I have read a disturbing topic on Valve where a user lost his system when using the steam script. There is a discussion on reddit.linux and on reddit/steam.

This may not be a common problem because I change all sorts of configuration about my system. The script in question does something in a really, really stupid way, but it probably doesn't trigger the fail scenario for every system because…

Original Bug:

I am not sure what happened. I moved the folder in the title to a drive mounted under /media/user/BLAH and symlinked /home/user/.local/steam to the new location.

I launched steam. It did not launch, it offered to let me browse, and still could not find it when I pointed to the new location. Steam crashed. I restarted it.

It re-installed itself and everything looked great. Until I looked and saw that steam had apparently deleted everything owned by my user recursively from the root directory. Including my 3tb external drive I back everything up to that was mounted under /media.

Everything important, for the most part, was in the cloud. It is a huge hassle, but it is not a disaster. If there is the chance that moving your steam folder can result in recursively deleting everything in the directory tree you should probably just throw up an error instead of trying to point to other stuff. Or you know, allow the user to pick an install directory initially like on windows.

My system is ubuntu 14.04, and the drive I moved it to was ntfs if its worth anything.

Best Answer

The problem starts around line 19 in the script "steam.sh.":

STEAMROOT="$(cd "${0%/*}" && echo $PWD)"

$STEAMROOT can become empty here effectively making the rm -rf "$STEAMROOT/"* further into the script the same as rm -rf "/"*.

There are patches showing up and there is a lot wrong with this script. Easiest to change and at least prevent deleting files it should not ...

rm -rf "$STEAMROOT/"*

to ...

[[ -n $STEAMROOT && $STEAMROOT =~ 'steam' ]] && rm -rf $STEAMROOT

Also possible to add an exit just after STEAMDATA is set:

STEAMROOT="$(cd "${0%/*}" && echo $PWD)"
if [ -z "$STEAMROOT" ]; then
    echo "stop script otherwise files are deleted from /."
    exit 1

If anyone out there installed steam as root be warned: it will delete your WHOLE disk.