Skip to content

Commit

Permalink
Acquire/release wakelock
Browse files Browse the repository at this point in the history
  • Loading branch information
nahuhh authored Jan 23, 2022
1 parent 7ca628c commit b894840
Showing 1 changed file with 40 additions and 10 deletions.
50 changes: 40 additions & 10 deletions src/install-monerod-in-termux.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ then
fi

termux-wake-lock
sleep 1
pkg update -y
pkg install nano wget termux-api jq -y

Expand Down Expand Up @@ -288,7 +289,7 @@ RESP=\$(termux-dialog radio -t "Run Node in:" -v "Background,Foreground" | jq '.
termux-job-scheduler --job-id 1 -s $TERMUX_SCHEDULED/xmr_notifications --period-ms 900000
termux-job-scheduler --job-id 2 -s $TERMUX_SCHEDULED/Update\ XMR\ Node --period-ms 86400000
sleep 1
termux-toast -g middle "Node Running in Background"
termux-toast -g middle "Node Running in Background. Check or Refresh Notification"
fi
if [ \$RESP = '"Foreground"' ]
Expand All @@ -298,7 +299,7 @@ RESP=\$(termux-dialog radio -t "Run Node in:" -v "Background,Foreground" | jq '.
termux-job-scheduler --job-id 1 -s $TERMUX_SCHEDULED/xmr_notifications --period-ms 900000
termux-job-scheduler --job-id 2 -s $TERMUX_SCHEDULED/Update\ XMR\ Node --period-ms 86400000
cd $MONERO_CLI
termux-toast -g middle "Started XMR Node"
termux-toast -g middle "Check or Refresh Notification"
sleep 1
./monerod --config-file $NODE_CONFIG/config.txt
fi
Expand All @@ -317,7 +318,7 @@ cp $TERMUX_SHORTCUTS/.Boot\ XMR\ Node $TERMUX_BOOT/Boot\ XMR\ Node
termux-job-scheduler --job-id 1 -s $TERMUX_SCHEDULED/xmr_notifications --period-ms 900000
termux-job-scheduler --job-id 2 -s $TERMUX_SCHEDULED/Update\ XMR\ Node --period-ms 86400000
sleep 1
termux-toast -g middle "Node Running in Background"
termux-toast -g middle "Node Running in Background. Check or Refresh Notification"
EOF

cat << EOF > Stop\ XMR\ Node
Expand All @@ -340,9 +341,7 @@ EOF
cd $MONERO_CLI
./monerod print_net_stats
./monerod status
sleep 5
cd $TERMUX_SCHEDULED
./xmr_notifications
sleep 10
EOF

cat << "EOF" > xmr_notifications
Expand Down Expand Up @@ -370,7 +369,38 @@ else
NOTIFICATION="Refresh the notification.
Otherwise, restart the node"
fi
termux-notification -i monero -c "$NOTIFICATION" -t "$NODE_ONLINE" --ongoing --priority low --alert-once --button1 DISCONNECT --button1-action 'monero-cli/monero-cli/monerod exit | termux-wake-unlock | termux-job-scheduler --cancel --job-id 1 | termux-job-scheduler --cancel --job-id 2 | termux-toast -g middle "Stopped XMR Node" | rm .termux/boot/Boot\ XMR\ Node | termux-notification -i monero -c "πŸ”΄ XMR Node Shutdown" --priority low' --button2 "REFRESH NODE STATUS" --button2-action 'bash -l -c termux-scheduled/xmr_notifications'
termux-notification -i monero -c "$NOTIFICATION" -t "$NODE_ONLINE" --ongoing --priority low --alert-once --button1 "SHUTDOWN NODE" --button1-action 'monero-cli/monero-cli/monerod exit | termux-wake-unlock | termux-job-scheduler --cancel --job-id 1 | termux-job-scheduler --cancel --job-id 2 | termux-toast -g middle "Stopped XMR Node" | rm .termux/boot/Boot\ XMR\ Node | termux-notification -i monero -c "πŸ”΄ XMR Node Shutdown" --priority low' --button2 "RELEASE WAKELOCK" --button2-action 'termux-wake-unlock | bash -l -c termux-scheduled/xmr_notifications_unwake' --button3 "REFRESH STATUS" --button3-action 'bash -l -c termux-scheduled/xmr_notifications_wake'
EOF

cp xmr_notifications xmr_notifications_wake
sed -i -z "s|sleep 2\n| \n|g" xmr_notifications_wake

cat << "EOF" > xmr_notifications_unwake
#!/data/data/com.termux/files/usr/bin/sh
REQ=$(curl -s http://127.0.0.1:18081/json_rpc -d '{"jsonrpc":"2.0","id":"0","method":"get_info"}' -H 'Content-Type: application/json')
if [ "$REQ" ]
then
DATA=$(echo $REQ | jq '.result')
DATE=$(date -d @$(echo "$DATA" | jq '.start_time' ))
VERSION=$(echo "$DATA" | jq -r '.version' )
NODE_ONLINE=$(echo "$DATA" | jq -r 'if .offline == false then "🟒 XMR Node Online" else "πŸ”΄ XMR Node Offline" end')
OUTGOING_CONNECTIONS=$(echo "$DATA" | jq '.outgoing_connections_count' )
P2P_CONNECTIONS=$(echo "$DATA" | jq '.incoming_connections_count' )
RPC_CONNECTIONS=$(echo "$DATA" | jq '.rpc_connections_count' )
UPDATE_AVAILABLE=$(echo "$DATA" | jq -r 'if .update_available == true then "πŸ“¬οΈ XMR Update Available" else "" end' )
SYNC_STATUS=$(printf %.1f $(echo "$DATA" | jq '(.height / .target_height)*100'))
STORAGE_REMAINING=$(printf %.1f $(echo "$DATA" | jq '.free_space * 0.000000001'))
LOCAL_IP=$(echo $(termux-wifi-connectioninfo | jq '.ip') | tr -d '"')
NOTIFICATION=$(printf '%s\n' "⛓️ XMR-$VERSION" "πŸ•οΈ Running Since: $DATE" "πŸ”„ Sync Progress: $SYNC_STATUS %" "πŸ“€οΈ OUT: $OUTGOING_CONNECTIONS / 🌱 P2P: $P2P_CONNECTIONS / πŸ“² RPC: $RPC_CONNECTIONS" "πŸ’Ύ Free Space: $STORAGE_REMAINING GB" "πŸ”Œ Local IP: ${LOCAL_IP}:18089" "$UPDATE_AVAILABLE" )
else
NODE_ONLINE="πŸ”΄ ERROR: Is your node running?"
NOTIFICATION="Refresh the notification.
Otherwise, restart the node"
fi
termux-notification -i monero -c "$NOTIFICATION" -t "$NODE_ONLINE" --ongoing --priority low --alert-once --button1 "SHUTDOWN NODE" --button1-action 'monero-cli/monero-cli/monerod exit | termux-wake-unlock | termux-job-scheduler --cancel --job-id 1 | termux-job-scheduler --cancel --job-id 2 | termux-toast -g middle "Stopped XMR Node" | rm .termux/boot/Boot\ XMR\ Node | termux-notification -i monero -c "πŸ”΄ XMR Node Shutdown" --priority low' --button2 "ACQUIRE WAKELOCK" --button2-action 'termux-wake-lock | bash -l -c termux-scheduled/xmr_notifications_wake' --button3 "REFRESH STATUS" --button3-action 'bash -l -c termux-scheduled/xmr_notifications_unwake'
EOF


Expand Down Expand Up @@ -448,7 +478,7 @@ then
rm -f .Boot\ XMR\ Node
rm -f $TERMUX_BOOT/*XMR\ Node*
cd $TERMUX_SCHEDULED
rm -f xmr_notifications
rm -f xmr_notifications*
rm -f Update\ XMR\ Node
cd $TERMUX_SHORTCUTS
Expand Down Expand Up @@ -481,11 +511,11 @@ chmod +x Stop\ XMR\ Node
chmod +x Update\ XMR\ Node
chmod +x XMR\ Node\ Status
chmod +x .Boot\ XMR\ Node
chmod +x xmr_notifications
chmod +x xmr_notifications*
chmod +x Uninstall\ XMR\ Node

cp .Boot\ XMR\ Node $TERMUX_BOOT/Boot\ XMR\ Node
mv xmr_notifications $TERMUX_SCHEDULED
mv xmr_notifications* $TERMUX_SCHEDULED
cp Update\ XMR\ Node $TERMUX_SCHEDULED


Expand Down

0 comments on commit b894840

Please sign in to comment.