Advertisement
Guest User

Untitled

a guest
Mar 8th, 2021
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.92 KB | None | 0 0
  1. [[ -n "$DEBUG" ]] && set -x
  2.  
  3.  
  4. # Variable
  5. KERNEL_SRC=/usr/src
  6. GRUB_CFG_FILE=/boot/grub2/grub.cfg
  7. LOG=/var/log/kernel_update
  8. DATE=$(date "+%d%m%Y")
  9.  
  10.  
  11. function usage () {
  12. echo "USAGE : "
  13. echo "$0 target_kernek_version"
  14. }
  15.  
  16. if [[ $# -ne 1 ]]
  17. then
  18. usage
  19. exit 1
  20. fi
  21.  
  22. target=$1
  23.  
  24. GETUID=$(id -u)
  25. if [ ${GETUID} -ne 0 ]
  26. then
  27. echo "This script must be run as root"
  28. exit 10
  29. fi
  30.  
  31.  
  32. if [ ! -d "${KERNEL_SRC}/linux-${target}" ]
  33. then
  34. echo "${KERNEL_SRC}/linux-${target} doesn't exist"
  35. exit 2
  36. fi
  37.  
  38.  
  39. if [ ! -d "${KERNEL_SRC}/linux" ]
  40. then
  41. echo "${KERNEL_SRC}/linux doesn't exist"
  42. exit 3
  43. fi
  44.  
  45. if [ ! -f "${KERNEL_SRC}/linux/.config" ]
  46. then
  47. echo "${KERNEL_SRC}/linux.config doesn't exist"
  48. exit 4
  49. fi
  50.  
  51. cp ${KERNEL_SRC}/linux/.config ${KERNEL_SRC}/linux-${target}
  52. if [ $? -ne 0 ]
  53. then
  54. echo "Error : cannot copy config file"
  55. # exit 5
  56. else
  57. echo "Copy ok"
  58. fi
  59.  
  60. rm ${KERNEL_SRC}/linux
  61. if [ $? -ne 0 ]
  62. then
  63. echo "Error : cannot remove old symbolic link"
  64. exit 4
  65. else
  66. echo "symbolic link ok"
  67. fi
  68.  
  69. ln -s ${KERNEL_SRC}/linux-${target} ${KERNEL_SRC}/linux
  70. if [ $? -ne 0 ]
  71. then
  72. echo "Error : cannot create symbolic link"
  73. exit 4
  74. else
  75. echo "symbolic link ok"
  76. fi
  77.  
  78. cd ${KERNEL_SRC}/linux
  79. pwd
  80.  
  81. ################################################################################
  82. # Choosing kernel options
  83. ################################################################################
  84. make oldconfig
  85.  
  86. ################################################################################
  87. # Choosing kernel options
  88. ################################################################################
  89. make menuconfig
  90.  
  91. ################################################################################
  92. # Compile and install kernel
  93. ################################################################################
  94. make -j5 && make modules_install
  95. #
  96. cp arch/x86_64/boot/bzImage /boot/kernel-${target}
  97. if [ $? -ne 0 ]
  98. then
  99. echo "Error : cannot copy kernel image to /boot"
  100. exit 5
  101. else
  102. echo "Copy ok"
  103. fi
  104.  
  105. ################################################################################
  106. # External modules : nvidia driver, virtual box ...
  107. ################################################################################
  108. emerge -1 @module-rebuild
  109. if [ $? -ne 0 ]
  110. then
  111. echo "Error : cannot rebuild external kernel modules"
  112. exit 6
  113. else
  114. echo "External kernel modules rebuilding ok"
  115. fi
  116.  
  117. ################################################################################
  118. # Grub
  119. ################################################################################
  120. # Backup
  121. cp -p ${GRUB_CFG_FILE} ${GRUB_CFG_FILE}.${DATE}
  122. if [ $? -ne 0 ]
  123. then
  124. echo "Error : cannot backup grub config file"
  125. exit 5
  126. else
  127. echo "Copy ok"
  128. fi
  129.  
  130. # Update grub config
  131. grub-mkconfig -o ${GRUB_CFG_FILE}
  132. if [ $? -ne 0 ]
  133. then
  134. echo "Error : cannot update grub config"
  135. exit 7
  136. else
  137. echo "Update ok"
  138. fi
  139.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement