diff options
author | Matthew Wild <mwild1@gmail.com> | 2011-02-26 00:23:48 +0000 |
---|---|---|
committer | Matthew Wild <mwild1@gmail.com> | 2011-02-26 00:23:48 +0000 |
commit | 2b4811c8430dcbec09c67b73e8f939b4047f1aec (patch) | |
tree | bda3a0bbd9d3dcd9f2f57fa0fbe32bc15090b220 | |
parent | 35a339b1d3defc1be8387324a601db4889096a22 (diff) | |
download | prosody-2b4811c8430dcbec09c67b73e8f939b4047f1aec.tar.gz prosody-2b4811c8430dcbec09c67b73e8f939b4047f1aec.zip |
tools/migration/*: Numerous changes and restructuring, and the addition of a Makefile
-rw-r--r-- | tools/migration/Makefile | 38 | ||||
-rw-r--r-- | tools/migration/main.lua | 23 | ||||
-rw-r--r-- | tools/migration/migrator/mtools.lua (renamed from tools/migration/mtools.lua) | 0 | ||||
-rw-r--r-- | tools/migration/migrator/prosody_files.lua (renamed from tools/migration/prosody_files.lua) | 2 | ||||
-rw-r--r-- | tools/migration/migrator/prosody_sql.lua (renamed from tools/migration/prosody_sql.lua) | 2 |
5 files changed, 56 insertions, 9 deletions
diff --git a/tools/migration/Makefile b/tools/migration/Makefile new file mode 100644 index 00000000..839f2d87 --- /dev/null +++ b/tools/migration/Makefile @@ -0,0 +1,38 @@ + +include ../../config.unix + +BIN = $(DESTDIR)$(PREFIX)/bin +CONFIG = $(DESTDIR)$(SYSCONFDIR) +SOURCE = $(DESTDIR)$(PREFIX)/lib/prosody +DATA = $(DESTDIR)$(DATADIR) +MAN = $(DESTDIR)$(PREFIX)/share/man + +INSTALLEDSOURCE = $(PREFIX)/lib/prosody +INSTALLEDCONFIG = $(SYSCONFDIR) +INSTALLEDMODULES = $(PREFIX)/lib/prosody/modules +INSTALLEDDATA = $(DATADIR) + +SOURCE_FILES = main.lua migrator/*.lua + +all: prosody-migrator.install migrator.cfg.lua.install $(SOURCE_FILES) + +install: prosody-migrator.install migrator.cfg.lua.install + install -d $(BIN) $(CONFIG) $(SOURCE) $(SOURCE)/migrator + install -d $(MAN)/man1 + install -d $(SOURCE)/migrator + install -m755 ./prosody-migrator.install $(BIN)/prosody-migrator + install -m644 $(SOURCE_FILES) $(SOURCE)/migrator + test -e $(CONFIG)/migrator.cfg.lua || install -m644 migrator.cfg.lua.install $(CONFIG)/migrator.cfg.lua + +clean: + rm -f prosody-migrator.install + rm -f migrator.cfg.lua.install + +prosody-migrator.install: main.lua + sed "s|^CFG_SOURCEDIR=.*;$$|CFG_SOURCEDIR='$(INSTALLEDSOURCE)';|; \ + s|^CFG_CONFIGDIR=.*;$$|CFG_CONFIGDIR='$(INSTALLEDCONFIG)';|;" \ + < main.lua > prosody-migrator.install + +migrator.cfg.lua.install: migrator.cfg.lua + sed "s|^local data_path = .*;$$|local data_path = '$(INSTALLEDDATA)';|;" \ + < migrator.cfg.lua > migrator.cfg.lua.install diff --git a/tools/migration/main.lua b/tools/migration/main.lua index e4891966..82eeab9d 100644 --- a/tools/migration/main.lua +++ b/tools/migration/main.lua @@ -1,4 +1,9 @@ -local default_config = "./migrator.cfg.lua"; +#!/usr/bin/env lua + +CFG_SOURCEDIR=os.getenv("PROSODY_SRCDIR"); +CFG_CONFIGDIR=os.getenv("PROSODY_CFGDIR"); + +local default_config = (CFG_CONFIGDIR or ".").."/migrator.cfg.lua"; -- Command-line parsing local options = {}; @@ -45,9 +50,12 @@ end config_chunk(); -if not package.loaded["util.json"] then +if CFG_SOURCEDIR then + package.path = CFG_SOURCEDIR.."/?.lua;"..package.path; + package.cpath = CFG_SOURCEDIR.."/?.so;"..package.cpath; +elseif not package.loaded["util.json"] then package.path = "../../?.lua;"..package.path - package.cpath = "../../?.dll;"..package.cpath + package.cpath = "../../?.so;"..package.cpath end local have_err; @@ -66,14 +74,14 @@ end if not config[from_store].type then have_err = true; print("Error: Input store type not specified in the config file"); -elseif not pcall(require, config[from_store].type) then +elseif not pcall(require, "migrator."..config[from_store].type) then have_err = true; print("Error: Unrecognised store type for '"..from_store.."': "..config[from_store].type); end if not config[to_store].type then have_err = true; print("Error: Output store type not specified in the config file"); -elseif not pcall(require, config[to_store].type) then +elseif not pcall(require, "migrator."..config[to_store].type) then have_err = true; print("Error: Unrecognised store type for '"..to_store.."': "..config[to_store].type); end @@ -88,13 +96,14 @@ if have_err then for store in pairs(config) do print("", store); end + print(""); os.exit(1); end local itype = config[from_store].type; local otype = config[to_store].type; -local reader = require(itype).reader(config[from_store]); -local writer = require(otype).writer(config[to_store]); +local reader = require("migrator."..itype).reader(config[from_store]); +local writer = require("migrator."..otype).writer(config[to_store]); local json = require "util.json"; diff --git a/tools/migration/mtools.lua b/tools/migration/migrator/mtools.lua index e7b774bb..e7b774bb 100644 --- a/tools/migration/mtools.lua +++ b/tools/migration/migrator/mtools.lua diff --git a/tools/migration/prosody_files.lua b/tools/migration/migrator/prosody_files.lua index df67c240..0a610d0e 100644 --- a/tools/migration/prosody_files.lua +++ b/tools/migration/migrator/prosody_files.lua @@ -9,7 +9,7 @@ local lfs = require "lfs"; local loadfile = loadfile; local setfenv = setfenv; local pcall = pcall; -local mtools = require "mtools"; +local mtools = require "migrator.mtools"; local next = next; local pairs = pairs; local json = require "util.json"; diff --git a/tools/migration/prosody_sql.lua b/tools/migration/migrator/prosody_sql.lua index ff33652a..3a9172ff 100644 --- a/tools/migration/prosody_sql.lua +++ b/tools/migration/migrator/prosody_sql.lua @@ -7,7 +7,7 @@ local next = next; local pairs = pairs; local t_sort = table.sort; local json = require "util.json"; -local mtools = require "mtools"; +local mtools = require "migrator.mtools"; local tostring = tostring; local tonumber = tonumber; |