#!/bin/bash # PiPilot Config Script INI_FILE="${1:-config.ini}" DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) PARSER=$DIR/bash-ini-parser/bash-ini-parser echo echo "::::: PiPilot Configuration :::::" echo if [ -f $INI_FILE ] ; then # INI initialization echo "Detected INI file: $INI_FILE" if [ -f $PARSER ]; then source $PARSER echo "Loaded bash-ini-parser (https://github.com/albfan/bash-ini-parser)" cfg_parser "$INI_FILE" echo "Parsed $INI_FILE" #Network Setup cfg_section_network if [ $device = "wifi" ]; then NET_DEV="wlan0" echo "Network device set to: '$NET_DEV'" if nmcli d wifi list | grep "*" | grep $ssid; then echo "Already connected to wifi: $ssid" else ifconfig $NET_DEV down echo "Disconnecting wifi" if nmcli c | grep $ssid; then nmcli c delete $ssid fi set -e echo "Connecting to wifi: $ssid" nmcli device wifi connect "$ssid" password "$key" ifname $NET_DEV set +e fi else NET_DEV="eth0" echo "Network device set to: '$NET_DEV'" fi if [ $inet = "dhcp" ]; then echo "Waiting for IP lease from DHCP server" ifconfig $NET_DEV up 0.0.0.0 0.0.0.0 dhclient $NET_DEV else echo "Setting static IP to: $ip, Netmask: $netmask, Network: $net, Gateway: $gateway" ifconfig $NET_DEV down ifconfig $NET_DEV $ip netmask $netmask up route add -net $net netmask $netmask gw $gateway dev $NET_DEV fi fi fi echo echo "::::: PiPilot Done! :::::" echo