}
int run_lua_script(const char *root, const char *name, const char *body,
- ssize_t len)
+ ssize_t len, int arg1)
{
int i, n;
lua_State *L;
return -1;
}
+ lua_newtable(L);
+ lua_pushvalue(L, LUA_GLOBALSINDEX);
+ lua_pushliteral(L, "arg");
+ lua_pushvalue(L, -3);
+ lua_rawset(L, -3);
+ lua_pop(L, 1);
+ lua_pushliteral(L, "<lua>");
+ lua_rawseti(L, -2, 1);
+ if (arg1 >= 0) {
+ lua_pushinteger(L, arg1);
+ lua_rawseti(L, -2, 2);
+ }
+ lua_pop(L, 1);
+
if (lua_pcall(L, 0, 0, 0)) {
fprintf(stderr, "lua script failed: %s\n", lua_tostring(L, -1));
lua_pop(L, 1);
razor_merger_destroy(struct razor_merger *merger);
int run_lua_script(const char *root, const char *name, const char *body,
- ssize_t len);
+ ssize_t len, int arg1);
int razor_run_script(const char *root, enum razor_property_flags script,
- const char *program, const char *body);
+ const char *program, const char *body, int arg1);
/* Utility functions */
* @set: a %razor_set
* @package: a %razor_package
* @root: the root into which the package is currently installed
+ * @install_count: the value to pass to uninstall scripts
*
* Removes an installed package.
**/
RAZOR_EXPORT int
razor_package_remove(struct razor_set *set, struct razor_package *package,
- const char *root)
+ const char *root, int install_count)
{
struct razor_file_iterator *fi;
struct razor_package_iterator *pi;
RAZOR_DETAIL_LAST);
environment_set(&env);
- retval = razor_run_script(root, RAZOR_PROPERTY_PREUN, program, script);
+ retval = razor_run_script(root, RAZOR_PROPERTY_PREUN, program, script,
+ install_count);
environment_unset(&env);
if (retval) {
RAZOR_DETAIL_LAST);
environment_set(&env);
- retval = razor_run_script(root, RAZOR_PROPERTY_POSTUN, program, script);
+ retval = razor_run_script(root, RAZOR_PROPERTY_POSTUN, program, script,
+ install_count);
environment_unset(&env);
environment_release(&env);
struct razor_package *package, ...);
int
razor_package_remove(struct razor_set *set, struct razor_package *package,
- const char *root);
+ const char *root, int install_count);
/**
void razor_rpm_get_details(struct razor_rpm *rpm, ...);
void razor_rpm_set_relocations(struct razor_rpm *rpm,
struct razor_relocations *relocations);
-int razor_rpm_install(struct razor_rpm *rpm, const char *root);
+int razor_rpm_install(struct razor_rpm *rpm, const char *root,
+ int install_count);
int razor_rpm_close(struct razor_rpm *rpm);
/**
}
static int
-run_script_lua(const char *root, unsigned int script_tag, const char *script)
+run_script_lua(const char *root, unsigned int script_tag, const char *script,
+ int arg1)
{
int root_fd, retval;
#if HAVE_LUA
break;
}
root_fd = chroot_push(root);
- retval = run_lua_script(root_fd < 0 ? root : NULL, name, script, -1);
+ retval = run_lua_script(root_fd < 0 ? root : NULL, name, script, -1,
+ arg1);
chroot_pop(root_fd);
#else /* HAVE_LUA */
fprintf(stderr, "lua not available to run script\n");
}
static int
-run_script_external(const char *root, const char *program, const char *script)
+run_script_external(const char *root, const char *program, const char *script,
+ int arg1)
{
int root_fd, retval;
FILE *fp;
+ char buf[32], *command;
if (program == NULL) {
#if MSWIN_API
}
root_fd = chroot_push(root);
- fp = popen(program, "w");
+ if (arg1 >= 0) {
+ sprintf(buf, "%d", arg1);
+ command = malloc(strlen(program) + strlen(buf) + 2);
+ sprintf(command, "%s %s", program, buf);
+ } else
+ command = strdup(program);
+ fp = popen(command, "w");
+ free(command);
if (!fp) {
perror(program);
static int
run_script(struct installer *installer,
- unsigned int program_tag, unsigned int script_tag)
+ unsigned int program_tag, unsigned int script_tag, int arg1)
{
int i, retval;
struct razor_rpm *rpm = installer->rpm;
const char *script = NULL, *program = NULL, *prefix;
- char buf[32], *p;
+ char buf[32];
struct environment env;
program = razor_rpm_get_indirect(rpm, program_tag, NULL);
}
if (program && strcmp(program, "<lua>") == 0)
- retval = run_script_lua(installer->root, script_tag, script);
+ retval = run_script_lua(installer->root, script_tag, script,
+ arg1);
else
- retval = run_script_external(installer->root, program, script);
+ retval = run_script_external(installer->root, program, script,
+ arg1);
if (rpm->relocations) {
environment_unset(&env);
int
razor_run_script(const char *root, enum razor_property_flags script,
- const char *program, const char *body)
+ const char *program, const char *body, int arg1)
{
int retval;
unsigned int script_tag;
script_tag = 0;
break;
}
- retval = run_script_lua(root, script_tag, body);
+ retval = run_script_lua(root, script_tag, body, arg1);
}
else
- retval = run_script_external(root, program, body);
+ retval = run_script_external(root, program, body, arg1);
return retval;
}
}
RAZOR_EXPORT int
-razor_rpm_install(struct razor_rpm *rpm, const char *root)
+razor_rpm_install(struct razor_rpm *rpm, const char *root, int install_count)
{
struct installer installer;
struct cpio_file_header *header;
if (installer_init(&installer))
return -1;
- run_script(&installer, RPMTAG_PREINPROG, RPMTAG_PREIN);
+ run_script(&installer, RPMTAG_PREINPROG, RPMTAG_PREIN, install_count);
while (installer.stream.avail_in > 0) {
installer.rest = sizeof *header;
if (installer_finish(&installer))
return -1;
- run_script(&installer, RPMTAG_POSTINPROG, RPMTAG_POSTIN);
+ run_script(&installer, RPMTAG_POSTINPROG, RPMTAG_POSTIN, install_count);
return 0;
}
free(s);
script = razor_file_get_contents(test_file, &len);
- r = run_lua_script(root, test_file, script, len);
+ r = run_lua_script(root, test_file, script, len, -1);
razor_file_free_contents(script, len);
recursive_remove(root);
if (relocations)
razor_rpm_set_relocations(rpm, relocations);
razor_transaction_fixup_package(trans, package, rpm);
- retval = razor_rpm_install(rpm, install_root);
+ retval = razor_rpm_install(rpm, install_root, 1);
if (retval < 0)
fprintf(stderr, "failed to install rpm %s\n", file);
razor_rpm_close(rpm);
relocations);
else if (action == RAZOR_INSTALL_ACTION_REMOVE)
retval = razor_package_remove(set, package,
- install_root);
+ install_root, 0);
}
razor_install_iterator_destroy(ii);
if prefix==nil then
prefix="/usr"
end
-if posix.stat(prefix.."/bin/zap")~=nil then
+if arg[2]==1 and posix.stat(prefix.."/bin/zap")~=nil then
mkdir_missing(prefix.."/var")
mkdir_missing(prefix.."/var/lib")
posix.mkdir(prefix.."/var/lib/zip")
if prefix==nil then
prefix="/usr"
end
-if posix.stat(prefix.."/bin/zap")~=nil then
+if arg[2]==0 and posix.stat(prefix.."/bin/zap")~=nil then
os.remove(prefix.."/var/lib/zip/data.zap")
os.remove(prefix.."/var/lib/zip")
end
if prefix==nil then
prefix="/usr"
end
-if posix.stat(prefix.."/bin/zip")~=nil then
+if arg[2]==1 and posix.stat(prefix.."/bin/zip")~=nil then
mkdir_missing(prefix.."/var")
mkdir_missing(prefix.."/var/lib")
posix.mkdir(prefix.."/var/lib/zsh")
if prefix==nil then
prefix="/usr"
end
-if posix.stat(prefix.."/bin/zip")~=nil then
+if arg[2]==0 and posix.stat(prefix.."/bin/zip")~=nil then
os.remove(prefix.."/var/lib/zsh/data.zip")
os.remove(prefix.."/var/lib/zsh")
end