[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: How do I rebuild alternative symlinks?



On Thu, Oct 26, 2006 at 02:30:09PM -0700, Tyler MacDonald wrote:
> I found a way to do it, but I think the solution was less than ideal:
> 
> Install "Debarnacle" from CPAN (isn't even in debian...)

Supposing /etc/alternatives is correct, I have a script to do that:
    for i in /var/lib/dpkg/alternatives/*; do
      j=$(basename $i)
      STATE=0
      while read a && [ -n "$a" ]; do
        case $STATE in
          0) STATE=1
              ;;
          1) STATE=2
             mkdir -p $(dirname "$a")
             if [ -e $a -o -L $a ]; then rm -rf $a; fi
             ln -s /etc/alternatives/${j} ${a}
              ;;
          *) STATE=1
             j="$a"
        esac
      done < $i
    done
  for i in /var/lib/dpkg/alternatives/*; do
    j=$(basename $i)
    STATE=0
    while read a && [ -n "$a" ]; do
      case $STATE in
     0) STATE=1
        ;;
     1) STATE=2
        b=$(ls -lL "$a" 2>&1 >/dev/null|wc -l)
        if [ "$b" -gt 0 ]; then
          rm -f "$a"; rm -f "/etc/alternatives/${j}"
        fi
        ;;
     *) STATE=1
        j="$a"
      esac
    done < $i
  done

The second loop just removes dangling alternatives. I don't like them.



Reply to: