You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

680 lines
20 KiB

  1. #!/bin/sh
  2. ##############################################
  3. # function library used by adblock-update.sh #
  4. # written by Dirk Brenken (dirk@brenken.org) #
  5. ##############################################
  6. #####################################
  7. # f_envload: load adblock environment
  8. #
  9. f_envload()
  10. {
  11. # source in openwrt function library
  12. #
  13. if [ -r "/lib/functions.sh" ]
  14. then
  15. . "/lib/functions.sh" 2>/dev/null
  16. else
  17. rc=500
  18. f_log "openwrt function library not found" "${rc}"
  19. f_deltemp
  20. fi
  21. # source in openwrt json helpers library
  22. #
  23. if [ -r "/usr/share/libubox/jshn.sh" ]
  24. then
  25. . "/usr/share/libubox/jshn.sh" 2>/dev/null
  26. else
  27. rc=505
  28. f_log "openwrt json helpers library not found" "${rc}"
  29. f_deltemp
  30. fi
  31. # get list with all installed openwrt packages
  32. #
  33. pkg_list="$(opkg list-installed 2>/dev/null)"
  34. if [ -z "${pkg_list}" ]
  35. then
  36. rc=510
  37. f_log "empty openwrt package list" "${rc}"
  38. f_deltemp
  39. fi
  40. }
  41. ######################################################
  42. # f_envparse: parse adblock config and set environment
  43. #
  44. f_envparse()
  45. {
  46. # set the C locale, characters are single bytes, the charset is ASCII
  47. # speeds up sort, grep etc.
  48. #
  49. LC_ALL=C
  50. # set initial defaults (may be overwritten by setting appropriate adblock config options)
  51. #
  52. adb_if="adblock"
  53. adb_minspace="20000"
  54. adb_maxtime="60"
  55. adb_maxloop="5"
  56. adb_unique="1"
  57. adb_blacklist="/etc/adblock/adblock.blacklist"
  58. adb_whitelist="/etc/adblock/adblock.whitelist"
  59. # adblock device name auto detection
  60. # derived from first entry in openwrt lan ifname config
  61. #
  62. adb_dev="$(uci get network.lan.ifname 2>/dev/null)"
  63. adb_dev="${adb_dev/ *}"
  64. # adblock ntp server name auto detection
  65. # derived from ntp list found in openwrt ntp server config
  66. #
  67. adb_ntpsrv="$(uci get system.ntp.server 2>/dev/null)"
  68. # function to read/set global options by callback,
  69. # prepare list items and build option list for all others
  70. #
  71. config_cb()
  72. {
  73. local type="${1}"
  74. local name="${2}"
  75. if [ "${type}" = "adblock" ]
  76. then
  77. option_cb()
  78. {
  79. local option="${1}"
  80. local value="${2}"
  81. eval "${option}=\"${value}\""
  82. }
  83. else
  84. option_cb()
  85. {
  86. local option="${1}"
  87. local value="${2}"
  88. local opt_out="$(printf "${option}" | sed -n '/.*_ITEM[0-9]$/p; /.*_LENGTH$/p; /enabled/p' 2>/dev/null)"
  89. if [ -z "${opt_out}" ]
  90. then
  91. all_options="${all_options} ${option}"
  92. fi
  93. }
  94. list_cb()
  95. {
  96. local list="${1}"
  97. local value="${2}"
  98. if [ "${list}" = "adb_wanlist" ]
  99. then
  100. adb_wandev="${adb_wandev} ${value}"
  101. elif [ "${list}" = "adb_ntplist" ]
  102. then
  103. adb_ntpsrv="${adb_ntpsrv} ${value}"
  104. elif [ "${list}" = "adb_catlist" ]
  105. then
  106. adb_cat_shalla="${adb_cat_shalla} ${value}"
  107. fi
  108. }
  109. fi
  110. }
  111. # function to iterate through option list, read/set all options in "enabled" sections
  112. #
  113. parse_config()
  114. {
  115. local config="${1}"
  116. config_get switch "${config}" "enabled"
  117. if [ "${switch}" = "1" ]
  118. then
  119. for option in ${all_options}
  120. do
  121. config_get value "${config}" "${option}"
  122. if [ -n "${value}" ]
  123. then
  124. local opt_src="$(printf "${option}" | sed -n '/^adb_src_[a-z0-9]*$/p' 2>/dev/null)"
  125. if [ -n "${opt_src}" ]
  126. then
  127. adb_sources="${adb_sources} ${value}"
  128. else
  129. eval "${option}=\"${value}\""
  130. fi
  131. fi
  132. done
  133. elif [ "${config}" = "wancheck" ]
  134. then
  135. unset adb_wandev
  136. elif [ "${config}" = "ntpcheck" ]
  137. then
  138. unset adb_ntpsrv
  139. elif [ "${config}" = "shalla" ]
  140. then
  141. unset adb_cat_shalla
  142. fi
  143. }
  144. # load adblock config and start parsing functions
  145. #
  146. config_load adblock
  147. config_foreach parse_config service
  148. config_foreach parse_config source
  149. # set temp variables and defaults
  150. #
  151. adb_tmpfile="$(mktemp -tu 2>/dev/null)"
  152. adb_tmpdir="$(mktemp -p /tmp -d 2>/dev/null)"
  153. unset adb_srcfind
  154. unset adb_revsrcfind
  155. # set adblock source ruleset definitions
  156. #
  157. rset_start="sed -r 's/[[:space:]]|[\[!#/:;_].*|[0-9\.]*localhost//g; s/[\^#/:;_\.\t ]*$//g'"
  158. rset_end="sed '/^[#/:;_\s]*$/d'"
  159. rset_adaway="${rset_start} | sed 's/\([0-9]\{1,3\}\.\)\{3\}[0-1]\{1,1\}//g' | ${rset_end}"
  160. rset_blacklist="${rset_start} | ${rset_end}"
  161. rset_disconnect="${rset_start} | ${rset_end}"
  162. rset_dshield="${rset_start} | ${rset_end}"
  163. rset_feodo="${rset_start} | ${rset_end}"
  164. rset_malware="${rset_start} | ${rset_end}"
  165. rset_palevo="${rset_start} | ${rset_end}"
  166. rset_shalla="${rset_start} | sed 's/\([0-9]\{1,3\}\.\)\{3\}[0-9]\{1,3\}$//g' | ${rset_end}"
  167. rset_spam404="${rset_start} | sed 's/^\|\|//g' | ${rset_end}"
  168. rset_winhelp="${rset_start} | sed 's/\([0-9]\{1,3\}\.\)\{3\}[0-1]\{1,1\}//g' | ${rset_end}"
  169. rset_yoyo="${rset_start} | sed 's/,/\n/g' | ${rset_end}"
  170. rset_zeus="${rset_start} | ${rset_end}"
  171. # set dnsmasq defaults
  172. #
  173. adb_dnsdir="/tmp/dnsmasq.d"
  174. adb_dnsformat="sed 's/^/address=\//;s/$/\/'${adb_ip}'/'"
  175. adb_dnsprefix="adb_list"
  176. }
  177. #############################################
  178. # f_envcheck: check environment prerequisites
  179. #
  180. f_envcheck()
  181. {
  182. # check adblock config file
  183. #
  184. check_config="$(grep -F "ruleset=rset_default" /etc/config/adblock 2>/dev/null)"
  185. if [ -n "${check_config}" ]
  186. then
  187. rc=515
  188. grep -Fv "#" "/etc/adblock/samples/adblock.conf.sample" > /etc/config/adblock
  189. f_log "new default adblock config applied, please check your configuration settings in /etc/config/adblock" "${rc}"
  190. f_deltemp
  191. fi
  192. # check required config options
  193. #
  194. adb_varlist="adb_ip adb_dev adb_domain"
  195. for var in ${adb_varlist}
  196. do
  197. if [ -z "$(eval printf \"\$"${var}"\")" ]
  198. then
  199. rc=520
  200. f_log "missing adblock config option (${var})" "${rc}"
  201. f_deltemp
  202. fi
  203. done
  204. # check main uhttpd configuration
  205. #
  206. check_uhttpd="$(uci get uhttpd.main.listen_http 2>/dev/null | grep -Fo "0.0.0.0" 2>/dev/null)"
  207. if [ -n "${check_uhttpd}" ]
  208. then
  209. rc=525
  210. lan_ip="$(uci get network.lan.ipaddr 2>/dev/null)"
  211. f_log "please bind main uhttpd instance to LAN only (lan ip: ${lan_ip})" "${rc}"
  212. f_deltemp
  213. fi
  214. # check adblock network device configuration
  215. #
  216. if [ ! -d "/sys/class/net/${adb_dev}" ]
  217. then
  218. rc=530
  219. f_log "invalid adblock network device input (${adb_dev})" "${rc}"
  220. f_deltemp
  221. fi
  222. # check adblock network interface configuration
  223. #
  224. check_if="$(printf "${adb_if}" | sed -n '/[^._0-9A-Za-z]/p' 2>/dev/null)"
  225. banned_if="$(printf "${adb_if}" | sed -n '/.*lan.*\|.*wan.*\|.*switch.*\|main\|globals\|loopback\|px5g/p' 2>/dev/null)"
  226. if [ -n "${check_if}" ] || [ -n "${banned_if}" ]
  227. then
  228. rc=535
  229. f_log "invalid adblock network interface input (${adb_if})" "${rc}"
  230. f_deltemp
  231. fi
  232. # check adblock ip address configuration
  233. #
  234. check_ip="$(printf "${adb_ip}" | sed -n '/\([0-9]\{1,3\}\.\)\{3\}[0-9]\{1,3\}/p' 2>/dev/null)"
  235. lan_ip="$(uci get network.lan.ipaddr 2>/dev/null)"
  236. if [ -z "${check_ip}" ]
  237. then
  238. rc=540
  239. f_log "invalid adblock ip address input (${adb_ip})" "${rc}"
  240. f_deltemp
  241. elif [ "${adb_ip}" = "${lan_ip}" ]
  242. then
  243. rc=545
  244. f_log "adblock ip needs to be a different subnet from the normal LAN (adblock ip: ${adb_ip})" "${rc}"
  245. f_deltemp
  246. fi
  247. # check adblock blacklist/whitelist configuration
  248. #
  249. if [ ! -r "${adb_blacklist}" ]
  250. then
  251. rc=550
  252. f_log "adblock blacklist not found" "${rc}"
  253. f_deltemp
  254. elif [ ! -r "${adb_whitelist}" ]
  255. then
  256. rc=555
  257. f_log "adblock whitelist not found" "${rc}"
  258. f_deltemp
  259. fi
  260. # check adblock temp directory
  261. #
  262. if [ -n "${adb_tmpdir}" ] && [ -d "${adb_tmpdir}" ]
  263. then
  264. f_space "${adb_tmpdir}"
  265. tmp_ok="true"
  266. else
  267. rc=560
  268. tmp_ok="false"
  269. f_log "temp directory not found" "${rc}"
  270. f_deltemp
  271. fi
  272. # check curl package dependency
  273. #
  274. check="$(printf "${pkg_list}" | grep "^curl -" 2>/dev/null)"
  275. if [ -z "${check}" ]
  276. then
  277. rc=565
  278. f_log "curl package not found" "${rc}"
  279. f_deltemp
  280. fi
  281. # check wget package dependency
  282. #
  283. check="$(printf "${pkg_list}" | grep "^wget -" 2>/dev/null)"
  284. if [ -z "${check}" ]
  285. then
  286. rc=570
  287. f_log "wget package not found" "${rc}"
  288. f_deltemp
  289. fi
  290. # check ca-certificates package and set wget/curl options accordingly
  291. #
  292. check="$(printf "${pkg_list}" | grep "^ca-certificates -" 2>/dev/null)"
  293. if [ -z "${check}" ]
  294. then
  295. curl_parm="-q --insecure --silent"
  296. wget_parm="--no-config --no-hsts --no-check-certificate --quiet"
  297. else
  298. curl_parm="-q --silent"
  299. wget_parm="--no-config --no-hsts --quiet"
  300. fi
  301. # check total and swap memory
  302. #
  303. mem_total="$(grep -F "MemTotal" "/proc/meminfo" 2>/dev/null | grep -o "[0-9]*" 2>/dev/null)"
  304. mem_free="$(grep -F "MemFree" "/proc/meminfo" 2>/dev/null | grep -o "[0-9]*" 2>/dev/null)"
  305. swap_total="$(grep -F "SwapTotal" "/proc/meminfo" 2>/dev/null | grep -o "[0-9]*" 2>/dev/null)"
  306. if [ $((mem_total)) -le 64000 ] && [ $((swap_total)) -eq 0 ]
  307. then
  308. adb_unique=0
  309. f_log "overall sort/unique processing will be disabled,"
  310. f_log "please consider adding an external swap device to supersize your /tmp directory (total: ${mem_total}, free: ${mem_free}, swap: ${mem_swap})"
  311. fi
  312. # check backup configuration
  313. #
  314. if [ -n "${adb_backupdir}" ] && [ -d "${adb_backupdir}" ]
  315. then
  316. f_space "${adb_backupdir}"
  317. backup_ok="true"
  318. else
  319. backup_ok="false"
  320. f_log "backup/restore will be disabled"
  321. fi
  322. # check dns query log configuration
  323. #
  324. adb_querydir="${adb_queryfile%/*}"
  325. adb_querypid="/var/run/adb_query.pid"
  326. if [ -n "${adb_querydir}" ] && [ -d "${adb_querydir}" ]
  327. then
  328. # check find capabilities
  329. #
  330. check="$(find --help 2>&1 | grep -F "mtime" 2>/dev/null)"
  331. if [ -z "${check}" ]
  332. then
  333. query_ok="false"
  334. f_log "busybox without 'find/mtime' support (min. r47362), dns query logging will be disabled"
  335. else
  336. f_space "${adb_querydir}"
  337. query_ok="true"
  338. query_name="${adb_queryfile##*/}"
  339. query_ip="${adb_ip//./\\.}"
  340. fi
  341. else
  342. query_ok="false"
  343. f_log "dns query logging will be disabled"
  344. if [ -s "${adb_querypid}" ]
  345. then
  346. kill -9 "$(cat "${adb_querypid}")" >/dev/null 2>&1
  347. f_log "remove old dns query log background process (pid: $(cat "${adb_querypid}" 2>/dev/null))"
  348. > "${adb_querypid}"
  349. fi
  350. fi
  351. # check debug log configuration
  352. #
  353. adb_logdir="${adb_logfile%/*}"
  354. if [ -n "${adb_logdir}" ] && [ -d "${adb_logdir}" ]
  355. then
  356. f_space "${adb_logdir}"
  357. log_ok="true"
  358. else
  359. log_ok="false"
  360. f_log "debug logging will be disabled"
  361. fi
  362. # check wan update configuration
  363. #
  364. if [ -n "${adb_wandev}" ]
  365. then
  366. f_wancheck "${adb_maxloop}"
  367. else
  368. wan_ok="false"
  369. f_log "wan update check will be disabled"
  370. fi
  371. # check ntp sync configuration
  372. #
  373. if [ -n "${adb_ntpsrv}" ]
  374. then
  375. f_ntpcheck "${adb_maxloop}"
  376. else
  377. ntp_ok="false"
  378. f_log "ntp time sync will be disabled"
  379. fi
  380. # check dynamic/volatile adblock network interface configuration
  381. #
  382. rc="$(ifstatus "${adb_if}" >/dev/null 2>&1; printf ${?})"
  383. if [ $((rc)) -ne 0 ]
  384. then
  385. json_init
  386. json_add_string name "${adb_if}"
  387. json_add_string ifname "${adb_dev}"
  388. json_add_string proto "static"
  389. json_add_array ipaddr
  390. json_add_string "" "${adb_ip}"
  391. json_close_array
  392. json_close_object
  393. ubus call network add_dynamic "$(json_dump)"
  394. rc=${?}
  395. if [ $((rc)) -eq 0 ]
  396. then
  397. f_log "created new dynamic/volatile network interface (${adb_if}, ${adb_ip})"
  398. else
  399. f_log "failed to initialize new dynamic/volatile network interface (${adb_if}, ${adb_ip})" "${rc}"
  400. f_remove
  401. fi
  402. fi
  403. # check dynamic/volatile adblock uhttpd instance configuration
  404. #
  405. rc="$(ps | grep "[u]httpd.*\-r ${adb_if}" >/dev/null 2>&1; printf ${?})"
  406. if [ $((rc)) -ne 0 ]
  407. then
  408. uhttpd -h "/www/adblock" -r "${adb_if}" -E "/adblock.html" -p "${adb_ip}:80" >/dev/null 2>&1
  409. rc=${?}
  410. if [ $((rc)) -eq 0 ]
  411. then
  412. f_log "created new dynamic/volatile uhttpd instance (${adb_if}, ${adb_ip})"
  413. else
  414. f_log "failed to initialize new dynamic/volatile uhttpd instance (${adb_if}, ${adb_ip})" "${rc}"
  415. f_remove
  416. fi
  417. fi
  418. # remove no longer used package list
  419. #
  420. unset pkg_list
  421. }
  422. ################################################
  423. # f_log: log messages to stdout, syslog, logfile
  424. #
  425. f_log()
  426. {
  427. local log_msg="${1}"
  428. local log_rc="${2}"
  429. local class="info "
  430. if [ -n "${log_msg}" ]
  431. then
  432. if [ $((log_rc)) -ne 0 ]
  433. then
  434. class="error"
  435. log_rc=", rc: ${log_rc}"
  436. log_msg="${log_msg}${log_rc}"
  437. fi
  438. /usr/bin/logger -s -t "adblock[${pid}] ${class}" "${log_msg}"
  439. if [ "${log_ok}" = "true" ] && [ "${ntp_ok}" = "true" ]
  440. then
  441. printf "%s\n" "$(/bin/date "+%d.%m.%Y %H:%M:%S") adblock[${pid}] ${class}: ${log_msg}" >> "${adb_logfile}"
  442. fi
  443. fi
  444. }
  445. ################################################
  446. # f_space: check mount points/space requirements
  447. #
  448. f_space()
  449. {
  450. local mp="${1}"
  451. if [ -d "${mp}" ]
  452. then
  453. df "${mp}" 2>/dev/null |\
  454. tail -n1 2>/dev/null |\
  455. while read filesystem overall used available scrap
  456. do
  457. av_space="${available}"
  458. if [ $((av_space)) -eq 0 ]
  459. then
  460. rc=575
  461. f_log "no space left on device/not mounted (${mp})" "${rc}"
  462. exit ${rc}
  463. elif [ $((av_space)) -lt $((adb_minspace)) ]
  464. then
  465. rc=580
  466. f_log "not enough space left on device (${mp})" "${rc}"
  467. exit ${rc}
  468. fi
  469. done
  470. rc=${?}
  471. if [ $((rc)) -eq 0 ]
  472. then
  473. space_ok="true"
  474. else
  475. space_ok="false"
  476. f_deltemp
  477. fi
  478. fi
  479. }
  480. ####################################################
  481. # f_deltemp: delete temp files, directories and exit
  482. #
  483. f_deltemp()
  484. {
  485. if [ -f "${adb_tmpfile}" ]
  486. then
  487. rm -f "${adb_tmpfile}" >/dev/null 2>&1
  488. fi
  489. if [ -d "${adb_tmpdir}" ]
  490. then
  491. rm -rf "${adb_tmpdir}" >/dev/null 2>&1
  492. fi
  493. f_log "domain adblock processing finished (${adb_version}, ${openwrt_version}, $(/bin/date "+%d.%m.%Y %H:%M:%S"))"
  494. exit ${rc}
  495. }
  496. ####################################################
  497. # f_remove: maintain and (re-)start domain query log
  498. #
  499. f_remove()
  500. {
  501. if [ "${query_ok}" = "true" ] && [ "${ntp_ok}" = "true" ]
  502. then
  503. query_date="$(date "+%Y%m%d")"
  504. if [ -s "${adb_querypid}" ] && [ ! -f "${adb_queryfile}.${query_date}" ]
  505. then
  506. kill -9 "$(cat "${adb_querypid}")" >/dev/null 2>&1
  507. rc=${?}
  508. if [ $((rc)) -eq 0 ]
  509. then
  510. find "${adb_backupdir}" -maxdepth 1 -type f -mtime +"${adb_queryhistory}" -name "${query_name}.*" -exec rm -f "{}" \; 2>/dev/null
  511. rc=${?}
  512. fi
  513. if [ $((rc)) -eq 0 ]
  514. then
  515. f_log "remove old domain query log background process (pid: $(cat "${adb_querypid}")) and do logfile housekeeping"
  516. else
  517. f_log "error during domain query removal/housekeeping (pid: $(cat "${adb_querypid}"))"
  518. fi
  519. > "${adb_querypid}"
  520. fi
  521. if [ ! -s "${adb_querypid}" ]
  522. then
  523. (logread -f 2>/dev/null & printf ${!} > "${adb_querypid}") | grep -Eo "(query\[A\].*)|([a-z0-9\.\-]* is ${query_ip}$)" 2>/dev/null >> "${adb_queryfile}.${query_date}" &
  524. rc=${?}
  525. if [ $((rc)) -eq 0 ]
  526. then
  527. sleep 1
  528. f_log "new domain query log background process started (pid: $(cat "${adb_querypid}"))"
  529. else
  530. f_log "error during domain query start"
  531. fi
  532. fi
  533. fi
  534. f_deltemp
  535. }
  536. ################################################################
  537. # f_restore: restore last adblocklist backup and restart dnsmasq
  538. #
  539. f_restore()
  540. {
  541. # remove bogus adblocklists
  542. #
  543. if [ -n "${adb_revsrclist}" ]
  544. then
  545. find "${adb_dnsdir}" -maxdepth 1 -type f \( ${adb_revsrcfind} \) -exec rm -f "{}" \; 2>/dev/null
  546. if [ $((rc)) -eq 0 ]
  547. then
  548. f_log "bogus adblocklists removed"
  549. else
  550. f_log "error during removal of bogus adblocklists" "${rc}"
  551. f_remove
  552. fi
  553. fi
  554. # restore backups
  555. #
  556. if [ "${backup_ok}" = "true" ] && [ -d "${adb_backupdir}" ] && [ "$(printf "${adb_backupdir}/${adb_dnsprefix}."*)" != "${adb_backupdir}/${adb_dnsprefix}.*" ]
  557. then
  558. cp -f "${adb_backupdir}/${adb_dnsprefix}."* "${adb_dnsdir}" >/dev/null 2>&1
  559. rc=${?}
  560. if [ $((rc)) -eq 0 ]
  561. then
  562. f_log "all available backups restored"
  563. else
  564. f_log "error during restore" "${rc}"
  565. f_remove
  566. fi
  567. fi
  568. /etc/init.d/dnsmasq restart >/dev/null 2>&1
  569. f_remove
  570. }
  571. #######################################################
  572. # f_wancheck: check for usable adblock update interface
  573. #
  574. f_wancheck()
  575. {
  576. local cnt=0
  577. local cnt_max="${1}"
  578. local dev
  579. local dev_out
  580. while [ $((cnt)) -le $((cnt_max)) ]
  581. do
  582. for dev in ${adb_wandev}
  583. do
  584. if [ -d "/sys/class/net/${dev}" ]
  585. then
  586. dev_out="$(cat /sys/class/net/${dev}/operstate 2>/dev/null)"
  587. rc=${?}
  588. if [ "${dev_out}" = "up" ]
  589. then
  590. wan_ok="true"
  591. f_log "get wan/update interface (${dev}), after ${cnt} loops"
  592. break 2
  593. fi
  594. fi
  595. done
  596. sleep 1
  597. cnt=$((cnt + 1))
  598. done
  599. if [ -z "${wan_ok}" ]
  600. then
  601. rc=585
  602. wan_ok="false"
  603. f_log "no wan/update interface(s) found (${adb_wandev# })" "${rc}"
  604. f_restore
  605. fi
  606. }
  607. #####################################
  608. # f_ntpcheck: check/get ntp time sync
  609. #
  610. f_ntpcheck()
  611. {
  612. local cnt=0
  613. local cnt_max="${1}"
  614. local ntp_pool
  615. for srv in ${adb_ntpsrv}
  616. do
  617. ntp_pool="${ntp_pool} -p ${srv}"
  618. done
  619. while [ $((cnt)) -le $((cnt_max)) ]
  620. do
  621. /usr/sbin/ntpd -nq ${ntp_pool} >/dev/null 2>&1
  622. rc=${?}
  623. if [ $((rc)) -eq 0 ]
  624. then
  625. ntp_ok="true"
  626. f_log "get ntp time sync (${adb_ntpsrv# }), after ${cnt} loops"
  627. break
  628. fi
  629. sleep 1
  630. cnt=$((cnt + 1))
  631. done
  632. if [ -z "${ntp_ok}" ]
  633. then
  634. rc=590
  635. ntp_ok="false"
  636. f_log "ntp time sync failed (${adb_ntpsrv# })" "${rc}"
  637. f_restore
  638. fi
  639. }