#!/usr/bin/env bash export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:${PATH}" export PATH="/snap/bin:${HOME}/.local/bin:${PATH}" : ${CHRONY_CONF="https://cdn.privex.io/extras/configs/chrony.conf"} has_command() { command -v "$@" &> /dev/null } if ! has_command curl; then echo -e " [...] curl not installed. automatically installing it..." if has_command yum; then >&2 yum install -y curl elif has_command apt-get; then DEBIAN_FRONTEND=noninteractive apt-get update -qy >/dev/null DEBIAN_FRONTEND=noninteractive apt-get install -qy curl > /dev/null elif has_command apk; then apk add curl elif has_command pacman; then pacman -Sy --noconfirm curl else echo -e " [!!!] curl is not installed, and we couldn't detect a known package manager to auto-install it!" echo -e " [!!!] please install 'curl' and re-run this script." exit 1 fi fi if ! has_command jq; then echo -e " [...] jq not installed. automatically installing it..." if has_command yum; then >&2 yum install -y jq elif has_command apt-get; then DEBIAN_FRONTEND=noninteractive apt-get update -qy >/dev/null DEBIAN_FRONTEND=noninteractive apt-get install -qy jq > /dev/null elif has_command apk; then apk add jq elif has_command pacman; then pacman -Sy --noconfirm jq else echo -e " [!!!] jq is not installed, and we couldn't detect a known package manager to auto-install it!" echo -e " [!!!] please install 'jq' and re-run this script." exit 1 fi fi if ! has_command chronyc; then echo -e " [...] chrony not installed. automatically installing it..." if has_command yum; then >&2 yum install -y chrony elif has_command apt-get; then DEBIAN_FRONTEND=noninteractive apt-get update -qy >/dev/null DEBIAN_FRONTEND=noninteractive apt-get install -qy chrony > /dev/null elif has_command apk; then apk add chrony elif has_command pacman; then pacman -Sy --noconfirm chrony else echo -e " [!!!] chrony is not installed, and we couldn't detect a known package manager to auto-install it!" echo -e " [!!!] please install 'chrony' and re-run this script." exit 1 fi fi getipdata() { curl -fsSL https://myip.privex.io/?format=json } echo " [...] Detecting your location...\n" ip_data="$(getipdata)" country_code="$(echo "$ip_data" | jq -r '.geo.country_code')" chrony_servers=() echo -e " >>> Your country code is: $country_code \n" case "$country_code" in SE|se|DK|dk|NO|no|IS|is) chrony_servers=("se1.chrony.privex.cc" "se2.chrony.privex.cc") ;; DE|de|FI|fi|FR|fr) chrony_servers=("fi1.chrony.privex.cc" "de1.chrony.privex.cc" "de2.chrony.privex.cc") ;; NL|nl) chrony_servers=("nl1.chrony.privex.cc" "fi1.chrony.privex.cc") ;; JP|jp|KO|ko|KR|kr|CN|cn|SG|sg|TW|tw) chrony_servers=("jp1.chrony.privex.cc") ;; CA|ca|US|us|MX|mx|BZ|bz) chrony_servers=("ca1.chrony.privex.cc") ;; esac flatchrony="" echo -e " >>> Using the following ADDITIONAL chrony servers (may be blank, don't worry if there's none): \n" for s in "${chrony_servers[@]}"; do sv="server $s iburst minpoll 4 maxpoll 8 prefer" echo -e "\t - ${sv}" flatchrony+="${sv}\n" done echo -e "\n ------------------------------------------- \n" echo -e " [...] Downloading and installing basic privex chrony config from: $CHRONY_CONF" curl -fsSL "$CHRONY_CONF" | sudo tee /etc/chrony/chrony.conf &>/dev/null echo -e " [...] Adding extra preferred chrony servers (if applicable) to /etc/chrony/chrony.conf" sudo sed -ri "s/# EXTRA_SERVERS/${flatchrony}/" /etc/chrony/chrony.conf echo -e " [...] Enabling and restarting chrony" systemctl enable chrony systemctl restart chrony echo -e "\n\n [+++] FINISHED \n\n"