From 0aaff7a35255a5093230f31afca61e3db02d38c8 Mon Sep 17 00:00:00 2001 From: Aaron Plattner Date: Fri, 16 Jan 2009 12:59:38 -0800 Subject: [PATCH] Add hooks to run distribution scripts from /usr/lib/nvidia. --- backup.c | 6 ++++- install-from-cwd.c | 23 ++++++++++++++++++++- misc.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++ misc.h | 1 + nvidia-installer.1.m4 | 43 ++++++++++++++++++++++++++++++++++++++-- nvidia-installer.c | 4 +++ nvidia-installer.h | 1 + option_table.h | 8 ++++++- 8 files changed, 130 insertions(+), 7 deletions(-) diff --git a/backup.c b/backup.c index 40a421f..465cf05 100644 --- a/backup.c +++ b/backup.c @@ -534,7 +534,9 @@ static int do_uninstall(Options *op) tmpstr = nvstrcat("Uninstalling ", b->description, " (", b->version, "):", NULL); - + + run_distro_hook(op, "pre-uninstall"); + ui_status_begin(op, tmpstr, "Uninstalling"); free(tmpstr); @@ -656,6 +658,8 @@ static int do_uninstall(Options *op) /* XXX what to do if this fails?... nothing */ } + run_distro_hook(op, "post-uninstall"); + free_backup_info(b); return TRUE; diff --git a/install-from-cwd.c b/install-from-cwd.c index 0f7a35e..07df293 100644 --- a/install-from-cwd.c +++ b/install-from-cwd.c @@ -80,6 +80,7 @@ int install_from_cwd(Options *op) CommandList *c; const char *msg; int ret; + int ran_pre_install_hook = FALSE; static const char edit_your_xf86config[] = "Please update your XF86Config or xorg.conf file as " @@ -127,6 +128,17 @@ int install_from_cwd(Options *op) if (!check_for_existing_driver(op, p)) goto exit_install; + /* run the distro preinstall hook */ + + if (!run_distro_hook(op, "pre-install")) { + if (!ui_yes_no(op, TRUE, + "The distribution-provided pre-install script failed! " + "Continue installation anyway?")) { + goto failed; + } + } + ran_pre_install_hook = TRUE; + /* attempt to build a kernel module for the target kernel */ if (!op->no_kernel_module) { @@ -226,7 +238,11 @@ int install_from_cwd(Options *op) /* execute the command list */ if (!do_install(op, p, c)) goto failed; - + + /* run the distro postinstall script */ + + run_distro_hook(op, "post-install"); + /* * check that everything is installed properly (post-install * sanity check) @@ -299,7 +315,10 @@ int install_from_cwd(Options *op) "on fixing installation problems in the README available " "on the Linux driver download page at www.nvidia.com."); } - + + if (ran_pre_install_hook) + run_distro_hook(op, "failed-install"); + /* fall through into exit_install... */ exit_install: diff --git a/misc.c b/misc.c index a6cb57a..d4a1d59 100644 --- a/misc.c +++ b/misc.c @@ -2407,6 +2407,57 @@ int run_nvidia_xconfig(Options *op) } /* run_nvidia_xconfig() */ +/* + * run_distro_hook() - run a distribution-provided hook script + */ + +int run_distro_hook(Options *op, const char *hook) +{ + int ret, status, shouldrun = op->run_distro_scripts; + char *cmd = nvstrcat("/usr/lib/nvidia/", hook, NULL); + + if (op->kernel_module_only) { + ui_expert(op, + "Not running distribution-provided %s script %s because " + "--kernel-module-only was specified.", + hook, cmd); + ret = TRUE; + goto done; + } + + if (access(cmd, X_OK) < 0) { + /* it's okay if the script doesn't exist or isn't executable */ + ui_expert(op, "No distribution %s script found.", hook); + ret = TRUE; + goto done; + } + + /* in expert mode, ask before running distro hooks */ + if (op->expert) { + shouldrun = ui_yes_no(op, shouldrun, + "Run distribution-provided %s script %s?", + hook, cmd); + } + + if (!shouldrun) { + ui_expert(op, + "Not running distribution-provided %s script %s", + hook, cmd); + ret = TRUE; + goto done; + } + + ui_status_begin(op, "Running distribution scripts", "Executing %s", cmd); + status = run_command(op, cmd, NULL, TRUE, 0, TRUE); + ui_status_end(op, "done."); + + ret = (status == 0); + +done: + nvfree(cmd); + return ret; +} + /* * nv_format_text_rows() - this function breaks the given string str diff --git a/misc.h b/misc.h index d3b6d7e..72fced0 100644 --- a/misc.h +++ b/misc.h @@ -119,6 +119,7 @@ int check_for_running_x(Options *op); int check_for_modular_xorg(Options *op); int check_for_nvidia_graphics_devices(Options *op, Package *p); int run_nvidia_xconfig(Options *op); +int run_distro_hook(Options *op, const char *hook); TextRows *nv_format_text_rows(const char *prefix, const char *buf, int width, int word_boundary); diff --git a/nvidia-installer.1.m4 b/nvidia-installer.1.m4 index ff8e1da..21b55ac 100644 --- a/nvidia-installer.1.m4 +++ b/nvidia-installer.1.m4 @@ -1,7 +1,7 @@ dnl This file is to be preprocessed by m4. changequote([[[, ]]])dnl define(__OPTIONS__, [[[include([[[options.1.inc]]])dnl]]])dnl -.\" Copyright (C) 2005 NVIDIA Corporation. +.\" Copyright (C) 2005-2009 NVIDIA Corporation. .\" __HEADER__ .\" Define the URL macro and then load the URL package if it exists. @@ -9,7 +9,7 @@ __HEADER__ \\$2 \(laURL: \\$1 \(ra\\$3 .. .if \n[.g] .mso www.tmac -.TH nvidia\-installer 1 2005-09-01 "nvidia\-installer __VERSION__" +.TH nvidia\-installer 1 2009-01-09 "nvidia\-installer __VERSION__" .SH NAME nvidia\-installer \- install, upgrade, or uninstall the NVIDIA Accelerated Graphics Driver Set .SH SYNOPSIS @@ -85,6 +85,43 @@ is released under the GPL and available here: Patches are welcome. dnl Call gen-manpage-opts to generate this section. __OPTIONS__ +.SH "DISTRIBUTION HOOK SCRIPTS" +.PP +Because the NVIDIA installer may interact badly with distribution packages that contain the NVIDIA driver, +.B nvidia\-installer +provides a mechanism for the distribution to handle manual installation of the driver. +If they exist, +.B nvidia\-installer +will run the following scripts: +.RS +\(bu /usr/lib/nvidia/pre\-install +.br +\(bu /usr/lib/nvidia/pre\-uninstall +.br +\(bu /usr/lib/nvidia/post\-uninstall +.br +\(bu /usr/lib/nvidia/post\-install +.br +\(bu /usr/lib/nvidia/failed\-install +.RE +Note that if installation of a new driver requires uninstallation of a previously installed driver, the +.B pre\- +and +.B post\-uninstall +scripts will be called +.I after +the +.B pre\-install +script. +If the install fails, the installer will execute +.B /usr/lib/nvidia/failed\-install +instead of +.BR /usr/lib/nvidia/post\-install . +These scripts should not require user interaction. +.PP +Use the +.B \-\-no\-distro\-scripts +option to disable execution of these scripts. .SH EXAMPLES .TP .B nvidia\-installer \-\-latest @@ -112,4 +149,4 @@ NVIDIA Corporation .BR nvidia-settings (1), .I /usr/share/doc/NVIDIA_GLX-1.0/README.txt .SH COPYRIGHT -Copyright \(co 2005 NVIDIA Corporation. +Copyright \(co 2005-2009 NVIDIA Corporation. diff --git a/nvidia-installer.c b/nvidia-installer.c index 714361d..b9d3d40 100644 --- a/nvidia-installer.c +++ b/nvidia-installer.c @@ -250,6 +250,7 @@ Options *parse_commandline(int argc, char *argv[]) op->selinux_option = SELINUX_DEFAULT; op->sigwinch_workaround = TRUE; + op->run_distro_scripts = TRUE; while (1) { @@ -432,6 +433,9 @@ Options *parse_commandline(int argc, char *argv[]) case NO_CC_VERSION_CHECK_OPTION: op->ignore_cc_version_check = TRUE; break; + case NO_DISTRO_SCRIPTS_OPTION: + op->run_distro_scripts = FALSE; + break; default: fmterr(""); diff --git a/nvidia-installer.h b/nvidia-installer.h index ecdf2d4..4c2f805 100644 --- a/nvidia-installer.h +++ b/nvidia-installer.h @@ -140,6 +140,7 @@ typedef struct __options { int sigwinch_workaround; int no_x_check; int no_nvidia_xconfig_question; + int run_distro_scripts; char *opengl_prefix; char *opengl_libdir; diff --git a/option_table.h b/option_table.h index 8a0d2bb..0ee356a 100644 --- a/option_table.h +++ b/option_table.h @@ -52,7 +52,8 @@ enum { X_LIBRARY_PATH_OPTION, NO_KERNEL_MODULE_OPTION, NO_X_CHECK_OPTION, - NO_CC_VERSION_CHECK_OPTION + NO_CC_VERSION_CHECK_OPTION, + NO_DISTRO_SCRIPTS_OPTION }; static const NVOption __options[] = { @@ -429,6 +430,11 @@ static const NVOption __options[] = { "installation in case of failures. Use this option to override this " "check." }, + { "no-distro-scripts", NO_DISTRO_SCRIPTS_OPTION, 0, + "Normally, nvidia-installer will run scripts from /usr/lib/nvidia before " + "and after installing or uninstalling the driver. Use this option to " + "disable execution of these scripts." }, + /* Orphaned options: These options were in the long_options table in * nvidia-installer.c but not in the help. */ { "debug", 'd', 0, NULL }, -- 1.5.6.3