代码拉取完成,页面将自动刷新
# -*- coding: UTF-8 -*-
#!/usr/bin/python3
# kmodtool - Helper script for building kernel module RPMs
import os,subprocess,sys
def print_verrel ():
#verrel=subprocess.getoutput("(rpm -q --qf '%{VERSION}-%{RELEASE}' `rpm -q kernel-devel` | head -n 1)")
# if (len(verrel)== 0):
verrel=subprocess.getoutput("uname -r")
return verrel
def print_rpmtemplate():
kmod_name = sys.argv[2]
# verrel=subprocess.getoutput("(rpm -q --qf '%{VERSION}-%{RELEASE}' `rpm -q kernel-devel` | head -n 1)")
# if (len(verrel)== 0):
verrel=subprocess.getoutput("uname -r")
if not kmod_name:
print("Please provide the kmodule-name as first parameter.")
exit()
get_rpmtemplate(kmod_name,verrel)
def get_rpmtemplate(kmod_name,verrel):
print("%package -n kmod-" + kmod_name)
print("Summary: " + kmod_name + " " + "kernel module(s)")
print("Group: System Environment/Kernel")
if "%{version}":
print("Version: %{version}")
if "%{release}":
print("Release: %{release}")
print("Provides: kernel-modules =" + " " + verrel)
print("Provides: "+ kmod_name + "-kmod = %{?epoch:%{epoch}:}%{version}-%{release}")
print("Requires(post): /usr/sbin/depmod")
print("Requires(postun): /usr/sbin/depmod")
print("%description -n kmod-" + kmod_name)
print("This package provides the " + kmod_name + " kernel modules built for the Linux")
print("kernel "+ verrel + " for the %{_target_cpu} family of processors.")
print("%post -n kmod-" + kmod_name)
print("if [ -e /boot/System.map-" + verrel + "]; then")
print(" /sbin/depmod -aeF /boot/System.map-" + verrel +" " + verrel +"> /dev/null || :")
print("fi")
if (kmp !=""):
print("modules=( $(find /lib/modules/" + verrel + "/extra/" + kmod_name + "| grep '\\.ko$'" + ") )")
print("""if [ -x "/sbin/weak-modules" ]; then
printf '%s\\n' "${modules[@]}" | /sbin/weak-modules --add-modules
fi""")
print("%preun -n kmod-" + kmod_name)
print("rpm -ql kmod-" + kmod_name + "| grep '\.ko$' > /var/run/rpm-kmod-" + kmod_name +"-modules")
print("%postun -n kmod-" + kmod_name)
print("/sbin/depmod -aF /boot/System.map-" + verrel+" " + verrel + " &> /dev/null || :")
if (kmp !=""):
print("modules=( $(cat /var/run/rpm-kmod-" + kmod_name + "-modules) )")
print("#rm /var/run/rpm-kmod-" + kmod_name + "-modules")
print("""if [ -x "/sbin/weak-modules" ]; then
printf '%s\\n' "${modules[@]}" | /sbin/weak-modules --remove-modules
fi""")
print("%files -n kmod-" + kmod_name)
kmp_override_filelist= sys.argv[3]
if kmp_override_filelist == '%filelist':
print("%defattr(644,root,root,755)")
print("/lib/modules/" + verrel)
print("/lib/firmware/")
else:
with open(kmp_override_filelist) as f:
for line in f:
print(line, end = '')
#for i in range(len(sys.argv)):
if (sys.argv[1] == "verrel"):
print_verrel()
if (sys.argv[1] == "rpmtemplate_kmp"):
kmp=1
print_rpmtemplate()
else:
print("Error: Unknown option 'sys.argv[i]'.")
exit()
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。