#!/bin/sh # Description: Script to be executed during a liveburner upgrade # but before the installation of the application packages. # It will mount the safezone and restore the files. EMMC_DEVICE="NOT_SUPPORTED" SAFEZONE_MOUNTPOINT="/tmp/safezeone" KEROS_CONFIGS_ARCHIVE="keros_config.tar.gz" LOGFILE="${SAFEZONE_MOUNTPOINT}/upgrade.log" # CPF CPF_CONFIGFILE="${SAFEZONE_MOUNTPOINT}/cpf_config.tar.gz" # BSCC BSCC_CONFFILE="var.xml" # WMC WMC_CONFIGS_ARCHIVE="wmc_config.tar.gz" WMC_SYSUPGRADE_FILE="/etc/sysupgrade.d/openvpn.conf" WMC_OPENVPN_CONFIG="/etc/openvpn/client-openvpn.conf" WMC_FIREWALL_RULES="/etc/firewall.d/iptables_openvpn.rules" WMC_SYSUPGRADE_FILES="${WMC_OPENVPN_CONFIG}" fatal_error() { echo "$1" exit 1 } detect_emmc() { for i in $(seq 0 9); do if [ -b "/dev/mmcblk${i}" ]; then EMMC_DEVICE="mmcblk${i}" break fi done if [ "${EMMC_DEVICE}" == "NOT_SUPPORTED" ]; then fatal_error "Emmc device not found. Kernel version: ${KERNEL_VERSION}. Please fix." fi } # Mount the safezone mountpoint in ${SAFEZONE_MOUNTPOINT} # mount_safezone() { echo "Mounting safezone" echo 0 > /sys/block/${EMMC_DEVICE}boot0/force_ro mkdir -p ${SAFEZONE_MOUNTPOINT} mount /dev/${EMMC_DEVICE}boot0 ${SAFEZONE_MOUNTPOINT} echo "Safezone ready to use" } # Restore configuration saved in safezone by preinst in # the new filesystem. # restore_keros_configurations() { echo "Restoring KerOS configurations from safezone..." if [ -f ${SAFEZONE_MOUNTPOINT}/${KEROS_CONFIGS_ARCHIVE} ] then tar -xvzf ${SAFEZONE_MOUNTPOINT}/${KEROS_CONFIGS_ARCHIVE} -C / echo "Restoration finished" else echo "No restoration files in safezone. Nothing done." fi } # Adapt KerOS system configuration files restored from # previous version. In this version, only the Connman configuration # files are adapted. # adjust_keros_configurations() { echo "Adjusting KerOS configurations..." for service_dir in $(find /etc/network/connman/ -type d \( -name ethernet_* -o -name wifi_* \)) do local settings_file="${service_dir}/settings" if [ -f "${settings_file}" ] then echo "Adjust configuration in ${settings_file}" sed -i '/^Config\.file.*/d' "${settings_file}" sed -i '/^Config\.ident.*/d' "${settings_file}" sed -i 's/^IPv4\.method\=fixed.*/IPv4\.method\=manual/g' "${settings_file}" fi done # Report nameservers for Ethernet interface if [ -f /etc/network/connman/lan.config ] then local nameservers=$(awk -F "=" '$1 ~ "Nameservers" {gsub(",",";",$2);gsub(" ","",$2);print $2}' /etc/network/connman/lan.config) if [ ! -z "${nameservers}" ] then for service_dir in $(find /etc/network/connman/ -type d -name ethernet_*) do local settings_file="${service_dir}/settings" if [ -f "${settings_file}" ] then echo "Apply static nameservers ${nameservers} in ${settings_file}" sed -i '/^Nameservers.*/d' "${settings_file}" echo "Nameservers=${nameservers}" >> "${settings_file}" fi done fi fi # Allow Connman to be configured by webui/restAPI for cnf_file in /etc/network/connman/lan.config /etc/network/connman/wlan.config do [ -f "${cnf_file}" ] && mv "${cnf_file}" "${cnf_file}.keros3" done echo "LAN and WLAN configuration files removed" echo "Adjustements finished" } # Restore SPF/CPF configurations from the content in the # safezone. In case of SPF to CPF upgrade, convert configuration. # restore_lora_configurations() { echo "Restoring CPF configurations from safezone..." if [ -f "${CPF_CONFIGFILE}" ]; then tar -xvzf "${CPF_CONFIGFILE}" -C / echo "CPF configuration restored" else echo "No CPF configuration in safezone. Nothing done." fi } # Restore configuration saved in safezone by preinst in # the new filesystem. # restore_bscc_configurations() { echo "Restoring BSCC configurations from safezone..." if [ -f ${SAFEZONE_MOUNTPOINT}/${BSCC_CONFFILE} ] then mkdir -p /user/bscc/ cp -f ${SAFEZONE_MOUNTPOINT}/${BSCC_CONFFILE} /user/bscc/ echo "Restoration finished" else echo "No restoration files in safezone. Nothing done." fi } # Restore Prove&Core SecureStorage information. restore_securestorage() { echo "Restore Prove&Core SecureStorage..." if [ -f ${SAFEZONE_MOUNTPOINT}/pcore_data.img.gz ]; then gunzip -c ${SAFEZONE_MOUNTPOINT}/pcore_data.img.gz | dd of=/dev/${EMMC_DEVICE} bs=512 seek=10240 echo "Prove&Core SecureStorage restored" else echo "No Prove&Core SecureStorage found. Nothing done." fi } # Adapt WMC configuration files for new firmware (if necessary) # adapt_wmc_configurations() { echo "Adapting WMC configuration files..." # Sysupgrade echo "${WMC_SYSUPGRADE_FILES}" > ${WMC_SYSUPGRADE_FILE} # Tunneling Tools 3.0 modifications # # OpenVPN configuration sed -i 's/^route-up/;route-up/g' ${WMC_OPENVPN_CONFIG} # Firewall rules cat << EOF > ${WMC_FIREWALL_RULES} #Firewall rules to accept OpenVPN traffic *filter -I INPUT -m udp -p udp --sport 1194 --dport 1024:65535 -j ACCEPT -I INPUT -m udp -p udp --sport 30000:35000 --dport 1024:65535 -j ACCEPT -I OUTPUT -m udp -p udp --sport 1024:65535 --dport 1194 -j ACCEPT -I OUTPUT -m udp -p udp --sport 1024:65535 --dport 30000:35000 -j ACCEPT COMMIT EOF # forcibly set lns, snmp & ntp addresses awk -F "\t" ' $2 == "lns" || $2 == "snmp" || $2 == "ntp.ran.com" { next } { print } END { printf "172.17.0.1\tlns\n" printf "172.17.0.1\tsnmp\n" printf "172.17.0.1\tntp.ran.com\n" }' < /etc/hosts > /etc/hosts.new \ && mv -f /etc/hosts.new /etc/hosts echo "Done" } # Restore WMC configuration from safezone restore_wmc_configurations() { echo "Restoring WMC configurations from safezone..." if [ -f ${SAFEZONE_MOUNTPOINT}/${WMC_CONFIGS_ARCHIVE} ] then # Restore the configuration tar -xvzf ${SAFEZONE_MOUNTPOINT}/${WMC_CONFIGS_ARCHIVE} -C / # Adapt for KerOS 4.0 adapt_wmc_configurations echo "Restoration finished" else echo "No restoration files in safezone. Nothing done." fi } #################### # MAIN KEROS PART #################### detect_emmc mount_safezone echo -e "\n== Start of PREAPPS script ==\n" 2>&1 | tee -a ${LOGFILE} # KerOS configuration restore_keros_configurations 2>&1 | tee -a ${LOGFILE} adjust_keros_configurations 2>&1 | tee -a ${LOGFILE} # LoRa configuration restore_lora_configurations 2>&1 | tee -a ${LOGFILE} # BSCC configuration restore_bscc_configurations 2>&1 | tee -a ${LOGFILE} # SecureStorage information restore_securestorage 2>&1 | tee -a ${LOGFILE} # WMC configuration restore_wmc_configurations 2>&1 | tee -a ${LOGFILE} #################### # MAIN CUSTOMER PART #################### # Example: # cp -fR ${SAFEZONE_MOUNTPOINT}/* /etc/ echo -e "\n== End of PREAPPS script ==\n" 2>&1 | tee -a ${LOGFILE} sync