From 954b805aabc4e4dc748cca526fa7150ce1c91ec4 Mon Sep 17 00:00:00 2001 From: Denis Knauf Date: Thu, 11 Apr 2013 15:38:23 +0200 Subject: [PATCH] ported to ruby (more usefull). nvidia-drivers: i do not know... --- .gitignore | 1 + linux-update | 38 ++-- linux-update.rb | 362 +++++++++++++++++++++++++++++++++++ postinst.d/10-nvidia-drivers | 9 +- 4 files changed, 384 insertions(+), 26 deletions(-) create mode 100755 linux-update.rb diff --git a/.gitignore b/.gitignore index 2a8f7e4..21168e3 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ *~ test +.*.swp diff --git a/linux-update b/linux-update index c55826c..d183585 100755 --- a/linux-update +++ b/linux-update @@ -9,20 +9,10 @@ usage() { echo "Usage: $0 $(help | sed -ne '3,$s/^\([^'"`printf '\t'`"']*\)'"`printf '\t'`"'.*$/\1/p' | tr '\n' '|' | sed -e 's/|/ | /g;s/ | $//')" } -help() { +help() { #@ Print this help message cat <&2 curl `download_uri "${1}"` } -unpack() { +unpack() { #@ simple unpack with unxz and tar in \$SOURCE_BASE_DIR (default: $SOURCE_BASE_DIR) unxz | tar -C "${SOURCE_BASE_DIR}" -xf - } -fetch() { +fetch() { #@ [V] downloads and unpack the kernel of V (default: latest_stable) download "${1}" | unpack } -update() { +update() { #@ downloads and unpack the latest_stable kernel if it isn't fetched yet if update_available then echo Update available: `latest_stable` @@ -131,11 +121,11 @@ configs() { done } -has_config() { +has_config() { #@ [V] This kernel has a config? configs | is_listed "$2" } -latest_config() { +latest_config() { #@ Which is the latest kernel with config? configs | latest_version } @@ -143,13 +133,13 @@ copy_to_dir_config() { cp "${2:-`latest_config | print_dir`}/.config" "${1:-`latest_fetched | print_dir`}" } -install_config() { +install_config() { #@ [V] Copys the config of the newest kernel with config to V. d="${1:-`latest_fetched | print_dir`}" s="${2:-`latest_config | print_dir`}" [ -e "$d/.config" ] || copy_to_dir_config "${d}" "${s}" } -oldconfig() { +oldconfig() { #@ [V] Run oldconfig (calls install_config previeusly). d="${1:-`latest_fetched | print_dir`}" install_config "$d" && make -C "$d" oldconfig } diff --git a/linux-update.rb b/linux-update.rb new file mode 100755 index 0000000..8bb255e --- /dev/null +++ b/linux-update.rb @@ -0,0 +1,362 @@ +#!/usr/bin/env ruby + +require 'shellwords' +require 'getoptlong' +require 'json' +require 'pathname' +require 'shell' +require 'uri' + +def load_required_gem lib, gem = nil, name = nil + gem ||= lib + name ||= gem + require lib +rescue LoadError + STDERR.puts <( other) version <=> other.version end + + def to_s + r = "linux-#{version} (#{moniker})" + r += " (EOL)" if end_of_life? + r + end + end + + class Fetched + attr_reader :dir + def initialize dir + @dir = Pathname.new dir + end + + def make *opts, &block + block ||= lambda {|rd| IO::copy_stream rd, STDOUT } } + dir = @dir.to_s + rd, wr = IO.pipe + pid = fork do + STDOUT.reopen wr + rd.close + exec 'make', '-C', dir, *opts + end + wr.close + wr = nil + reader = Thread.new { block.call rd } + Process.waitpid pid + raise Base::MakeFailed, "make #{opts.join ' '}" unless 0 == $?.exitstatus + reader.value + ensure + rd.close if rd + wr.close if wr + end + + def version + @version ||= make '-is', 'kernelversion' do |rd| + Versionomy.parse rd.readlines.join.chomp + end + end + + def config + dir + '.config' + end + + def configured? + return @configured if @configured + @configured = config.exist? + end + + def <=>( other) version <=> other.version end + + def to_s + r = "#{dir}" + r += " #{version}" if @version + r += " #{configured? ? :configured : 'not configured'}" if nil != @configured + r + end + + def open_config opts = nil, &block + opts ||= 'r' + if block_given? + File.open config, opts, &block + else + File.open config, opts + end + end + + def import_config_from_io( io) open_config('w') {|c| io.each_line {|l| c.print l } } end + + def import_config file_or_io_or_fetched + case file_or_io_or_fetched + when IO then import_config_from_io file_or_io_or_fetched + when Fetched + file_or_io_or_fetched.open_config &method(:import_config_from_io) + else + File.open file_or_io_or_fetched.to_s, &method(:import_config_from_io) + end + end + + def oldconfig + make 'oldconfig' + end + + def menuconfig + make 'menuconfig' + end + + def compile + make 'all' + end + + def install + make 'modules_install', 'install' + end + end + + class Base + class Error a} + end + end + end + end +end + +begin # if __FILE__ == $0 + $debug = true if $DEBUG + LinuxUpdate::Cmd.start ARGV +rescue LinuxUpdate::Cmd::Error, LinuxUpdate::Base::Error + STDERR.puts "Error: #{$!}" + STDERR.puts $!.backtrace.map {|c| "\t#{c}" } if $debug + raise + #exit 1 +rescue Object + STDERR.puts "Unknown and unexpected Error: #{$!} (#{$!.class})" + STDERR.puts $!.backtrace.map {|c| "\t#{c}" } if $debug + raise + #exit 2 +end if __FILE__ == $0 diff --git a/postinst.d/10-nvidia-drivers b/postinst.d/10-nvidia-drivers index 62ee586..343d18c 100755 --- a/postinst.d/10-nvidia-drivers +++ b/postinst.d/10-nvidia-drivers @@ -1,8 +1,13 @@ #!/usr/bin/env sh +NVDSRC="${NVDSRC:-/usr/src/nvidia-drivers}" [ -e "$0.disabled" ] && exit 0 which make >/dev/null 2>&1 || exit 0 -[ -d "/usr/src/nvidia-drivers" ] || exit 0 +[ -d "$NVDSRC" ] || exit 0 +V="${1:-`uname -r`}" +SYSSRC="/lib/modules/$V/source" +SYSOUT="/lib/modules/$V/build" echo Build NVIDIA module... >&2 -exec make -C /usr/src/nvidia-drivers SYSSRC="/lib/modules/$1/build" module-install +cd "$SYSSRC" +exec make -C "$NVDSRC" SYSOUT="$SYSOUT" SYSSRC="$SYSSRC" module-install