Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  1. Open a terminal application on your Revolution Pi or connect via SSH.

  2. Navigate to the desired directory where you want to create the script using the cd <directory path> command. For example:

    Code Block
    languagebash
    cd /home/pi/
  3. Create a new empty file with your desired name and the ".sh" file extension using a text editor of your choice. For example:

    Code Block
    languagebash
    nano static_pibridge_mac.sh
  4. Copy the script code into nano Nano text editor.

    Code Block
    languagebash
    #!/bin/bash
    
    if [[ $(id -u) != 0 ]]; then
        echo "usage: sudo $(basename $0)"
        exit 1
    fi
    
    pibridge_static_mac() {
        interface=$1
    
        if [[ $interface != "pileft" && $interface != "piright" ]]; then
                echo 2>&1 "interface is not a PiBridge interface: ${interface}"
                exit 3
        elif [[ ! -e /sys/class/net/${interface} ]]; then
                echo 2>&1 "warning: network interface does not exists: ${interface}"
        fi
    
        mac=$(ip l show $interface | grep ether | xargs | cut -f 2 -d ' ' | sed -e 's/://g')
    
        mac_hi=${mac:0:8}
        mac_lo=${mac:8:12}
    
        grep -q dtparam=${interface}_mac_hi /boot/config.txt || echo "dtparam=${interface}_mac_hi=0x$mac_hi" >> /boot/config.txt
        grep -q dtparam=${interface}_mac_lo /boot/config.txt || echo "dtparam=${interface}_mac_lo=0x$mac_lo" >> /boot/config.txt
    }
    
    pibridge_static_mac pileft
    pibridge_static_mac piright
  5. Save the script by pressing ⌨️ "Ctrl + X", followed by "Y" to save the file and "Enter" to exit the Nano text editor.

  6. Enter the following command to make the script executable:

    Code Block
    languagebash
    sudo codechmodchmod +x static_pibridge_mac.sh

    This grants the script execution permission.

  7. To run the script, enter the following command:

    Code Block
    languagebash
    ./static_pibridge_mac.sh

    This will start the script and execute the code.

...