1
1
mirror of https://github.com/NixOS/mobile-nixos.git synced 2024-12-15 02:43:24 +03:00
mobile-nixos/bin/menuconfig
2020-03-27 16:34:33 -04:00

58 lines
1.2 KiB
Ruby
Executable File
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env nix-shell
#!nix-shell -p ruby -i ruby
require "shellwords"
ROOT = File.join(__dir__, "..")
def usage()
puts "Usage: #{$PROGRAM_NAME} [--only-save] <device_name>"
end
# Poor approximation to arguments parsing.
params, other_args = ARGV.partition { |s| s.match(/^--/) }
if other_args.empty?
$stderr.puts "Device name required."
usage
exit 1
end
DEVICE = other_args.shift
FILE = Dir.glob(File.join(ROOT, "devices", DEVICE, "kernel", "config.*")).sort.first
ONLY_SAVE = !!params.delete("--only-save")
unless params.empty?
$stderr.puts "Unknown parameters #{params.join(", ")}."
usage
exit 1
end
unless other_args.empty?
$stderr.puts "Unexpected arguments #{other_args.join(", ")}."
usage
exit 1
end
unless File.exists?(FILE)
$stderr.puts "Could not find kernel configuration file for #{DEVICE}."
usage
exit 1
end
Dir.chdir(ROOT) do
tool = File.join(`#{[
"nix-build",
"--no-out-link",
"--argstr", "device", DEVICE,
"-A", "config.mobile.device.info.kernel.menuconfig"
].shelljoin}`.strip, "bin/nconf")
if ONLY_SAVE
# Equivalent to F9,Enter
`echo -e "[20~\n" | #{[tool, FILE].shelljoin}`
else
system(tool, FILE)
end
end
# vim: ft=ruby