locking & windows/cygwin support

This commit is contained in:
morphium 2011-07-12 22:30:25 +02:00
parent 6682b1fcf9
commit 960987e00f
1 changed files with 33 additions and 10 deletions

View File

@ -1,4 +1,5 @@
#!/bin/sh
echo "* try to open tronlab's moleflap"
HOST='moleflap.hq.c3d2.de'
@ -10,6 +11,7 @@ PREFIX_LEN=4
PORT=80
STORE_ENC="$STORE.enc"
STORE_TMP="$STORE.tmp"
LOCKFILE="$STORE.lock"
FORCE_PGP=0
WGET="wget"
@ -18,10 +20,15 @@ checkhost() {
# checks if host is reachable. returns 0 on success
ping6 -c 1 $HOST >/dev/null 2>/dev/null
if [ $? -eq 0 ]; then
WGET="wget --prefer-family=IPv6"
return 0;
fi
ping -c 1 $HOST >/dev/null 2>/dev/null
WGET="wget --prefer-family=IPv6"
return 0;
fi
if [ "cygwin" = `uname -o | tr [:upper:] [:lower:]` ]
then
ping $HOST 56 1 >/dev/null 2>/dev/null
else
ping -c 1 $HOST >/dev/null 2>/dev/null
fi
if [ $? -eq 0 ]; then return 0; fi
return 1;
}
@ -107,6 +114,11 @@ EOF
exit
}
removelock()
{
rm $LOCKFILE
}
# Process command line arguments
for i in $@; do
case "$i" in
@ -117,23 +129,33 @@ for i in $@; do
esac
done
# lockfile
if [ -e $LOCKFILE ]
then
echo "lockfile exists ... exiting"
exit 1
else
echo $(date) > $LOCKFILE
fi
# test for connection
checkhost
if [ "$?" -eq "1" ]
then
if [ "x$CONNECT" = "x" ]; then
echo "can't connect to host $HOST"
exit;
echo "can't ping host $HOST ... exiting"
removelock
exit 1;
else
$CONNECT;
fi
fi
do_pgp
if [ $? -gt 2 ]; then
echo "fatal error"
exit
echo "fatal error ... exiting"
removelock
exit 1
fi
if [ -e $STORE ]
@ -143,7 +165,7 @@ else
echo "Please enter your valid token:"
read token
# save new token first
echo "$token" > $STORE
echo "$token" > $STORE
fi
newtoken=`$WGET -qO - http://$HOST:$PORT/open?$token`
@ -156,3 +178,4 @@ else
echo "* moleflap unreachable"
fi
removelock