1.1 --- a/pre-inst/pre-inst.c Mon Jul 13 13:19:03 2020 +0100
1.2 +++ b/pre-inst/pre-inst.c Tue Jul 14 13:17:21 2020 +0100
1.3 @@ -90,7 +90,7 @@
1.4 unsigned pre_install_thread(void *data)
1.5 {
1.6 int retval;
1.7 - gchar *path=data;
1.8 + const char *repository=data;
1.9 gchar *s,*uri;
1.10 char *install[]={"plover-gtkui",NULL};
1.11 GError *error=NULL;
1.12 @@ -106,19 +106,17 @@
1.13 free(uri);
1.14 if (verify_and_fix(prefix))
1.15 {
1.16 - g_free(path);
1.17 g_free(prefix);
1.18 return -1;
1.19 }
1.20 - retval=!plover_install(path,prefix,install,&error);
1.21 + retval=!plover_install_uri(repository,prefix,install,&error);
1.22 if (!retval)
1.23 - retval=!plover_update(path,prefix,NULL,&error);
1.24 + retval=!plover_update_uri(repository,prefix,NULL,&error);
1.25 if (error)
1.26 {
1.27 fprintf(stderr,"%s\n",error->message);
1.28 g_error_free(error);
1.29 }
1.30 - g_free(path);
1.31 #ifdef WIN32
1.32 PostQuitMessage(retval);
1.33 PostThreadMessage(main_thread_id,WM_QUIT,retval,0);
1.34 @@ -136,7 +134,7 @@
1.35 #else
1.36 void *
1.37 #endif
1.38 -pre_install(const char *path)
1.39 +pre_install(const char *repository)
1.40 {
1.41 #ifdef WIN32
1.42 HANDLE retval;
1.43 @@ -146,10 +144,10 @@
1.44 razor_set_lua_loader("posix",(void (*)())luaopen_posix);
1.45 razor_set_lua_loader("whelk",(void (*)())luaopen_whelk);
1.46 #ifdef WIN32
1.47 - retval=(HANDLE)_beginthreadex(NULL,0,pre_install_thread,(void *)path,0,
1.48 - NULL);
1.49 + retval=(HANDLE)_beginthreadex(NULL,0,pre_install_thread,(void *)repository,
1.50 + 0,NULL);
1.51 #else
1.52 - if (pre_install_thread(path))
1.53 + if (pre_install_thread((void *)repository))
1.54 retval=NULL;
1.55 else
1.56 retval=(void *)1; /* Non-NULL to indicate success */
1.57 @@ -343,12 +341,14 @@
1.58 * Run a command after completing request.
1.59 *
1.60 * Command may refer to %INSTALL_PREFIX% which will be replaced by the
1.61 - * (first) install prefix used and/or %TEST_RESULT% which will be replaced
1.62 + * (first) install prefix used, by %TEST_RESULT% which will be replaced
1.63 * by either "pass" or "fail" depending as to whether the request succeeded
1.64 - * or not. Command may also include double quotes which will be used to
1.65 - * affect how the command is split into arguments much like a shell does.
1.66 + * or not and/or by %REPOSITORY% which will be replaced by the URI of the
1.67 + * repository used. Command may also include double quotes which will be used
1.68 + * to affect how the command is split into arguments much like a shell does.
1.69 */
1.70 -gboolean run_post(int argc,char **argv,gboolean test_result,GError **error)
1.71 +gboolean run_post(int argc,char **argv,gboolean test_result,
1.72 + const char *repository,GError **error)
1.73 {
1.74 int i,post_argc;
1.75 char *s;
1.76 @@ -391,6 +391,15 @@
1.77 g_free(post_argv[i]);
1.78 post_argv[i]=expanded;
1.79 }
1.80 + s=strstr(post_argv[i],"%REPOSITORY%");
1.81 + if (s)
1.82 + {
1.83 + *s='\0';
1.84 + s+=strlen("%REPOSITORY%");
1.85 + expanded=g_strconcat(post_argv[i],repository,s,NULL);
1.86 + g_free(post_argv[i]);
1.87 + post_argv[i]=expanded;
1.88 + }
1.89 }
1.90 #ifdef USE_G_SPAWN
1.91 if (!g_spawn_sync(NULL,post_argv,NULL,G_SPAWN_SEARCH_PATH,NULL,NULL,
1.92 @@ -429,14 +438,14 @@
1.93 }
1.94
1.95 #ifdef WIN32
1.96 -DWORD win32_pre_install_gui(char *path)
1.97 +DWORD win32_pre_install_gui(char *repository)
1.98 {
1.99 HANDLE thread;
1.100 INITCOMMONCONTROLSEX icc={0,};
1.101 MSG msg;
1.102 DWORD retval;
1.103 main_thread_id=GetCurrentThreadId();
1.104 - thread=(HANDLE)pre_install(path);
1.105 + thread=(HANDLE)pre_install(repository);
1.106 if (!thread)
1.107 return EXIT_FAILURE;
1.108 icc.dwSize=sizeof(icc);
1.109 @@ -456,7 +465,7 @@
1.110 }
1.111 #endif /* WIN32 */
1.112
1.113 -gchar *pre_install_default_path(const char *argv0)
1.114 +gchar *pre_install_default_repository(const char *argv0)
1.115 {
1.116 size_t length;
1.117 void *contents;
1.118 @@ -464,13 +473,13 @@
1.119 gchar *s,*uri;
1.120 struct razor_error *tmp_error=NULL;
1.121 /*
1.122 - * The default path is the executable itself if it's an archive
1.123 + * The default repository is the executable itself if it's an archive
1.124 * or otherwise the directory in which the executable is stored.
1.125 */
1.126 path=plover_get_program(argv0);
1.127 uri=razor_path_to_uri(path);
1.128 + free(path);
1.129 s=g_strconcat(uri,"/repodata/comps.xml",NULL);
1.130 - free(uri);
1.131 contents=razor_uri_get_contents(s,&length,FALSE,&tmp_error);
1.132 g_free(s);
1.133 if (contents)
1.134 @@ -480,21 +489,24 @@
1.135 if (razor_error_matches(tmp_error,RAZOR_GENERAL_ERROR,
1.136 RAZOR_GENERAL_ERROR_UNSUPPORTED_ARCHIVE))
1.137 {
1.138 - g_free(path);
1.139 path=plover_get_program_directory(argv0);
1.140 + uri=razor_path_to_uri(path);
1.141 + free(path);
1.142 }
1.143 razor_error_free(tmp_error);
1.144 }
1.145 - return path;
1.146 + return uri;
1.147 }
1.148
1.149 int main(int argc,char **argv)
1.150 {
1.151 gboolean success,uninstall=FALSE,enable_post=FALSE;
1.152 GError *error=NULL;
1.153 - gchar *path=NULL;
1.154 + gchar *path=NULL,*repository=NULL;
1.155 GOptionContext *context;
1.156 GOptionEntry options[]={
1.157 + {"repository",0,0,G_OPTION_ARG_STRING,&repository,
1.158 + "Repository location","uri"},
1.159 {"path",0,0,G_OPTION_ARG_FILENAME,&path,
1.160 "Repository path","path"},
1.161 {"uninstall",'u',0,G_OPTION_ARG_NONE,&uninstall,
1.162 @@ -527,11 +539,12 @@
1.163 "If --post is specified, then the command to run and its arguments\n"
1.164 "should be listed at the end of the command line.\n"
1.165 "Command may refer to %INSTALL_PREFIX% which will be replaced by the\n"
1.166 - "(first) install prefix used and/or %TEST_RESULT% which will be\n"
1.167 + "(first) install prefix used, by %TEST_RESULT% which will be\n"
1.168 "replaced by either \"pass\" or \"fail\" depending as to whether the\n"
1.169 - "request succeeded or not. Command may also include double quotes which\n"
1.170 - "will be used to affect how the command is split into arguments much\n"
1.171 - "like a shell does.");
1.172 + "request succeeded or not and/or by %REPOSITORY% which will be\n"
1.173 + "replaced by the URI of the repository used. Command may also include\n"
1.174 + "double quotes which will be used to affect how the command is split\n"
1.175 + "into arguments much like a shell does.");
1.176 g_option_context_set_strict_posix(context,TRUE);
1.177 g_option_context_set_ignore_unknown_options(context,TRUE);
1.178 if (!g_option_context_parse(context,&argc,&argv,&error))
1.179 @@ -540,19 +553,27 @@
1.180 g_printerr("Use \"%s --help\" for help\n",(*argv)[0]);
1.181 exit(1);
1.182 }
1.183 + if (repository && path)
1.184 + {
1.185 + g_printerr("pre-install: "
1.186 + "Only one of --repository and --path can be specified\n");
1.187 + exit(1);
1.188 + }
1.189 + if (path)
1.190 + repository=razor_path_to_uri(path);
1.191 + else if (!repository)
1.192 + repository=pre_install_default_repository(argv[0]);
1.193 if (uninstall)
1.194 success=pre_uninstall();
1.195 else
1.196 {
1.197 - if (!path)
1.198 - path=pre_install_default_path(argv[0]);
1.199 #ifdef WIN32
1.200 - success=win32_pre_install_gui(path)==EXIT_SUCCESS;
1.201 + success=win32_pre_install_gui(repository)==EXIT_SUCCESS;
1.202 #else
1.203 - success=!!pre_install(path);
1.204 + success=!!pre_install(repository);
1.205 #endif
1.206 }
1.207 - if (enable_post && !run_post(argc,argv,success,&error))
1.208 + if (enable_post && !run_post(argc,argv,success,repository,&error))
1.209 {
1.210 #ifndef WIN32
1.211 fprintf(stderr,"Error in post: %s\n",error->message);