Skip to content

Commit

Permalink
Added preuninstall and postuninstall hooks to the config file.
Browse files Browse the repository at this point in the history
  • Loading branch information
icculus committed Feb 26, 2008
1 parent 0553881 commit eaae940
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 30 deletions.
24 changes: 24 additions & 0 deletions docs.txt
Expand Up @@ -285,6 +285,30 @@ Here are the elements, and the attributes they can possess.
Setup.Package table as a parameter.


preuninstall (no default, mustBeFunction)

If this attribute is defined, it is called by the uninstaller after the
user confirms that uninstallation is acceptable and deletion of
files is about to begin. It passes something like the finalized
Setup.Package table as a parameter. This function is serialized for later
use, in a different program running in a different context: it may NOT use
any Lua upvalues (they will be local variables set to nil when the function
runs) and any globals you reference may or may not exist when the
function runs. Try to do the bare minimum here if you must use this hook.


postinstall (no default, mustBeFunction)

If this attribute is defined, it is called by the uninstaller after the
uninstallation has successfully finished. It passes something like the
finalized Setup.Package table as a parameter. This function is serialized
for later use, in a different program running in a different context: it
may NOT use any Lua upvalues (they will be local variables set to nil when
the function runs) and any globals you reference may or may not exist when
the function runs. Try to do the bare minimum here if you must use this
hook.


updateurl (no default, mustBeUrl)

This is written to the manifest files for the aid of external tools, but
Expand Down
29 changes: 2 additions & 27 deletions scripts/mojosetup_init.lua
Expand Up @@ -266,6 +266,8 @@ function Setup.Package(tab)
{ "superuser", false, mustBeBool },
{ "write_manifest", true, mustBeBool },
{ "support_uninstall", true, mustBeBool },
{ "preuninstall", nil, mustBeFunction },
{ "postuninstall", nil, mustBeFunction }
})

if MojoSetup.installs == nil then
Expand All @@ -278,33 +280,6 @@ function Setup.Package(tab)
return tab

--[[
preuninstall
This is a shell script which is executed at the very beginning
of the uninstall process. It will be run before any RPM uninstall
scripts. This file is not installed, but is added to the
beginning of uninstall script.
postuninstall
This is a shell script which is executed at the very end of the
uninstall process. It will be run after any RPM uninstall
scripts. This file is not installed, but is added to the
end of the uninstall script.
IMPORTANT: An actual file name for a shell scripts needs to be specified,
not a command, for both pre/postuninstall entries.
"sh script.sh" is incorrect, but "script.sh" is correct.
Both the preuninstall and postuninstall scripts will have access
to the default environment variables. See the 'SCRIPT' section
for details.
Also, these scripts will be run at the very beginning and very
end of the install cleanup if the install is aborted.
nouninstall This is an optional flag which, if specified, tells setup
not to generate an uninstall script after it runs. It also
doesn't generate any data for product queries and auto-updating.
promptbinaries When set to "yes", setup will create a checkbox
to allow the user whether or not to create
a symbolic link to the binaries.
Expand Down
12 changes: 9 additions & 3 deletions scripts/mojosetup_mainline.lua
Expand Up @@ -726,9 +726,9 @@ local function set_destination(dest)
end


local function run_config_defined_hook(func, install)
local function run_config_defined_hook(func, pkg)
if func ~= nil then
local errstr = func(install)
local errstr = func(pkg)
if errstr ~= nil then
MojoSetup.fatal(errstr)
end
Expand Down Expand Up @@ -829,6 +829,8 @@ local function serialize(obj)
retval = tostring(obj)
elseif objtype == "string" then
retval = string.format("%q", obj)
elseif objtype == "function" then
retval = "loadstring(" .. string.format("%q", string.dump(obj)) .. ")"
elseif objtype == "table" then
retval = "{\n"
local tab = string.rep("\t", indent)
Expand Down Expand Up @@ -981,7 +983,9 @@ local function install_manifests(desc, key)
version = MojoSetup.install.version,
manifest = MojoSetup.manifest,
splash = MojoSetup.install.splash,
desktopmenuitems = MojoSetup.install.desktopmenuitems
desktopmenuitems = MojoSetup.install.desktopmenuitems,
preuninstall = MojoSetup.install.preuninstall,
postuninstall = MojoSetup.install.postuninstall
}

-- now build these things...
Expand Down Expand Up @@ -1800,6 +1804,7 @@ local function uninstaller()

if uninstall_permitted then
start_gui(package.description, package.splash)
run_config_defined_hook(package.preuninstall, package)

uninstall_desktop_menu_items(package)

Expand All @@ -1823,6 +1828,7 @@ local function uninstaller()

local filelist = flatten_manifest(package.manifest, prepend_dest_dir)
delete_files(filelist, callback, true)
run_config_defined_hook(package.postuninstall, package)
MojoSetup.gui.final(_("Uninstall complete"))
stop_gui()
end
Expand Down

0 comments on commit eaae940

Please sign in to comment.