#!/bin/sh # # Copyright (c) 2005 Canonical LTD # # Author: Matt Zimmerman # # 2006, Oliver Grawert # Vagrant Cascadian # 2007, Scott Balneaves # Oliver Grawert # 2008, Vagrant Cascadian # Warren Togami # Oliver Grawert # 2009, Warren Togami # 2012, Alkis Georgopoulos # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License as # published by the Free Software Foundation; either version 2 of the # License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, you can find it on the World Wide # Web at http://www.gnu.org/copyleft/gpl.html, or write to the Free # Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, # MA 02110-1301, USA. # usage() { cat <&2 continue fi ln -sf "$file" "$tftpname/$name$flavor" ln -sf "$initrd" "$tftpname/$(echo "$name$flavor" | sed -n "$INITRD_NAME")" last_flavor=$flavor fi done } # distro specific functions # For all kernels in TFTP, find the kernel $version from vmlinuz-* filename. # If the corresponding /opt/ltsp/$name/lib/modules/$version is missing, # then delete kernel and images for this version from tftpboot directory. # Distros that don't match vmlinuz-* should override this function. cleanup_kernels() { local name tftpboot chroot name=$1 tftpboot=$2 chroot=$3 # Loop through every vmlinuz-* file for kernelpath in $(find "$tftpboot/$name/" -type f -name 'vmlinuz-*' -o -name 'vmlinux-*'); do kernel=${kernelpath##*/} case $kernel in vmlinuz-*) version=${kernel#vmlinuz-} ;; vmlinux-*) version=${kernel#vmlinux-} ;; esac if [ ! -d "$chroot/lib/modules/$version" ]; then echo "Removing $kernelpath" # Common rm -f "$tftpboot/$name/$kernel" rm -f "$tftpboot/$name/config-$version" rm -f "$tftpboot/$name/System.map-$version" rm -rf "$tftpboot/$name/dtbs-$version/" # Fedora rm -f "$tftpboot/$name/.vmlinuz-$version.hmac" rm -f "$tftpboot/$name/initrd-$version.img" rm -f "$tftpboot/$name/initramfs-$version.img" rm -f "$tftpboot/$name/elf-$version.img" rm -f "$tftpboot/$name/wraplinux-nbi-$version.img" rm -f "$tftpboot/$name/aout-$version.img" rm -f "$tftpboot/$name/symvers-$version.gz" # Debian rm -f "$tftpboot/$name/initrd.img-$version" rm -f "$tftpboot/$name/nbi.img-$version" # Ubuntu rm -f "$tftpboot/$name/abi-$version" rm -f "$tftpboot/$name/vmcoreinfo-$version" fi done } # Set an optional MODULES_BASE, so help2man can be called from build env MODULES_BASE=${MODULES_BASE:-/usr/share/ltsp} # This also sources vendor functions and .conf file settings . ${MODULES_BASE}/ltsp-server-functions if ! args=$(getopt -n "$0" -o b:h \ -l "base:,help,version" -- "$@") then exit 1 fi eval "set -- $args" while true ; do case "$1" in -b|--base) shift; BASE=$1 ;; -h|--help) usage; exit 0 ;; --version) ltsp_version; exit 0 ;; --) shift ; break ;; *) die "$0: Internal error!" ;; esac shift done require_root BASE=${BASE:-"/opt/ltsp"} # Remove trailing /, if present BASE=${BASE%/} # Chroots can be specified in the command line. If not, update all of them. if [ $# -eq 0 ]; then set -- $(list_chroots) fi test $# -gt 0 || die "No chroots found in $BASE" for tftpdir in $TFTP_DIRS; do if [ ! -d "$tftpdir" ]; then # skip directory continue fi for name in "$@"; do update_kernels "$name" "$tftpdir" done # Update selinux file contexts if possible restorecon -R "$tftpdir" 2> /dev/null || : done