dkms-helper 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. #!/bin/bash
  2. set -e
  3. DKMS=$(which dkms)
  4. usage() {
  5. echo "$(basename $0): Helper functions for DKMS (Dynamic Kernel Module Support)"
  6. echo "Usage: $0 [add|remove|generate_conf]"
  7. echo "Options:"
  8. echo " remove -a : Remove all versions of DAHDI for all kernels."
  9. echo ""
  10. echo "Examples:"
  11. echo ""
  12. echo " build_tools/dkms-helper add"
  13. echo " Installs the current version of DAHDI into the DKMS system."
  14. echo ""
  15. echo " build_tools/dkms-helper remove"
  16. echo " Removes the current version of DAHDI from all kernels."
  17. echo ""
  18. echo " build_tools/dkms-helper generate_conf > dkms.conf"
  19. echo " Create a dkms.conf based on the currently compiled kernel"
  20. echo " modules. This is also done as part of add and is not"
  21. echo " normally needed as a separate step."
  22. echo ""
  23. echo "NOTE: Because firmware files could be different between different"
  24. echo "versions of DAHDI, and the firmware files are installed into the common"
  25. echo "/lib/firmware directory, you should remove a given version of DAHDI from all"
  26. echo "kernels before installing a new version of DAHDI to avoid potential"
  27. echo "conflicts."
  28. echo ""
  29. }
  30. generate_configuration() {
  31. echo 'PACKAGE_NAME="dahdi-linux"'
  32. echo "PACKAGE_VERSION=\"$(build_tools/make_version .)\""
  33. echo 'MAKE="make KSRC=/lib/modules/${kernelver}/build"'
  34. echo 'CLEAN="make clean"'
  35. echo 'AUTOINSTALL="yes"'
  36. let "module_number=0" || true
  37. for file in $(find ./ -type f -name "*.ko"); do
  38. MODULE_LOCATION=$(dirname $file | cut -d\/ -f 2-)
  39. echo "BUILT_MODULE_NAME[$module_number]=\"$(basename $file .ko)\""
  40. echo "BUILT_MODULE_LOCATION[$module_number]=\"$MODULE_LOCATION\""
  41. echo "DEST_MODULE_LOCATION[$module_number]=\"/kernel/dahdi/$(echo $MODULE_LOCATION | cut -d\/ -f 3-)\""
  42. let "module_number=${module_number}+1" || true
  43. done
  44. if [ $module_number -eq 0 ]; then
  45. echo "WARNING: You should build the modules before generating a config." >&2
  46. exit 1
  47. fi
  48. }
  49. add() {
  50. GIT=$(which git)
  51. VERSION="$(build_tools/make_version .)"
  52. if [ $(id -u) != "0" ]; then
  53. echo "You must run $0 as root."
  54. exit 1
  55. fi
  56. echo "Building for version ${VERSION}"
  57. make > /dev/null
  58. echo "Copying to /usr/src/dahdi-linux-${VERSION}"
  59. if [ ! -d /usr/src/dahdi-linux-${VERSION} ]; then
  60. if [ -d .git ]; then
  61. ${GIT} checkout-index -a --prefix=/usr/src/dahdi-linux-${VERSION}/
  62. else
  63. cp -f -r * /usr/src/dahdi-linux-${VERSION}/
  64. fi
  65. fi
  66. make -C /usr/src/dahdi-linux-${VERSION} install-firmware firmware-loaders
  67. build_tools/dkms-helper generate_conf > /usr/src/dahdi-linux-${VERSION}/dkms.conf
  68. echo $VERSION > /usr/src/dahdi-linux-${VERSION}/.version
  69. ${DKMS} add -m dahdi-linux -v ${VERSION}
  70. ${DKMS} build -m dahdi-linux -v ${VERSION}
  71. ${DKMS} install --force -m dahdi-linux -v ${VERSION}
  72. }
  73. remove() {
  74. if [ $(id -u) != "0" ]; then
  75. echo "You must run $0 as root."
  76. exit 1
  77. fi
  78. REMOVE_ALL=false
  79. shift
  80. while getopts "a" opt; do
  81. case $opt in
  82. a) REMOVE_ALL=true ;;
  83. *) echo "Unknown option to remove" ; exit 1;;
  84. esac
  85. done
  86. if [ $REMOVE_ALL == true ]; then
  87. # Remove all installed dahdi versions for all kernels.
  88. for version in $(${DKMS} status -m dahdi-linux | cut -d, -f 2 | sed -e "s/^\s\+//"); do
  89. echo "Removing version ${version}"
  90. ${DKMS} remove -m dahdi-linux -v ${version} --all
  91. rm -f -r /usr/src/dahdi-linux-${version}
  92. done
  93. else
  94. # Just remove the version for the current tree.
  95. GIT=$(which git)
  96. VERSION="$(build_tools/make_version .)"
  97. ${DKMS} remove -m dahdi-linux -v ${VERSION} --all
  98. if [ -e /usr/src/dahdi-linux-${VERSION}/dkms.conf ]; then
  99. rm -f -r /usr/src/dahdi-linux-${VERSION}
  100. else
  101. echo "/usr/src/dahdi-linux-${VERSION} not a dkms dir?"
  102. exit 1
  103. fi
  104. fi
  105. }
  106. # Run the command...
  107. shift $(($OPTIND-1))
  108. COMMAND=$1
  109. case $COMMAND in
  110. add) add $*; exit $? ;;
  111. remove) remove $* ; exit $? ;;
  112. generate_conf) generate_configuration; exit $? ;;
  113. *) echo "unknown command $0" ; usage; exit 1;;
  114. esac
  115. exit 0