819da59577758a7a328020546127091e45bc59e7Kay Sievers# kernel-install(8) completion -*- shell-script -*-
819da59577758a7a328020546127091e45bc59e7Kay Sievers#
819da59577758a7a328020546127091e45bc59e7Kay Sievers# This file is part of systemd.
819da59577758a7a328020546127091e45bc59e7Kay Sievers#
819da59577758a7a328020546127091e45bc59e7Kay Sievers# Copyright 2013 Kay Sievers
e861b62154173b730c3fd8ca040641fba8870bb6Harald Hoyer# Copyright 2013 Harald Hoyer
819da59577758a7a328020546127091e45bc59e7Kay Sievers#
819da59577758a7a328020546127091e45bc59e7Kay Sievers# systemd is free software; you can redistribute it and/or modify it
819da59577758a7a328020546127091e45bc59e7Kay Sievers# under the terms of the GNU Lesser General Public License as published by
819da59577758a7a328020546127091e45bc59e7Kay Sievers# the Free Software Foundation; either version 2.1 of the License, or
819da59577758a7a328020546127091e45bc59e7Kay Sievers# (at your option) any later version.
819da59577758a7a328020546127091e45bc59e7Kay Sievers#
819da59577758a7a328020546127091e45bc59e7Kay Sievers# systemd is distributed in the hope that it will be useful, but
819da59577758a7a328020546127091e45bc59e7Kay Sievers# WITHOUT ANY WARRANTY; without even the implied warranty of
819da59577758a7a328020546127091e45bc59e7Kay Sievers# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
819da59577758a7a328020546127091e45bc59e7Kay Sievers# General Public License for more details.
819da59577758a7a328020546127091e45bc59e7Kay Sievers#
819da59577758a7a328020546127091e45bc59e7Kay Sievers# You should have received a copy of the GNU Lesser General Public License
819da59577758a7a328020546127091e45bc59e7Kay Sievers# along with systemd; If not, see <http://www.gnu.org/licenses/>.
819da59577758a7a328020546127091e45bc59e7Kay Sievers
819da59577758a7a328020546127091e45bc59e7Kay Sievers_kernel_install() {
e861b62154173b730c3fd8ca040641fba8870bb6Harald Hoyer local comps
e861b62154173b730c3fd8ca040641fba8870bb6Harald Hoyer local MACHINE_ID
e861b62154173b730c3fd8ca040641fba8870bb6Harald Hoyer local cur=${COMP_WORDS[COMP_CWORD]}
e861b62154173b730c3fd8ca040641fba8870bb6Harald Hoyer
e861b62154173b730c3fd8ca040641fba8870bb6Harald Hoyer case $COMP_CWORD in
e861b62154173b730c3fd8ca040641fba8870bb6Harald Hoyer 1)
e861b62154173b730c3fd8ca040641fba8870bb6Harald Hoyer comps="add remove"
e861b62154173b730c3fd8ca040641fba8870bb6Harald Hoyer ;;
e861b62154173b730c3fd8ca040641fba8870bb6Harald Hoyer 2)
819da59577758a7a328020546127091e45bc59e7Kay Sievers comps=$(cd /lib/modules; echo [0-9]*)
e861b62154173b730c3fd8ca040641fba8870bb6Harald Hoyer if [[ ${COMP_WORDS[1]} == "remove" ]] && [[ -f /etc/machine-id ]]; then
e861b62154173b730c3fd8ca040641fba8870bb6Harald Hoyer read MACHINE_ID < /etc/machine-id
e861b62154173b730c3fd8ca040641fba8870bb6Harald Hoyer if [[ $MACHINE_ID ]] && ( [[ -d /boot/$MACHINE_ID ]] || [[ -L /boot/$MACHINE_ID ]] ); then
e861b62154173b730c3fd8ca040641fba8870bb6Harald Hoyer comps=$(cd "/boot/$MACHINE_ID"; echo [0-9]*)
e861b62154173b730c3fd8ca040641fba8870bb6Harald Hoyer fi
e861b62154173b730c3fd8ca040641fba8870bb6Harald Hoyer fi
e861b62154173b730c3fd8ca040641fba8870bb6Harald Hoyer ;;
e861b62154173b730c3fd8ca040641fba8870bb6Harald Hoyer 3)
e861b62154173b730c3fd8ca040641fba8870bb6Harald Hoyer [[ "$cur" ]] || cur=/boot/vmlinuz-${COMP_WORDS[2]}
e861b62154173b730c3fd8ca040641fba8870bb6Harald Hoyer comps=$(compgen -f -- "$cur")
e861b62154173b730c3fd8ca040641fba8870bb6Harald Hoyer compopt -o filenames
e861b62154173b730c3fd8ca040641fba8870bb6Harald Hoyer ;;
e861b62154173b730c3fd8ca040641fba8870bb6Harald Hoyer esac
819da59577758a7a328020546127091e45bc59e7Kay Sievers
819da59577758a7a328020546127091e45bc59e7Kay Sievers COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
819da59577758a7a328020546127091e45bc59e7Kay Sievers return 0
819da59577758a7a328020546127091e45bc59e7Kay Sievers}
819da59577758a7a328020546127091e45bc59e7Kay Sievers
819da59577758a7a328020546127091e45bc59e7Kay Sieverscomplete -F _kernel_install kernel-install