Dry out a potentially dangerous script?

My predecessor installed the shitty piece of software on an old machine (running Linux) that I inherited. The shitty piece of software mentioned has installed flotsam everywhere, and it's bloated enough that I want it as soon as possible - it no longer has any functional goals since we moved on to better software.

The provider provided an uninstall script. Not trusting the crappy piece of software, I opened the uninstall script in the editor (200 + line Bash monster), and it starts with something like this:

SWROOT=`cat /etc/vendor/path.conf`
...
rm -rf $SWROOT/bin
...

It turns out that it is /etc/vendor/path.confabsent. I don’t know why, I don’t know how, but it is. If I ran this cute little script, it would delete the folder /bin, which would have pretty funny consequences. Of course, this script is required rootto run!

I dealt with this problem by simply manually executing all of the install commands (guh), where appropriate. Such a suck because I had to interpolate all the commands manually. In general, is there any way to β€œdry run” the script so that it unloads all the commands that it executed without actually executing them?

+4
source share
2 answers

script Kornshell. script ksh -D, , . set -xv, , .

set -n . Kornshell BASH . Bourne script, Kornshell, BASH .

ksh -u, - script. , . ​​ . null.

, script , , , .

, , , .

+7

bash ( ksh, zsh, - , )

, , ​​ , : , , - , - .

bash, ksh zsh - script , -n

bash -n someScript  # syntax-check a script, without executing it.
  • , , 0.
  • , , , , stderr, :
    • 2 bash
    • 3 ksh
    • 1 zsh

bash, ksh zsh :

  • -v [1] stderr .

  • -x, stderr (env. var. PS4 ).


-n -v / -x :

  • -n, -x , .

  • -n, -v .

    • , , ; , , -n .

[1] , , , , , , , while (, ) - .

+1

Source: https://habr.com/ru/post/1535675/


All Articles