diff -r 0e1a57225c62 -r 212150407fcc pre-inst/pre-inst.c --- a/pre-inst/pre-inst.c Mon Jul 13 13:19:03 2020 +0100 +++ b/pre-inst/pre-inst.c Tue Jul 14 13:17:21 2020 +0100 @@ -90,7 +90,7 @@ unsigned pre_install_thread(void *data) { int retval; - gchar *path=data; + const char *repository=data; gchar *s,*uri; char *install[]={"plover-gtkui",NULL}; GError *error=NULL; @@ -106,19 +106,17 @@ free(uri); if (verify_and_fix(prefix)) { - g_free(path); g_free(prefix); return -1; } - retval=!plover_install(path,prefix,install,&error); + retval=!plover_install_uri(repository,prefix,install,&error); if (!retval) - retval=!plover_update(path,prefix,NULL,&error); + retval=!plover_update_uri(repository,prefix,NULL,&error); if (error) { fprintf(stderr,"%s\n",error->message); g_error_free(error); } - g_free(path); #ifdef WIN32 PostQuitMessage(retval); PostThreadMessage(main_thread_id,WM_QUIT,retval,0); @@ -136,7 +134,7 @@ #else void * #endif -pre_install(const char *path) +pre_install(const char *repository) { #ifdef WIN32 HANDLE retval; @@ -146,10 +144,10 @@ razor_set_lua_loader("posix",(void (*)())luaopen_posix); razor_set_lua_loader("whelk",(void (*)())luaopen_whelk); #ifdef WIN32 - retval=(HANDLE)_beginthreadex(NULL,0,pre_install_thread,(void *)path,0, - NULL); + retval=(HANDLE)_beginthreadex(NULL,0,pre_install_thread,(void *)repository, + 0,NULL); #else - if (pre_install_thread(path)) + if (pre_install_thread((void *)repository)) retval=NULL; else retval=(void *)1; /* Non-NULL to indicate success */ @@ -343,12 +341,14 @@ * Run a command after completing request. * * Command may refer to %INSTALL_PREFIX% which will be replaced by the - * (first) install prefix used and/or %TEST_RESULT% which will be replaced + * (first) install prefix used, by %TEST_RESULT% which will be replaced * by either "pass" or "fail" depending as to whether the request succeeded - * or not. Command may also include double quotes which will be used to - * affect how the command is split into arguments much like a shell does. + * or not and/or by %REPOSITORY% which will be replaced by the URI of the + * repository used. Command may also include double quotes which will be used + * to affect how the command is split into arguments much like a shell does. */ -gboolean run_post(int argc,char **argv,gboolean test_result,GError **error) +gboolean run_post(int argc,char **argv,gboolean test_result, + const char *repository,GError **error) { int i,post_argc; char *s; @@ -391,6 +391,15 @@ g_free(post_argv[i]); post_argv[i]=expanded; } + s=strstr(post_argv[i],"%REPOSITORY%"); + if (s) + { + *s='\0'; + s+=strlen("%REPOSITORY%"); + expanded=g_strconcat(post_argv[i],repository,s,NULL); + g_free(post_argv[i]); + post_argv[i]=expanded; + } } #ifdef USE_G_SPAWN if (!g_spawn_sync(NULL,post_argv,NULL,G_SPAWN_SEARCH_PATH,NULL,NULL, @@ -429,14 +438,14 @@ } #ifdef WIN32 -DWORD win32_pre_install_gui(char *path) +DWORD win32_pre_install_gui(char *repository) { HANDLE thread; INITCOMMONCONTROLSEX icc={0,}; MSG msg; DWORD retval; main_thread_id=GetCurrentThreadId(); - thread=(HANDLE)pre_install(path); + thread=(HANDLE)pre_install(repository); if (!thread) return EXIT_FAILURE; icc.dwSize=sizeof(icc); @@ -456,7 +465,7 @@ } #endif /* WIN32 */ -gchar *pre_install_default_path(const char *argv0) +gchar *pre_install_default_repository(const char *argv0) { size_t length; void *contents; @@ -464,13 +473,13 @@ gchar *s,*uri; struct razor_error *tmp_error=NULL; /* - * The default path is the executable itself if it's an archive + * The default repository is the executable itself if it's an archive * or otherwise the directory in which the executable is stored. */ path=plover_get_program(argv0); uri=razor_path_to_uri(path); + free(path); s=g_strconcat(uri,"/repodata/comps.xml",NULL); - free(uri); contents=razor_uri_get_contents(s,&length,FALSE,&tmp_error); g_free(s); if (contents) @@ -480,21 +489,24 @@ if (razor_error_matches(tmp_error,RAZOR_GENERAL_ERROR, RAZOR_GENERAL_ERROR_UNSUPPORTED_ARCHIVE)) { - g_free(path); path=plover_get_program_directory(argv0); + uri=razor_path_to_uri(path); + free(path); } razor_error_free(tmp_error); } - return path; + return uri; } int main(int argc,char **argv) { gboolean success,uninstall=FALSE,enable_post=FALSE; GError *error=NULL; - gchar *path=NULL; + gchar *path=NULL,*repository=NULL; GOptionContext *context; GOptionEntry options[]={ + {"repository",0,0,G_OPTION_ARG_STRING,&repository, + "Repository location","uri"}, {"path",0,0,G_OPTION_ARG_FILENAME,&path, "Repository path","path"}, {"uninstall",'u',0,G_OPTION_ARG_NONE,&uninstall, @@ -527,11 +539,12 @@ "If --post is specified, then the command to run and its arguments\n" "should be listed at the end of the command line.\n" "Command may refer to %INSTALL_PREFIX% which will be replaced by the\n" - "(first) install prefix used and/or %TEST_RESULT% which will be\n" + "(first) install prefix used, by %TEST_RESULT% which will be\n" "replaced by either \"pass\" or \"fail\" depending as to whether the\n" - "request succeeded or not. Command may also include double quotes which\n" - "will be used to affect how the command is split into arguments much\n" - "like a shell does."); + "request succeeded or not and/or by %REPOSITORY% which will be\n" + "replaced by the URI of the repository used. Command may also include\n" + "double quotes which will be used to affect how the command is split\n" + "into arguments much like a shell does."); g_option_context_set_strict_posix(context,TRUE); g_option_context_set_ignore_unknown_options(context,TRUE); if (!g_option_context_parse(context,&argc,&argv,&error)) @@ -540,19 +553,27 @@ g_printerr("Use \"%s --help\" for help\n",(*argv)[0]); exit(1); } + if (repository && path) + { + g_printerr("pre-install: " + "Only one of --repository and --path can be specified\n"); + exit(1); + } + if (path) + repository=razor_path_to_uri(path); + else if (!repository) + repository=pre_install_default_repository(argv[0]); if (uninstall) success=pre_uninstall(); else { - if (!path) - path=pre_install_default_path(argv[0]); #ifdef WIN32 - success=win32_pre_install_gui(path)==EXIT_SUCCESS; + success=win32_pre_install_gui(repository)==EXIT_SUCCESS; #else - success=!!pre_install(path); + success=!!pre_install(repository); #endif } - if (enable_post && !run_post(argc,argv,success,&error)) + if (enable_post && !run_post(argc,argv,success,repository,&error)) { #ifndef WIN32 fprintf(stderr,"Error in post: %s\n",error->message);