Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Определение версии прошивки #205

Closed
AltGrF13 opened this issue Nov 4, 2024 · 3 comments
Closed

Определение версии прошивки #205

AltGrF13 opened this issue Nov 4, 2024 · 3 comments

Comments

@AltGrF13
Copy link
Contributor

AltGrF13 commented Nov 4, 2024

version_os()(ndmc -c show version | grep version | head -1 | cut -d: -f2| tr -d ' ')

У меня не определяет, т.к. первая строка с version пустая

~ # ndmc -c show version

          release: 4.02.C.1.0-1
          sandbox: stable
            title: 4.2.1
             arch: mips

              ndm:
                exact: 0-7e1d38c
                cdate: 2 Oct 2024

              bsp:
                exact: 0-27d6a29f37
                cdate: 2 Oct 2024

              ndw:
              version:
             features: dual_image,wifi_button,usb_3,usb_3_first,led_control,wifi5ghz,vht2ghz,mimo2ghz,mimo5ghz,
                       atf2ghz,atf5ghz,wifi6,wifi_ft,wpa3,wsa5ghz,hwnat,sfp
           components: base,cloudcontrol,corewireless,dhcpd,dns-tls,ext,igmp,ipsec,l2tp,lang-en,lang-ru,mdns,
                       miniupnpd,ndmp,ndns,opkg,pingcheck,ppe,storage,trafficcontrol,tsmb,usb,wireguard

             ndw4:
              version: 4.2.4.24

     manufacturer: Keenetic Ltd.
           vendor: Keenetic
           series: KN
            model: Giga (KN-1011)
       hw_version: 11108000
          hw_type: router
            hw_id: KN-1011
           device: Giga
           region: EA
      description: Router

~ # ndmc -c show version | grep version
              version:
              version: 4.2.4.24
       hw_version: 11108000
~ # ndmc -c show version | grep version | head -1
              version:

Надёжнее как-то так (opt/etc/ndm/ndm):

version_os()(ndmc -c show version | grep -F 'version' | grep -oE '[0-9]\.[0-9\.]*[0-9]' | head -1)
@qzeleza
Copy link
Owner

qzeleza commented Nov 7, 2024

Внес исправления в следующую бету, спасибо.

@AltGrF13
Copy link
Contributor Author

AltGrF13 commented Nov 11, 2024

У человека в чате новый случай, когда определение версии ошибается. Доработал ещё более надёжно, на 4 роутерах работает.

get_version() {
  if [ -n "${1}" ]; then
    local version_data="${1}"
  else
    local version_data=$(ndmc -c show version)
  fi

  echo "${version_data}" | grep -F 'version' | grep -oE '[0-9][0-9\.]*[0-9]' | head -1
}

version_os() {
  local versions_data=$(ndmc -c show version)

  # пробуем использовать version только в блоке с ndw4
  local version_ndw4=$(echo "${versions_data}" | grep -zoP '(?s)ndw4:.+?\n\n')
  if [ -n "${version_ndw4}" ]; then
    version_ndw4=$(get_version "${version_ndw4}")
    if [ -n "${version_ndw4}" ]; then
      echo "${version_ndw4}"
      return
    fi
  fi

  # иначе любой
  echo $(get_version "${versions_data}")
}

@AltGrF13 AltGrF13 reopened this Nov 11, 2024
@qzeleza
Copy link
Owner

qzeleza commented Nov 11, 2024

Спасибо, включил в следующую бету

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants