Bug 12964 - a li'l pile of fixing for init.d (INSTALL_ROOT,groups,no asking in INSTALL))
: a li'l pile of fixing for init.d (INSTALL_ROOT,groups,no asking in INSTALL))
Status: CLOSED FIXED
Product: Codex
Classification: Unclassified
Component: smgl
: test grimoire
: Other other
: P2 major
Assigned To: Grimoire Bug List
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2006-08-09 05:54 UTC by Thomas Orgis
Modified: 2007-04-01 02:08 UTC (History)
2 users (show)

See Also:


Attachments
more consistent INSTALL_ROOT support (4.57 KB, patch)
2006-08-13 18:30 UTC, Thomas Orgis
Details | Diff
patch 2: better init.d backup routine (1.46 KB, patch)
2006-08-13 18:32 UTC, Thomas Orgis
Details | Diff
patch 3: groups and static dev (2.06 KB, patch)
2006-08-13 18:36 UTC, Thomas Orgis
Details | Diff
step 4: first_install as persistent variable, not file (1.02 KB, patch)
2006-08-24 04:12 UTC, Thomas Orgis
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Thomas Orgis 2006-08-09 05:54:59 UTC
So, I've seen that init.d is really dangerous for $INSTALL_ROOT != "" and fixed 
it to work on cast of a to-be chroot.
It also uses groups on static dev tree generation that may not yet exist...

Well, Just see the diff that follows; I'm asking here for some 
feedback/approval before I commit this to git and possibly break a kindof vital 
spell...

diff --git a/smgl/init.d/CONFIGURE b/smgl/init.d/CONFIGURE
index 604e247..86d7bf2 100755
--- a/smgl/init.d/CONFIGURE
+++ b/smgl/init.d/CONFIGURE
@@ -16,4 +16,8 @@ if  grep -q devfs /proc/filesystems  &&
   message "\n${MESSAGE_COLOR}NOTICE: Switching from devfs to udev or static 
currently needs manual editing of /etc/fstab.${DEFAULT_COLOR}\n"
 fi  &&
 
-config_query_list  DEVICES  "Choose /dev management mode:"  $DEVICES_LIST
+config_query_list  DEVICES  "Choose /dev management mode:"  $DEVICES_LIST &&
+if [[ "$DEVICES" != "devfs" ]]
+then
+  config_query  CREATE_DEV_TREE  "check for / create static /dev tree" y
+fi
diff --git a/smgl/init.d/FINAL b/smgl/init.d/FINAL
index 39e56ed..27e9f85 100755
--- a/smgl/init.d/FINAL
+++ b/smgl/init.d/FINAL
@@ -1,7 +1,9 @@
+# that's ugly, should be a safe/random file name
+# hm, and are these files never updated?
 if  [  -e  /tmp/initd_first_install  ]  ;  then
-  install  -m 754  $SCRIPT_DIRECTORY/files/tshutdown  /sbin/tshutdown
+  install  -m 754  $SCRIPT_DIRECTORY/files/tshutdown  
${INSTALL_ROOT}/sbin/tshutdown
   install  -m 754  $SCRIPT_DIRECTORY/files/smgl-cleanup  \
-        /etc/init.d/runlevels/%S/
+        ${INSTALL_ROOT}/etc/init.d/runlevels/%S/
   rm -f /tmp/initd_first_install
 fi
 
@@ -20,7 +22,7 @@ if  [  -e  /tmp/devices2dev  ]  ;  then
   rm  /tmp/devices2dev
 fi
 
-sedit  "s/DEVICES=.*/DEVICES=$DEVICES/"  /etc/sysconfig/devices
+sedit  "s/DEVICES=.*/DEVICES=$DEVICES/"  ${INSTALL_ROOT}/etc/sysconfig/devices
 
 if  [  "$DEVICES" == "devfs"  ]; then
   sedit  "s:/dev/tty\(.\):/dev/vc/\1:"  ${INSTALL_ROOT}/etc/inittab
@@ -30,6 +32,7 @@ else
 fi
 
 # remove /etc/inittab from the simpleinit install log
+# this should work for $INSTALL_ROOT/etc/inittab, too
 for i in $INSTALL_LOGS/simpleinit* $MD5SUM_LOGS/simpleinit*
 do if [ -f $i ] ; then
   sedit  "/\/etc\/inittab/D"  $i
@@ -41,9 +44,9 @@ # The next sedit is to fix my (sandalle)
 # where casting from a queue (or not using -r) will not reassign
 # it. Should be removed in about a month (~20040926)
 #
-if  grep  -q  "mountall$"  /etc/sysconfig/facilities;  then
-  
message "${MESSAGE_COLOR}Fixing /etc/sysconfig/facilities:local_fs${DEFAULT_COLOR}"  
&&
-  sedit  's:mountall:mountall.sh:'  /etc/sysconfig/facilities
+if  grep  -q  "mountall$"  ${INSTALL_ROOT}/etc/sysconfig/facilities;  then
+  message "${MESSAGE_COLOR}Fixing 
${INSTALL_ROOT}/etc/sysconfig/facilities:local_fs${DEFAULT_COLOR}"  &&
+  sedit  's:mountall:mountall.sh:'  ${INSTALL_ROOT}/etc/sysconfig/facilities
 fi  &&
 #
 # End rename fix
diff --git a/smgl/init.d/INSTALL b/smgl/init.d/INSTALL
index d0ca990..023633a 100755
--- a/smgl/init.d/INSTALL
+++ b/smgl/init.d/INSTALL
@@ -1,16 +1,26 @@
 check_static_dev () {
   echo  "checking if your static /dev is ok..."  &&
   mkdir  /tmp/$$.bindmount                       &&
-  mount  --bind  /  /tmp/$$.bindmount            &&
+  mount  --bind  ${INSTALL_ROOT}/  /tmp/$$.bindmount            &&
   cd  /tmp/$$.bindmount/dev                      &&
   if [ ! -c console -o ! -c null ]; then
-    if query "You don't seem to have a static /dev tree, should i create it ?" 
y
-    then $SCRIPT_DIRECTORY/MAKEDEV generic-nopty md
-      mkdir  -p  shm  pts  &&
-      mknod  initctl  p
-    fi
+    message "Ok, going to create!" &&
+  # asked in CONFIGURE
+  # if query "You don't seem to have a static /dev tree, should i create it ?" 
y
+  # then
+    create_group kmem &&
+    create_group tty &&
+    create_group ppp &&
+    create_group lp &&
+    create_group disk &&
+    create_group floppy &&
+    # existing nodes should not make me fail
+    $SCRIPT_DIRECTORY/MAKEDEV generic-nopty md || true &&
+    mkdir  -p  shm  pts  &&
+    mknod  initctl  p || true
+  # fi
   else
-    echo "seems ok"
+  echo "seems ok"
   fi                         &&
   cd  /                      &&
   umount  /tmp/$$.bindmount  &&
@@ -39,7 +49,7 @@ FD=$SCRIPT_DIRECTORY/files    # Files Di
 ID=${INSTALL_ROOT}/etc/init.d                # Init Dir
 RD=${INSTALL_ROOT}/etc/init.d/runlevels      # Runlevels Dir
 
-if  [ "$DEVICES" != "devfs" ]; then
+if  [[ "$DEVICES" != "devfs" ]] && [[ "$CREATE_DEV_TREE" == y ]]; then
   check_static_dev
 fi  &&
 
@@ -78,19 +88,22 @@ mkdep 3 2                               
 mkdep 4 3                                                   &&
 mkdep 5 4                                                   &&
 
-if ! grep -sq runlevels /etc/inittab ; then
-    pinfo "Installing /etc/inittab..."                      &&
+if ! grep -sq runlevels ${INSTALL_ROOT}/etc/inittab ; then
+    pinfo "Installing ${INSTALL_ROOT}/etc/inittab..."                      &&
     install -v -m 644 $FD/inittab ${INSTALL_ROOT}/etc/inittab
 fi                                                          &&
 
 pinfo "Other stuff..."                                      &&
 
 # Proper shutdown procedure
-ln -fsv ${TRACK_ROOT}/etc/sysconfig/shutdown ${INSTALL_ROOT}/etc/shutdown.conf  
&&
+# TRACK_ROOT???
+# ln -fsv ${TRACK_ROOT}/etc/sysconfig/shutdown 
${INSTALL_ROOT}/etc/shutdown.conf  &&
+ln -fsv sysconfig/shutdown ${INSTALL_ROOT}/etc/shutdown.conf  &&
 
 # Yeah, I know
 ln  -sfv  /bin/true  $RD/rc  &&
 
 # LILO uses the auto runlevel when it doesn't encounter any user input
-ln  -sfv  /etc/init.d/runlevels/%default              \
+# path relative to be safer for chroots
+ln  -sfv  %default              \
           ${INSTALL_ROOT}/etc/init.d/runlevels/%auto
diff --git a/smgl/init.d/PRE_BUILD b/smgl/init.d/PRE_BUILD
index 4270519..ef8bb82 100755
--- a/smgl/init.d/PRE_BUILD
+++ b/smgl/init.d/PRE_BUILD
@@ -1,21 +1,43 @@
 # Remove old init.d
 if ! [ "$CROSS_INSTALL" = "on" ] ; then
-if  [  !  -e  /etc/init.d/smgl_init  ]  ;  then
-  touch /tmp/initd_first_install
+if  [  !  -e  ${INSTALL_ROOT}/etc/init.d/smgl_init  ]  ;  then
+  touch /tmp/initd_first_install &&
 
-  mkdir  -p  /etc/init.d.backup
+  if [[ -e ${INSTALL_ROOT}/etc/init.d ]]
+  then
 
-  mv  /etc/init.d  /etc/init.d.backup
+  message "doing backup of old init.d" &&
+  local bd=${INSTALL_ROOT}/etc/init.d.backup &&
+
+  if [[ -e ${bd} ]]
+  then
+    message "$bd exists, trying with number suffix" &&
+    local num=2 &&
+    while [[ -e ${bd}.$num ]]
+    do
+      let num+=1 &&
+      message "trying ${bd}.$num..."
+    done
+    message "using ${bd}.$num" &&
+    bd=${bd}.$num
+  fi &&
+  
+  
+  mkdir  -pv  $bd &&
+
+  mv  ${INSTALL_ROOT}/etc/init.d ${bd} &&
 
   for  l  in  0 1 2 3 4 5 6 S  ;  do
-    [  -d  /etc/rc$l.d  ]  &&  mv  /etc/rc$l.d  /etc/init.d.backup
+    [  -d  ${INSTALL_ROOT}/etc/rc$l.d  ]  &&  mv  ${INSTALL_ROOT}/etc/rc$l.d  
${bd}
   done
+  
+  fi
 fi
-fi
+fi &&
 
 # remove left behind file, bug #5784.
-if [ -f /etc/init.d/runlevels/%3/z-misc.sh ]; then
-  rm /etc/init.d/runlevels/%3/z-misc.sh
-fi
+if [ -f ${INSTALL_ROOT}/etc/init.d/runlevels/%3/z-misc.sh ]; then
+  rm ${INSTALL_ROOT}/etc/init.d/runlevels/%3/z-misc.sh
+fi &&
 
 true
Comment 1 Thomas Orgis 2006-08-09 06:01:43 UTC
Hah! For that patch to really work, one should add definitions for some groups 
to grimoire:

kmem
tty
disk
floppy
lp


I suggest (my current /etc/group):

kmem:x:15:
tty:x:5:orgis
disk:x:6:
floppy:x:25:orgis
lp:x:7:

(o' course ignore the user, that's just me;-)

plus: create_group should fail if it cannot find a definition!
Comment 2 Thomas Orgis 2006-08-09 06:16:08 UTC
OK, also, the old init.d backup in PRE_BUILD could change the rcX.d part:

  for  l  in  0 1 2 3 4 5 6 S  ;  do
    if [[  -d  ${INSTALL_ROOT}/etc/rc$l.d  ]]
    then
      mv  ${INSTALL_ROOT}/etc/rc$l.d  ${bd}
    fi
  done

The old variant silently fails if there is no /etc/rcX.d directory...
Comment 3 Thomas Orgis 2006-08-09 06:30:08 UTC
man... last update from me before someone else had his chance:

there are some more groups... you really have to cast stuff with an 
empty /etc/passwd (note: mine had  just a root account in it created by a 
special spell for being able to install sorcery in chroot).

so I have now in the relevant part of INSTALL:

    create_group kmem &&
    create_group tty &&
    create_group ppp &&
    create_group lp &&
    create_group disk &&
    create_group floppy &&
    create_group audio &&


and these groups in the fresh /etc/group (after casting smgl-fhs and init.d):

root:*:0:
games:x:60:
mail:x:8:
utmp:x:43:
ppp:x:20:
kmem:x:15:
tty:x:5:
lp:x:7:
disk:x:6:
floppy:x:25:
audio:x:29:

Comment 4 Thomas Orgis 2006-08-13 18:30:45 UTC
Created attachment 6430 [details]
more consistent INSTALL_ROOT support

first of three incremental patches to be applied with patch -Np1 in spell dir
Comment 5 Thomas Orgis 2006-08-13 18:32:10 UTC
Created attachment 6431 [details]
patch 2: better init.d backup routine
Comment 6 Thomas Orgis 2006-08-13 18:36:14 UTC
Created attachment 6432 [details]
patch 3: groups and static dev

This is the last one of the broken up parts of the too-big-to-review patch.

There are now 3 steps:

1. put more INSTALL_ROOT in it; this was halfway done before
2. fix/improve the init.d backup routine
3. fix static dev tree creation by creating needed groups and asking in
CONFIGURE instead in the middle of a cast

Please comment on these so that I can commit to git.
Comment 7 David Kowis 2006-08-21 07:47:29 UTC
Seems sane to me. But it's 7:45am on a monday...

Others should probably review this, as it's kinda critical to making the system
boot. Like the backup routine. <tangent>It might be nice to have that as a
grimoire level function, since a few spells use it.</tangent>

If I'm understanding correctly, you could start with an empty /etc/passwd (well,
with root) and casting this would create the necessary users/groups? That's
pretty nice :)
Comment 8 Thomas Orgis 2006-08-21 08:16:39 UTC
Well, the working cast of stuff with empty /etc/passwd is a long/mid/(short;-) 
term goal I have. 
Atm. I even have a root-account spell that creates at least the one line you 
need to get going in a fresh chroot. 
But that will be subject of the account system reworking that is in the 
mindworks (I have to prepare that proposal...). 
Comment 9 Jeremy Blosser 2006-08-21 12:05:15 UTC
are these standalone patches or do they depend on each other?
Comment 10 Thomas Orgis 2006-08-21 14:02:01 UTC
They're incremental steps (from 1 to 3). Stuff really depends on each other.
Comment 11 Eric Sandall 2006-08-23 12:32:25 UTC
1. Perhaps use a persistent variable instead of checking [[ -e  /tmp/
initd_first_install ]].
2. TRACK_ROOT is used to define where you will be running from. From: http://
wiki.sourcemage.org/install_root_and_others
"TRACK_ROOT This describes what prefix should be given to files installed in 
the install log."
Comment 12 Thomas Orgis 2006-08-23 12:55:12 UTC
Point 1: Yes, I think, too, that this temp file in the role of a peristent 
flag us some ugly thing. It would have been the next thing to change for 
me;-). Will prepare a fourth incremental patch for that. 
 
Point 2: So you agree with me that the usage of TRACK_ROOT was wrong and my 
variant of that is better? I cannot see how the symlink of etc/shutdown.conf 
is related to TRACK_ROOT... well, at least I cannot see why this should be 
good. 
Comment 13 Eric Sandall 2006-08-23 13:55:54 UTC
I don't believe any init script/package should be using TRACK_ROOT as it will 
*only* be run from 'inside' the system, not outside (which is what TRACK_ROOT 
is for, AFAIK), so yes I agree, I was just answering your question (or what I 
thought was a question) about what TRACK_ROOT was.
Comment 14 Thomas Orgis 2006-08-24 04:12:23 UTC
Created attachment 6443 [details]
step 4: first_install as persistent variable, not file

incremental after steps 1,2,3
Comment 15 Thomas Orgis 2006-08-31 19:26:49 UTC
So, anyone against me commiting these changes in the next days? 
Comment 16 Eric Sandall 2006-09-01 19:09:16 UTC
I'd say go for the commit if it seems to be working on your machine. You'll know
soon enough if our machines break. ;)
Comment 17 Thomas Orgis 2006-09-03 06:55:51 UTC
It is in test now: 
 
commit 557bc9028c2705ae3d65b7973234a8ed03a5dfd7 
 
Short after my commit that added the definition for the group tty, Jaka fixed 
bug #7768 for util-inux using that group definition. 
He requested stable integration of his fix... should I request integration 
here, too, to make sure that the new groups file is integrated? 
I guess we don't want the whole changes to init.d in stable immediately 
(although it is bugfixing) and also that the integrator is conscious enough to 
see the issue - so: no.(?) 
Comment 18 Jeremy Blosser 2007-03-31 01:22:04 UTC
closing fixed bugs
Comment 19 Jeremy Blosser 2007-04-01 01:08:04 UTC
reassign to sm-grimoire-bugs