diff options
-rwxr-xr-x | anaconda | 15 | ||||
-rw-r--r-- | comps.py | 2 | ||||
-rw-r--r-- | isys/imount.c | 66 | ||||
-rw-r--r-- | isys/imount.h | 8 | ||||
-rw-r--r-- | isys/isys.c | 23 | ||||
-rw-r--r-- | isys/isys.py | 3 | ||||
-rw-r--r-- | text.py | 9 | ||||
-rw-r--r-- | todo.py | 79 |
8 files changed, 172 insertions, 33 deletions
@@ -8,7 +8,7 @@ mode = None test = 0 force = 0 debug = 0 -rootPath = '/mnt' +rootPath = '/mnt/sysimage' runLive = 0 for n in args: @@ -84,16 +84,3 @@ intf.run(todo) todo.installSystem() del intf - -l = lilo.LiloConfiguration() -l.addEntry('boot', '/dev/hda') -l.addEntry('map', '/boot/map') -l.addEntry('install', '/boot/boot.b') -l.addEntry('prompt') -l.addEntry('timeout', 50) -s = lilo.LiloConfiguration() -s.addEntry('label', 'linux') -s.addEntry('root', '/dev/hda8') -s.addEntry('read-only') -l.addImage('/boot/vmlinuz', s) -#l.write('/etc/lilo.conf') @@ -64,7 +64,7 @@ class ComponentSet: file.close() top = lines[0] lines = lines[1:] - if (top != "2\n"): + if (top != "2\n" and top != "0.1\n"): raise TypeError, "comp file version 2 expected" comp = None diff --git a/isys/imount.c b/isys/imount.c index fb2c9bae2..0d7e24d26 100644 --- a/isys/imount.c +++ b/isys/imount.c @@ -3,11 +3,15 @@ #include <string.h> #include <sys/errno.h> #include <sys/mount.h> +#include <unistd.h> #include "imount.h" #define _(foo) foo +static int mkdirChain(char * chain); +static int mkdirIfNone(char * directory); + int doPwMount(char * dev, char * where, char * fs, int rdonly, int istty, char * acct, char * pw) { char * buf = NULL; @@ -22,7 +26,7 @@ int doPwMount(char * dev, char * where, char * fs, int rdonly, int istty, if (!strcmp(fs, "smb")) { #if 0 /* disabled for now */ - /*mkdirChain(where);*/ + mkdirChain(where); if (!acct) acct = "guest"; if (!pw) pw = ""; @@ -33,7 +37,7 @@ int doPwMount(char * dev, char * where, char * fs, int rdonly, int istty, while (*chptr && *chptr != ':') chptr++; if (!*chptr) { /*logMessage("bad smb mount point %s", where);*/ - return 0; + return IMOUNT_ERR_OTHER; } *chptr = '\0'; @@ -48,7 +52,8 @@ int doPwMount(char * dev, char * where, char * fs, int rdonly, int istty, #endif #endif /* disabled */ } else { - /*mkdirChain(where);*/ + if (mkdirChain(where)) + return IMOUNT_ERR_ERRNO; if (!isnfs && *dev == '/') { buf = dev; @@ -67,9 +72,9 @@ int doPwMount(char * dev, char * where, char * fs, int rdonly, int istty, if (nfsmount(buf, where, &flags, &extra_opts, &mount_opt)) { /*logMessage("\tnfsmount returned non-zero");*/ - fprintf(stderr, "nfs mount failed: %s\n", - nfs_error()); - return 1; + /*fprintf(stderr, "nfs mount failed: %s\n", + nfs_error());*/ + return IMOUNT_ERR_OTHER; } #endif } @@ -84,11 +89,56 @@ int doPwMount(char * dev, char * where, char * fs, int rdonly, int istty, flag, mount_opt);*/ if (mount(buf, where, fs, flag, mount_opt)) { - fprintf(stderr, "mount failed: %s\n", strerror(errno)); - return 1; + return IMOUNT_ERR_ERRNO; } } return 0; } +static int mkdirChain(char * origChain) { + char * chain; + char * chptr; + + chain = alloca(strlen(origChain) + 1); + strcpy(chain, origChain); + chptr = chain; + + while ((chptr = strchr(chptr, '/'))) { + *chptr = '\0'; + if (mkdirIfNone(chain)) { + *chptr = '/'; + return IMOUNT_ERR_ERRNO; + } + + *chptr = '/'; + chptr++; + } + + if (mkdirIfNone(chain)) + return IMOUNT_ERR_ERRNO; + + return 0; +} + +static int mkdirIfNone(char * directory) { + int rc, mkerr; + char * chptr; + + /* If the file exists it *better* be a directory -- I'm not going to + actually check or anything */ + if (!access(directory, X_OK)) return 0; + + /* if the path is '/' we get ENOFILE not found" from mkdir, rather + then EEXIST which is weird */ + for (chptr = directory; *chptr; chptr++) + if (*chptr != '/') break; + if (!*chptr) return 0; + + rc = mkdir(directory, 0755); + mkerr = errno; + + if (!rc || mkerr == EEXIST) return 0; + + return IMOUNT_ERR_ERRNO; +} diff --git a/isys/imount.h b/isys/imount.h index 409fd2302..c7647ffab 100644 --- a/isys/imount.h +++ b/isys/imount.h @@ -1,2 +1,10 @@ +#ifndef H_IMOUNT +#define H_IMOUNT + +#define IMOUNT_ERR_ERRNO 1 +#define IMOUNT_ERR_OTHER 2 + int doPwMount(char * dev, char * where, char * fs, int rdonly, int istty, char * acct, char * pw); + +#endif diff --git a/isys/isys.c b/isys/isys.c index 402d1e16a..8fba620ee 100644 --- a/isys/isys.c +++ b/isys/isys.c @@ -9,18 +9,39 @@ #include "imount.h" static PyObject * doMount(PyObject * s, PyObject * args); +static PyObject * doUMount(PyObject * s, PyObject * args); static PyMethodDef balkanModuleMethods[] = { { "mount", (PyCFunction) doMount, METH_VARARGS, NULL }, + { "umount", (PyCFunction) doUMount, METH_VARARGS, NULL }, { NULL } } ; +static PyObject * doUMount(PyObject * s, PyObject * args) { + char * fs; + + if (!PyArg_ParseTuple(args, "s", &fs)) return NULL; + + if (umount(fs)) { + PyErr_SetFromErrno(PyExc_SystemError); + return NULL; + } + + Py_INCREF(Py_None); + return Py_None; +} + static PyObject * doMount(PyObject * s, PyObject * args) { char * fs, * device, * mntpoint; + int rc; if (!PyArg_ParseTuple(args, "sss", &fs, &device, &mntpoint)) return NULL; - doPwMount(device, mntpoint, fs, 0, 0, NULL, NULL); + rc = doPwMount(device, mntpoint, fs, 0, 0, NULL, NULL); + if (rc == IMOUNT_ERR_ERRNO) + PyErr_SetFromErrno(PyExc_SystemError); + else if (rc) + PyErr_SetString(PyExc_SystemError, "mount failed"); Py_INCREF(Py_None); return Py_None; diff --git a/isys/isys.py b/isys/isys.py index 7e9e4860d..44d2d6dde 100644 --- a/isys/isys.py +++ b/isys/isys.py @@ -2,3 +2,6 @@ import _isys def mount(device, location, fstype = "ext2"): return _isys.mount(fstype, device, location) + +def umount(what): + return _isys.umount(what) @@ -1,5 +1,6 @@ from snack import * import _balkan +import sys class WelcomeWindow: def run(self, screen): @@ -95,6 +96,7 @@ class InstallInterface: def __init__(self): self.screen = SnackScreen() + #self.screen.suspendCallback(killSelf, self) def __del__(self): self.screen.finish() @@ -114,3 +116,10 @@ class InstallInterface: else: dir = 1 step = step + dir + + todo.liloLocation("/dev/hda") + +def killSelf(screen): + print "HERE" + del screen + sys.exit(0) @@ -1,8 +1,11 @@ # For an install to proceed, the following todo fields must be filled in # -# mount list via addMount() (unless todo.runLive) +# mount list (unless todo.runLive) addMount() +# lilo boot.b installation (may be None) liloLocation() import rpm, os +import util, isys +from lilo import LiloConfiguration def instCallback(what, amount, total, key, data): if (what == rpm.RPMCALLBACK_INST_OPEN_FILE): @@ -15,17 +18,41 @@ def instCallback(what, amount, total, key, data): elif (what == rpm.RPMCALLBACK_INST_PROGRESS): data.setPackageScale(amount, total) - class ToDo: + def umountFilesystems(self): + self.mounts.sort(mountListCmp) + self.mounts.reverse() + for n in self.mounts: + isys.umount(n) + + def makeFilesystems(self): + self.mounts.sort(mountListCmp) + for n in self.mounts: + (device, mntpoint, format) = n + if not format: continue + w = self.intf.waitWindow("Formatting", + "Formatting %s filesystem..." % (mntpoint,)) + util.execWithRedirect("mke2fs", [ "mke2fs", device ], + stdout = None, searchPath = 1) + w.pop() + + def mountFilesystems(self): + for n in self.mounts: + (device, mntpoint, format) = n + isys.mount(device, self.instPath + mntpoint) + def installSystem(self): # make sure we have the header list and comps file self.headerList() comps = self.compsList() - os.mkdir(self.instPath + '/var') - os.mkdir(self.instPath + '/var/lib') - os.mkdir(self.instPath + '/var/lib/rpm') + self.makeFilesystems() + self.mountFilesystems() + + #os.mkdir(self.instPath + '/var') + #os.mkdir(self.instPath + '/var/lib') + #os.mkdir(self.instPath + '/var/lib/rpm') db = rpm.opendb(1, self.instPath) ts = rpm.TransactionSet(self.instPath, db) @@ -34,11 +61,33 @@ class ToDo: ts.add(p.h, (p.h, self.method)) ts.order() - p = self.intf.packageProgessWindow() - ts.run(0, 0, instCallback, p) + #p = self.intf.packageProgessWindow() + #ts.run(0, 0, instCallback, p) + + self.installLilo() - def addMount(self, device, location): - self.mounts.append((device, location)) + def installLilo(self): + if not self.liloDevice: return + + # FIXME: make an initrd here + + l = LiloConfiguration() + l.addEntry("boot", self.liloDevice) + l.addEntry("map", "/boot/map") + l.addEntry("install", "/boot/boot.b") + l.addEntry("prompt") + l.addEntry("timeout", "50") + + sl = LiloConfiguration() + sl.addEntry("label", "linux") + sl.addEntry("root", "/dev/hda8") + sl.addEntry("read-only") + + l.addImage("/boot/vmlinuz-2.2.2", sl) + l.write(self.instPath + "/etc/lilo.conf") + + def addMount(self, device, location, reformat = 1): + self.mounts.append((device, location, reformat)) def freeHeaders(self): if (self.hdList): @@ -52,6 +101,9 @@ class ToDo: w.pop() return self.hdList + def liloLocation(self, device): + self.liloDevice = device + def compsList(self): if (not self.comps): self.headerList() @@ -68,3 +120,12 @@ class ToDo: self.instPath = rootPath self.runLive = runLive pass + +def mountListCmp(first, second): + mnt1 = first[1] + mnt2 = first[2] + if (first < second): + return -1 + elif (first == second): + return 0 + return 1 |