Skip to content

Commit

Permalink
Add a postexec option that can be used to chain the installer to a
Browse files Browse the repository at this point in the history
newly installed program.
  • Loading branch information
jwhite66 committed Jun 9, 2010
1 parent de85af1 commit b5d82e3
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 2 deletions.
7 changes: 7 additions & 0 deletions docs.txt
Expand Up @@ -323,6 +323,13 @@ Here are the elements, and the attributes they can possess.
hook.


postexec (no default, mustBeString)

This attribute can be used to chain the installer to another process
on a successful installation. The string can contain $DESTINATION which
will be replaced with the installation destination.


updateurl (no default, mustBeUrl)

This is written to the manifest files for the aid of external tools, but
Expand Down
11 changes: 11 additions & 0 deletions lua_glue.c
Expand Up @@ -1102,6 +1102,16 @@ static int luahook_platform_uninstalldesktopmenuitem(lua_State *L)
} // luahook_platform_uninstalldesktopmenuitem


static int luahook_platform_exec(lua_State *L)
{
const char *cmd = luaL_checkstring(L, 1);
logDebug("exec %0", cmd);
MojoPlatform_exec(cmd);
logError("exec %0 failed", cmd);
return retvalBoolean(L, 0);
} // luahook_platform_exec


static int luahook_movefile(lua_State *L)
{
boolean retval = false;
Expand Down Expand Up @@ -1809,6 +1819,7 @@ boolean MojoLua_initLua(void)
set_cfunc(luaState, luahook_platform_mkdir, "mkdir");
set_cfunc(luaState, luahook_platform_installdesktopmenuitem, "installdesktopmenuitem");
set_cfunc(luaState, luahook_platform_uninstalldesktopmenuitem, "uninstalldesktopmenuitem");
set_cfunc(luaState, luahook_platform_exec, "exec");
lua_setfield(luaState, -2, "platform");

// Set the GUI functions...
Expand Down
3 changes: 3 additions & 0 deletions platform.h
Expand Up @@ -245,6 +245,9 @@ boolean MojoPlatform_installDesktopMenuItem(const char *data);
// Returns (true) on success and (false) on failure.
boolean MojoPlatform_uninstallDesktopMenuItem(const char *data);

// Exec a given process name
int MojoPlatform_exec(const char *cmd);

#if !SUPPORT_MULTIARCH
#define MojoPlatform_switchBin(img, len)
#else
Expand Down
8 changes: 8 additions & 0 deletions platform_unix.c
Expand Up @@ -29,6 +29,7 @@
#include <fcntl.h>
#include <sys/wait.h>
#include <limits.h>
#include <errno.h>

#if MOJOSETUP_HAVE_SYS_UCRED_H
# ifdef MOJOSETUP_HAVE_MNTENT_H
Expand Down Expand Up @@ -1255,6 +1256,13 @@ boolean MojoPlatform_uninstallDesktopMenuItem(const char *data)
} // MojoPlatform_uninstallDesktopMenuItem


int MojoPlatform_exec(const char *cmd)
{
execl(cmd, cmd, NULL);
return errno;
} // MojoPlatform_exec


#if SUPPORT_MULTIARCH
void MojoPlatform_switchBin(const uint8 *img, size_t len)
{
Expand Down
8 changes: 8 additions & 0 deletions platform_windows.c
Expand Up @@ -517,6 +517,14 @@ boolean MojoPlatform_uninstallDesktopMenuItem(const char *data)
} // MojoPlatform_uninstallDesktopMenuItem


int MojoPlatform_exec(const char *cmd)
{
STUBBED("exec");
return 127;
} // MojoPlatform_exec



boolean MojoPlatform_spawnTerminal(void)
{
assert(!MojoPlatform_istty());
Expand Down
3 changes: 2 additions & 1 deletion scripts/mojosetup_init.lua
Expand Up @@ -317,7 +317,8 @@ function Setup.Package(tab)
{ "write_manifest", true, mustBeBool },
{ "support_uninstall", true, mustBeBool },
{ "preuninstall", nil, mustBeFunction },
{ "postuninstall", nil, mustBeFunction }
{ "postuninstall", nil, mustBeFunction },
{ "postexec", nil, mustBeString}
})

if MojoSetup.installs == nil then
Expand Down
13 changes: 12 additions & 1 deletion scripts/mojosetup_mainline.lua
Expand Up @@ -1836,7 +1836,6 @@ local function do_install(install)
-- Done with these things. Make them eligible for garbage collection.
stages = nil
MojoSetup.manifest = nil
MojoSetup.destination = nil
MojoSetup.manifestdir = nil
MojoSetup.metadatadir = nil
MojoSetup.controldir = nil
Expand Down Expand Up @@ -1877,6 +1876,7 @@ end


local function installer()
local postexec = nil
MojoSetup.loginfo("Installer starting")

MojoSetup.revertinstall = real_revertinstall -- replace the stub.
Expand All @@ -1890,13 +1890,24 @@ local function installer()
if not install.disabled then
saw_an_installer = true
do_install(install)

if (install.postexec ~= nil) then
postexec = string.gsub(install.postexec, "$DESTINATION", MojoSetup.destination)
end

MojoSetup.collectgarbage() -- nuke all the tables we threw around...
end
end

if not saw_an_installer then
MojoSetup.fatal(_("Nothing to do!"))
end

if postexec ~= nil then
MojoSetup.platform.exec(postexec)
end

MojoSetup.destination = nil
end


Expand Down

0 comments on commit b5d82e3

Please sign in to comment.