http://www.politiker-stopp.de/gfx/politiker-stopp-print.png

Benjamin Schieder

[ROCKLINUX] RECOVERING YOUR /OPT DIRECTORY

2006 July 17 | 0 comments

Yesterday I accidentally crashed my /opt filesystem. This is a follow-up problem to my previous mdadm trouble.
Anyway, I ended up with creating a new filesystem on the md/3 array containing the /opt filesystem.

With a quick shellscript I was then able to reinstall the packages residing in /opt:

cd /mnt/cdrom//pkgs
mine -l | grep ' opt/' | cut -f1 -d: | sort | uniq |
while read package ; do
mine -r -s $package
mine -i $package[:-]*.gem
done


While this works fine for /opt/, there were concerns that the use of other programs than mine(.static) and a potentially statically linked /bin/sh might make the script less useful than it could be. So I have rewritten it using /bin/sh and mine(.static) only:

#!/bin/sh

dir="$1"
[ -x "`which mine.static`" ] && alias mine=mine.static

[ "${dir:0:1}" == "/" ] && dir="${dir:1}"

length="${#dir}"
oldpkg=""
OLDIFS="${IFS}"

mine -l | while read package file ; do
        [ "${file:0:${length}}" == "${dir}" ] && echo $package
done | while read package ; do
        IFS=:
        set $package
        IFS="${OLDIFS}"
        package=$1
        if [ "${package}" != "${oldpkg}" ] ; then
                echo "${package}"
                oldpkg="${package}"
        fi
done | while read package ; do
        echo mine -r -s "${package}"
        echo mine -i "${package}"
done



EOF

Category: blog

Tags: ROCKLinux


Post a comment

All comments are held for moderation; basic HTML formatting is accepted.

Name: (required)
E-mail: (required, not published)
Website: (optional)
Comment: