I was recently writing a Makefile for cramfs, specifically the distclean and install sections. The installation would copy the program binaries to /usr/bin while the cleanup would remove them… simple enough right?
I wrote a for loop to go through $(PROGS) and remove them from $(INSTLOC):
INSTLOC = /usr/bin
PROGS = mkcramfs cramfsck
all: $(PROGS)
distclean clean:
for p in $(PROGS);\
do\
rm -rf $$p $(INSTLOC)/$$p;\
done
install:
cp $(PROGS) $(INSTLOC)
The problem was that I ran this as root (tsk tsk), and since Makefile requires that for loop variables be escaped (line 9: $$p not $p), the rm command translated to this:
rm -rf /usr/bin/
Great! So now I had no binaries in /usr/bin, which includes: yum, bash, crontab, python, perl… (800+ in total on a minimal install).
Since I only deleted the binaries, the programs were still listed as installed in the RPM database. The first thing I had to do was reinstall yum and it’s “usrbin” dependency python:
[root@demon ~]# mount /dev/sr0 /media/cdrom [root@demon ~]# cd /media/cdrom/Packages [root@demon ~]# rpm -Uvh --force python-2.6.5-3.el6.i686.rpm [root@demon ~]# rpm -Uvh --force yum-3.2.27-14.el6.noarch.rpm
The next step was to figure out which packages had binaries in /usr/bin so I can reinstall them:
[root@demon ~]# rpm -qf $(rpm -qla|grep ^/usr/bin)|uniq|sort
… and finally send those to yum to do a reinstall and get the binaries back:
[root@demon ~]# yum reinstall $(rpm -qf $(rpm -qla|grep ^/usr/bin)|uniq|sort) [root@demon ~]# ls -la /usr/bin|wc -l 848 [root@demon ~]#
… crisis averted! Snapshot time.
One last note: If you manually installed third party RPMs (not listed in the /etc/yum.repos.d repositories), they will not be reinstalled. You can perform reinstall these one by one using the rpm -Uvh command above. Keep in mind that if these RPMs have not undergone proper QA they may overwrite your current configuration files
You can run these RPMs through rpmlint to see if they produce any warnings or errors that may cause a problem when reinstalling:
[root@demon ~]# rpmlint -iv iplog-2.2.1-1_RH7.i386.rpm ... iplog.i386: W: conffile-without-noreplace-flag /etc/iplog.conf A configuration file is stored in your package without the noreplace flag. A way to resolve this is to put the following in your SPEC file: %config(noreplace) /etc/your_config_file_here ... [root@demon ~]#
Goodluck!