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