Last active
December 17, 2022 10:30
-
-
Save koonix/74aeeb74fb79076d1eb53a30904c4335 to your computer and use it in GitHub Desktop.
A proof-of-concept script that shows android notifications on linux.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# show android notifications on linux. | |
# it updates duckdns ddns and portforwards via upnp. | |
# requires a duckdns account, NetworkManager, miniupnpc and an2linux. | |
# config | |
duckdns_token= # put your duckdns token here | |
local_ddns= # local ddns name | |
public_ddns= # public ddns name | |
port=46352 # an2linux's port which will be port-forwarded | |
main() { | |
if [ -n "$local_ddns" ]; then | |
event | while IFS= read -r line; do update $local_ddns $(getlocalip); done & | |
fi | |
if [ -n "$public_ddns" ]; then | |
event | while IFS= read -r line; do update $public_ddns; upnp; done & | |
interval | while IFS= read -r line; do update $public_ddns; upnp; done & | |
fi | |
an2linuxserver.py <&- >/dev/null 2>&1 | |
} | |
interval() { | |
while :; do echo; sleep 10m; done | |
} | |
event() { | |
nmcli monitor | egrep --line-buffered "is now 'full'|is now the primary" | |
} | |
update() { | |
echo Updating $1... | |
msg=$(curl -sSL "https://duckdns.org/update?domains=${1}&token=${duckdns_token}${2:+&ip=$2}") | |
[ "$msg" = OK ] && echo Updated $1. || echo Failed Updating $1. | |
} | |
upnp() { | |
upnpc -e duckdns -a $(getlocalip) $port $port TCP >/dev/null 2>&1 && | |
echo Forwarded Port $port. | |
} | |
getlocalip() { | |
ip route get 1 | grep -Po 'src\s+\K\S+' | |
} | |
trap 'pkill -P $$' EXIT | |
main "$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment