Add an update command 0.2
authorJ. Ali Harlow <ali@juiblex.co.uk>
Thu, 13 Aug 2009 18:01:16 +0000 (19:01 +0100)
committerJ. Ali Harlow <ali@juiblex.co.uk>
Thu, 13 Aug 2009 18:01:16 +0000 (19:01 +0100)
13 files changed:
.gitignore
Makefile.am
configure.ac
plover/plover.h
plover/razor.c
plover/util.c
setup/setup.c
update/Makefile.am [new file with mode: 0644]
update/icon16.png [new file with mode: 0644]
update/icon22.png [new file with mode: 0644]
update/icon32.png [new file with mode: 0644]
update/resources.rc.in [new file with mode: 0644]
update/update.c [new file with mode: 0644]

index 4eedacf..5f74325 100644 (file)
@@ -16,3 +16,5 @@ stamp-h1
 plover/plover.pc
 setup/resources.rc
 setup/setup
+update/resources.rc
+update/update
index 8932f06..23ca042 100644 (file)
@@ -1 +1 @@
-SUBDIRS=plover setup
+SUBDIRS=plover setup update
index 9a640e2..5c102bf 100644 (file)
@@ -1,7 +1,7 @@
 #                                               -*- Autoconf -*-
 # Process this file with autoconf to produce a configure script.
 
-AC_INIT([plover],[0.1],[ali@juiblex.co.uk])
+AC_INIT([plover],[0.2],[ali@juiblex.co.uk])
 AC_PREREQ(2.59)
 AC_CONFIG_AUX_DIR([config])
 AC_CONFIG_SRCDIR([plover/plover.h])
@@ -11,6 +11,8 @@ plover/Makefile
 plover/plover.pc
 setup/Makefile
 setup/resources.rc
+update/Makefile
+update/resources.rc
 ])
 AM_INIT_AUTOMAKE(no-define)
 case $VERSION in
index 97d0eeb..291d8fc 100644 (file)
@@ -34,6 +34,8 @@ struct comps
 };
 
 char *plover_strconcat(const char *string,...);
+char *plover_default_prefix_for_vendor(const char *vendor);
+char *plover_get_program_directory(const char *argv0);
 
 struct razor_set *plover_razor_set_create_from_yum(const char *base);
 
index 4fb4c41..42838ca 100644 (file)
@@ -262,6 +262,91 @@ int plover_install(const char *base,const char *prefix,char **pkgs)
     return razor_root_commit(root);
 }
 
+int plover_update(const char *base,const char *prefix,char **pkgs)
+{
+    int i;
+    char *install_root,*s;
+    struct razor_root *root;
+    struct razor_set *system,*set,*upstream,*next;
+    struct razor_transaction *trans;
+    struct razor_relocations *relocations;
+    install_root=getenv("RAZOR_ROOT");
+    if (!install_root)
+       install_root="";
+    if (prefix)
+    {
+       relocations=razor_relocations_create();
+       razor_relocations_add(relocations,"/usr",prefix);
+    }
+    set=razor_root_open_read_only(install_root);
+    if (!set)
+       return 0;
+    razor_set_destroy(set);
+    root=razor_root_open(install_root);
+    if (!root)
+       return -1;
+    system=razor_root_get_system_set(root);
+    if (!system)
+    {
+       razor_root_close(root);
+       return -1;
+    }
+    s=plover_strconcat(base,"/repodata",NULL);
+    if (!s)
+    {
+       razor_root_close(root);
+       return -1;
+    }
+    if (chdir(s)<0)
+    {
+       perror(s);
+       free(s);
+       razor_root_close(root);
+       return -1;
+    }
+    free(s);
+    set=plover_razor_set_create_from_yum(base);
+    if (!set)
+    {
+       razor_root_close(root);
+       return -1;
+    }
+    upstream=plover_relocate_packages(set,base,relocations);
+    razor_set_destroy(set);
+    trans=razor_transaction_create(system,upstream);
+    if (pkgs)
+       for(i=0;pkgs[i];i++)
+       {
+           if (plover_mark_package_for_update(trans,system,pkgs[i]))
+           {
+               fprintf(stderr,"%s: Package not found\n",pkgs[i]);
+               razor_transaction_destroy(trans);
+               razor_set_destroy(upstream);
+               razor_set_destroy(system);
+               razor_root_close(root);
+               return -1;
+           }
+       }
+    else
+       razor_transaction_update_all(trans);
+    razor_transaction_resolve(trans);
+    if (razor_transaction_describe(trans)>0)
+    {
+       razor_transaction_destroy(trans);
+       razor_set_destroy(upstream);
+       razor_set_destroy(system);
+       razor_root_close(root);
+       return -1;
+    }
+    next=razor_transaction_commit(trans);
+    plover_run_transaction(trans,base,install_root,system,next,relocations);
+    razor_root_update(root,next);
+    razor_transaction_destroy(trans);
+    razor_set_destroy(next);
+    razor_set_destroy(upstream);
+    return razor_root_commit(root);
+}
+
 static int plover_mark_packages_for_removal(struct razor_transaction *trans,
   struct razor_set *set,const char *pkg)
 {
index df4d3f9..989ad99 100644 (file)
 #include <stdlib.h>
 #include <stdarg.h>
 #include <string.h>
+#include <limits.h>
+#ifdef WIN32
+#include <windows.h>
+#include <shlobj.h>
+#endif
 #include "config.h"
 #include "plover.h"
 
@@ -51,3 +56,46 @@ char *plover_strconcat(const char *string,...)
     }
     return result;
 }
+
+char *plover_default_prefix_for_vendor(const char *vendor)
+{
+#ifdef WIN32
+    char path[PATH_MAX];
+    SHGetFolderPath(NULL,CSIDL_PROGRAM_FILES|CSIDL_FLAG_DONT_VERIFY,NULL,0,
+      path);
+    return plover_strconcat(path,"\\",vendor?vendor:"Plover",NULL);
+#else
+    return NULL;
+#endif
+}
+
+/*
+ * Get the directory containing the program executable.
+ */
+
+char *plover_get_program_directory(const char *argv0)
+{
+    char *s;
+#ifdef WIN32
+    char path[PATH_MAX],*t;
+    GetModuleFileName(NULL,path,sizeof(path));
+    s=strrchr(path,'/');
+    if (s)
+    {
+       t=strrchr(s,'\\');
+       if (t)
+           s=t;
+    }
+    else
+       s=strrchr(path,'\\');
+    if (s)
+       *s='\0';
+    return strdup(path);
+#else
+    s=argv0?strrchr(argv0,'/'):NULL;
+    if (s)
+       return strndup(argv0,s-argv0);
+    else
+       return strdup(".");
+#endif
+}
index 9bfbda1..05b443c 100644 (file)
@@ -86,34 +86,15 @@ static void *alloc_lua(void *user_data,void *ptr,size_t osize,size_t nsize)
        return realloc(ptr,nsize);
 }
 
-void setup()
+void setup(const char *argv0)
 {
-    char path[PATH_MAX],*s,*t,*prefix;
+    char *path,*s,*prefix;
     int changed;
     struct comps *comps;
     struct comps_group *group;
     struct comps_requirement *pkg;
     struct vector *packages=NULL;
-#ifdef WIN32
-    SHGetFolderPath(NULL,CSIDL_PROGRAM_FILES|CSIDL_FLAG_DONT_VERIFY,NULL,0,
-      path);
-    prefix=strdup(path);
-    GetModuleFileName(NULL,path,sizeof(path));
-    s=strrchr(path,'/');
-    if (s)
-    {
-       t=strrchr(s,'\\');
-       if (t)
-           s=t;
-    }
-    else
-       s=strrchr(path,'\\');
-    if (s)
-       *s='\0';
-#else
-    strcpy(path,"/tmp");
-    prefix=NULL;
-#endif
+    path=plover_get_program_directory(argv0);
     s=plover_strconcat(path,"/repodata/comps.xml",NULL);
     comps=plover_comps_new_from_file(s);
     if (!comps)
@@ -122,11 +103,7 @@ void setup()
        exit(1);
     }
     free(s);
-#ifdef WIN32
-    s=plover_strconcat(prefix,"\\",comps->vendor?comps->vendor:"Plover",NULL);
-    free(prefix);
-    prefix=s;
-#endif
+    prefix=plover_default_prefix_for_vendor(comps->vendor);
     group=plover_comps_lookup_group(comps,"base");
     if (!group)
     {
@@ -151,6 +128,7 @@ void setup()
            }
        }
     } while(changed);
+    plover_comps_free(comps);
     if (!packages->len)
     {
        fprintf(stderr,"No packages to install\n");
@@ -158,10 +136,8 @@ void setup()
     }
     plover_install(path,prefix,packages->strings);
     vector_free(packages);
-    plover_comps_free(comps);
-#ifdef WIN32
     free(prefix);
-#endif
+    free(path);
 }
 
 int main(int argc,char **argv)
@@ -171,5 +147,5 @@ int main(int argc,char **argv)
     if (argc>1 && !strcmp(argv[1],"-u"))
        plover_remove(NULL);
     else
-       setup();
+       setup(argv[0]);
 }
diff --git a/update/Makefile.am b/update/Makefile.am
new file mode 100644 (file)
index 0000000..c39f6de
--- /dev/null
@@ -0,0 +1,22 @@
+AM_CFLAGS=-g $(SETUP_CFLAGS)
+LDADD=../plover/libplover.la $(SETUP_LIBS)
+INCLUDES=-I$(top_srcdir)
+
+bin_PROGRAMS=update
+
+update_SOURCES=update.c
+update_LDFLAGS=-all-static
+if HAVE_WINDRES
+update_SOURCES+=resources.rc
+endif
+
+.png.pnm:
+       pngtopnm $< | pnmquant 256 > $@
+
+resources.$(OBJEXT): resources.rc update.ico
+       $(WINDRES) resources.rc $@
+
+update.ico:     icon16.pnm icon22.pnm icon32.pnm
+        ppmtowinicon -output=$@ $^
+
+EXTRA_DIST=icon16.png icon22.png icon32.png
diff --git a/update/icon16.png b/update/icon16.png
new file mode 100644 (file)
index 0000000..0ca1590
Binary files /dev/null and b/update/icon16.png differ
diff --git a/update/icon22.png b/update/icon22.png
new file mode 100644 (file)
index 0000000..4b7f82c
Binary files /dev/null and b/update/icon22.png differ
diff --git a/update/icon32.png b/update/icon32.png
new file mode 100644 (file)
index 0000000..361cd51
Binary files /dev/null and b/update/icon32.png differ
diff --git a/update/resources.rc.in b/update/resources.rc.in
new file mode 100644 (file)
index 0000000..ea31644
--- /dev/null
@@ -0,0 +1,32 @@
+#include <winver.h>
+
+MAINICON ICON "update.ico"
+
+VS_VERSION_INFO VERSIONINFO
+    FILEVERSION @PLOVER_MAJOR_VERSION@,@PLOVER_MINOR_VERSION@,@PLOVER_MICRO_VERS
+ION@,0
+    PRODUCTVERSION @PLOVER_MAJOR_VERSION@,@PLOVER_MINOR_VERSION@,@PLOVER_MICRO_V
+ERSION@,0
+    FILEOS VOS__WINDOWS32
+    FILETYPE VFT_APP
+    {
+       BLOCK "StringFileInfo"
+       {
+           BLOCK "080904B0"
+           {
+               VALUE "CompanyName","The plover development team"
+               VALUE "FileDescription","Plover setup program"
+               VALUE "FileVersion","@PACKAGE_VERSION@"
+               VALUE "InternalName","update"
+               VALUE "LegalCopyright",
+                 "Copyright (c) 2009 J. Ali Harlow et al"
+               VALUE "OriginalFilename","update.exe"
+               VALUE "ProductName","plover"
+               VALUE "ProductVersion","@PACKAGE_VERSION@"
+           }
+       }
+       BLOCK "VarFileInfo"
+       {
+           VALUE "Translation",0x809,0x4B0
+       }
+    }
diff --git a/update/update.c b/update/update.c
new file mode 100644 (file)
index 0000000..13fc828
--- /dev/null
@@ -0,0 +1,52 @@
+/*
+ * Copyright (C) 2009  J. Ali Harlow <ali@juiblex.co.uk>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include <stdlib.h>
+#include <lua.h>
+#include "config.h"
+#include "plover/plover.h"
+#include "whelk/whelk.h"
+
+LUALIB_API int luaopen_posix(lua_State *L);
+
+void update(const char *argv0)
+{
+    char *path,*s,*prefix;
+    struct comps *comps;
+    path=plover_get_program_directory(argv0);
+    s=plover_strconcat(path,"/repodata/comps.xml",NULL);
+    comps=plover_comps_new_from_file(s);
+    if (!comps)
+    {
+       perror(s);
+       exit(1);
+    }
+    free(s);
+    prefix=plover_default_prefix_for_vendor(comps->vendor);
+    plover_comps_free(comps);
+    plover_update(path,prefix,NULL);
+    free(prefix);
+    free(path);
+}
+
+int main(int argc,char **argv)
+{
+    razor_set_lua_loader("posix",luaopen_posix);
+    razor_set_lua_loader("whelk",luaopen_whelk);
+    update(argv[0]);
+}