iamthesgt
12-08-2011, 07:19
So I was writing a Makefile for a VideoServer to install the web interface pages. The Makefile had the typical rules - all, clean, install, uninstall. To uninstall, it needed to remove all the executables from a certain directory /var/www (this is on Linux, btw). However, it needed to be dynamic in that it should be able to tell what distro of Linux it was running and set a path variable accordingly, since there are different places the files go in different distributions. So I wrote a bash script for inside the Makefile to set this path variable. The clean rule was like this:
rm -r ${installdir)/*
Some of you probably already see where this is going. Needless to say, the installdir variable never got set, and held an empty value. Big problem was, the install/uninstall options had to be run as super user in order to write/delete to those particular locations. Well, it started removing files, just the wrong ones. For those of you who don't use Linux, the top-level directory is "/". This holds all the folders needed for the OS, programs, and your files. EVERYTHING is in this folder. The * in this case acts as a wildcard and means 'all files' and the -r option for the rm command (remove) means recursively, or go into all subfolders and delete those too (still not sure why the -r option was set). So it did exactly what I told it to - "rm -r /*", or my entire filesystem.
Moral of the story is, be careful with su and rm. Even a simple Makefile can cause lots of problems.
rm -r ${installdir)/*
Some of you probably already see where this is going. Needless to say, the installdir variable never got set, and held an empty value. Big problem was, the install/uninstall options had to be run as super user in order to write/delete to those particular locations. Well, it started removing files, just the wrong ones. For those of you who don't use Linux, the top-level directory is "/". This holds all the folders needed for the OS, programs, and your files. EVERYTHING is in this folder. The * in this case acts as a wildcard and means 'all files' and the -r option for the rm command (remove) means recursively, or go into all subfolders and delete those too (still not sure why the -r option was set). So it did exactly what I told it to - "rm -r /*", or my entire filesystem.
Moral of the story is, be careful with su and rm. Even a simple Makefile can cause lots of problems.