diff --git a/ponmngr/files/airoha/lib/xpon/airoha.sh b/ponmngr/files/airoha/lib/xpon/airoha.sh index 485f947b3..f7b67be53 100644 --- a/ponmngr/files/airoha/lib/xpon/airoha.sh +++ b/ponmngr/files/airoha/lib/xpon/airoha.sh @@ -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 } diff --git a/ponmngr/files/broadcom/lib/xpon/broadcom.sh b/ponmngr/files/broadcom/lib/xpon/broadcom.sh index 3211af980..17dd26b67 100644 --- a/ponmngr/files/broadcom/lib/xpon/broadcom.sh +++ b/ponmngr/files/broadcom/lib/xpon/broadcom.sh @@ -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 diff --git a/ponmngr/files/common/etc/init.d/xpon b/ponmngr/files/common/etc/init.d/xpon index 3518cd488..a845f34a8 100755 --- a/ponmngr/files/common/etc/init.d/xpon +++ b/ponmngr/files/common/etc/init.d/xpon @@ -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 diff --git a/ponmngr/files/common/etc/uci-defaults/60-xpon-generate b/ponmngr/files/common/etc/uci-defaults/60-xpon-generate index 6a3bfb6dc..e7144be5f 100755 --- a/ponmngr/files/common/etc/uci-defaults/60-xpon-generate +++ b/ponmngr/files/common/etc/uci-defaults/60-xpon-generate @@ -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,37 +19,38 @@ 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 } 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 + 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 configure_serial_number fi configure_loid_authentication - exit - else - rm -f /etc/config/xpon - fi -fi + exit + else + rm -f /etc/config/xpon + fi +fi touch /etc/config/xpon uci set xpon.ani=ani diff --git a/ponmngr/files/common/lib/xpon/get_uci_config.sh b/ponmngr/files/common/lib/xpon/get_uci_config.sh index 77b1f56d9..b71e3b7a6 100644 --- a/ponmngr/files/common/lib/xpon/get_uci_config.sh +++ b/ponmngr/files/common/lib/xpon/get_uci_config.sh @@ -1,13 +1,15 @@ #!/bin/sh -configure_equipment_id() { - 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 +configure_equipment_id() { + local eqid="$(uci -q get xpon.ani.equipment_id)" + + set_equipment_id "${eqid}" +} + +configure_loid_authentication() { + local loid="$(uci -q get xpon.ani.loid)" + local loid_pwd="$(uci -q get xpon.ani.loid_password)" + + set_loid_authentication "${loid}" "${loid_pwd}" }