set -ux

: $GFDOCKER_PRIMARY_USER

REGRESS_DIR=~/gfarm/regress

$REGRESS_DIR/bin/am_I_gfarmroot
is_gfarmroot=$?
me=$GFDOCKER_PRIMARY_USER

trap_sigs='1 2 15'
restore() {
    if [ $is_gfarmroot -ne 0 ]; then
        gfgroup -r -m gfarmroot $me
    fi
}
trap 'restore' $trap_sigs

if [ $is_gfarmroot -ne 0 ]; then
    gfgroup -a -m gfarmroot $me
fi

cd $REGRESS_DIR/manual/lib/libgfarm/gfarm/gfs_pio_failover
cp gfmd-failover-local.gfservice.sh gfmd-failover-local.sh
make
gfmkdir -p /tmp
gfchmod 1777 /tmp
./test-all.sh auto
RESULT=$?
restore
exit $RESULT
