|
@@ -1,13 +1,16 @@
|
|
|
|
+#!/bin/bash
|
|
|
|
+PATH="/usr/sbin:/usr/bin:/sbin:/bin"
|
|
binpath=$(uci get AdGuardHome.AdGuardHome.binpath)
|
|
binpath=$(uci get AdGuardHome.AdGuardHome.binpath)
|
|
|
|
+touch /var/run/update_core
|
|
if [ -z "$binpath" ]; then
|
|
if [ -z "$binpath" ]; then
|
|
uci get AdGuardHome.AdGuardHome.binpath="/tmp/AdGuardHome/AdGuardHome"
|
|
uci get AdGuardHome.AdGuardHome.binpath="/tmp/AdGuardHome/AdGuardHome"
|
|
binpath="/tmp/AdGuardHome/AdGuardHome"
|
|
binpath="/tmp/AdGuardHome/AdGuardHome"
|
|
fi
|
|
fi
|
|
mkdir -p ${binpath%/*}
|
|
mkdir -p ${binpath%/*}
|
|
-/usr/bin/AdGuardHome
|
|
|
|
|
|
+
|
|
function check_if_already_running(){
|
|
function check_if_already_running(){
|
|
running_tasks="$(ps |grep "AdGuardHome" |grep "update_core" |grep -v "grep" |awk '{print $1}' |wc -l)"
|
|
running_tasks="$(ps |grep "AdGuardHome" |grep "update_core" |grep -v "grep" |awk '{print $1}' |wc -l)"
|
|
- [ "${running_tasks}" -gt "2" ] && echo -e "\nA task is already running." >>/tmp/AdGuardHome_update.log && exit 2
|
|
|
|
|
|
+ [ "${running_tasks}" -gt "2" ] && echo -e "\nA task is already running." >>/tmp/AdGuardHome_update.log && rm /var/run/update_core && exit 2
|
|
}
|
|
}
|
|
|
|
|
|
function clean_log(){
|
|
function clean_log(){
|
|
@@ -18,18 +21,19 @@ function check_latest_version(){
|
|
latest_ver="$(wget -O- https://api.github.com/repos/AdguardTeam/AdGuardHome/releases/latest 2>/dev/null|grep -E 'tag_name' |grep -E 'v[0-9.]+' -o 2>/dev/null)"
|
|
latest_ver="$(wget -O- https://api.github.com/repos/AdguardTeam/AdGuardHome/releases/latest 2>/dev/null|grep -E 'tag_name' |grep -E 'v[0-9.]+' -o 2>/dev/null)"
|
|
[ -z "${latest_ver}" ] && echo -e "\nFailed to check latest version, please try again later." >>/tmp/AdGuardHome_update.log && exit 1
|
|
[ -z "${latest_ver}" ] && echo -e "\nFailed to check latest version, please try again later." >>/tmp/AdGuardHome_update.log && exit 1
|
|
now_ver="$($binpath --check-config 2>&1| grep -E 'v[0-9.]+' -o)"
|
|
now_ver="$($binpath --check-config 2>&1| grep -E 'v[0-9.]+' -o)"
|
|
- if [ "${latest_ver}" != "${now_ver}" ]; then
|
|
|
|
|
|
+ if [ "${latest_ver}"x != "${now_ver}"x ]; then
|
|
clean_log
|
|
clean_log
|
|
echo -e "Local version: ${now_ver}., cloud version: ${latest_ver}." >>/tmp/AdGuardHome_update.log
|
|
echo -e "Local version: ${now_ver}., cloud version: ${latest_ver}." >>/tmp/AdGuardHome_update.log
|
|
- update_core
|
|
|
|
|
|
+ doupdate_core
|
|
else
|
|
else
|
|
echo -e "\nLocal version: ${now_ver}, cloud version: ${latest_ver}." >>/tmp/AdGuardHome_update.log
|
|
echo -e "\nLocal version: ${now_ver}, cloud version: ${latest_ver}." >>/tmp/AdGuardHome_update.log
|
|
echo -e "You're already using the latest version." >>/tmp/AdGuardHome_update.log
|
|
echo -e "You're already using the latest version." >>/tmp/AdGuardHome_update.log
|
|
|
|
+ rm /var/run/update_core
|
|
exit 3
|
|
exit 3
|
|
fi
|
|
fi
|
|
}
|
|
}
|
|
|
|
|
|
-function update_core(){
|
|
|
|
|
|
+function doupdate_core(){
|
|
echo -e "Updating core..." >>/tmp/AdGuardHome_update.log
|
|
echo -e "Updating core..." >>/tmp/AdGuardHome_update.log
|
|
mkdir -p "/tmp/AdGuardHome/update" >/dev/null 2>&1
|
|
mkdir -p "/tmp/AdGuardHome/update" >/dev/null 2>&1
|
|
rm -rf /tmp/AdGuardHome/update/* >/dev/null 2>&1
|
|
rm -rf /tmp/AdGuardHome/update/* >/dev/null 2>&1
|
|
@@ -58,6 +62,7 @@ function update_core(){
|
|
;;
|
|
;;
|
|
*)
|
|
*)
|
|
echo -e "error not support $Archt" >>/tmp/AdGuardHome_update.log
|
|
echo -e "error not support $Archt" >>/tmp/AdGuardHome_update.log
|
|
|
|
+ rm /var/run/update_core
|
|
exit 1
|
|
exit 1
|
|
;;
|
|
;;
|
|
esac
|
|
esac
|
|
@@ -67,6 +72,7 @@ function update_core(){
|
|
if [ ! -e "/tmp/AdGuardHome/update/AdGuardHome" ]; then
|
|
if [ ! -e "/tmp/AdGuardHome/update/AdGuardHome" ]; then
|
|
echo -e "Failed to download core." >>/tmp/AdGuardHome_update.log
|
|
echo -e "Failed to download core." >>/tmp/AdGuardHome_update.log
|
|
rm -rf "/tmp/AdGuardHome/update" >/dev/null 2>&1
|
|
rm -rf "/tmp/AdGuardHome/update" >/dev/null 2>&1
|
|
|
|
+ rm /var/run/update_core
|
|
exit 1
|
|
exit 1
|
|
else
|
|
else
|
|
if [ "$(uci get AdGuardHome.AdGuardHome.lessspace)"x != "1"x ]; then
|
|
if [ "$(uci get AdGuardHome.AdGuardHome.lessspace)"x != "1"x ]; then
|
|
@@ -78,7 +84,8 @@ function update_core(){
|
|
if [ "$?" == "0" ]; then
|
|
if [ "$?" == "0" ]; then
|
|
uci set AdGuardHome.AdGuardHome.lessspace="1"
|
|
uci set AdGuardHome.AdGuardHome.lessspace="1"
|
|
else
|
|
else
|
|
- echo cp failed
|
|
|
|
|
|
+ echo "cp failed" >>/tmp/AdGuardHome_update.log
|
|
|
|
+ rm /var/run/update_core
|
|
exit 1
|
|
exit 1
|
|
fi
|
|
fi
|
|
fi
|
|
fi
|
|
@@ -86,7 +93,8 @@ function update_core(){
|
|
/etc/init.d/AdGuardHome stop
|
|
/etc/init.d/AdGuardHome stop
|
|
cp -f /tmp/AdGuardHome/update/AdGuardHome/AdGuardHome "$binpath"
|
|
cp -f /tmp/AdGuardHome/update/AdGuardHome/AdGuardHome "$binpath"
|
|
if [ "$?" != "0" ]; then
|
|
if [ "$?" != "0" ]; then
|
|
- echo cp failed
|
|
|
|
|
|
+ echo "cp failed" >>/tmp/AdGuardHome_update.log
|
|
|
|
+ rm /var/run/update_core
|
|
exit 1
|
|
exit 1
|
|
fi
|
|
fi
|
|
fi
|
|
fi
|
|
@@ -94,8 +102,9 @@ function update_core(){
|
|
/etc/init.d/AdGuardHome restart
|
|
/etc/init.d/AdGuardHome restart
|
|
fi
|
|
fi
|
|
rm -rf "/tmp/AdGuardHome/update" >/dev/null 2>&1
|
|
rm -rf "/tmp/AdGuardHome/update" >/dev/null 2>&1
|
|
- echo -e "Succeeded in updating core." >/tmp/AdGuardHome_update.log
|
|
|
|
|
|
+ echo -e "Succeeded in updating core." >>/tmp/AdGuardHome_update.log
|
|
echo -e "Local version: ${now_ver}, cloud version: ${latest_ver}.\n" >>/tmp/AdGuardHome_update.log
|
|
echo -e "Local version: ${now_ver}, cloud version: ${latest_ver}.\n" >>/tmp/AdGuardHome_update.log
|
|
|
|
+ rm /var/run/update_core
|
|
}
|
|
}
|
|
|
|
|
|
function main(){
|
|
function main(){
|