3 | #
4 | # This program is free software: you can redistribute it and/or modify it under
5 | # the terms of the GNU General Public License version 3, as published by the
6 | # Free Software Foundation.
7 | #
8 | # This program is distributed in the hope that it will be useful, but WITHOUT
9 | # ANY WARRANTY; without even the implied warranties of MERCHANTABILITY,
10 | # SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 | # General Public License for more details.
12 | #
13 | # You should have received a copy of the GNU General Public License along with
14 | # this program. If not, see .
15 |
16 | import codecs
17 | import glob
18 | import importlib
19 | import os
20 | import setuptools
21 | import sys
22 |
23 |
24 | version = '0.3.4'
25 |
26 |
27 | # Automatically installing python packages with system dependencies can be
28 | # tricky on some binary distributions, so we ask the user to install them using
29 | # their distribution's package manager.
30 | missing_packages = []
31 | for package in ['bs4', 'docutils', 'lxml']:
32 | if not importlib.find_loader(package):
33 | missing_packages.append(package)
34 | if missing_packages:
35 | print("The following python packages cannot be found on your system, it is",
36 | "recommended to install them using your distribution's package",
37 | "manager:")
38 | for package in missing_packages:
39 | print(package)
40 | sys.exit(1)
41 |
42 | # We can now import docutils
43 | from docutils.core import publish_file
44 |
45 | here = os.path.abspath(os.path.dirname(__file__))
46 |
47 | with codecs.open(os.path.join(here, 'README.rst'), encoding='utf-8') as f:
48 | long_description = f.read()
49 |
50 | # Generate README.html from README.rst
51 | with open('README.rst', 'r') as readme_rst, open('README.html', 'w') as \
52 | readme_html:
53 | publish_file(source=readme_rst, destination=readme_html, writer_name='html')
54 |
55 | # If the user requested a --user install from pip or does not have read, write
56 | # and execute access to /etc, then we install settings into
57 | # ~/.config/kernelconfig instead instead of /etc/kernelconfig.
58 | if '--user' in sys.argv:
59 | etc_dir = '../.config'
60 | else:
61 | etc_dir = '/etc'
62 | etc_dir = os.path.join(etc_dir, 'kernelconfig')
63 |
64 | # The actual setuptools information
65 | setuptools.setup(
66 | name='kernelconfig',
67 | version=version,
68 | description="""Generate custom Linux kernel configurations from curated sources""",
69 | long_description=long_description,
70 | url="https://github.com/Calchan/kernelconfig",
71 | author='Denis Dupeyron',
72 | author_email='calchan@gentoo.org',
73 | license='GPLv3',
74 | classifiers=[
75 | 'Development Status :: 3 - Alpha',
76 | 'Environment :: Console',
77 | 'Intended Audience :: System Administrators',
78 | 'License :: OSI Approved :: GNU General Public License v3 (GPLv3)',
79 | 'Natural Language :: English',
80 | 'Operating System :: POSIX :: Linux',
81 | 'Programming Language :: Python :: 3.4',
82 | 'Topic :: System :: Installation/Setup',
83 | 'Topic :: System :: Operating System Kernels :: Linux'],
84 | keywords='Linux kernel configuration',
85 | packages=setuptools.find_packages(),
86 | data_files=[('share/kernelconfig/sources', glob.glob('sources/*')),
87 | (etc_dir, glob.glob('settings/*')),
88 | ('share/doc/kernelconfig-' + version, ['README.html'])],
89 | entry_points={'console_scripts': ['kernelconfig=kernelconfig.main:run']})
90 |
--------------------------------------------------------------------------------
/sources/arch:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 |
3 | IFS=$'\n'
4 |
5 | history_url='https://git.archlinux.org/svntogit/packages.git/log/trunk/PKGBUILD?h=packages/linux&ofs='
6 | commit_url='https://git.archlinux.org/svntogit/packages.git/plain/trunk/PKGBUILD?h=packages/linux&id='
7 | config_url='https://git.archlinux.org/svntogit/packages.git/plain/trunk/config?h=packages/linux&id='
8 |
9 | if [[ "${2}" != "x86_64" ]]; then
10 | echo "Architecture ${2} is not supported by Arch"
11 | exit 1
12 | fi
13 |
14 | kernel_maj_min=$(echo ${3} | sed 's/^\([0-9]*\)\.\([0-9]*\)\..*/\1.\2/')
15 |
16 | offset=0
17 | while true; do
18 | commit_lines=$(curl -s "${history_url}${offset}" | grep ".* | .*/\1/")
21 | message=$(echo ${line} | sed "s/.*linux&id=[a-f0-9]*'>\([^<]*\)<.*/\1/")
22 | pkg_maj_min=$(echo ${message} | sed 's/^\([0-9]*\)\.\([0-9]*\)\..*/\1.\2/')
23 | if [[ "${pkg_maj_min}" == "${kernel_maj_min}" ]]; then
24 | echo "Using configuration from Arch kernel ${message}"
25 | curl -s "${config_url}${commit}" > arch_config
26 | cp arch_config "${1}"
27 | exit
28 | fi
29 | done
30 | offset=$((offset+50))
31 | done
32 |
--------------------------------------------------------------------------------
/sources/liquorix:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 |
3 | if [[ "${2}" == "x86_64" ]]; then
4 | name="amd64"
5 | elif [[ "${2}" == "i386" ]] || [[ "${2}" == "i686" ]]; then
6 | name="i386"
7 | if [[ "${4}" == "--pae" ]]; then
8 | name="${name}-pae"
9 | fi
10 | fi
11 | name="config.${name}"
12 | echo "Downloading ${name} from Liquorix"
13 | wget --quiet "http://liquorix.net/sources/${3}/${name}"
14 | cp "${name}" "${1}"
15 |
--------------------------------------------------------------------------------
/sources/ubuntu:
--------------------------------------------------------------------------------
1 | #!/usr/bin/python3
2 | # kernelconfig - Generate custom kernel configurations from curated sources
3 | # Copyright (C) 2015 Denis Dupeyron
4 | #
5 | # This program is free software: you can redistribute it and/or modify it under
6 | # the terms of the GNU General Public License version 3, as published by the
7 | # Free Software Foundation.
8 | #
9 | # This program is distributed in the hope that it will be useful, but WITHOUT
10 | # ANY WARRANTY; without even the implied warranties of MERCHANTABILITY,
11 | # SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 | # General Public License for more details.
13 | #
14 | # You should have received a copy of the GNU General Public License along with
15 | # this program. If not, see .
16 |
17 | import argparse
18 | import re
19 | import operator
20 | import subprocess
21 | import time
22 | from urllib import request
23 |
24 | from bs4 import BeautifulSoup
25 |
26 |
27 | def download(url):
28 | print("Downloading " + url)
29 | with request.urlopen(url) as response:
30 | return response.read()
31 |
32 |
33 | def add_splitconfig(splitconfig):
34 | global splitconfigs
35 | print("Adding " + splitconfig)
36 | splitconfigs.append(splitconfig)
37 |
38 |
39 | argparser = argparse.ArgumentParser(description="""
40 | Download Ubuntu base configurations.""")
41 | argparser.add_argument("config", type=str, help="""
42 | Absolute path to kernel config""")
43 | argparser.add_argument("arch", type=str, help="""
44 | Architecture as given by 'uname -m'""")
45 | argparser.add_argument("version", type=str, help="""
46 | Major kernel version in the form X.Y""")
47 | argparser.add_argument("--lowlatency", action='store_true', help="""
48 | Enable low-latency timing and preemption (i386, i686 and x86_64 only)""")
49 | args = argparser.parse_args()
50 |
51 | # Everything starts from this page.
52 | top_url = 'http://kernel.ubuntu.com/~kernel-ppa/mainline/'
53 | # Download it.
54 | top_page = download(top_url)
55 | # Parse it.
56 | soup = BeautifulSoup(top_page, 'lxml')
57 | # The page only has a big table. Extract it.
58 | table = soup.find_all('table')[0]
59 | # The table is made of rows containing a version, a date and some cruft.
60 | all_versions = []
61 | for row in table:
62 | version = ''
63 | date = ''
64 | try:
65 | # Find the version number in that row.
66 | for cell in row.find_all('a', href=True):
67 | version = cell['href']
68 | # Now try to search all cells for something looking like a date.
69 | for cell in row.find_all('td'):
70 | try:
71 | date = time.strptime(cell.string, '%Y-%m-%d %H:%M ')
72 | # If the cell contents fail to convert to a date, skip it.
73 | except (TypeError, ValueError):
74 | pass
75 | # If any of the find_all() above fails then skip the entire row.
76 | except AttributeError:
77 | pass
78 | try:
79 | # Create a tuple for each valid row with:
80 | # - Complete version number as extrated above
81 | # - Major kernel version number in the form X.Y
82 | # - Time string in the form YYYYMMDDHHMM
83 | all_versions.append((version,
84 | re.sub(r'v(\d*\.\d*).*', r'\1', version),
85 | time.strftime('%Y%m%d%H%M', date)))
86 | # The header and footer rows do not contain suitable data and thus the
87 | # conversions above for the major kernel version and the time string will
88 | # fail. In that case skip the row.
89 | except TypeError:
90 | pass
91 | # Now just retain those rows whose major kernel version matches the one passed
92 | # as argument of this script.
93 | all_versions = [(lv, sv, d) for lv, sv, d in all_versions if sv == args.version]
94 | # Then sort them all chronologically using the time string.
95 | all_versions = sorted(all_versions, key=operator.itemgetter(2))
96 | # And finally select the last (most recent) one, and only keep the URL path.
97 | version_path = all_versions[-1][0]
98 |
99 | # We can now reconstruct the full URL to the page of the desired kernel.
100 | version_page = download(top_url + version_path)
101 | # And parse it.
102 | soup = BeautifulSoup(version_page, 'lxml')
103 | # One of the files we need has a variable name, let's figure it out.
104 | patch3_name = [cell.string for cell in soup.find_all('a', href=True) if
105 | re.match(r'[0-9]*-configs-based-on-Ubuntu-.*\.patch',
106 | cell.string)][0]
107 |
108 | # The two files we need are patches.
109 | for patch_name in ['0001-base-packaging.patch', patch3_name]:
110 | # Let's download them and save them to disk.
111 | with open(patch_name, 'wb') as patch_file:
112 | patch_file.write(download(top_url + version_path + patch_name))
113 | # Apply them to nothing since there are only file creations.
114 | print("Applying " + patch_name)
115 | with open(patch_name, 'r') as patch_file:
116 | subprocess.call(['patch', '--silent', '-p1'], stdin=patch_file)
117 |
118 | # We can start picking the files we need. All architectures need this one.
119 | splitconfigs = []
120 | add_splitconfig('config.common.ubuntu')
121 |
122 | # We add the architecture- and option-specific files to the list.
123 | # TODO Do it for the remaining architectures.
124 |
125 | if args.arch == 'i386' or args.arch == 'i686':
126 | add_splitconfig('i386/config.common.i386')
127 | if args.lowlatency:
128 | add_splitconfig('i386/config.flavour.lowlatency')
129 | else:
130 | add_splitconfig('i386/config.flavour.generic')
131 |
132 | if args.arch == 'x86_64':
133 | add_splitconfig('amd64/config.common.amd64')
134 | if args.lowlatency:
135 | add_splitconfig('amd64/config.flavour.lowlatency')
136 | else:
137 | add_splitconfig('amd64/config.flavour.generic')
138 |
139 | # We now have the list of necessary files. We just need to concatenate them and
140 | # save the result.
141 | with open(args.config, 'w') as config_file:
142 | for splitconfig in splitconfigs:
143 | with open('debian.master/config/' + splitconfig, 'r') as split_file:
144 | config_file.write(split_file.read())
145 |
--------------------------------------------------------------------------------
|