diff --git a/board/shredos/fsoverlay/.lftprc b/board/shredos/fsoverlay/.lftprc new file mode 100755 index 0000000000..a03d8b25e8 --- /dev/null +++ b/board/shredos/fsoverlay/.lftprc @@ -0,0 +1,6 @@ +set cmd:fail-exit true +set net:timeout 5 +set net:max-retries 1 + + + diff --git a/board/shredos/fsoverlay/usr/bin/nwipe_launcher b/board/shredos/fsoverlay/usr/bin/nwipe_launcher index afd8e22e7c..e6db2c3d98 100755 --- a/board/shredos/fsoverlay/usr/bin/nwipe_launcher +++ b/board/shredos/fsoverlay/usr/bin/nwipe_launcher @@ -6,6 +6,10 @@ trap "echo" INT # initialise country_code="" nwipe_options_string="" +lftp_command_line="" + +\rm lftp.log +echo "[`date`] lftp log" > lftp.log # read the kernel command line for the loadkeys label for setting the correct keyboard layout country_code=$(kernel_cmdline_extractor loadkeys) @@ -35,6 +39,29 @@ then else /usr/bin/nwipe --logfile=nwipe_log_$(date +%Y%m%d-%H%M%S).txt $nwipe_options_string fi + +# read the kernel command line for a lftp command +# example lftp command "open 192.168.1.60; user joe joe's_password; cd data; mput nwipe_*.txt +lftp_command_line=$(kernel_cmdline_extractor lftp) +if [ $? == 0 ] +then + echo "Found lftp commands on kernel command line, preparing lftp" + if [ ! -d "exported" ]; then + mkdir exported + echo "created exported directory" + fi + echo "Executing users lftp commands" + lftp -c "$lftp_command_line" >> lftp.log + if [ $? == 0 ] + then + echo "lftp completed sucessfully" + echo "moving nwipe logs to ../exported" + mv nwipe_*.txt exported/ + else + echo "[`date`] lftp command failed, lftp -c \"$lftp_command_line\" See lftp.log for details" + fi +fi + printf "Paused, press a key to restart nwipe." read -rsn1 input sleep 1; diff --git a/board/shredos/fsoverlay/usr/bin/shredos_net.sh b/board/shredos/fsoverlay/usr/bin/shredos_net.sh index b3501ecf77..80a598a3b6 100755 --- a/board/shredos/fsoverlay/usr/bin/shredos_net.sh +++ b/board/shredos/fsoverlay/usr/bin/shredos_net.sh @@ -5,8 +5,13 @@ # with those devices set up as DHCP hot plug. We then monitor the link # state (whether the ethernet cable is connected). # -# Shutdown all network interfaces if any are up -ifdown -a +version=1.0-211023-2337 +# +# Forcefully shutdown all network interfaces if any are up +ifdown -f -a + +# Bring up loopback device +ifup lo # delete the existing non populated interfaces file rm /etc/network/interfaces @@ -17,9 +22,10 @@ echo "iface lo inet loopback" >> /etc/network/interfaces echo "" >> /etc/network/interfaces # Create a list of all network devices -#net_devices=$(ip add | grep ": " | awk '{print $2}' | sed 's/://') net_devices=$(ls -1 /sys/class/net) +active_device="none" + # Populate /etc/network/interfaces with each network device if ethernet or wifi for device in $net_devices do @@ -31,21 +37,43 @@ do fi done -# Bring all network devices up and record whether they +# Check for existing active ethernet devices and set active_device variable for device in $net_devices do - ifup $device - if [ $? == 0 ]; + # We're only interested in ethernet (enxxxx) devices + if [[ $device == en* ]]; then + # initial creation of device operstate and status variables for + # each network device, indirectly referenced so you won't see + # those variable names in this code, but even so they are there. + # Variable such as enp6s0_operstate, enp6s0_carrier, enp6s0_status + # are created for each device. + + device_operstate="$device"_operstate + device_status="$device"_status + device_carrier="$device"_carrier + + # no need to check the return status, whether it works or not we need + # to initialise the device statuses. +# ifdown $device + # Obtain network device link status - device_operstate=$(more /sys/class/net/$device/operstate) + eval "$device_operstate"=$(more /sys/class/net/$device/operstate) + eval device_operstate_result="\${$device_operstate}" # If the device link status is up record the current state - if [ $device_operstate == "up" ]; + if [ $device_operstate_result == "up" ]; then - device_status="up" + eval "$device_status"="up" + echo "[OK] $device is up" + active_device="$device" else - device_status="down" + eval "$device_status"="down" + echo "[OK] $device is down" + if [ "$active_device" == "$device" ]; + then + active_device="none" + fi fi fi done @@ -55,63 +83,91 @@ done # device. ie it's association with an IPv4/IPv6 address is removed. # When the link status is 'up' then we bring the network back up # which means we request a IP address via DHCP. This is therefore -# acting as a hotplug for ethernet. +# acting as a hotplug for ethernet. We only need one active ethernet +# connection, so on a system with multiple ethernet points as soon +# as one is active and succesfully retrieves a IP addres via DHCP we +# no longer try to bring the rest up. +# while [ 1 ]; do for device in $net_devices do + # We're only interested in ethernet (enxxxx) devices if [[ $device == en* ]]; then - # Obtain network device link status - device_carrier=$(more "/sys/class/net/$device/carrier") - device_operstate=$(more "/sys/class/net/$device/operstate") - if [[ $device_carrier != 1 ]]; - then - if [[ $device_carrier != 0 ]]; - then - ifup $device - if [ $? == 0 ]; - then - device_status="up" - echo "[OK] $device is now up" - else - device_status="down" - echo "[FAIL] $device could not be brought up" - fi - fi - fi + # and we are only interested in one device being active at any one time + if [ "$active_device" == "$device" ] || [ "$active_device" == "none" ]; + then + # Obtain network device link status and carrier states + device_operstate="$device"_operstate + eval "$device_operstate"=$(more /sys/class/net/$device/operstate) + eval device_operstate_result="\${$device_operstate}" - if [[ $device_operstate == down ]]; - then - if [[ $device_status == up ]]; + device_carrier="$device"_carrier + eval "$device_carrier"=$(more /sys/class/net/$device/carrier) + eval device_carrier_result="\${$device_carrier}" + + device_status="$device"_status + eval device_status_result="\${$device_status}" + +# eval echo "device=$device, status=""\${$device_status}"", device_operstate_result=$device_operstate_result, device_carrier_result=$device_carrier_result, device_status_result=$device_status_result" + + if [[ $device_carrier_result != 1 ]]; then - ifdown $device - if [ $? == 0 ]; + if [[ $device_carrier_result != 0 ]]; then - device_status="down" - echo "[OK] $device is now down" - else - echo "[FAIL] $device could not be brought down" + ifup $device + if [ $? == 0 ]; + then + eval "$device_status"="up" + echo "[OK] $device is up" + active_device="$device" + else + eval "$device_status"="down" + echo "[FAIL] $device ifup failed" + if [ "$active_device" == "$device" ]; + then + active_device="none" + fi + fi fi - fi - else - if [[ $device_status == down ]]; + fi + + if [[ $device_operstate_result == down ]]; then - ifup $device - if [ $? == 0 ]; + if [[ $device_status_result == up ]]; then - device_status="up" - echo "[OK] $device is now up" - else - echo "[FAIL] $device could not be brought up" + ifdown -f $device + if [ $? == 0 ]; + then + eval "$device_status"="down" + echo "[OK] $device is down" + else + echo "[FAIL] $device ifdown failed" + fi + fi + else + if [[ $device_status_result == down ]]; + then + ifup $device + if [ $? == 0 ]; + then + eval "$device_status"="up" + echo "[OK] $device is up" + else + echo "[FAIL] $device ifup failed" + fi fi fi fi fi done + + # Never remove this sleep statement ! Could be changed to 1 second for + # a less responsive hotplug, however 0.5 seconds provides sufficient + # responsiveness while not wasting CPU cycles. sleep 0.5 done -