/usr/bin/ubuntu-drivers is in ubuntu-drivers-common 1:0.4.17.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 | #! /usr/bin/python3
'''Driver package query/installation tool for Ubuntu'''
# (C) 2012 Canonical Ltd.
# Author: Martin Pitt <martin.pitt@ubuntu.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
import argparse
import subprocess
import sys
import os
import logging
import apt
import UbuntuDrivers.detect
def parse_args():
'''Parse command line arguments.'''
# build help for commands
commands = []
command_help = 'Available commands:'
for c in globals():
if c.startswith('command_'):
name = c.split('_', 1)[1]
commands.append(name)
command_help += '\n %s: %s' % (name, globals()[c].__doc__)
parser = argparse.ArgumentParser(description='List/install driver packages for Ubuntu.',
epilog=command_help, formatter_class=argparse.RawDescriptionHelpFormatter)
parser.add_argument('command', metavar='<command>', choices=commands,
help='See below')
parser.add_argument('--package-list', metavar='PATH',
help='Create file with list of installed packages (in autoinstall mode)')
return parser.parse_args()
def command_list(args):
'''Show all driver packages which apply to the current system.'''
packages = UbuntuDrivers.detect.system_driver_packages()
print('\n'.join(packages))
return 0
def command_devices(args):
'''Show all devices which need drivers, and which packages apply to them.'''
drivers = UbuntuDrivers.detect.system_device_drivers()
for device, info in drivers.items():
print('== %s ==' % device)
for k, v in info.items():
if k == 'drivers':
continue
print('%-9s: %s' % (k, v))
for pkg, pkginfo in info['drivers'].items():
info_str = ''
if pkginfo['from_distro']:
info_str += ' distro'
else:
info_str += ' third-party'
if pkginfo['free']:
info_str += ' free'
else:
info_str += ' non-free'
if pkginfo.get('builtin'):
info_str += ' builtin'
if pkginfo.get('recommended'):
info_str += ' recommended'
print('%-9s: %s -%s' % ('driver', pkg, info_str))
print('')
def command_autoinstall(args):
'''Install drivers that are appropriate for automatic installation.'''
cache = apt.Cache()
packages = UbuntuDrivers.detect.system_driver_packages(cache)
packages = UbuntuDrivers.detect.auto_install_filter(packages)
if not packages:
print('No drivers found for automatic installation.')
return
# ignore packages which are already installed
to_install = []
for p in packages:
if not cache[p].installed:
to_install.append(p)
if not packages:
print('All drivers for automatic installation are already installed.')
return
ret = subprocess.call(['apt-get', 'install', '-o',
'DPkg::options::=--force-confnew', '-y'] + to_install)
# create package list
if ret == 0 and args.package_list:
with open(args.package_list, 'a') as f:
f.write('\n'.join(to_install))
f.write('\n')
return ret
def command_debug(args):
'''Print all available information and debug data about drivers.'''
logging.basicConfig(level=logging.DEBUG, stream=sys.stdout)
print('=== log messages from detection ===')
aliases = UbuntuDrivers.detect.system_modaliases()
cache = apt.Cache()
packages = UbuntuDrivers.detect.system_driver_packages(cache)
auto_packages = UbuntuDrivers.detect.auto_install_filter(packages)
print('=== modaliases in the system ===')
for alias in aliases:
print(alias)
print('=== matching driver packages ===')
for package, info in packages.items():
p = cache[package]
try:
inst = p.installed.version
except AttributeError:
inst = '<none>'
try:
cand = p.candidate.version
except AttributeError:
cand = '<none>'
if package in auto_packages:
auto = ' (auto-install)'
else:
auto = ''
info_str = ''
if info['from_distro']:
info_str += ' [distro]'
else:
info_str += ' [third party]'
if info['free']:
info_str += ' free'
else:
info_str += ' non-free'
if 'modalias' in info:
info_str += ' modalias: ' + info['modalias']
if 'syspath' in info:
info_str += ' path: ' + info['syspath']
if 'vendor' in info:
info_str += ' vendor: ' + info['vendor']
if 'model' in info:
info_str += ' model: ' + info['model']
print('%s: installed: %s available: %s%s%s ' % (package, inst, cand, auto, info_str))
#
# main
#
args = parse_args()
# run the function corresponding to the specified command
command = globals()['command_' + args.command]
sys.exit(command(args))
|