1.1 --- a/pre-inst/pre-inst.c Fri Jun 24 17:30:23 2016 +0100
1.2 +++ b/pre-inst/pre-inst.c Wed Sep 12 17:12:06 2018 +0100
1.3 @@ -135,19 +135,18 @@
1.4 #else
1.5 void *
1.6 #endif
1.7 -pre_install(const char *argv0)
1.8 +pre_install(const char *path)
1.9 {
1.10 #ifdef WIN32
1.11 HANDLE retval;
1.12 #else
1.13 void *retval;
1.14 #endif
1.15 - char *path;
1.16 razor_set_lua_loader("posix",(void (*)())luaopen_posix);
1.17 razor_set_lua_loader("whelk",(void (*)())luaopen_whelk);
1.18 - path=plover_get_program_directory(argv0);
1.19 #ifdef WIN32
1.20 - retval=(HANDLE)_beginthreadex(NULL,0,pre_install_thread,path,0,NULL);
1.21 + retval=(HANDLE)_beginthreadex(NULL,0,pre_install_thread,(void *)path,0,
1.22 + NULL);
1.23 #else
1.24 if (pre_install_thread(path))
1.25 retval=NULL;
1.26 @@ -344,7 +343,7 @@
1.27 *
1.28 * Command may refer to %INSTALL_PREFIX% which will be replaced by the
1.29 * (first) install prefix used and/or %TEST_RESULT% which will be replaced
1.30 - * bu either "pass" or "fail" depending as to whether the request succeeded
1.31 + * by either "pass" or "fail" depending as to whether the request succeeded
1.32 * or not. Command may also include double quotes which will be used to
1.33 * affect how the command is split into arguments much like a shell does.
1.34 */
1.35 @@ -429,14 +428,14 @@
1.36 }
1.37
1.38 #ifdef WIN32
1.39 -DWORD win32_pre_install_gui(char *argv0)
1.40 +DWORD win32_pre_install_gui(char *path)
1.41 {
1.42 HANDLE thread;
1.43 INITCOMMONCONTROLSEX icc={0,};
1.44 MSG msg;
1.45 DWORD retval;
1.46 main_thread_id=GetCurrentThreadId();
1.47 - thread=(HANDLE)pre_install(argv0);
1.48 + thread=(HANDLE)pre_install(path);
1.49 if (!thread)
1.50 return EXIT_FAILURE;
1.51 icc.dwSize=sizeof(icc);
1.52 @@ -458,8 +457,19 @@
1.53
1.54 int main(int argc,char **argv)
1.55 {
1.56 - gboolean success;
1.57 + gboolean success,uninstall=FALSE,enable_post=FALSE;
1.58 GError *error=NULL;
1.59 + gchar *path=NULL;
1.60 + GOptionContext *context;
1.61 + GOptionEntry options[]={
1.62 + {"path",0,0,G_OPTION_ARG_FILENAME,&path,
1.63 + "Repository path","path"},
1.64 + {"uninstall",'u',0,G_OPTION_ARG_NONE,&uninstall,
1.65 + "Uninstall all packages",NULL},
1.66 + {"post",0,0,G_OPTION_ARG_NONE,&enable_post,
1.67 + "Run command after request is processed",NULL},
1.68 + {NULL}
1.69 + };
1.70 #ifdef WIN32
1.71 /*
1.72 * pre-inst is normally a GUI application, but rpm scripts may well
1.73 @@ -478,20 +488,38 @@
1.74 }
1.75 #endif
1.76 plover_exception_handler_init();
1.77 - if (argc>1 && !strcmp(argv[1],"-u"))
1.78 + context=g_option_context_new("[command] - install the main installer");
1.79 + g_option_context_add_main_entries(context,options,NULL);
1.80 + g_option_context_set_description(context,
1.81 + "If --post is specified, then the command to run and its arguments\n"
1.82 + "should be listed at the end of the command line.\n"
1.83 + "Command may refer to %INSTALL_PREFIX% which will be replaced by the\n"
1.84 + "(first) install prefix used and/or %TEST_RESULT% which will be\n"
1.85 + "replaced by either \"pass\" or \"fail\" depending as to whether the\n"
1.86 + "request succeeded or not. Command may also include double quotes which\n"
1.87 + "will be used to affect how the command is split into arguments much\n"
1.88 + "like a shell does.");
1.89 + g_option_context_set_strict_posix(context,TRUE);
1.90 + g_option_context_set_ignore_unknown_options(context,TRUE);
1.91 + if (!g_option_context_parse(context,&argc,&argv,&error))
1.92 {
1.93 + g_printerr("pre-install: %s\n",error->message);
1.94 + g_printerr("Use \"%s --help\" for help\n",(*argv)[0]);
1.95 + exit(1);
1.96 + }
1.97 + if (uninstall)
1.98 success=pre_uninstall();
1.99 - argc--;
1.100 - argv++;
1.101 + else
1.102 + {
1.103 + if (!path)
1.104 + path=plover_get_program_directory(argv[0]);
1.105 +#ifdef WIN32
1.106 + success=win32_pre_install_gui(path)==EXIT_SUCCESS;
1.107 +#else
1.108 + success=!!pre_install(path);
1.109 +#endif
1.110 }
1.111 - else
1.112 -#ifdef WIN32
1.113 - success=win32_pre_install_gui(argv[0])==EXIT_SUCCESS;
1.114 -#else
1.115 - success=!!pre_install(argv[0]);
1.116 -#endif
1.117 - if (argc>1 && !strcmp(argv[1],"--post") &&
1.118 - !run_post(argc-1,argv+1,success,&error))
1.119 + if (enable_post && !run_post(argc-1,argv+1,success,&error))
1.120 {
1.121 #ifndef WIN32
1.122 fprintf(stderr,"Error in post: %s\n",error->message);