do_dkms revision 7eaaa8a4480370b82ef3735994f986f338fb4df2
7eaaa8a4480370b82ef3735994f986f338fb4df2vboxsync#!/bin/sh
7eaaa8a4480370b82ef3735994f986f338fb4df2vboxsync
7eaaa8a4480370b82ef3735994f986f338fb4df2vboxsync#
7eaaa8a4480370b82ef3735994f986f338fb4df2vboxsync# Script to register/build/unregister a kernel module with DKMS.
7eaaa8a4480370b82ef3735994f986f338fb4df2vboxsync#
7eaaa8a4480370b82ef3735994f986f338fb4df2vboxsync# Copyright (C) 2010 Oracle Corporation
7eaaa8a4480370b82ef3735994f986f338fb4df2vboxsync#
7eaaa8a4480370b82ef3735994f986f338fb4df2vboxsync# This file is part of VirtualBox Open Source Edition (OSE), as
7eaaa8a4480370b82ef3735994f986f338fb4df2vboxsync# available from http://www.virtualbox.org. This file is free software;
7eaaa8a4480370b82ef3735994f986f338fb4df2vboxsync# you can redistribute it and/or modify it under the terms of the GNU
7eaaa8a4480370b82ef3735994f986f338fb4df2vboxsync# General Public License (GPL) as published by the Free Software
7eaaa8a4480370b82ef3735994f986f338fb4df2vboxsync# Foundation, in version 2 as it comes in the "COPYING" file of the
7eaaa8a4480370b82ef3735994f986f338fb4df2vboxsync# VirtualBox OSE distribution. VirtualBox OSE is distributed in the
7eaaa8a4480370b82ef3735994f986f338fb4df2vboxsync# hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
7eaaa8a4480370b82ef3735994f986f338fb4df2vboxsync#
7eaaa8a4480370b82ef3735994f986f338fb4df2vboxsync
7eaaa8a4480370b82ef3735994f986f338fb4df2vboxsyncDKMS=`which dkms 2>/dev/null`
7eaaa8a4480370b82ef3735994f986f338fb4df2vboxsyncif [ -n "$DKMS" ]
7eaaa8a4480370b82ef3735994f986f338fb4df2vboxsyncthen
7eaaa8a4480370b82ef3735994f986f338fb4df2vboxsync if [ "$1" = "uninstall" ]; then
7eaaa8a4480370b82ef3735994f986f338fb4df2vboxsync
7eaaa8a4480370b82ef3735994f986f338fb4df2vboxsync echo "Uninstalling modules from DKMS"
7eaaa8a4480370b82ef3735994f986f338fb4df2vboxsync for m in _OLDMODULES_
7eaaa8a4480370b82ef3735994f986f338fb4df2vboxsync do
7eaaa8a4480370b82ef3735994f986f338fb4df2vboxsync $DKMS status -m $m | while read line
7eaaa8a4480370b82ef3735994f986f338fb4df2vboxsync # first, remove _any_ old module
7eaaa8a4480370b82ef3735994f986f338fb4df2vboxsync do
7eaaa8a4480370b82ef3735994f986f338fb4df2vboxsync if echo "$line" | grep -q added > /dev/null ||
7eaaa8a4480370b82ef3735994f986f338fb4df2vboxsync echo "$line" | grep -q built > /dev/null ||
7eaaa8a4480370b82ef3735994f986f338fb4df2vboxsync echo "$line" | grep -q installed > /dev/null; then
7eaaa8a4480370b82ef3735994f986f338fb4df2vboxsync # either 'vboxvideo, <version>: added'
7eaaa8a4480370b82ef3735994f986f338fb4df2vboxsync # or 'vboxvideo, <version>, ...: installed'
7eaaa8a4480370b82ef3735994f986f338fb4df2vboxsync version=`echo "$line" | sed "s/$m,\([^,]*\)[,:].*/\1/;t;d"`
7eaaa8a4480370b82ef3735994f986f338fb4df2vboxsync echo " removing old DKMS module $m version $version"
7eaaa8a4480370b82ef3735994f986f338fb4df2vboxsync $DKMS remove -m $m -v $version --all
7eaaa8a4480370b82ef3735994f986f338fb4df2vboxsync fi
7eaaa8a4480370b82ef3735994f986f338fb4df2vboxsync done
7eaaa8a4480370b82ef3735994f986f338fb4df2vboxsync done
7eaaa8a4480370b82ef3735994f986f338fb4df2vboxsync # there should not be any more matches
7eaaa8a4480370b82ef3735994f986f338fb4df2vboxsync status=`$DKMS status -m _MODULE_ -v _VERSION_`
7eaaa8a4480370b82ef3735994f986f338fb4df2vboxsync if echo $status | grep added > /dev/null ||
7eaaa8a4480370b82ef3735994f986f338fb4df2vboxsync echo $status | grep built > /dev/null ||
7eaaa8a4480370b82ef3735994f986f338fb4df2vboxsync echo $status | grep installed > /dev/null
7eaaa8a4480370b82ef3735994f986f338fb4df2vboxsync then
7eaaa8a4480370b82ef3735994f986f338fb4df2vboxsync $DKMS remove -m _MODULE_ -v _VERSION_ --all
7eaaa8a4480370b82ef3735994f986f338fb4df2vboxsync fi
7eaaa8a4480370b82ef3735994f986f338fb4df2vboxsync exit 0
7eaaa8a4480370b82ef3735994f986f338fb4df2vboxsync
7eaaa8a4480370b82ef3735994f986f338fb4df2vboxsync elif [ "$1" = "install" ]; then
7eaaa8a4480370b82ef3735994f986f338fb4df2vboxsync
7eaaa8a4480370b82ef3735994f986f338fb4df2vboxsync echo "Attempting to install using DKMS"
7eaaa8a4480370b82ef3735994f986f338fb4df2vboxsync if $DKMS add -m _MODULE_ -v _VERSION_ &&
7eaaa8a4480370b82ef3735994f986f338fb4df2vboxsync $DKMS build -m _MODULE_ -v _VERSION_ &&
7eaaa8a4480370b82ef3735994f986f338fb4df2vboxsync $DKMS install -m _MODULE_ -v _VERSION_ --force
7eaaa8a4480370b82ef3735994f986f338fb4df2vboxsync then
7eaaa8a4480370b82ef3735994f986f338fb4df2vboxsync exit 0
7eaaa8a4480370b82ef3735994f986f338fb4df2vboxsync fi
7eaaa8a4480370b82ef3735994f986f338fb4df2vboxsync echo "Failed to install using DKMS, attempting to install without"
7eaaa8a4480370b82ef3735994f986f338fb4df2vboxsync
7eaaa8a4480370b82ef3735994f986f338fb4df2vboxsync fi
7eaaa8a4480370b82ef3735994f986f338fb4df2vboxsyncfi
7eaaa8a4480370b82ef3735994f986f338fb4df2vboxsync
7eaaa8a4480370b82ef3735994f986f338fb4df2vboxsyncexit 1