On Sun, Jun 03, 2007 at 03:24:14PM +0300, Hussam Al-Tayeb wrote:
> I have a suggestion. Why not take this even further and make a nice
> script called for example 'services' that adds or removes daemons from
> rc.conf
> For example,
> "services add samba" will add samba to rc.conf
> "services remove samba" would remove samba fdrom rc.conf daemons array.
> Another nice thing it to make it throw a message to the user is the
> daemon samba isn't actually there ( installed ) or is already added.
> That would be real cool and useful.
for those who do not like editors:
#!/bin/bash
# sed command
SED="sed --in-place"
CONFIG="/etc/rc.conf"
function daemons_add {
# param 1: member
# param 2: config (default: $CONFIG)
local member=${1}
# check for init script
if [[ ! -e /etc/rc.d/${member} ]]; then
echo /etc/rc.d/${member} does not exist! >&2
return 1
else
${SED} -e "s/DAEMONS=(\([^)]*\))/DAEMONS=(\1 ${1})/" ${CONFIG}
fi
}
function daemons_remove
{
# param 1: member
# param 2: config (default: $CONFIG)
local member=${1}
${SED} "s/DAEMONS=(\([^)]*\)${1}\([^)]*\))/DAEMONS=(\1\2)/" ${CONFIG}
}
function usage {
echo "$0 add|remove daemon [daemon]..."
}
command=${1}
daemons=(${@:2})
# usage check
if [[ $# -lt 2 || (${command} != add && ${command} != remove) ]]; then
usage >&2
exit 1
fi
for daemon in [EMAIL PROTECTED]; do
daemons_${command} ${daemon}
done
_______________________________________________
arch mailing list
[email protected]
http://archlinux.org/mailman/listinfo/arch