#!/bin/sh
# Install a freedt service directory.
die () {
echo >&2 $1
exit 21
}
_mkdir () {
mkdir $1 || die "Unable to make directory $1"
}
_chmod () {
chmod $1 $2 || die "Unable to change mode of $2 to $1"
}
_chowngrp () {
chown $1 $3 || die "Unable to set owner of $3 to $1"
chgrp $2 $3 || die "Unable to set group of $3 to $1"
}
_cd () {
cd $1 || die "Unable to change to $1"
}
_touch () {
touch $1 || die "Unable to touch $1"
}
if [ $# -lt 3 ] ; then
echo Usage: mkservice account logaccount servicedir
echo e.g. mkservice root kernellog /etc/linuxkmsgd
exit 20
fi
user=$1
grp=`id -g $user` || die "Unable to get group of $user"
loguser=$2
loggrp=`id -g $loguser` || die "Unable to get group of $loguser"
dir=$3
_mkdir $dir
_chmod 03700 $dir
_cd $dir
_mkdir log
_chmod 02755 log
_mkdir log/main
_chowngrp $loguser $loggrp log/main
_chmod 02755 log/main
# These are necessary for multilog, but dumblog doesn't need them.
# _touch log/main/status
# _chowngrp $loguser $loggrp log/main/status
# _chmod 0644 log/main/status
_touch run
_chmod 0644 run
cat >run <<EOF
#!/bin/sh
exec 2>&1
exec setuidgid $user #some command#
EOF
_chmod 0755 run
_touch log/run
_chmod 0644 log/run
cat >log/run <<EOF
#!/bin/sh
exec setuidgid $loguser dumblog main/log
EOF
_chmod 0755 log/run
syntax highlighted by Code2HTML, v. 0.9.1