Permalink
Browse files

Completely rewrite

  • Loading branch information...
1 parent da9fce7 commit 1f2cc73f411da1b3266de73c17f7bc52e6ea05d4 @jcdubacq committed Mar 7, 2013
Showing with 156 additions and 67 deletions.
  1. +134 −59 enforce_config
  2. +2 −2 lib/fix-groups/{fixgroups.revert → POSTREV}
  3. +1 −1 lib/fix-groups/{fixgroups.run → POSTRUN}
  4. 0 lib/{network/network.revert → network-manager/POSTREV}
  5. +3 −0 lib/network-manager/POSTRUN
  6. 0 lib/{network → network-manager}/README
  7. +1 −0 lib/network-manager/TAGS
  8. +0 −3 lib/network/network.run
  9. +1 −0 lib/record-manual/KEEPDIR
  10. 0 ...anual/{etckeeper%_post-install.d%_20storepackages → etc/etckeeper/post-install.d/20storepackages}
  11. 0 ...-manual/{etckeeper%_pre-install.d%_20storepackages → etc/etckeeper/pre-install.d/20storepackages}
  12. 0 ...manual/{etckeeper%_update-install.d%_30storepackages → etc/etckeeper/update-install.d/30packages}
  13. 0 ...-manual/{etckeeper%_update-install.d%_50vcs-commit → etc/etckeeper/update-install.d/50vcs-commit}
  14. 0 lib/repository-dubacq/{run.revert → POSTREV}
  15. 0 lib/repository-dubacq/{run.run → POSTRUN}
  16. 0 ...repository-dubacq/{apt%_preferences.d%_debian-dubacq-fr → etc/apt/preferences.d/debian-dubacq-fr}
  17. 0 ...pt%_sources.list.d%_debian.dubacq.fr.sid.list → etc/apt/sources.list.d/debian.dubacq.fr.sid.list}
  18. BIN ...trusted.gpg.d%_jcdubacq-archive-keyring.gpg → etc/apt/trusted.gpg.d/jcdubacq-archive-keyring.gpg}
  19. +2 −0 lib/repository-sidexp/POSTRUN
  20. 0 lib/repository-sidexp/{apt%_preferences.d%_experimental → etc/apt/preferences.d/experimental}
  21. 0 lib/repository-sidexp/{apt%_preferences.d%_unstable → etc/apt/preferences.d/unstable}
  22. 0 ...sitory-sidexp/{apt%_sources.list.d%_experimental.list → etc/apt/sources.list.d/experimental.list}
  23. 0 lib/repository-sidexp/{apt%_sources.list.d%_unstable.list → etc/apt/sources.list.d/unstable.list}
  24. +0 −2 lib/repository-sidexp/run.run
  25. 0 lib/superusers/{sudoers.d%_superusers → etc/sudoers.d/superusers}
  26. +6 −0 order.revert
  27. +6 −0 order.run
View
@@ -1,94 +1,169 @@
#!/bin/sh
set -e
cd /etc
+DEBUG=echo
# settings
APT="apt-get --assume-yes"
ACCOUNT=jcdubacq
HOSTINSTALL=fiona
ACCOUNTHOME=$(getent passwd $ACCOUNT|cut -f6 -d:)
-INSTALL=${ACCOUNTHOME}/INSTALL
+INSTALL=$(dirname "$0")
+bold=$(tput smso)
+offbold=$(tput rmso)
printf '[user]\n\tname = Jean-Christophe Dubacq (as root)\n\temail = jean-christophe.dubacq@ens-lyon.org\n' > /root/.gitconfig
-if [ -f $INSTALL/modified ]; then
- REVERT=1
- rm -f $INSTALL/modified
-else
- REVERT=0
- touch $INSTALL/modified
-fi
export ACCOUNT ACCOUNTHOME INSTALL REVERT HOSTINSTALL APT
# run
-chapter() {
- bold=$(tput smso)
- offbold=$(tput rmso)
- if [ "$REVERT" = 1 ]; then
- echo "${bold}[Revert $@]${offbold}"
+mkdir -p /var/lib/INSTALL
+
+checkPackage() {
+ local PKG
+ local REVERT
+ local PKGDIR
+ local ACTION
+ local INSTALLED
+ PKG="$1"
+ REVERT="$2"
+ PKGDIR="$3"
+ ACTION="$4"
+ INSTALLED="/var/lib/INSTALL/${PKG}"
+
+ if [ "$REVERT" = "0" ]; then
+ CURRENT=$(find "$PKGDIR" -type f -print0 |xargs -0 md5sum|md5sum -|cut -c1-32)
else
- echo "${bold}[$@]${offbold}"
+ CURRENT="XXX"
+ fi
+ if [ -f "${INSTALLED}" ]; then
+ VALUE=$(cat "${INSTALLED}")
+ else
+ VALUE="XXX"
+ fi
+ if [ "$ACTION" = "test" ]; then
+ if [ "$VALUE" != "$CURRENT" ]; then
+ return 1
+ else
+ return 0
+ fi
+ elif [ "$ACTION" = "stamp" ]; then
+ if [ "$CURRENT" = "XXX" ]; then
+ rm -f "${INSTALLED}"
+ else
+ echo -n "$CURRENT" > "$INSTALLED"
+ fi
+ else
+ die "Unknown action $ACTION"
fi
}
+chapter() {
+ echo "${bold}[$@]${offbold}"
+}
+
runit() {
- BASEDIR=$1
- TOPDIR="$INSTALL/lib/$BASEDIR"
- if [ -f "$TOPDIR"/README ]; then COMMENT=$(cat "$TOPDIR"/README); else COMMENT="Adding modification $1"; fi
- chapter "$1: $COMMENT"
- find $TOPDIR -print | while read i; do
- ii="${i#$TOPDIR/}"
- if [ "${ii#_}" != "$ii" ]; then
- j="/root/${ii#_}"
- else
- j="/etc/${ii}"
+ local TAG
+ local REVERT
+ local PKGDIR
+ local TAGS
+ local PKGDIR
+ local PKG
+ TAG="$1"
+ REVERT=0
+ if [ "${TAG%-}" != "${TAG}" ]; then
+ TAG="${TAG%-}"
+ REVERT=1
+ fi
+ if [ "$REVERT" = 1 ]; then
+ LIST=order.revert
+ else
+ LIST=order.run
+ fi
+ while read PKG; do
+ TAGS=" all ${PKG} "
+ PKGDIR="$INSTALL/lib/$PKG"
+ if [ -f "$PKGDIR/TAGS" ]; then
+ for NEWTAG in $(cat "$PKGDIR/TAGS"); do
+ TAGS="${TAGS}${NEWTAG} "
+ done
fi
- jj=$(dirname "$ii")
- POSTRUN=0
- POSTREVERT=0
- case "$ii" in
- VERSION|README)
- true
- ;;
- POSTRUN)
- if [ "$REVERT" = 0 ]; then FILE="$j"; export FILE; POSTRUN=1; fi
- ;;
- POSTREVERT)
- if [ "$REVERT" = 1 ]; then FILE="$j"; export FILE; POSTREVERT=1; fi
- ;;
- *.debconf)
- if [ "$REVERT" = 0 ]; then debconf-set-selections < "$i"; fi
- ;;
- *.patch)
- if [ "$REVERT" = 1 ]; then OPTION=-R;else OPTION=-N;fi
- patch -p1 "$OPTION" < $i
- ;;
- *)
+ if [ "${TAGS#* ${TAG} }" != "${TAGS}" ]; then
+ # The package has the requisited tag
+ checkPackage "$PKG" "$REVERT" "$PKGDIR" "test" \
+ && echo "$PKG already in requisited state" \
+ || execPackage "$PKG" "$REVERT" "$PKGDIR"
+ fi
+ done < $INSTALL/$LIST
+}
+
+execPackage() {
+ local PKG
+ local REVERT
+ local PKGDIR
+ local FILE
+ local COMMENT
+ local FILEDIR
+ local TARGET
+ local DEP
+ PKG="$1"
+ REVERT="$2"
+ PKGDIR="$3"
+ if [ -f "${PKGDIR}/DEPS" ]; then
+ chapter "${PKG}: Processing dependencies"
+ for DEP in $(cat "${PKGDIR}/DEPS"); do
+ runit "$DEP"
+ done
+ fi
+ if [ -f "${PKGDIR}/README" ]; then
+ COMMENT="${PKG}: $(cat < "${PKGDIR}/README")"
+ else
+ COMMENT="${PKG}"
+ fi
+ [ "$REVERT" = 0 ]||COMMENT="Removing ${COMMENT}"
+ chapter "$COMMENT"
+ find "$PKGDIR" -type f -print |sort| while read FILE; do
+ TARGET="/${FILE#${PKGDIR}/}"
+ THISFILE="$FILE"; export THISFILE
+ FILEDIR=$(dirname "$TARGET")
+ case "$TARGET" in
+ /README|/KEEPDIR|/TAGS|/DEPS)
+ true;;
+ /_PRERUN|/POSTRUN|*._run)
+ [ "$REVERT" = 0 ] && $DEBUG sh "$FILE" || true;;
+ /_PREREV|/POSTREV|*._rev)
+ [ "$REVERT" = 1 ] && $DEBUG sh "$FILE" || true;;
+ /etc/*|/root/*)
if [ "$REVERT" = 1 ]; then
- echo "Removing $j"
- rm "$j"
- rmdir --ignore-fail-on-non-empty "$jj"
+ echo "Removing $TARGET"
+ $DEBUG rm -- "$TARGET"
+ [ -f "$PKGDIR/KEEPDIR" ] && grep -q "^$FILEDIR$" "$PKGDIR/KEEPDIR" \
+ && echo "Keeping $FILEDIR" \
+ || $DEBUG rmdir --ignore-fail-on-non-empty "$FILEDIR"
else
- echo "Copying $i to $j"
- mkdir -p "$jj"
- cp "$i" "$j"
+ echo "Copying $FILE to $TARGET"
+ $DEBUG mkdir -p "$FILEDIR"
+ $DEBUG cp -- "$FILE" "$TARGET"
fi
;;
esac
done
- if [ "$POSTRUN" = 1 ]; then
- sh "${TOPDIR}/POSTRUN"
- fi
- if [ "$POSTREVERT" = 1 ]; then
- sh "${TOPDIR}/POSTREVERT"
- fi
- shift
- etckeeper commit "$COMMENT"||true
+ $DEBUG etckeeper commit "$COMMENT"||true
+ checkPackage "$PKG" "$REVERT" "$PKGDIR" stamp
+ return 0
}
# doing
+if [ -z "$1" ]; then
+ runit all
+else
+ runit "$1"
+fi
+exit 0
+
+
if [ "$REVERT" = 0 ]; then
chapter "Checking basic packages"
${APT} install debconf-utils
@@ -6,8 +6,8 @@ done
for GROUP in cdrom floppy audio dip video plugdev; do
adduser $ACCOUNT $GROUP || true
done
-perl -pi -e 's/USERGROUPS=no/USERGROUPS=yes/' /etc/adduser.conf || true
-perl -pi -e "s/^${ACCOUNT}:x:1000:100:/${ACCOUNT}:x:1000:1000:/" /etc/passwd||true
+perl -pi -e 's/USERGROUPS=no/USERGROUPS=yes/' /etc/adduser.conf
+perl -pi -e "s/^${ACCOUNT}:x:1000:100:/${ACCOUNT}:x:1000:1000:/" /etc/passwd
find ${ACCOUNTHOME} -gid 1000 -print0|xargs -0 --no-run-if-empty chown ${ACCOUNT}:100||true
addgroup --gid 1000 $ACCOUNT||true
adduser $ACCOUNT $ACCOUNT||true
@@ -9,4 +9,4 @@ done
perl -pi -e 's/USERGROUPS=yes/USERGROUPS=no/' /etc/adduser.conf
perl -pi -e "s/^${ACCOUNT}:x:1000:1000/${ACCOUNT}:x:1000:100/" /etc/passwd
find ${ACCOUNTHOME} -gid 1000 -print0|xargs -0 --no-run-if-empty chown ${ACCOUNT}:users
-delgroup ${ACCOUNT}
+delgroup ${ACCOUNT}||true
File renamed without changes.
@@ -0,0 +1,3 @@
+#!/bin/sh
+perl -pi -e 's/^/#NetworkManager#/g if (/eth0/ and ! /^#NetworkManager#/)' /etc/network/interfaces
+# do not relaunch instantly the network, could break existing connections
File renamed without changes.
View
@@ -0,0 +1 @@
+network
View
@@ -1,3 +0,0 @@
-#!/bin/sh
-perl -pi -e 's/^/#NetworkManager#/g if (/eth0/)' /etc/network/interfaces
-# do not relaunch instantly the network, could break existing connections
@@ -0,0 +1 @@
+/etc/etckeeper/update-install.d
File renamed without changes.
File renamed without changes.
@@ -0,0 +1,2 @@
+#!/bin/sh
+${APT} update
@@ -1,2 +0,0 @@
-#!/bin/sh
-apt-get update
View
@@ -0,0 +1,6 @@
+fix-groups
+network-manager
+repository-sidexp
+repository-dubacq
+superusers
+record-manual
View
@@ -0,0 +1,6 @@
+record-manual
+repository-dubacq
+repository-sidexp
+network-manager
+superusers
+fix-groups

0 comments on commit 1f2cc73

Please sign in to comment.