Skip to content
Browse files

Add tags support

  • Loading branch information...
1 parent 0c11784 commit 1e75ad1962bd88cbc70a28fa32d706863649096a @jcdubacq committed
Showing with 106 additions and 69 deletions.
  1. +1 −5 TODO.md
  2. +89 −52 enforce_config
  3. +3 −0 lib/record-manual/_PREREV
  4. +7 −0 lib/record-manual/_PRERUN
  5. +0 −7 order.run
  6. +3 −5 order.revert → tags/basic
  7. +3 −0 tags/oberon
View
6 TODO.md
@@ -8,12 +8,8 @@ Turning this program in a real program
Managing several computers
--------------------------
- * add _tag_ lists
- * remove order.run order.revert
* automatic dependency on tag:basic and tag:common
- * reject removing tag:basic (can be done individually)
- * default action is to do tag:hostname
A _tag list_ is just a dependency beginning with tag:, maybe tag- or
tag/. All these dependencies are processed as another dependency file
-(read lines one by one, run line).
+(read lines one by one, run line).
View
141 enforce_config
@@ -1,6 +1,5 @@
#!/bin/sh
set -e
-cd /etc
if [ "$1" = "--debug" ]; then
shift
DEBUG=echo
@@ -13,9 +12,12 @@ ACCOUNT=jcdubacq
HOSTINSTALL=fiona
ACCOUNTHOME=$(getent passwd $ACCOUNT|cut -f6 -d:)
INSTALL=$(dirname "$0")
+if [ -x /usr/bin/realpath ]; then
+ INSTALL=$(realpath "$INSTALL")
+fi
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
+cd /etc
export ACCOUNT ACCOUNTHOME INSTALL REVERT HOSTINSTALL APT
@@ -66,39 +68,74 @@ chapter() {
echo "${bold}[$@]${offbold}"
}
-runit() {
+runtag() {
local TAG
local REVERT
- local PKGDIR
- local TAGS
- local PKGDIR
+ local CMD
local PKG
TAG="$1"
+ REVERT="$2"
+ TAGDIR="${INSTALL}/tags"
+ if [ "$TAG" = "basic" ]&&[ "$REVERT" = 1 ]; then
+ echo "Basic tasks really shouldn't be removed"
+ echo "Please remove them individually"
+ tac ${TAGDIR}/basic|xargs echo
+ return
+ fi
+ if [ "$REVERT" = 1 ]; then
+ CMD=tac
+ else
+ CMD=cat
+ fi
+ if [ -f "${TAGDIR}/${TAG}" ]; then
+ $CMD "${TAGDIR}/${TAG}"| while read PKG; do
+ runitreal "$PKG" "$REVERT"
+ done
+ fi
+}
+
+runit() {
+ local TAG
+ local REVERT
+ TAG="$1"
REVERT=0
if [ "${TAG%-}" != "${TAG}" ]; then
TAG="${TAG%-}"
REVERT=1
fi
- if [ "$REVERT" = 1 ]; then
- LIST=order.revert
+ runitreal "$TAG" "$REVERT"
+}
+
+runitreal() {
+ local TAG
+ local REVERT
+ local PKGDIR
+ local TAGS
+ local PKGDIR
+ local PKG
+ TAG="$1"
+ REVERT="$2"
+ if [ "${TAG#tag:}" != "${TAG}" ]; then
+ runtag "${TAG#tag:}" "$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
- if [ "${TAGS#* ${TAG} }" != "${TAGS}" ]; then
+ find "${INSTALL}/lib" -type d -maxdepth 1 -mindepth 1 -print\
+ |while read PKG; do
+ PKG=$(basename "$PKG")
+ TAGS=" ${PKG} "
+ PKGDIR="$INSTALL/lib/$PKG"
+ if [ -f "$PKGDIR/TAGS" ]; then
+ for NEWTAG in $(cat "$PKGDIR/TAGS"); do
+ TAGS="${TAGS}${NEWTAG} "
+ done
+ fi
+ 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
+ checkPackage "$PKG" "$REVERT" "$PKGDIR" "test" \
+ && echo "$PKG already in requisited state" \
+ || execPackage "$PKG" "$REVERT" "$PKGDIR"
+ fi
+ done
+ fi
}
execPackage() {
@@ -127,33 +164,33 @@ execPackage() {
[ "$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 $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 $FILE to $TARGET"
- $DEBUG mkdir -p "$FILEDIR"
- $DEBUG cp -- "$FILE" "$TARGET"
- fi
- if [ "${FILE%.crypt}" != "${FILE}" ]; then
- $DEBUG /usr/bin/decryptfile "$TARGET"
- fi
- ;;
- esac
+ 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 $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 $FILE to $TARGET"
+ $DEBUG mkdir -p "$FILEDIR"
+ $DEBUG cp -- "$FILE" "$TARGET"
+ fi
+ if [ "${FILE%.crypt}" != "${FILE}" ]; then
+ $DEBUG /usr/bin/decryptfile "$TARGET"
+ fi
+ ;;
+ esac
done
$DEBUG etckeeper commit "$COMMENT"||true
$DEBUG checkPackage "$PKG" "$REVERT" "$PKGDIR" stamp
@@ -163,7 +200,7 @@ execPackage() {
# doing
if [ -z "$1" ]; then
- runit all
+ runit "tag:$(hostname -s)"
else
runit "$1"
fi
View
3 lib/record-manual/_PREREV
@@ -0,0 +1,3 @@
+#!/bin/sh
+git config --unset user.name
+git config --unset user.email
View
7 lib/record-manual/_PRERUN
@@ -0,0 +1,7 @@
+#! /bin/sh
+if [ -x /usr/bin/git ]; then
+ git config user.name 'Jean-Christophe Dubacq (as root)'
+ git config user.email 'jean-christophe.dubacq@ens-lyon.org'
+else
+ printf '[user]\n\tname = Jean-Christophe Dubacq (as root)\n\temail = jean-christophe.dubacq@ens-lyon.org\n' > /root/.gitconfig
+fi
View
7 order.run
@@ -1,7 +0,0 @@
-record-manual
-repository-dubacq
-cryptstore
-repository-sidexp
-network-manager
-superusers
-fix-groups
View
8 order.revert → tags/basic
@@ -1,7 +1,5 @@
+record-manual
fix-groups
-network-manager
-repository-sidexp
-cryptstore
repository-dubacq
-superusers
-record-manual
+cryptstore
+network-manager
View
3 tags/oberon
@@ -0,0 +1,3 @@
+tag:basic
+superusers
+repository-sidexp

0 comments on commit 1e75ad1

Please sign in to comment.
Something went wrong with that request. Please try again.