ponmngr: Refactor code.

Cleanup code and make sure we can use whitespace
in passwords.
This commit is contained in:
Markus Gothe 2024-03-05 15:23:14 +01:00
parent 504d124486
commit b8b2dcb6fe
5 changed files with 69 additions and 68 deletions

View file

@ -3,39 +3,34 @@
. /lib/functions.sh
set_serial_number() {
vendor_id=$1
vssn=$2
local vendor_id="$1"
local vssn="$2"
# Vendor id is not taken from serial automatically, propagate it as well
/userfs/bin/omcicfgCmd set vendorId ${vendor_id}
/userfs/bin/omcicfgCmd set sn ${vendor_id}${vssn}
/userfs/bin/omcicfgCmd set vendorId "${vendor_id}"
/userfs/bin/omcicfgCmd set sn "${vendor_id}${vssn}"
}
set_equipment_id() {
local eqid=$1
local eq_id_default="KE2.119.241R2B"
local eqid="$1"
if [ -z "$eqid" ]; then
if [ -z "${eqid}" ]; then
return
fi
if [ "$eqid" = "$eq_id_default" ]; then
return
fi
/userfs/bin/omcicfgCmd set equipmentId ${eqid}
/userfs/bin/omcicfgCmd set equipmentId "${eqid}"
}
set_loid_authentication() {
local loid=$1
local loid_pwd=$2
local loid="$1"
local loid_pwd="$2"
[ -z "$loid" ] && return
[ -z "${loid}" ] && return
/userfs/bin/omcicfgCmd set loid ${loid}
/userfs/bin/omcicfgCmd set loid "${loid}"
if [ -n "$loid_pwd" ]; then
/userfs/bin/omcicfgCmd set loidPasswd ${loid_pwd}
if [ -n "${loid_pwd}" ]; then
/userfs/bin/omcicfgCmd set loidPasswd "${loid_pwd}"
fi
}

View file

@ -3,37 +3,39 @@
. /lib/functions.sh
set_serial_number() {
vendor_id=$1
vssn=$2
local vendor_id="$1"
local vssn="$2"
vendor_id="$(echo $vendor_id | hexdump -e '4/1 "%02X" "\n"')"
vendor_id=${vendor_id:0:8}
vendor_id="$(echo "${vendor_id}" | hexdump -e '4/1 "%02X" "\n"')"
vendor_id="${vendor_id:0:8}"
bs /b/c gpon onu_sn={vendor_id=$vendor_id,vendor_specific=$vssn}
}
set_equipment_id() {
equipment_id=$1
local equipment_id="$1"
[ -z "$equipment_id" ] && return
json_add_string "equipment_id" $equipment_id
json_add_string "equipment_id" "$equipment_id"
}
set_loid_authentication() {
loid=$1
loid_password=$2
local loid="$1"
local loid_password="$2"
[ -z "$loid" ] && return
json_add_string "loid" $loid
json_add_string "loid_password" $loid_password
json_add_string "loid" "$loid"
json_add_string "loid_password" "$loid_password"
}
apply_xpon_uci_config() {
local sn
json_init
json_add_object 'ani'
sn="$(uci -q get xpon.ani.serial_number)"
json_add_string "serial_number" $sn
json_add_string "serial_number" "$sn"
configure_loid_authentication
configure_equipment_id
json_close_object

View file

@ -11,21 +11,21 @@ include /lib/xpon
configure_serial_number() {
# serial number generation is taken care in the uci defaults, so if
# serial number is not found here its a misconfig
serial_number="$(uci -q get xpon.ani.serial_number)"
local serial_number="$(uci -q get xpon.ani.serial_number)"
if [ ${#serial_number} -eq 12 ]; then
vendor_id="${serial_number:0:4}"
vssn="${serial_number:4:8}"
local vendor_id="${serial_number:0:4}"
local vssn="${serial_number:4:8}"
else
logger -s -t "xpon" "Serial number not found in uci, ont will probably not be registered at the olt"
logger -s -t "xpon" "Please configure a valid serial number"
logger -s -t "xpon" "Serial number not found in UCI, ONT will probably not be registered at the OLT."
logger -s -t "xpon" "Please configure a valid serial number."
return
fi
set_serial_number $vendor_id $vssn
set_serial_number "${vendor_id}" "${vssn}"
}
start_service() {
if [ "$(uci -q get xpon.ani.enable)" == "1" ]; then
if [ "$(uci -q get xpon.ani.enable)" = "1" ]; then
configure_serial_number
apply_xpon_uci_config
init_xpon

View file

@ -3,14 +3,15 @@
configure_serial_number() {
# check if serial number is present in the production data
production_sn="$(fw_printenv -n gponsn)"
local production_sn="$(fw_printenv -n gponsn)"
if [ ${#production_sn} -eq 12 ]; then
uci set xpon.ani.serial_number=$production_sn
uci set xpon.ani.serial_number="${production_sn}"
else
macaddr="$(fw_printenv -n ethaddr | tr -d ':' | tr 'a-z' 'A-Z')"
vendor_id="IOPS"
vssn="${macaddr:4:8}"
uci set xpon.ani.serial_number=$vendor_id$vssn
local macaddr="$(fw_printenv -n ethaddr | tr -d ':' | tr 'a-z' 'A-Z')"
local vendor_id="IOPS"
local vssn="${macaddr:4:8}"
uci set xpon.ani.serial_number="${vendor_id}${vssn}"
fi
}
@ -18,20 +19,21 @@ configure_loid_authentication() {
local production_loid
local production_loidpwd
loid="$(uci -q get xpon.ani.loid)"
loidpwd="$(uci -q get xpon.ani.loid_password)"
if [ -z $loid ]; then
local loid="$(uci -q get xpon.ani.loid)"
local loidpwd="$(uci -q get xpon.ani.loid_password)"
if [ -z "${loid}" ]; then
production_loid="$(fw_printenv -n gponloid)"
fi
if [ -z $loidpwd ]; then
if [ -z "${loidpwd}" ]; then
production_loidpwd="$(fw_printenv -n gponloid_password)"
fi
if [ -n $production_loid ]; then
uci set xpon.ani.loid=$production_loid
if [ -n "${production_loid}" ]; then
uci set xpon.ani.loid="${production_loid}"
fi
if [ -n $production_loidpwd ]; then
uci set xpon.ani.loid_password=$production_loidpwd
if [ -n "${production_loidpwd}" ]; then
uci set xpon.ani.loid_password="${production_loidpwd}"
fi
}
@ -39,8 +41,8 @@ configure_loid_authentication() {
if [ -s "/etc/config/xpon" ]; then
if uci -q get xpon.ani >/dev/null; then
# generate serial number in case its not present and return
serial_number="$(uci -q get xpon.ani.serial_number)"
if [ ${#serial_number} -ne 12 ]; then
SERIAL_NUMBER="$(uci -q get xpon.ani.serial_number)"
if [ ${#SERIAL_NUMBER} -ne 12 ]; then
configure_serial_number
fi
configure_loid_authentication

View file

@ -1,13 +1,15 @@
#!/bin/sh
configure_equipment_id() {
eqid="$(uci -q get xpon.ani.equipment_id)"
set_equipment_id $eqid
local eqid="$(uci -q get xpon.ani.equipment_id)"
set_equipment_id "${eqid}"
}
configure_loid_authentication() {
loid="$(uci -q get xpon.ani.loid)"
loid_pwd="$(uci -q get xpon.ani.loid_password)"
set_loid_authentication $loid $loid_pwd
local loid="$(uci -q get xpon.ani.loid)"
local loid_pwd="$(uci -q get xpon.ani.loid_password)"
set_loid_authentication "${loid}" "${loid_pwd}"
}