moth/install

115 lines
1.7 KiB
Bash
Executable File

#! /bin/sh
DESTDIR=$1
if [ -z "$DESTDIR" ]; then
echo "Usage: $0 DESTDIR"
exit
fi
cd $(dirname $0)
older () {
[ -z "$1" ] && return 1
target=$1; shift
[ -f $target ] || return 0
for i in "$@"; do
[ $i -nt $target ] && return 0
done
return 1
}
copy () {
target=$DESTDIR/$1
if older $target $1; then
echo "COPY $1"
mkdir -p $(dirname $target)
cp $1 $target
fi
}
cc () {
target=$DESTDIR/bin/$(basename $1 .c)
if older $target $@; then
src=$1; shift
echo "CC $src"
gcc -Wall -Werror -o $target $@ $src
fi
}
web () {
target=$DESTDIR/www/${1#*/}
if older $target $1; then
echo "WEB $1"
mkdir -p $(dirname $target)
cp $1 $target
fi
}
cgi () {
target=$DESTDIR/www/$(basename $1 .c)
if older $target $@; then
mkdir -p $(dirname $target)
src=$1; shift
echo "CGI $src"
gcc -Wall -Werror -o $target $@ src/common.c $src
fi
}
setup() {
[ -d $DESTDIR/state ] && return
echo "SETUP"
for i in points.new points.tmp teams; do
dir=$DESTDIR/state/$i
mkdir -p $dir
setfacl -m ${www}:rwx $dir
done
>> $DESTDIR/state/points.log
if ! [ -f $DESTDIR/assigned.txt ]; then
hd </dev/urandom | awk '{print $3 $4 $5 $6;}' | head -n 100 > $DESTDIR/assigned.txt
fi
}
echo "Figuring out web user..."
for www in www-data http _; do
id $www && break
done
if [ $www = _ ]; then
echo "Unable to determine httpd user on this system. Dying."
exit 1
fi
mkdir -p $DESTDIR || exit 1
setup
git ls-files | while read fn; do
case "$fn" in
install|.*)
;;
doc/*)
;;
html/*)
web $fn
;;
bin/*)
copy $fn
;;
src/common.c)
;;
src/pointscli.c)
cc $fn src/common.c
;;
src/*.cgi.c)
cgi $fn
;;
src/*.c)
cc $fn
;;
src/*.h)
;;
*)
echo "??? $fn"
;;
esac
done