Skip to content
Frank Denis edited this page Jul 21, 2019 · 41 revisions

Automatic Update For Linux

The script below will check to see if dnscrypt-proxy needs updating by comparing the installed version with the latest git version.

If the installed version is older, then the script will update to the newest version.

Tested on: Ubuntu 18.04

Requirements

This script requires dnscrypt-proxy to be installed as a service using,./dnscrypt-proxy -service install and for dnscrypt-proxy to be installed in /opt/dnscrypt-proxy and for the configuration file to be named dnscrypt-proxy.toml.

If dnscrypt-proxy is not run as root then, change sudo chown root:root -R /opt/dnscrypt-proxy to the user dnscrypt-proxy is run as.

Configuration

Initially make sure all the above requirements are met.

Then to get this script to automatically run add this as a cron job under root using sudo crontab -e but, change the file path to the file path the script is saved.

0 */12 * * * /path/dnscrypt-proxy-update.sh

Also, this script needs to be run as root.

#!/bin/sh

Update() {
    cd /opt/dnscrypt-proxy
    sudo mv dnscrypt-proxy.toml /opt/
    cd /opt
    sudo curl -L -O $( curl -s https://api.github.com/repos/jedisct1/dnscrypt-proxy/releases/latest | grep dnscrypt-proxy-linux_x86_64- | grep browser_download_url | head -1 | cut -d \" -f 4 )
    sudo service dnscrypt-proxy stop
    sudo rm -rf /opt/dnscrypt-proxy
    sudo tar xvzf dnscrypt-proxy-linux_x86_64-*.tar.gz
    cd linux-x86_64
    sudo mkdir /opt/dnscrypt-proxy
    sudo mv * /opt/dnscrypt-proxy
    sudo mv -f /opt/dnscrypt-proxy.toml /opt/dnscrypt-proxy
    sudo chown root:root -R /opt/dnscrypt-proxy
    sudo chmod 775 /opt/dnscrypt-proxy
    sudo cp -f /etc/resolv.conf /etc/resolv.conf.backup
    cd /opt
    sudo rm -rf dnscrypt-proxy-linux_x86_*
    sudo rm -rf linux-x86_64
    sudo service dnscrypt-proxy start
    sudo service dnscrypt-proxy status
}

lversion=$(
    cd /opt/dnscrypt-proxy
    ./dnscrypt-proxy -version
)

rmersion=$(
    curl -s https://api.github.com/repos/jedisct1/dnscrypt-proxy/releases/latest | grep "tag_name" | head -1 | cut -d \" -f 4
)

echo locally installed
echo $lversion

echo remote git version
echo $rmersion

if [[ "$rmersion" > "$lversion" ]]
then
    echo Updating && Update
else
    echo No Update Needed
fi
Clone this wiki locally