Live data from Hacker News

Moved ~/.local/share/steam. Ran steam. It deleted everything owned by user

github.com

1–10 of 280 posts

Re: Moved ~/.local/share/steam. Ran steam. It deleted everything owned by user

#3
Here's the offending shell script code:

  # figure out the absolute path to the script being run a bit
  # non-obvious, the ${0%/*} pulls the path out of $0, cd's into the
  # specified directory, then uses $PWD to figure out where that
  # directory lives - and all this in a subshell, so we don't affect
  # $PWD
  STEAMROOT="$(cd "${0%/*}" && echo $PWD)"
  [...]
  # Scary!
  rm -rf "$STEAMROOT/"*
The programmer knew the danger and did nothing but write the "Scary!" comment. Sad, but all-too-familiar.

Re: Moved ~/.local/share/steam. Ran steam. It deleted everything owned by user

#4

What is this magic doing? $(cd "${0%/*}")

$0 is the path of the script. ${0%/* } takes $0, deletes the smallest substring matching /* from the right (the filename) and returns the rest, which would be the directory of the script. So this changes the directory to the directory the script is located in.

Re: Moved ~/.local/share/steam. Ran steam. It deleted everything owned by user

#5

    # Scary!
    rm -rf "$STEAMROOT/"*
Anybody who writes a line like this deserves their software engineer license revoked. This isn't the first time I've seen shit like this (I've seen it in scripts expected to be run as root, no less); it makes my blood boil.

Seriously. "xargs rm -df -- EDIT: I shouldn't be so harsh, if it weren't for the comment admitting knowing how poor an idea this line is.

Re: Moved ~/.local/share/steam. Ran steam. It deleted everything owned by user

#6

What is this magic doing? $(cd "${0%/*}")

Per a subsequent comment in the github thread:

"the ${0%/*} pulls the path out of $0, cd's into the specified directory, then uses $PWD to figure out where that directory lives - and all this in a subshell, so we don't affect $PWD"

So for example, that would take /user/amputect/seam_setup.sh and change directories into into /user/amputect.

Re: Moved ~/.local/share/steam. Ran steam. It deleted everything owned by user

#8
The biggest lesson here is that backing up your files is extremely important. Both local backups and remote backups.

I like the 3-2-1 rule:

  At least three copies,
  In two different formats,
  with one of those copies off-site.
Software is written by humans who will undoubtably miss a corner case and not think of every possible environment.

Re: Moved ~/.local/share/steam. Ran steam. It deleted everything owned by user

#9
This is a danger of me-ware being used before it becomes software. Software assumes and defends against others using and running it. Me-ware makes no assumptions because me is the only one running it.

The transition from meware to software is a hard one - and usually it's how we get terrible reputations as an industry. Basically it's a prototype till it's burned enough beta users.

Edit OMG - that is actually Steam from valve - I take it back - this is supposed to be software.

Re: Moved ~/.local/share/steam. Ran steam. It deleted everything owned by user

#10

What is this magic doing? $(cd "${0%/*}")

$0 is the path of the script. ${0%/* } takes $0, deletes the smallest substring matching /* from the right (the filename) and returns the rest, which would be the directory of the script. So this changes the directory to the directory the script is located in.

Is there any good reason to use this approach over the more readable 'dirname $0'? Not that it would have made any difference to the bug in question of course.
Post reply on HN