Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/system/bin/sh
- DNSCRYPT_PROXY="/system/xbin/dnscrypt-proxy"
- CONFFILE="/data/local/dnscrypt-proxy/dnscrypt-proxy.toml"
- PIDFILE="/data/local/tmp/dnscrypt-proxy.pid"
- APPEND="-A"
- WAITFORDAEMON=10
- STOP=0
- nohup="nohup"
- _log() {
- log -p i -t dnscrypt-init -- $1
- echo "$1" 1>&2
- }
- _wait_for_pid() {
- cnt=0
- while true ; do
- sleep 1
- if test -s "$PIDFILE" ; then
- pid=$(cat "$PIDFILE")
- if kill -0 $pid 2>/dev/null ; then
- return 0
- fi
- fi
- [ "`expr $cnt % 3`" != 2 ] || _log "."
- cnt=`expr $cnt + 1`
- if [ $cnt -gt $WAITFORDAEMON ] ; then
- break
- fi
- done
- return 1
- }
- ## Begin
- if [ "$1" = "--debug" ] ; then
- nohup=""
- _log "Attempting to run dnscrypt-proxy in foreground"
- fi
- if [ "$1" = "--stop" ] ; then
- STOP=1
- APPEND="-D"
- _log "Stopping dnscrypt-proxy"
- else
- _log "Starting dnscrypt-proxy"
- fi
- if [ -s "$PIDFILE" ] ; then
- # if dnscrypt-proxy is running, kill
- kill $(cat "$PIDFILE")
- rm -f "$PIDFILE"
- fi
- if [ $STOP -eq 0 ] ; then
- cmd="""$DNSCRYPT_PROXY"" -config ""$CONFFILE"" -pidfile=""$PIDFILE"""
- if [ "$nohup" != "" ] ; then
- $nohup $cmd >/dev/null 2>&1 &
- _wait_for_pid
- if [ $? -ne 0 ] ; then
- # delete iptable rule
- APPEND="-D"
- _log "failed to start dnscrypt-proxy"
- _log "Try running '$0 --debug' or enable logging and check the logs for errors"
- exit 1
- fi
- else
- $cmd
- fi
- fi
- iptables -t nat $APPEND OUTPUT -p tcp --dport 53 -j DNAT --to-destination 127.0.0.1:533
- iptables -t nat $APPEND OUTPUT -p udp --dport 53 -j DNAT --to-destination 127.0.0.1:533
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement