diff --git a/bootmac b/bootmac index c1cfed3533c38d1cb5662d2f12e75ea7846a370c..bbd968885d8f2349923dcc5dd92c352853786055 100644 --- a/bootmac +++ b/bootmac @@ -23,6 +23,7 @@ help_info() { echo "bootmac options:" echo " -b | --bluetooth = Configure Bluetooth interface's MAC" echo " -w | --wlan = Configure WLAN interface's MAC" + echo " -g | --generate-only = Generate and print the MAC address to stdout, but do not configure the interface. This option must be specified with either -b or -w, but not both." echo "" echo "bootmac will configure the MAC addresses for both interfaces if no arguments are passed" } @@ -34,6 +35,11 @@ unknown_option() { exit 1 } +# Set default values for arguments +WLAN_CONFIGURE_ARG=0 +BLUETOOTH_CONFIGURE_ARG=0 +GENERATE_ONLY_ARG=0 + # If no arguments are passed, default to configuring both WLAN and Bluetooth if [ "$#" -eq 0 ]; then WLAN_CONFIGURE_ARG=1 @@ -41,7 +47,7 @@ if [ "$#" -eq 0 ]; then fi # Use the "getopts" built-in to parse arguments -while getopts bwh-: arg; do +while getopts bwhg-: arg; do case "$arg" in w) WLAN_CONFIGURE_ARG=1 @@ -49,6 +55,9 @@ while getopts bwh-: arg; do b) BLUETOOTH_CONFIGURE_ARG=1 ;; + g) + GENERATE_ONLY_ARG=1 + ;; h) help_info exit 0 @@ -61,6 +70,9 @@ while getopts bwh-: arg; do bluetooth) BLUETOOTH_CONFIGURE_ARG=1 ;; + generate-only) + GENERATE_ONLY_ARG=1 + ;; help) help_info exit 0 @@ -81,6 +93,14 @@ if [ "$((OPTIND-1))" != "$#" ]; then unknown_option fi +# If "generate-only" is specified, either Wi-Fi or Bluetooth must be requested, but not both +if [ "$GENERATE_ONLY_ARG" = 1 ] && [ "$((WLAN_CONFIGURE_ARG+BLUETOOTH_CONFIGURE_ARG))" != 1 ]; then + echo "ERROR: Either Wi-Fi or Bluetooth must be requested together with --generate-only." >&2 + echo "" >&2 + help_info + exit 1 +fi + mac_generate() { # Try to retrieve the serial number from the cmdline log "retrieving device serial number" @@ -150,6 +170,15 @@ mac_wlan() { mac_generate +if [ "$GENERATE_ONLY_ARG" = 1 ]; then + if [ "$WLAN_CONFIGURE_ARG" = 1 ]; then + echo "$WLAN_MAC" + elif [ "$BLUETOOTH_CONFIGURE_ARG" = 1 ]; then + echo "$BT_MAC" + fi + exit 0 +fi + if [ "$WLAN_CONFIGURE_ARG" = 1 ]; then log "Configuring MAC address for WLAN" mac_wlan