plover/plover.pc
setup/resources.rc
setup/setup
+update/resources.rc
+update/update
-SUBDIRS=plover setup
+SUBDIRS=plover setup update
# -*- 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])
plover/plover.pc
setup/Makefile
setup/resources.rc
+update/Makefile
+update/resources.rc
])
AM_INIT_AUTOMAKE(no-define)
case $VERSION in
};
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);
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)
{
#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"
}
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
+}
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)
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)
{
}
}
} while(changed);
+ plover_comps_free(comps);
if (!packages->len)
{
fprintf(stderr,"No packages to install\n");
}
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)
if (argc>1 && !strcmp(argv[1],"-u"))
plover_remove(NULL);
else
- setup();
+ setup(argv[0]);
}
--- /dev/null
+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
--- /dev/null
+#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
+ }
+ }
--- /dev/null
+/*
+ * 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]);
+}