|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +MAMID=${MAM_ID:-} |
| 4 | + |
| 5 | +BUFFER=${MAM_BUFFER:-55000} # Stay above 55000, so always have 5k available, even after buying a wedge. |
| 6 | +VIP=${MAM_VIP:-1} # Set this to 1 to enable buying of VIP |
| 7 | +WEDGEHOURS=${MAM_WEDGEHOURS:-0} # Buy a wedge every 4 hours - set to 0 to not buy wedges |
| 8 | +WORKDIR=${MAM_WORKDIR:-/tmp} # Directory for temp files. |
| 9 | + |
| 10 | +POINTSURL='https://www.myanonamouse.net/json/bonusBuy.php/?spendtype=upload&amount=' |
| 11 | +VIPURL='https://www.myanonamouse.net/json/bonusBuy.php/?spendtype=VIP&duration=max&_=' |
| 12 | +WEDGEURL='https://www.myanonamouse.net/json/bonusBuy.php/?spendtype=wedges&source=points&_='$TIMESTAMP |
| 13 | + |
| 14 | +cd ${WORKDIR} |
| 15 | + |
| 16 | +################################################################################# |
| 17 | +################################################################################# |
| 18 | +echo Checking existing cookie file. |
| 19 | +MAMUID=`curl -s -b ${WORKDIR}/MAM.cookies -c ${WORKDIR}/MAM.cookies https://www.myanonamouse.net/jsonLoad.php?snatch_summary | tee ${WORKDIR}/MAM.json | jq .uid 2>/dev/null` |
| 20 | + |
| 21 | +if [ "${MAMUID}x" = "x" ] |
| 22 | +then |
| 23 | + echo Session invalid. |
| 24 | + if [ "x$MAMID" = "x__LONGSTRING__" ] |
| 25 | + then |
| 26 | + echo Please update the MAMID in the script |
| 27 | + exit 1 |
| 28 | + fi |
| 29 | + |
| 30 | + MAMUID=`curl -s -b "mam_id=${MAMID}" -c ${WORKDIR}/MAM.cookies https://www.myanonamouse.net/jsonLoad.php?snatch_summary | tee ${WORKDIR}/MAM.json | jq .uid 2>/dev/null` |
| 31 | + if [ "${MAMUID}x" = "x" ] |
| 32 | + then |
| 33 | + echo " => Cannot create new session!" |
| 34 | + exit 1 |
| 35 | + else |
| 36 | + echo " => New Session created" |
| 37 | +# exit 1 |
| 38 | + fi |
| 39 | + else |
| 40 | + echo " => Existing session valid" |
| 41 | +fi |
| 42 | + |
| 43 | +POINTS=`jq .seedbonus < ${WORKDIR}/MAM.json` |
| 44 | + |
| 45 | +TIMESTAMP=`date +%s%3N` |
| 46 | + |
| 47 | +# First - find out how many points we have. |
| 48 | +echo Collecing current points. |
| 49 | +POINTS=`curl -s -b ${WORKDIR}/MAM.cookies -c ${WORKDIR}/MAM.cookies https://www.myanonamouse.net/jsonLoad.php?id=${MAMUID} | jq '.seedbonus'` |
| 50 | + |
| 51 | +if [ $? -ne 0 ] |
| 52 | +then |
| 53 | + echo " => Failed to get number of bonus points - aborting." |
| 54 | + exit 1 |
| 55 | +else |
| 56 | + echo " => Current points: $POINTS" |
| 57 | +fi |
| 58 | + |
| 59 | +# Check to see if we should buy a wedge. (Hours above, less 10 minutes to cope with offsets) |
| 60 | +if [ $WEDGEHOURS -gt 0 ] |
| 61 | +then |
| 62 | + WEDGEMINS=`expr $WEDGEHOURS \* 60 - 10` |
| 63 | + find ${WORKDIR}/wedge.last -mmin -${WEDGEMINS} 2>/dev/null | grep -i wedge.last > /dev/null 2>/dev/null |
| 64 | + if [ $? -ne 0 ] |
| 65 | + then |
| 66 | + echo Need to buy a wedge! |
| 67 | + if [ $POINTS -lt 50000 ] |
| 68 | + then |
| 69 | + echo "Not enough points, aborting" |
| 70 | + exit 1 |
| 71 | + fi |
| 72 | + |
| 73 | + curl -s -b ${WORKDIR}/MAM.cookies -c ${WORKDIR}/MAM.cookies $WEDGEURL |
| 74 | + touch ${WORKDIR}/wedge.last |
| 75 | + |
| 76 | + POINTS=`curl -s -b ${WORKDIR}/MAM.cookies -c ${WORKDIR}/MAM.cookies https://www.myanonamouse.net/jsonLoad.php?id=${MAMUID} | jq '.seedbonus'` |
| 77 | + fi |
| 78 | +fi |
| 79 | + |
| 80 | +# Maximize VIP |
| 81 | +if [ "x$VIP" != "x" ] |
| 82 | +then |
| 83 | + VIPRESULT=`curl -s -b ${WORKDIR}/MAM.cookies -c ${WORKDIR}/MAM.cookies ${VIPURL}${TIMESTAMP} 2>/dev/null | jq .success` |
| 84 | + if [ "x$VIPRESULT" != "xtrue" ] |
| 85 | + then |
| 86 | + echo VIP purchase failed! |
| 87 | + fi |
| 88 | +fi |
| 89 | + |
| 90 | +for i in 100 20 5 1 |
| 91 | +do |
| 92 | + echo Checking to spend ${i}GB |
| 93 | + UPLOADREQUIRED=`expr $i \* 500 + ${BUFFER}` |
| 94 | + while [ $POINTS -gt $UPLOADREQUIRED ] |
| 95 | + do |
| 96 | + echo $POINTS is more than $UPLOADREQUIRED - buying ${i}G of upload |
| 97 | + NEWPOINTS=`curl -s -b ${WORKDIR}/MAM.cookies -c ${WORKDIR}/MAM.cookies ${POINTSURL}${i}'&_='$TIMESTAMP | jq '.seedbonus' | sed -e 's/\..*$//'` |
| 98 | + if [ $? -ne 0 ] |
| 99 | + then |
| 100 | + echo Spend failed - cannot see new Bonus points. |
| 101 | + exit 1 |
| 102 | + fi |
| 103 | + |
| 104 | + if [ $NEWPOINTS -lt $POINTS ] |
| 105 | + then |
| 106 | + POINTS=$NEWPOINTS |
| 107 | + else |
| 108 | + echo Points did not change - spending failed. |
| 109 | + exit 1 |
| 110 | + fi |
| 111 | + done |
| 112 | +done |
0 commit comments