moth/install.sh

84 lines
1.5 KiB
Bash
Raw Normal View History

2017-02-05 16:42:55 -07:00
#! /bin/sh -e
2017-02-05 20:39:34 -07:00
DESTDIR="$1"
2017-02-05 16:42:55 -07:00
if [ -z "$DESTDIR" ]; then
2017-02-05 20:39:34 -07:00
echo "Usage: $0 DESTDIR"
exit
2017-02-05 16:42:55 -07:00
fi
cd $(dirname $0)
older () {
2017-02-05 20:39:34 -07:00
[ -z "$1" ] && return 1
target="$1"; shift
[ -f "$target" ] || return 0
for i in "$@"; do
[ "$i" -nt "$target" ] && return 0
done
return 1
2017-02-05 16:42:55 -07:00
}
copy () {
2017-02-05 20:39:34 -07:00
src="$1"
target="$2/$src"
targetdir=$(dirname "$target")
if older "$target" "$src"; then
echo "COPY $src"
mkdir -p "$targetdir"
cp "$src" "$target"
fi
2017-02-05 16:42:55 -07:00
}
setup() {
2017-02-05 20:39:34 -07:00
www="$1"
[ -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
mkdir -p "$DESTDIR/packages"
>> "$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
2017-02-05 16:42:55 -07:00
2017-02-05 20:39:34 -07:00
mkdir -p "$DESTDIR/www"
ln -sf ../state/points.json "$DESTDIR/www"
ln -sf ../state/puzzles.json "$DESTDIR/www"
2017-02-05 16:42:55 -07:00
}
echo "Figuring out web user..."
for www in www-data http tc _ _www; do
2017-02-05 20:39:34 -07:00
id $www && break
2017-02-05 16:42:55 -07:00
done
if [ $www = _ ]; then
2017-02-05 20:39:34 -07:00
echo "Unable to determine httpd user on this system. Dying."
exit 1
2017-02-05 16:42:55 -07:00
fi
2017-02-05 20:39:34 -07:00
mkdir -p "$DESTDIR" || exit 1
2017-02-05 16:42:55 -07:00
2017-02-05 20:39:34 -07:00
setup $www
2017-02-05 16:42:55 -07:00
git $SRCDIR ls-files | while read fn; do
2017-02-05 20:39:34 -07:00
case "$fn" in
example-puzzles/*|tools/*|docs/*|install.sh|setup.cfg|README.md|.gitignore|src/mothd)
true # skip
;;
2017-02-05 16:42:55 -07:00
www/*)
2017-02-05 20:39:34 -07:00
copy "$fn" "$DESTDIR/"
;;
2017-02-05 16:42:55 -07:00
bin/*)
2017-02-05 20:39:34 -07:00
copy "$fn" "$DESTDIR/"
;;
2017-02-05 16:42:55 -07:00
*)
2017-02-05 20:39:34 -07:00
echo "??? $fn"
;;
esac
2017-02-05 16:42:55 -07:00
done
echo "All done installing."