Earlier in Crontab I made use of Hooks.runUnless to only run crontab when it needed updating. MCM.Hooks can be used to generate a script to perform system checks and make desired changes. MCM.Hooks is written somewhat in the style of MCM itself, in that it first runs readonly commands and then, after prompting, makes changes to the system.


import MCM.ScriptRegister as ScriptRegister
import MCM.Require as Require

define actionhook(action cond mode
		description = echo -n "Action will be: "; cat <<"EOF_Hook4"
			+ @action
			+ EOF_Hook4
		key = @cond@action
	case mode
	when unless
		join = ||
	when when
		join = &&
	.readonlyhook cond> @cond key> @key mode> @mode
		readonlycmd: something=1; @description
	Fragment group> actions name> @key
		content: { @cond
			+ } @join { @action
			+ }

define readonlyhook(cond mode readonlycmd
		key = @cond@readonlycmd
	case mode
	when unless
		join = ||
	when when
		join = &&
	Fragment group> readonly name> @key
		content: { @cond
			+ } @join { @readonlycmd
			+ }

define readonlyhookUnless(readonlycmd unless
		key = @unless@readonlycmd
	.readonlyhook cond> @unless key> @key mode> unless readonlycmd> @readonlycmd

define readonlyhookWhen(readonlycmd when
		key = @when@readonlycmd
	.readonlyhook cond> @when mode> when readonlycmd> @readonlycmd

define runUnless(command cond)
	.actionhook action> @command cond> @cond mode> unless

define runWhen(command cond)
	.actionhook action> @command cond> @cond mode> when

define writeScript()
	ScriptRegister.register name> 50_hooks
		content: #!/bin/bash
			+ something=0
			+ if [ $something -eq 0 ];then exit;fi
			+ echo 'Implement the above actions?'
			+ select ii in "Implement" "Ignore"; do
			+     case $ii in
			+         Implement ) break;;
			+         Ignore ) exit;;
			+     esac
			+ done
			+ true