update-translator script for review
Hi,
please take a look at the attached script.
Use the -v and -d (dry run) option to see what it does. Try:
mkdir /var/state/translator
update-translator -v -n /homes -t "/hurd/usermux /hurd/symlink"
update-translator -v -n /homes -t "/hurd/usermux /hurd/symlink" -a remove
update-translator -v -n /homes -t "/hurd/usermux /hurd/symlink" -a purge
Try changing the translator manually and running the script again.
settrans /homes /hurd/usermux /hurd/firmlink
update-translator -v -n /homes -t "/hurd/usermux /hurd/symlink"
update-translator -v -n /homes -t "/hurd/usermux /hurd/special-symlink"
(the latter is hypothetical and will not result in a working translator
setup. However, my script won't care).
What is missing now is a working policy how to call the script in the
postinst/prerm scripts. Especially which flags to pass to settrans to treat
the active translator right (should it be killed? should it be ignored,
etc).
Suggestions welcome.
Marcus
--
`Rhubarb is no Egyptian god.' Debian http://www.debian.org Check Key server
Marcus Brinkmann GNU http://www.gnu.org for public PGP Key
Marcus.Brinkmann@ruhr-uni-bochum.de PGP Key ID 36E7CD09
http://homepage.ruhr-uni-bochum.de/Marcus.Brinkmann/
#!/bin/sh
usage="usage: $0: [OPTIONS] [SETTRANS-OPTIONS]"
dry_run=
nsys_trans=
action=configure
verbose=true
while :; do
case $1 in
--help|--hel|--he|--h|-h|-\?)
echo "$usage"
echo "Update a system translator."
echo
echo "OPTIONS can be:"
echo " -?, --help Give this help list."
echo " --usage Give a short usage message."
echo " -v, --verbose Print out diagnostic information."
echo " -d, --dry-run Do not execute commands, just show them."
echo
echo " -a ACTION Specify what to do. ACTION can be one of"
echo " configure (default), remove, purge."
echo " -i IDENT Specify unique identifier. Default is"
echo " basename(node)."
echo " -n NODE Node to set the translator on. Default is"
echo ' /servers/`basename(translator)`.'
echo " -t TRANSLATOR Translator command string (with arguments)."
echo
echo "SETTRANS-OPTIONS are passed to settrans."
exit 0;;
--usage|--usag|--usa|--us|--u|-u)
echo "$usage"
exit 0;;
--verbose|--verbos|--verbo|--verb|--ver|--ve|--v|-v)
verbose=echo
shift;;
--dry-run|--dry-ru|--dry-r|--dry-|--dry|--dr|--d|-d)
dry_run=echo
shift;;
-a)
action=$2
shift 2;;
-i)
key=$2
shift 2;;
-n)
node=$2
shift 2;;
-t)
nsys_trans=$2
shift 2;;
-*)
echo $0: Unknown argument: $1
exit 1;;
*)
break;;
esac
done
st_opt=${1+@}
getfirstarg () { echo $1 ; }
# insert check for node here. Absolute path, not ending in /.
node=${node-/servers/`basename \`getfirstarg $nsys_trans\``}
if [ -z "$node" -o x"$node" = "x/servers/" ] ; then
echo $0: No node specified. Use -n option.
exit 0
fi
key=${key-`basename "$node"`}
if [ -z "$key" ] ; then
echo $0: No identifier could be determined. Specify -i option.
exit 0
fi
# Static data and configuration.
repository=/var/state/translator
# Get current state according to database.
#
# installed: We installed the translator.
# removed: It was removed last time.
# purged: It is not registered at all currently.
if [ -e "$repository/$key" ] ; then
osys_trans=`head -n1 "$repository/$key" 2> /dev/null`
user_trans=`tail -n+2 "$repository/$key" 2> /dev/null | head -n1`
if [ -z "$user_trans" ] ; then
user_trans=`showtrans "$node" 2> /dev/null`
state=installed
else
state=removed
fi
else
osys_trans=
user_trans=
state=purged
fi
# locking!
# trap signals
case $action in
configure)
case $state in
purged)
$verbose "Installing new translator."
$dry_run settrans -cfg $st_opt "$node" $nsys_trans
;;
removed)
if [ x"$osys_trans" = x"$nsys_trans" ] ; then
$verbose "Reinstalling user translator."
$dry_run settrans -c $st_opt "$node" $user_trans
else
if [ x"$user_trans" = x"$osys_trans" ] ; then
$verbose "Reinstalling (new) system translator."
$dry_run settrans -c $st_opt "$node" $nsys_trans
else
echo 'The translator invocation included in the package changed and'
echo 'the system administrator changed the translator manually.'
echo
echo Old translator in package: $osys_trans
echo New translator in package: $nsys_trans
echo Previous system setup: $user_trans
echo
echo 'Requested action:'
echo 'Y or I : Install the new translator.'
echo 'N or O : Keep previous setup.'
read -p "Please enter: " answer
if [ "x$answer" = "xy" -o "x$answer" = "xY" -o "x$answer" = "xi" -o "x$answer" = "xI" ] ; then
$dry_run settrans -c $st_opt "$node" $nsys_trans
fi
fi
fi
;;
installed)
if [ x"$osys_trans" = x"$nsys_trans" -o x"$user_trans" = x"$nsys_trans" ] ; then
$verbose "Updating system translator, no change."
exit 0;
else
if [ x"$user_trans" = x"$osys_trans" ] ; then
$verbose "Updating system translator."
$dry_run settrans -c $opt "$node" $nsys_trans
else
echo 'The translator invocation included in the package changed and'
echo 'the system administrator changed the translator manually.'
echo
echo Old translator in package: $osys_trans
echo New translator in package: $nsys_trans
echo Current system setup: $user_trans
echo
echo 'Requested action:'
echo 'Y or I : Install the new translator.'
echo 'N or O : Keep current setup.'
read -p "Please enter: " answer
if [ "x$answer" = "xy" -o "x$answer" = "xY" -o "x$answer" = "xi" -o "x$answer" = "xI" ] ; then
$dry_run settrans -c $st_opt "$node" $nsys_trans
fi
fi
fi
;;
esac
if [ -z "$dry_run" ] ; then
echo "$nsys_trans" > "$repository/$key"
else
echo echo \"$nsys_trans\" \> \"$repository/$key\"
fi
exit 0
;;
remove)
case $state in
installed)
$verbose "Removing translator."
$dry_run settrans $opt "$node"
$dry_run rm -f "$node"
if [ -z "$dry_run" ] ; then
echo "$osys_trans" > "$repository/$key"
echo "$user_trans" >> "$repository/$key"
else
echo echo \"$osys_trans\" \> \"$repository/$key\"
echo echo \"$user_trans\" \>\> \"$repository/$key\"
fi
;;
*)
echo "$0: Can not remove non-existing translator."
exit 0
;;
esac
;;
purge)
case $state in
removed)
$verbose "Purging translator."
$dry_run rm -f "$repository/$key"
;;
installed)
echo $0: Error: Purging installed translator not allowed, remove first.
exit 1
;;
purged)
echo $0: Can not purge non-existing translator.
exit 0
;;
esac
;;
*)
echo "$0: unknown action $action"
exit 1
esac
Reply to: