Verified Commit 1724605b authored by Vojtech Myslivec's avatar Vojtech Myslivec
Browse files

turris-diagnostics: Add script and cron to check country is set

parent 5788d574
......@@ -9,7 +9,7 @@ include $(TOPDIR)/rules.mk
PKG_NAME:=turris-diagnostics
PKG_VERSION:=9.3
PKG_RELEASE:=1
PKG_RELEASE:=2
PKG_SOURCE_PROTO:=git
PKG_SOURCE_URL:=https://gitlab.nic.cz/turris/diagnostics.git
PKG_SOURCE_VERSION:=v$(PKG_VERSION)
......@@ -34,9 +34,14 @@ endef
define Package/$(PKG_NAME)/install
$(INSTALL_DIR) $(1)/usr/share/diagnostics/
$(INSTALL_BIN) $(PKG_BUILD_DIR)/diagnostics.sh $(1)/usr/share/diagnostics/diagnostics.sh
$(INSTALL_DIR) $(1)/usr/share/diagnostics/modules
$(INSTALL_BIN) $(PKG_BUILD_DIR)/modules/module.sh $(1)/usr/share/diagnostics/modules/module.sh
$(INSTALL_BIN) $(PKG_BUILD_DIR)/modules/*.module $(1)/usr/share/diagnostics/modules/
$(INSTALL_BIN) ./files/country-check.sh $(1)/usr/share/diagnostics/country-check.sh
$(INSTALL_DIR) $(1)/etc/cron.d/
$(INSTALL_BIN) ./files/country-check.cron $(1)/etc/cron.d/diagnostics-country-check
endef
$(eval $(call BuildPackage,$(PKG_NAME)))
## crontab
MAILTO=""
0 8 * * 1 root /usr/share/diagnostics/country-check.sh
#!/bin/sh
set -e
COUNTRY_SYSTEM_VALID='true'
COUNTRY_WIRELESS_VALID='true'
MISSING_COUNTRY_MESSAGE=$(cat <<-EOF
Your system does not have a country (region) set correctly.
Please go to the Foris web interface, make sure you have set correct
country in the "Region and time" tab and then "Save" your wireless
configuration in the "Wi-Fi" tab again.
EOF
)
main() {
# check all wireless wi-fi device sections
. /lib/functions.sh
config_load wireless
config_foreach wireless_section_check_country wifi-device
# check system configuration (there is always only one section)
check_country_system
send_notification
}
check_valid_country() {
local country="$1"
[ -n "$country" -a "$country" != '00' ]
}
wireless_section_check_country() {
local section_name="$1"
local disabled
config_get_bool disabled "$section_name" disabled 0
[ "$disabled" = '1' ] && {
return
}
local country
config_get country "$section_name" country
if ! check_valid_country "$country"; then
COUNTRY_WIRELESS_VALID='false'
fi
}
check_country_system() {
local country
country="$(uci get -q 'system.@system[0]._country')" || true
  • uci-option "-q" should be before uci-command "get". so it should be : country="$(uci -q get 'system.@system[0]._country')" || true

    Edited by Maxmilian Picmaus
Please register or sign in to reply
if ! check_valid_country "$country"; then
COUNTRY_SYSTEM_VALID='false'
fi
}
send_notification() {
if [ "$COUNTRY_WIRELESS_VALID" = 'false' -o "$COUNTRY_SYSTEM_VALID" = 'false' ]; then
create_notification -s error "$MISSING_COUNTRY_MESSAGE"
fi
}
main
  • cron.d file does not need explicit execute attribute. cznic/turris-diagnostics/files/country-check.cron aka /etc/cron.d/diagnostics-country-check

    btw: this is my first time on gitlab, so if this is not the way how to initiate change/fix, i am sorry. i think it is so trivial, making this an issue is kind of overpower. But i am more then happy to try (after i get more familiar with git).

  • @veehell thanks, fixed in turris/turris-os-packages!563

Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment