diff -r 360621bc323e -r 8a668d0a0d10 pre-inst/pre-inst.c --- a/pre-inst/pre-inst.c Fri Jun 24 17:30:23 2016 +0100 +++ b/pre-inst/pre-inst.c Wed Sep 12 17:12:06 2018 +0100 @@ -135,19 +135,18 @@ #else void * #endif -pre_install(const char *argv0) +pre_install(const char *path) { #ifdef WIN32 HANDLE retval; #else void *retval; #endif - char *path; razor_set_lua_loader("posix",(void (*)())luaopen_posix); razor_set_lua_loader("whelk",(void (*)())luaopen_whelk); - path=plover_get_program_directory(argv0); #ifdef WIN32 - retval=(HANDLE)_beginthreadex(NULL,0,pre_install_thread,path,0,NULL); + retval=(HANDLE)_beginthreadex(NULL,0,pre_install_thread,(void *)path,0, + NULL); #else if (pre_install_thread(path)) retval=NULL; @@ -344,7 +343,7 @@ * * Command may refer to %INSTALL_PREFIX% which will be replaced by the * (first) install prefix used and/or %TEST_RESULT% which will be replaced - * bu either "pass" or "fail" depending as to whether the request succeeded + * 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. */ @@ -429,14 +428,14 @@ } #ifdef WIN32 -DWORD win32_pre_install_gui(char *argv0) +DWORD win32_pre_install_gui(char *path) { HANDLE thread; INITCOMMONCONTROLSEX icc={0,}; MSG msg; DWORD retval; main_thread_id=GetCurrentThreadId(); - thread=(HANDLE)pre_install(argv0); + thread=(HANDLE)pre_install(path); if (!thread) return EXIT_FAILURE; icc.dwSize=sizeof(icc); @@ -458,8 +457,19 @@ int main(int argc,char **argv) { - gboolean success; + gboolean success,uninstall=FALSE,enable_post=FALSE; GError *error=NULL; + gchar *path=NULL; + GOptionContext *context; + GOptionEntry options[]={ + {"path",0,0,G_OPTION_ARG_FILENAME,&path, + "Repository path","path"}, + {"uninstall",'u',0,G_OPTION_ARG_NONE,&uninstall, + "Uninstall all packages",NULL}, + {"post",0,0,G_OPTION_ARG_NONE,&enable_post, + "Run command after request is processed",NULL}, + {NULL} + }; #ifdef WIN32 /* * pre-inst is normally a GUI application, but rpm scripts may well @@ -478,20 +488,38 @@ } #endif plover_exception_handler_init(); - if (argc>1 && !strcmp(argv[1],"-u")) + context=g_option_context_new("[command] - install the main installer"); + g_option_context_add_main_entries(context,options,NULL); + g_option_context_set_description(context, + "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" + "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."); + 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)) { + g_printerr("pre-install: %s\n",error->message); + g_printerr("Use \"%s --help\" for help\n",(*argv)[0]); + exit(1); + } + if (uninstall) success=pre_uninstall(); - argc--; - argv++; + else + { + if (!path) + path=plover_get_program_directory(argv[0]); +#ifdef WIN32 + success=win32_pre_install_gui(path)==EXIT_SUCCESS; +#else + success=!!pre_install(path); +#endif } - else -#ifdef WIN32 - success=win32_pre_install_gui(argv[0])==EXIT_SUCCESS; -#else - success=!!pre_install(argv[0]); -#endif - if (argc>1 && !strcmp(argv[1],"--post") && - !run_post(argc-1,argv+1,success,&error)) + if (enable_post && !run_post(argc-1,argv+1,success,&error)) { #ifndef WIN32 fprintf(stderr,"Error in post: %s\n",error->message);