tftpboot cleanup script draft

Warren Togami <[email protected]>
Newsgroups gmane.linux.terminal-server.devel
Message-ID <[email protected]>
Attached is an early draft of the tftpboot cleanup script.

It should theoretically be safe.  But can anybody think of a better way 
other than the wildcard and grep scraping to safely loop through all 
directories or vmlinuz-* files even if you have no matches?

After we clean this up I aim on adding this inside the 
ltsp-update-kernels script.

Warren Togami
[email protected]

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/

_____________________________________________________________________
Ltsp-developer mailing list.   To un-subscribe, or change prefs, goto:
      https://lists.sourceforge.net/lists/listinfo/ltsp-developer
For additional LTSP help,   try #ltsp channel on irc.freenode.net
cleanup.sh (application/x-sh, 1.4 KB)
#!/bin/sh

# Get TFTPDIR value
[ -e /etc/sysconfig/ltspdist ] && . /etc/sysconfig/ltspdist
# Set it to a default if not set
[ -z "$TFTPDIR" ] && TFTPDIR=/var/lib/tftpboot

### Cleanup old kernels and images from tftpboot directory ###
# Find $version from vmlinuz-* filename
# if corresponding /opt/ltsp/$arch/lib/modules/$version is missing
# then delete kernel and images from tftpboot directory

# Loop through every arch
for archpath in $TFTPDIR/ltsp/*; do
    # Cope with empty directory
    echo $archpath |grep "\*$" > /dev/null
    [ $? -eq 0 ] && continue
    arch=`basename $archpath`

    # Loop through every vmlinuz-* file
    for kernelpath in $archpath/vmlinuz-*; do
        # Cope with lack of vmlinuz-*
        echo $kernelpath |grep "\*$" > /dev/null
        [ $? -eq 0 ] && continue

        kernel=`basename $kernelpath`
        version=${kernel##vmlinuz-}
        if [ ! -d /opt/ltsp/$arch/lib/modules/$version ]; then
            set -x
            # Common
            rm -f $archpath/vmlinuz-$version
            rm -f $archpath/config-$version
            rm -f $archpath/System.map-$version
            # Fedora
            rm -f $archpath/initrd-$version
            rm -f $archpath/elf-$version
            rm -f $archpath/wraplinux-nbi-$version
            # Debian
            rm -f $archpath/initrd.img-$version
            rm -f $archpath/nbi.img-$version
        fi
    done
done
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.