Skip to content
DaCoolX edited this page Feb 22, 2020 · 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.

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

This script needs to be run as root.

It assumes that you are running Linux on an x86_64 CPU. Change linux and x86_64 in the PLATFORM and CPU_ARCH variables respectivly to the actual platform you are running if it is different (for example, on a Raspberry Pi, it should probably be linux_arm instead of linux_x86_64).

#! /bin/sh

INSTALL_DIR="/opt/dnscrypt-proxy"
LATEST_URL="https://api.github.com/repos/jedisct1/dnscrypt-proxy/releases/latest"
PLATFORM="linux"
CPU_ARCH="x86_64"

Update() {
    workdir="$(mktemp -d)"
    curl -sL $(curl -sL "$LATEST_URL" |
        grep dnscrypt-proxy-${PLATFORM}_${CPU_ARCH}- | grep browser_download_url | head -1 | cut -d \" -f 4) |
        tar xz -C "$workdir" -f - ${PLATFORM}-${CPU_ARCH}/dnscrypt-proxy &&
        [ -x ${PLATFORM}-${CPU_ARCH}/dnscrypt-proxy ] &&
        mv -f "${INSTALL_DIR}/dnscrypt-proxy" "${INSTALL_DIR}/dnscrypt-proxy.old" || : &&
        mv -f "${workdir}/${PLATFORM}-${CPU_ARCH}/dnscrypt-proxy" "${INSTALL_DIR}/" &&
        cd "$INSTALL_DIR" && rm -fr "$workdir" &&
        ./dnscrypt-proxy -check && ./dnscrypt-proxy -service install 2>/dev/null || : &&
        ./dnscrypt-proxy -service restart || ./dnscrypt-proxy -service start
}

lversion=$("${INSTALL_DIR}/dnscrypt-proxy" -version)
rmersion=$(curl -sL "$LATEST_URL" | grep "tag_name" | head -1 | cut -d \" -f 4)
[ -z "$lversion" ] && exit 1
[ -z "$rmersion" ] && exit 1

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