+ fi
+ xshok_pretty_echo_and_log "Completed: cron installed, as file: ${cron_dir}/${cron_filename}"
+}
+
+# Auto upgrade the master.conf and the
+function xshok_upgrade() {
+
+ if [ "$allow_upgrades" == "no" ] ; then
+ xshok_pretty_echo_and_log "ERROR: --upgrade has been disabled, allow_upgrades=no"
+ exit 1
+ fi
+ if ! xshok_is_root ; then
+ xshok_pretty_echo_and_log "ERROR: Only root can run the upgrade"
+ exit 1
+ fi
+
+ xshok_pretty_echo_and_log "Checking for updates ..."
+
+ found_upgrade="no"
+ if [ -n "$curl_bin" ] ; then
+ # shellcheck disable=SC2086
+ latest_version="$($curl_bin --compressed $curl_proxy $curl_insecure $curl_output_level --connect-timeout "${downloader_connect_timeout}" --remote-time --location --retry "${downloader_tries}" --max-time "${downloader_max_time}" "https://raw.githubusercontent.com/extremeshok/clamav-unofficial-sigs/${git_branch}/clamav-unofficial-sigs.sh" 2>&11 | $grep_bin "^script_version=" | head -n1 | cut -d '"' -f 2)"
+ # shellcheck disable=SC2086
+ latest_config_version="$($curl_bin --compressed $curl_proxy $curl_insecure $curl_output_level --connect-timeout "${downloader_connect_timeout}" --remote-time --location --retry "${downloader_tries}" --max-time "${downloader_max_time}" "https://raw.githubusercontent.com/extremeshok/clamav-unofficial-sigs/${git_branch}/config/master.conf" 2>&11 | $grep_bin "^config_version=" | head -n1 | cut -d '"' -f 2)"
+ else
+ # shellcheck disable=SC2086
+ latest_version="$($wget_bin $wget_compression $wget_proxy $wget_insecure $wget_output_level --connect-timeout="${downloader_connect_timeout}" --random-wait --tries="${downloader_tries}" --timeout="${downloader_max_time}" "https://raw.githubusercontent.com/extremeshok/clamav-unofficial-sigs/${git_branch}/clamav-unofficial-sigs.sh" -O - 2>&12 | $grep_bin "^script_version=" | head -n1 | cut -d '"' -f 2)"
+ # shellcheck disable=SC2086
+ latest_config_version="$($wget_bin $wget_compression $wget_proxy $wget_insecure $wget_output_level --connect-timeout="${downloader_connect_timeout}" --random-wait --tries="${downloader_tries}" --timeout="${downloader_max_time}" "https://raw.githubusercontent.com/extremeshok/clamav-unofficial-sigs/${git_branch}/config/master.conf" -O - 2>&12 | $grep_bin "^config_version=" | head -n1 | cut -d '"' -f 2)"
+ fi
+
+ # config_dir/master.conf
+ if [ "$latest_config_version" ] ; then
+ # shellcheck disable=SC2183,SC2086
+ if [ "$(printf "%02d%02d%02d%02d" ${latest_config_version//./ })" -gt "$(printf "%02d%02d%02d%02d" ${config_version//./ })" ] ; then
+ found_upgrade="yes"
+ xshok_pretty_echo_and_log "ALERT: Upgrading config from v${config_version} to v${latest_config_version}"
+ if [ -w "${config_dir}/master.conf" ] && [ -f "${config_dir}/master.conf" ] ; then
+ echo "Downloading https://raw.githubusercontent.com/extremeshok/clamav-unofficial-sigs/${git_branch}/config/master.conf"
+ xshok_file_download "${work_dir}/master.conf.tmp" "https://raw.githubusercontent.com/extremeshok/clamav-unofficial-sigs/${git_branch}/config/master.conf" "notimestamp"
+ ret="$?"
+ if [ "$ret" -ne 0 ] ; then
+ xshok_pretty_echo_and_log "ERROR: Could not download https://raw.githubusercontent.com/extremeshok/clamav-unofficial-sigs/${git_branch}/config/master.conf"
+ exit 1
+ fi
+ if ! $grep_bin -m 1 "config_version" "${work_dir}/master.conf.tmp" > /dev/null 2>&1 ; then
+ echo "ERROR: Downloaded master.conf is incomplete, please re-run"
+ exit 1
+ fi
+ # Copy over permissions from old version
+ OCTAL_MODE="$(stat -c "%a" "${config_dir}/master.conf")"
+ xshok_pretty_echo_and_log "Running update process"
+ if ! mv -f "${work_dir}/master.conf.tmp" "${config_dir}/master.conf" ; then
+ xshok_pretty_echo_and_log "ERROR: failed moving ${work_dir}/master.conf.tmp to ${config_dir}/master.conf"
+ exit 1
+ fi
+ if ! chmod "$OCTAL_MODE" "${config_dir}/master.conf" ; then
+ xshok_pretty_echo_and_log "ERROR: unable to set permissions on ${config_dir}/master.conf"
+ exit 1
+ fi
+ xshok_pretty_echo_and_log "Completed"
+ else
+ xshok_pretty_echo_and_log "ERROR: ${config_dir}/master.conf is not a file or is not writable"
+ exit 1
+ fi
+ fi
+ fi
+
+ if [ "$latest_version" ] ; then
+ # shellcheck disable=SC2183,SC2086
+ if [ "$(printf "%02d%02d%02d%02d" ${latest_version//./ })" -gt "$(printf "%02d%02d%02d%02d" ${script_version//./ })" ] ; then
+ found_upgrade="yes"
+ xshok_pretty_echo_and_log "ALERT: Upgrading script from v${script_version} to v${latest_version}"
+ if [ -w "${config_dir}/master.conf" ] && [ -f "${config_dir}/master.conf" ] ; then
+ echo "Downloading https://raw.githubusercontent.com/extremeshok/clamav-unofficial-sigs/${git_branch}/clamav-unofficial-sigs.sh"
+ xshok_file_download "${work_dir}/clamav-unofficial-sigs.sh.tmp" "https://raw.githubusercontent.com/extremeshok/clamav-unofficial-sigs/${git_branch}/clamav-unofficial-sigs.sh" "notimestamp"
+ ret=$?
+ if [ "$ret" -ne 0 ] ; then
+ xshok_pretty_echo_and_log "ERROR: Could not download https://raw.githubusercontent.com/extremeshok/clamav-unofficial-sigs/${git_branch}/clamav-unofficial-sigs.sh"
+ exit 1
+ fi
+ # Detect to make sure the entire script is avilable, fail if the script is missing contents
+ if [ "$(tail -n 1 "${work_dir}/clamav-unofficial-sigs.sh.tmp" | head -n 1 | cut -c 1-7)" != "exit \$?" ] ; then
+ echo "ERROR: Downloaded clamav-unofficial-sigs.sh is incomplete, please re-run"
+ exit 1
+ fi
+ # Copy over permissions from old version
+ OCTAL_MODE="$(stat -c "%a" "${this_script_full_path}")"
+
+ xshok_pretty_echo_and_log "Inserting update process..."
+ # Generate the update script
+ cat > "${work_dir}/xshok_update_script.sh" << EOF
+#!/usr/bin/env bash
+echo "Running update process"
+# Overwrite old file with new
+if ! mv -f "${work_dir}/clamav-unofficial-sigs.sh.tmp" "${this_script_full_path}" ; then
+ echo "ERROR: failed moving ${work_dir}/clamav-unofficial-sigs.sh.tmp to ${this_script_full_path}"
+ rm -f \$0
+ exit 1
+fi
+if ! chmod "$OCTAL_MODE" "${this_script_full_path}" ; then
+ echo "ERROR: unable to set permissions on ${this_script_full_path}"
+ rm -f \$0
+ exit 1
+fi
+ echo "Completed"
+ # echo "---------------------"
+ # echo "Optional, run as root: "
+ # echo "clamav-unofficial-sigs.sh --install-all"
+ echo "---------------------"
+ echo "Run once as root: "
+ echo "clamav-unofficial-sigs.sh --force"
+
+ #remove the tmp script before exit
+ rm -f \$0
+EOF
+ # Replaced with $0, so code will update and then call itself with the same parameters it had
+ #exec "${0}" "$@"
+ bash_bin="$(command -v bash 2> /dev/null)"
+ exec "$bash_bin" "${work_dir}/xshok_update_script.sh"
+ echo "Running once as root"
+ else
+ xshok_pretty_echo_and_log "ERROR: ${config_dir}/master.conf is not a file or is not writable"
+ exit 1
+ fi
+ fi
+fi
+
+if [ "$found_upgrade" == "no" ] ; then
+ xshok_pretty_echo_and_log "No updates available"
+fi