#!/bin/sh # Data here https://docs.miromico.ch/gateways-cards/miro-edgecard/ # Gitlab here https://gitlab.com/fmlr/miro_edge/sx1302_hal # https://docs.miromico.ch/gateways-cards/miro-edgecard/integration/ # To run from Internet: # sudo sh -c "$(curl -s https://apps.control2net.com/apt/install-miromico-pico-packet-forwarder)" _UPGRADING=0 _DIR_INSTALL="/opt/miromico/sx1302_hal-master/packet_forwarder" _LOCAL_CONF_EXIST=0 _GLOBAL_CONF_EXIST=0 # 0: Not Exist, 1: Exist as file, 2: Exist as soft-link. # clear screen tput clear echo "" # Check if we are upgrading or installing a clean install _FILE="$_DIR_INSTALL/lora_pkt_fwd" if [ -f "$_FILE" ]; then # # Upgrade is going to be done # Take backup of config files if upgrading # _UPGRADING=1 echo "\e[1;36m-------------------------------------------------------" echo "| MIROMICO PICO PACKET FORWARDER IS ALREADY INSTALLED |" echo "| UPGRADING WILL BE PERFORMED! |" echo "-------------------------------------------------------\e[0m" echo "" echo "\e[1;33mTAKE BACKUP" echo "==========================================================\e[0m" # # Prepare backup folder for all configuration files that apply # _DIR="$HOME/miromico_cfg_backup" if [ ! -d "$_DIR" ]; then mkdir $_DIR # sudo chmod 0755 /opt/miromico echo " * Backup folder for configuration files created at '$_DIR'." else echo " * Backup folder '$_DIR' for configuration files already exist." fi echo "" # # Take backup of all configuration files # _FILE="$_DIR_INSTALL/local_conf.json" if [ -f "$_FILE" ]; then _LOCAL_CONF_EXIST=1 sudo cp $_FILE $_DIR echo " * '$_FILE'" echo " is backed up." else echo " * '$_FILE'" echo " does not exist, no backup taken." fi echo "" _FILE="$_DIR_INSTALL/global_conf.json" if [ -L "$_FILE" ]; then _GLOBAL_CONF_EXIST=2 sudo cp -a $_FILE $_DIR echo " * '$_FILE'" echo " is a symlink. Link only backed up." elif [ -f "$_FILE" ]; then _GLOBAL_CONF_EXIST=1 sudo cp $_FILE $_DIR echo " * '$_FILE'" echo " is backed up." else echo " * '$_FILE'" echo " does not exist, no backup taken." fi echo "" _FILE="$_DIR_INSTALL/cfg" if [ -d "$_FILE" ]; then sudo cp -r $_FILE $_DIR echo " * Subfolder 'cfg' is backed up." else echo " * Subfolder 'cfg' does not exist, no backup taken" fi echo "" # # Stop the Packet Forwarder if running # I decided to comment out the below two lines because of possible reboot in old shit! #echo "Stopping Packet Forwarder..." #sudo systemctl stop miromico-pico-packet-forwarder.service echo "BACKUP COMPLEATE" echo "UPGRADING WILL NOW START after 3sec..." sleep 3 else echo "\e[1;36m---------------------------------------------------" echo "| MIROMICO PICO PACKET FORWARDER IS NOT INSTALLED |" echo "| CLEAN INSTALL WILL BE PERFORMED! |" echo "---------------------------------------------------\e[0m" fi echo "" echo "\e[1;33mDOWNLOAD AND INSTALL" echo "==========================================================\e[0m" # # Make temporary folder for the install # _DIR_TEMP="$HOME/tmp_miromico_install" if [ ! -d "$_DIR_TEMP" ]; then mkdir $_DIR_TEMP sudo chmod 0755 $_DIR_TEMP echo " * Temporary folder while installing created at '$_DIR_TEMP'." else echo " * Temporary folder '$_DIR_TEMP' for installation files already exist." echo " * Any existing files will be overwritten." fi echo "" # # Create install folder if needed. # _DIR_OPT_MIROMICO="/opt/miromico" if [ ! -d "$_DIR_OPT_MIROMICO" ]; then sudo mkdir $_DIR_OPT_MIROMICO sudo chmod 0755 $_DIR_OPT_MIROMICO echo " * Install folder '$_DIR_OPT_MIROMICO' created." else echo " * Install folder '$_DIR_OPT_MIROMICO' already exist." fi echo "" # # Get the compressed tar file for installation from apps.go-iot.io and uncompress it # echo " * Downloading install file from Go-IoT web site to" echo " '$_DIR_TEMP'..." echo "\e[1;35m----------------- BEGIN -----------------" cd $_DIR_TEMP wget https://apps.control2net.com/apt/lorawan/miromico-pico-packet-forwarder.tar.gz echo "------------------ END ------------------\e[0m" echo "" echo " * Uncompressing downloaded install file to" echo " '$_DIR_OPT_MIROMICO'..." sudo tar -xzf miromico-pico-packet-forwarder.tar.gz -C $_DIR_OPT_MIROMICO echo "" if [ $_UPGRADING -gt 0 ]; then # # Restore backed up config files: # global_conf.json # local_conf.json # if previously backed up. # # If there where not local_conf.json originally then remove the one. # copied in with the install. # # The config backup will be left in user home folder if needed for disaster restore. # echo "RESTORING CONFIGURATION FILES" if [ $_LOCAL_CONF_EXIST -gt 0 ]; then echo " * Restoring 'local_conf.json'." sudo cp $_DIR/local_conf.json $_DIR_OPT_MIROMICO/sx1302_hal-master/packet_forwarder/ else sudo rm $_DIR_OPT_MIROMICO/sx1302_hal-master/packet_forwarder/local_conf.json fi if [ $_GLOBAL_CONF_EXIST -eq 1 ]; then echo " * Restoring 'global_conf.json' file." sudo rm _DIR_OPT_MIROMICO/sx1302_hal-master/packet_forwarder/global_conf.json sudo cp $_DIR/global_conf.json $_DIR_OPT_MIROMICO/sx1302_hal-master/packet_forwarder/ elif [ $_GLOBAL_CONF_EXIST -eq 2 ]; then echo " * Restoring 'global_conf.json' symlink." # sudo rm _DIR_OPT_MIROMICO/sx1302_hal-master/packet_forwarder/global_conf.json sudo cp -a $_DIR/global_conf.json $_DIR_OPT_MIROMICO/sx1302_hal-master/packet_forwarder/ else echo " * There was no global_conf.json, default symlink will point to EU868 MHz, 8 channnel config file." echo " Change this symlink if needed to a different region config file in subfolder 'cfg/'" fi fi echo "" echo " * Removing '$_DIR_TEMP'" cd $HOME sudo rm -r $_DIR_TEMP echo "" # # Configuring # echo "\e[1;33mCONFIGURING..." echo "==========================================================\e[0m" echo " * Setting up the packet-forwarder as systemd service." #echo "----------------- BEGIN -----------------" cd $_DIR_OPT_MIROMICO/sx1302_hal-master/packet_forwarder/systemd sudo cp -p miromico-pico-packet-forwarder.service /lib/systemd/system sudo systemctl daemon-reload #echo "------------------ END ------------------" echo "" if [ $_UPGRADING -eq 0 ]; then echo " * Enabling externa antenna as the default antenna..." echo "\e[1;35m----------------- BEGIN -----------------" sudo $_DIR_OPT_MIROMICO/sx1302_hal-master/util_ant_sel/ant_sel -d /dev/ttyACM0 -a 1 echo "------------------ END ------------------\e[0m" echo "" echo " * Set unique ID for packet-forwarder in local_conf.json from eth0 MAC address..." echo "\e[1;35m----------------- BEGIN -----------------" sudo $_DIR_OPT_MIROMICO/sx1302_hal-master/packet_forwarder/update_gwid_from_eth0_mac.sh $_DIR_OPT_MIROMICO/sx1302_hal-master/packet_forwarder/local_conf.json echo "------------------ END ------------------\e[0m" echo "" echo " * The 'global_conf.json', defaults to be a copy from 'global_conf.json.sx1250.EU868.USB', " echo " a 8 channnel config file." echo " If that is not correct, copy any of the other 'global_conf.json.sx125....' to file" echo " 'global_conf.json'" else echo " * Antenna settings left as was before upgrade." echo " To set to external antenna run this command:" echo " sudo /opt/miromico/sx1302_hal-master/util_ant_sel/ant_sel -d /dev/ttyACM0 -a 1" echo " For further details refer to 'Anetnna Selection' section in:" echo " https://docs.miromico.ch/gateways-cards/miro-edgecard/integration/" fi echo "" # # Enabling and starting/restarting the packet-forwarder as a service # echo "\e[1;33mENABLING & STARTING THE PACKET-FORWARDER SERVICE...." echo "==========================================================\e[0m" if [ $_UPGRADING -eq 0 ]; then echo " * Packet Forwarder service enabled such that it will autostart at each reboot" sudo systemctl enable miromico-pico-packet-forwarder.service echo "" echo " * Please configure properly the forward-to 'server_address'" echo " properties in file 'local_conf.json' before starting the packet forwarder service." echo " 'The same file; local_conf.json' contains details of how to do that." echo "" echo " If not done before, we strongly recommend you read content in files" echo " 'how_to_use.README' and global_conf.json.README'". echo "" echo " NOTE: If DINGO-manager refers to 'global_conf.json' please read about how to" echo " change that to local_conf.json in file 'how_to_use.README'" else echo " * Packet Forwarder 'enabled' configuration left as was before upgrade." echo "" echo " * Stopping Packet Forwarder service if currently running after 3 seconds..." echo " NOTE! If the previous version is so old that it had to reboot to restart" echo " the box will now reboot after 5 seconds." echo " REMEMBER: If this installation is on hardware still with this problem" echo " Then please add this configuration line into your global_conf.json" echo " or local_conf.json file:" echo " "reboot_at_shutdown": false" echo " You can find a template for this in subfolder file:" echo " cfg/local_conf.json" sleep 3 sudo systemctl stop miromico-pico-packet-forwarder.service echo "" echo " * Starting Packet Forwarder service after 5 seconds..." sleep 5 sudo systemctl start miromico-pico-packet-forwarder.service fi echo "" echo "\e[1;33mFINISHED" echo "==========================================================\e[0m" echo "" cd $_DIR_OPT_MIROMICO/sx1302_hal-master/packet_forwarder #echo "Use thOSE commands to control the service:" #echo " sudo systemctl status miromico-pico-packet-forwarder.service (show service status)" #echo " sudo systemctl start miromico-pico-packet-forwarder.service (start the service)" #echo " sudo systemctl stop miromico-pico-packet-forwarder.service (stop the service)" #echo " sudo systemctl restart miromico-pico-packet-forwarder.service (restart the service)" #echo " sudo systemctl enable miromico-pico-packet-forwarder.service (service starts after reboot)" #echo " sudo systemctl disable miromico-pico-packet-forwarder.service (service does not start after reboot)" #echo " $_DIR_OPT_MIROMICO/sx1302_hal-master/packet_forwarder/lora_pkt_fwd (start server directly, not as service)" #echo " journalctl -f -u miromico-pico-packet-forwarder.service (show service log)"