diff --git a/subscripts/5Udev_rules/1Add_udev_rules.sh b/subscripts/5Udev_rules/1Add_udev_rules.sh new file mode 100755 index 0000000..ee3a9aa --- /dev/null +++ b/subscripts/5Udev_rules/1Add_udev_rules.sh @@ -0,0 +1,223 @@ +#!/bin/bash + +source "$(dirname "$0")/DISREGARD_common/udev_rules_common.sh" + +choose_write_mode() { + local title="$1" + local prompt="$2" + OPTIONS=( + "1" "Create a new file" + "2" "Append to existing file" + ) + local choice + choice=$(show_menu "$title" "$prompt") + + if [ $? -ne 0 ]; then + exit 1 + fi + + if [ "$choice" = "1" ]; then + printf '%s\n' "new" + else + printf '%s\n' "append" + fi +} + +choose_frame_template() { + list_files_from_dir "$(dirname "$0")/DISREGARD_udev_rules" "Udev config" "Select which udev rules you want to use:" "No udev rules were found." +} + +resolve_rules_target_path() { + local file_name="$1" + + if [[ "$file_name" == /* ]]; then + printf '%s\n' "$file_name" + return + fi + + if [[ "$file_name" != *.rules ]]; then + file_name="${file_name}.rules" + fi + + printf '/etc/udev/rules.d/%s\n' "$file_name" +} + +get_device_info() { + local device="$1" + local device_path="/dev/$device" + local device_info + + device_info=$(udevadm info "$device_path" | grep "S: serial/by-id/" || true) + device_info="${device_info}\n$(udevadm info "$device_path" | grep "DEVNAME" || true)" + device_info="${device_info}\n$(udevadm info "$device_path" | grep "ID_VENDOR_FROM_DATABASE" || true)" + device_info="${device_info}\n$(udevadm info "$device_path" | grep "ID_MODEL_FROM_DATABASE" || true)" + device_info="${device_info}\n$(udevadm info "$device_path" | grep "ID_VENDOR_ID" || true)" + device_info="${device_info}\n$(udevadm info "$device_path" | grep "ID_MODEL_ID" || true)" + device_info="${device_info}\n$(udevadm info "$device_path" | grep "ID_MODEL=" || true)" + device_info="${device_info}\n$(udevadm info "$device_path" | grep "ID_SERIAL=" || true)" + device_info="${device_info}\n$(udevadm info "$device_path" | grep "ID_SERIAL_SHORT" || true)" + device_info="${device_info}\n$(udevadm info "$device_path" | grep "ID_PCI_CLASS_FROM_DATABASE" || true)" + device_info="${device_info}\n$(udevadm info "$device_path" | grep "ID_PCI_SUBCLASS_FROM_DATABASE" || true)" + + printf '%b\n' "$device_info" +} + +get_udev_value() { + local device="$1" + local key="$2" + udevadm info "/dev/$device" | grep "$key" | head -n 1 | sed -e "s/^.*=//" +} + +choose_mrs_board() { + # Shows a dialog with a list of .rules files from the DISREGARD_udev_rules directory and allows the user to select one + template_file=$(choose_frame_template) + + # If no template file was found or selected, exit the script + if [ -z "$template_file" ]; then + exit 1 + fi + + # Replace placeholder values in the rules template + template_contents=$(sed -e "s/TO_BE_REPLACED/$USER/g" "$template_file") + + printf "%s\n\n" "$template_contents" >>"$tmp_file" +} + +configure_connected_devices() { + # List devices that the user might be interesting in adding udev rules for + devices=$(ls /dev | grep -e ttyUSB -e ttyACM -e ttyTHS) + + if [ -z "$devices" ]; then + msg_box "No devices matching the ttyUSBx, ttyACMx, or ttyTHS pattern found." + exit 1 + fi + + generated_rules="" + + # Loop over found devices and for each prompt user whether they want to add a udev rule for that device. + # If they do, ask what they want to name the symlink for that device and then write the corresponding udev rule to target file + for device in $devices; do + device_info=$(get_device_info "$device") + idVendor=$(get_udev_value "$device" "ID_VENDOR_ID") + idProduct=$(get_udev_value "$device" "ID_MODEL_ID") + Serial=$(get_udev_value "$device" "ID_SERIAL_SHORT") + + yesno_def_yes "Do you want to add a udev rule for this device? $device:\n$device_info" + ret_val=$? + + # skip unless user answered Yes (return code 0) + if [ $ret_val -ne 0 ]; then + continue + fi + + symlink=$(input_box "What should this device be named?") + if [ -z "$symlink" ]; then + continue + fi + + rule_line="SUBSYSTEM==\"tty\", ATTRS{idVendor}==\"$idVendor\", ATTRS{idProduct}==\"$idProduct\"" + if [ -n "$Serial" ]; then + rule_line="$rule_line, ATTRS{serial}==\"$Serial\"" + fi + rule_line="$rule_line, SYMLINK+=\"$symlink\", OWNER=\"$USER\", MODE=\"0666\"" + + generated_rules+="$rule_line"$'\n' + done + + if [ -z "$generated_rules" ]; then + msg_box "No udev rules were added." + exit 1 + fi + + echo "$generated_rules" >>"$tmp_file" +} + +choose_where_write_rules() { + # Shows a dialog asking how to store the rule, either in a new file or appended to an existing one + # If the user chooses to create a new file, they are asked for the name of the new file. + # If a file with that name already exists, the script asks if the user wants to overwrite the file + write_mode=$(choose_write_mode "Udev config" "How do you want to store these udev rules?") + if [ "$write_mode" = "new" ]; then + target_file_name=$(input_box "What should the new udev rules file be named?" "99-usb-serial-MRS.rules") + if [ -z "$target_file_name" ]; then + exit 1 + fi + + target_file=$(resolve_rules_target_path "$target_file_name") + if [ -z "$target_file" ]; then + exit 1 + fi + + if [ -e "$target_file" ]; then + yesno_def_no "The file already exists: $target_file\n\nDo you want to overwrite this file with the selected rules instead?" + ret_val=$? + + # If user did not agree to overwrite, abort + if [ $ret_val -ne 0 ]; then + exit 1 + fi + + fi + elif [ "$write_mode" = "append" ]; then + target_file=$(list_existing_udev_rules_file) + if [ -z "$target_file" ]; then + exit 1 + fi + else + exit 1 + fi +} + +# Create a temp file for the rules before we write them to the final destination +tmp_file=$(mktemp) +trap 'rm -f "$tmp_file"' EXIT # Ensure the temp file is removed when the script exits + +# Ask if the user has a distribution board +yesno_def_yes "Do you have a MRS distribution board with existing udev .rules file?" +ret_val=$? + +if [ $ret_val -eq 0 ]; then + choose_mrs_board +fi + +# Ask if the user wants to add rules for connected devices (ttyUSBx, ttyACMx, ttyTHSx) +yesno_def_yes "Do you want to add rules for connected devices (ttyUSBx, ttyACMx, ttyTHSx)?" +ret_val=$? + +if [ $ret_val -eq 0 ]; then + configure_connected_devices +fi + +# If the temp file is empty at this point, there are no rules to write, so we can exit the script +if [ ! -s "$tmp_file" ]; then + msg_box "No udev rules were selected or generated, so nothing to write." + exit 1 +fi + +# Ask the user where they want to write the rules (new file, overwrite existing file, append to existing file) +choose_where_write_rules + +sed -i '1s/^/# Following lines were added by MRS UAV System Install utility:\n/' $tmp_file + +yesno_def_yes "Write the following rules to this file?\nTarget: $target_file\n\nNew rules:\n$(cat "$tmp_file")" +ret_val=$? + +# abort if user did not confirm +if [ $ret_val -ne 0 ]; then + exit 1 +fi + +if [ "$write_mode" = "new" ]; then + # If the user chose to create a new file, we can just move the temp file to the target location + sudo mv "$tmp_file" "$target_file" +else + # If the user chose to append to an existing file, we need to concatenate the temp file with the existing file and write the result to the target location + cat "$tmp_file" >>"$target_file" + rm "$tmp_file" +fi + +sudo chown root:root "$target_file" +sudo chmod 644 "$target_file" + +sudo udevadm control --reload-rules +sudo udevadm trigger diff --git a/subscripts/5Udev_rules/1Setup_new_udev_rules_file.sh b/subscripts/5Udev_rules/1Setup_new_udev_rules_file.sh deleted file mode 100755 index 877505f..0000000 --- a/subscripts/5Udev_rules/1Setup_new_udev_rules_file.sh +++ /dev/null @@ -1,210 +0,0 @@ -#!/bin/bash -show_menu() { - whiptail --title "Udev config" --menu "$1:" 0 0 0 "${OPTIONS[@]}" 3>&1 1>&2 2>&3 -} - -yesno_def_no () { - whiptail --title "Netplan Config" --yesno "$1" --yes-button "No" --no-button "Yes" 0 0 - ret_val=$? - - if [ $ret_val -eq 255 ]; then - exit 1 - elif [ $ret_val -eq 1 ]; then - # echo "User hit Yes" - return 1 - elif [ $ret_val -eq 0 ]; then - # echo "User hit No" - return 0 - else - echo "Error state" - fi -} - -yesno_def_yes () { - whiptail --title "Netplan Config" --yesno "$1" 0 0 - ret_val=$? - - if [ $ret_val -eq 255 ]; then - exit 1 - elif [ $ret_val -eq 0 ]; then - # echo "User hit Yes" - return 1 - elif [ $ret_val -eq 1 ]; then - # echo "User hit No" - return 0 - else - echo "Error state" - fi -} - -input_box () { - tmp=$(whiptail --inputbox "$1" 0 0 "$2" 3>&1 1>&2 2>&3) - ret_val=$? - - if [ $ret_val -eq 255 ]; then - # User hit Escape - exit 1 - elif [ $ret_val -eq 1 ]; then - # User hit Cancel - exit 1 - elif [ $ret_val -eq 0 ]; then - # valid input - echo $tmp #this will output the string that is user input, and we can capture it into a variable - e.g. foo=$(input_box) - return 0 - else - echo "Error state" - exit 0 - fi -} - -error_msg () { - whiptail --title "Netplan config" --msgbox "$1" 0 0 -} - -yesno_def_no "Delete some selected previous udev rules files? (Remanants from previous setups etc.)" -ret_val=$? - -if [ $ret_val -eq 1 ]; then - OPTIONS=() - FULL_FILEPATHS=() - - folder_path="/etc/udev/rules.d" - index="1" - for file in "$folder_path"/*; do - filename=$file - filename="${file##*"/"}" - # filename="${filename%.*}" - # filename="${filename//_/ }" - - if [[ ! -d ${file} ]]; then - OPTIONS+=("$index") - let "index++" - has_99=$(echo $filename | grep "99") - OPTIONS+=("$filename") - OPTIONS+=("OFF") - FULL_FILEPATHS+=("$file") - fi - done - - SELECTIONS=$(whiptail --separate-output --title "Udev rules setup" --checklist "Delete any previous udev rules file?\nCAUTION - this can break things! Only delete files if you know what you are doing.\n\nChoose options by pressing the spacebar" 0 0 0 "${OPTIONS[@]}" 3>&1 1>&2 2>&3) - - ret_val=$? - - if [[ "$ret_val" -eq 1 ]]; then - exit 1 - fi - if [[ "$ret_val" -eq 255 ]]; then - exit 1 - fi - - for CHOICE in $SELECTIONS; do - sudo rm ${FULL_FILEPATHS[$((CHOICE - 1))]} - done -fi - -FILENAME=/tmp/99-usb-serial-MRS.rules -sudo rm $FILENAME - -yesno_def_yes "Are you using an MRS distribution board?" -ret_val=$? - -if [ $ret_val -eq 1 ]; then - - OPTIONS=() - FULL_FILEPATHS=() - - folder_path="$(dirname "$0")/DISREGARD_udev_rules" - index="1" - for file in "$folder_path"/*; do - filename=$file - filename="${file##*"/"}" - # filename="${filename%.*}" - # filename="${filename//_/ }" - - if [[ ! -d ${file} ]]; then - OPTIONS+=("$index") - let "index++" - has_99=$(echo $filename | grep "99") - OPTIONS+=("$filename") - FULL_FILEPATHS+=("$file") - fi - done - # echo $OPTIONS - - chosen_filename="" - choice=$(show_menu "What frame udev rules do you want to use?") - if [ $? -eq 0 ]; then - chosen_filename=$(echo ${FULL_FILEPATHS[$((choice - 1))]}) - else - # echo "Menu canceled." - exit 1 - fi - - cp $chosen_filename $FILENAME - -else - touch $FILENAME -fi - -hostname=$(cat /etc/hostname) -sudo chown root:root $FILENAME - -sudo sed -i -e "s/TO_BE_REPLACED/$hostname/g" $FILENAME - -devices=$(ls /dev | grep -e ttyUSB -e ttyACM) - -if [ -z "${devices}" ]; then - error_msg "No devices matching the ttyUSBx or ttyACMx pattern found." -else - - - for device in ${devices}; do - - device_info=$(udevadm info /dev/$device | grep "S: serial/by-id/") - device_info="${device_info}\n"$(udevadm info /dev/$device | grep "DEVNAME") - device_info="${device_info}\n"$(udevadm info /dev/$device | grep "ID_VENDOR_FROM_DATABASE") - device_info="${device_info}\n"$(udevadm info /dev/$device | grep "ID_MODEL_FROM_DATABASE") - device_info="${device_info}\n"$(udevadm info /dev/$device | grep "ID_VENDOR_ID") - device_info="${device_info}\n"$(udevadm info /dev/$device | grep "ID_MODEL_ID") - device_info="${device_info}\n"$(udevadm info /dev/$device | grep "ID_MODEL=") - device_info="${device_info}\n"$(udevadm info /dev/$device | grep "ID_SERIAL=") - device_info="${device_info}\n"$(udevadm info /dev/$device | grep "ID_SERIAL_SHORT") - device_info="${device_info}\n"$(udevadm info /dev/$device | grep "ID_PCI_CLASS_FROM_DATABASE") - device_info="${device_info}\n"$(udevadm info /dev/$device | grep "ID_PCI_SUBCLASS_FROM_DATABASE") - - idVendor=$(udevadm info /dev/$device | grep "ID_VENDOR_ID") - idVendor="${idVendor##*"="}" - idProduct=$(udevadm info /dev/$device | grep "ID_MODEL_ID") - idProduct="${idProduct##*"="}" - Serial=$(udevadm info /dev/$device | grep "ID_SERIAL_SHORT") - Serial="${Serial##*"="}" - - - yesno_def_yes "Do you want to add udev rule for this device? $device:\n$device_info" - ret_val=$? - - if [ ! $ret_val -eq 1 ]; then - continue - fi - - symlink=$(input_box "What should this device be named?") # NOTE - when called like this, we cannot "exit 0" from within the inputbox() function, as it is ran in a sub-shell, and the exit will only exit the sub-shell - ret_val=$? - - if [ $ret_val -eq 255 ]; then - exit 1 - fi - if [ $ret_val -eq 1 ]; then - exit 1 - else - echo -e "\n#Following line was added by MRS UAV System Intall utility:" | sudo tee -a $FILENAME > /dev/null - - if [ -z "${Serial}" ]; then - echo -e "SUBSYSTEM==\"tty\", ATTRS{idVendor}==\"$idVendor\", ATTRS{idProduct}==\"$idProduct\", SYMLINK+=\"$symlink\", OWNER=\"$hostname\", MODE=\"0666\"" | sudo tee -a $FILENAME > /dev/null - else - echo -e "SUBSYSTEM==\"tty\", ATTRS{idVendor}==\"$idVendor\", ATTRS{idProduct}==\"$idProduct\", ATTRS{serial}==\"$Serial\", SYMLINK+=\"$symlink\", OWNER=\"$hostname\", MODE=\"0666\"" | sudo tee -a $FILENAME > /dev/null - fi - fi - done -fi - -sudo cp $FILENAME /etc/udev/rules.d/ diff --git a/subscripts/5Udev_rules/2Add_udev_rules_to_an_existing_file.sh b/subscripts/5Udev_rules/2Add_udev_rules_to_an_existing_file.sh deleted file mode 100755 index 3384abe..0000000 --- a/subscripts/5Udev_rules/2Add_udev_rules_to_an_existing_file.sh +++ /dev/null @@ -1,142 +0,0 @@ -#!/bin/bash - -show_menu() { - whiptail --title "Udev config" --menu "$1:" 0 0 0 "${OPTIONS[@]}" 3>&1 1>&2 2>&3 -} - -inputbox() { - whiptail --inputbox "$1" 10 30 3>&1 1>&2 2>&3 -} - -yesno_def_no () { - whiptail --title "Udev Config" --yesno "$1" --yes-button "No" --no-button "Yes" 0 0 - ret_val=$? - - if [ $ret_val -eq 255 ]; then - exit 1 - elif [ $ret_val -eq 1 ]; then - # echo "User hit Yes" - return 1 - elif [ $ret_val -eq 0 ]; then - # echo "User hit No" - return 0 - else - echo "Error state" - fi -} - -yesno_def_yes () { - whiptail --title "Udev Config" --yesno "$1" 0 0 - ret_val=$? - - if [ $ret_val -eq 255 ]; then - exit 1 - elif [ $ret_val -eq 0 ]; then - # echo "User hit Yes" - return 1 - elif [ $ret_val -eq 1 ]; then - # echo "User hit No" - return 0 - else - echo "Error state" - fi -} - -error_msg () { - whiptail --title "Udev config" --msgbox "$1" 0 0 -} - -OPTIONS=() -FULL_FILEPATHS=() - -folder_path="/etc/udev/rules.d" -index="1" -for file in "$folder_path"/*; do - filename=$file - filename="${file##*"/"}" - # filename="${filename%.*}" - # filename="${filename//_/ }" - - if [[ ! -d ${file} ]]; then - OPTIONS+=("$index") - let "index++" - has_99=$(echo $filename | grep "99") - OPTIONS+=("$filename") - FULL_FILEPATHS+=("$file") - fi -done -# echo $OPTIONS - -chosen_filename="" -choice=$(show_menu "Select which udev rules file do you want to add to:") -if [ $? -eq 0 ]; then - chosen_filename=$(echo ${FULL_FILEPATHS[$((choice - 1))]}) -else - # echo "Menu canceled." - exit 1 -fi - - -yesno_def_yes "Do you want to add to this file? $chosen_filename?\n\ncontents: \n\n\n$(cat $chosen_filename)" -ret_val=$? - -if [ ! $ret_val -eq 1 ]; then - exit 1 -fi -devices=$(ls /dev | grep -e ttyUSB -e ttyACM) - -if [ -z "${devices}" ]; then - error_msg "No devices matching the ttyUSBx or ttyACMx pattern found." -else - - hostname=$(cat /etc/hostname) - - for device in ${devices}; do - - device_info=$(udevadm info /dev/$device | grep "S: serial/by-id/") - device_info="${device_info}\n"$(udevadm info /dev/$device | grep "DEVNAME") - device_info="${device_info}\n"$(udevadm info /dev/$device | grep "ID_VENDOR_FROM_DATABASE") - device_info="${device_info}\n"$(udevadm info /dev/$device | grep "ID_MODEL_FROM_DATABASE") - device_info="${device_info}\n"$(udevadm info /dev/$device | grep "ID_VENDOR_ID") - device_info="${device_info}\n"$(udevadm info /dev/$device | grep "ID_MODEL_ID") - device_info="${device_info}\n"$(udevadm info /dev/$device | grep "ID_MODEL=") - device_info="${device_info}\n"$(udevadm info /dev/$device | grep "ID_SERIAL=") - device_info="${device_info}\n"$(udevadm info /dev/$device | grep "ID_SERIAL_SHORT") - device_info="${device_info}\n"$(udevadm info /dev/$device | grep "ID_PCI_CLASS_FROM_DATABASE") - device_info="${device_info}\n"$(udevadm info /dev/$device | grep "ID_PCI_SUBCLASS_FROM_DATABASE") - - idVendor=$(udevadm info /dev/$device | grep "ID_VENDOR_ID") - idVendor="${idVendor##*"="}" - idProduct=$(udevadm info /dev/$device | grep "ID_MODEL_ID") - idProduct="${idProduct##*"="}" - Serial=$(udevadm info /dev/$device | grep "ID_SERIAL_SHORT") - Serial="${Serial##*"="}" - - - yesno_def_yes "Do you want to add udev rule for this device? $device:\n$device_info" - ret_val=$? - - if [ ! $ret_val -eq 1 ]; then - continue - fi - - symlink=$(inputbox "What should this device be named?") # NOTE - when called like this, we cannot "exit 0" from within the inputbox() function, as it is ran in a sub-shell, and the exit will only exit the sub-shell - ret_val=$? - - if [ $ret_val -eq 255 ]; then - exit 1 - fi - if [ $ret_val -eq 1 ]; then - exit 1 - else - echo $symlink - echo -e "\n#Following line was added by MRS UAV System Intall utility:" | sudo tee -a $chosen_filename > /dev/null - - if [ -z "${Serial}" ]; then - echo -e "SUBSYSTEM==\"tty\", ATTRS{idVendor}==\"$idVendor\", ATTRS{idProduct}==\"$idProduct\", SYMLINK+=\"$symlink\", OWNER=\"$hostname\", MODE=\"0666\"" | sudo tee -a $chosen_filename > /dev/null - else - echo -e "SUBSYSTEM==\"tty\", ATTRS{idVendor}==\"$idVendor\", ATTRS{idProduct}==\"$idProduct\", ATTRS{serial}==\"$Serial\", SYMLINK+=\"$symlink\", OWNER=\"$hostname\", MODE=\"0666\"" | sudo tee -a $chosen_filename > /dev/null - fi - fi - done -fi diff --git a/subscripts/5Udev_rules/2Remove_udev_rules.sh b/subscripts/5Udev_rules/2Remove_udev_rules.sh new file mode 100755 index 0000000..09383d8 --- /dev/null +++ b/subscripts/5Udev_rules/2Remove_udev_rules.sh @@ -0,0 +1,23 @@ +#!/bin/bash + +source "$(dirname "$0")/DISREGARD_common/udev_rules_common.sh" + +target_file=$(list_existing_udev_rules_file) +if [ -z "$target_file" ]; then + exit 1 +fi + +yesno_def_yes "Do you want to delete this file?\nFile: $target_file\nContents:\n$(cat "$target_file")" +ret_val=$? + +# abort if user did not confirm +if [ $ret_val -ne 0 ]; then + exit 1 +fi + +sudo rm "$target_file" + +sudo udevadm control --reload-rules +sudo udevadm trigger + +exit 1 # Exit 1 so that we go back to the udev menu instead of the main menu diff --git a/subscripts/5Udev_rules/3List_udev_rules.sh b/subscripts/5Udev_rules/3List_udev_rules.sh new file mode 100755 index 0000000..31b5f0c --- /dev/null +++ b/subscripts/5Udev_rules/3List_udev_rules.sh @@ -0,0 +1,12 @@ +#!/bin/bash + +source "$(dirname "$0")/DISREGARD_common/udev_rules_common.sh" + +target_file=$(list_existing_udev_rules_file) +if [ -z "$target_file" ]; then + exit 1 +fi + +msg_box "File: $target_file\nContents:\n$(cat "$target_file")" + +exit 1 # Exit 1 so that we go back to the udev menu instead of the main menu diff --git a/subscripts/5Udev_rules/DISREGARD_common/udev_rules_common.sh b/subscripts/5Udev_rules/DISREGARD_common/udev_rules_common.sh new file mode 100755 index 0000000..4061a29 --- /dev/null +++ b/subscripts/5Udev_rules/DISREGARD_common/udev_rules_common.sh @@ -0,0 +1,102 @@ +#!/bin/bash + +show_menu() { + whiptail --title "$1" --menu "$2" 0 0 0 "${OPTIONS[@]}" 3>&1 1>&2 2>&3 +} + +ask_yesno() { + local prompt="$1" + local default="$2" # "yes" or "no" + + if [ "$default" = "no" ]; then + whiptail --title "Udev Config" --yesno "$prompt" 0 0 --defaultno + else + whiptail --title "Udev Config" --yesno "$prompt" 0 0 + fi + + ret_val=$? + if [ $ret_val -eq 255 ]; then + exit 1 + elif [ $ret_val -eq 0 ]; then + return 0 + elif [ $ret_val -eq 1 ]; then + return 1 + else + echo "Error state" + exit 1 + fi +} + +yesno_def_no() { + ask_yesno "$1" "no" +} + +yesno_def_yes() { + ask_yesno "$1" "yes" +} + +input_box() { + local prompt="$1" + local default_value="$2" + local tmp + tmp=$(whiptail --inputbox "$prompt" 0 0 "$default_value" 3>&1 1>&2 2>&3) + ret_val=$? + + if [ $ret_val -eq 255 ]; then + exit 1 + elif [ $ret_val -eq 1 ]; then + exit 1 + elif [ $ret_val -eq 0 ]; then + printf '%s\n' "$tmp" + return 0 + else + echo "Error state" + exit 0 + fi +} + +msg_box() { + whiptail --title "Udev config" --msgbox "$1" 0 0 +} + +list_files_from_dir() { + local folder_path="$1" + local menu_title="$2" + local menu_prompt="$3" + local empty_message="$4" + local options=() + local files=() + local index=1 + local file + + shopt -s nullglob + for file in "$folder_path"/*; do + if [[ -d "$file" ]]; then + continue + fi + + options+=("$index" "${file##*/}") + files+=("$file") + index=$((index + 1)) + done + shopt -u nullglob + + if [ ${#files[@]} -eq 0 ]; then + msg_box "$empty_message" + return 1 + fi + + OPTIONS=("${options[@]}") + local choice + choice=$(show_menu "$menu_title" "$menu_prompt") + + if [ $? -ne 0 ]; then + exit 1 + fi + + printf '%s\n' "${files[$((choice - 1))]}" +} + +list_existing_udev_rules_file() { + list_files_from_dir "/etc/udev/rules.d" "Udev config" "Select which udev rules file you want to use:" "No files found in /etc/udev/rules.d." +} diff --git a/subscripts/5Udev_rules/DISREGARD_udev_rules/X500.rules b/subscripts/5Udev_rules/DISREGARD_udev_rules/X500.rules index 47edeb0..dc6c796 100644 --- a/subscripts/5Udev_rules/DISREGARD_udev_rules/X500.rules +++ b/subscripts/5Udev_rules/DISREGARD_udev_rules/X500.rules @@ -1,9 +1,9 @@ # RULES for X500 Distribution Board # Pixhawk -SUBSYSTEM=="tty", ATTRS{idVendor}=="0403", ATTRS{idProduct}=="6011", ENV{ID_USB_INTERFACE_NUM}=="03", SYMLINK+="pixhawk",OWNER="TO_BE_REPLACED",MODE="0666" +SUBSYSTEM=="tty", ATTRS{idVendor}=="0403", ATTRS{idProduct}=="6011", ENV{ID_USB_INTERFACE_NUM}=="02", SYMLINK+="pixhawk",OWNER="TO_BE_REPLACED",MODE="0666" # MRS Module 1 SUBSYSTEM=="tty", ATTRS{idVendor}=="0403", ATTRS{idProduct}=="6011", ENV{ID_USB_INTERFACE_NUM}=="00", SYMLINK+="MRS_MODULE1",OWNER="TO_BE_REPLACED",MODE="0666" # MRS Module 2 SUBSYSTEM=="tty", ATTRS{idVendor}=="0403", ATTRS{idProduct}=="6011", ENV{ID_USB_INTERFACE_NUM}=="01", SYMLINK+="MRS_MODULE2",OWNER="TO_BE_REPLACED",MODE="0666" # MRS Module 3 -SUBSYSTEM=="tty", ATTRS{idVendor}=="0403", ATTRS{idProduct}=="6011", ENV{ID_USB_INTERFACE_NUM}=="02", SYMLINK+="MRS_MODULE3",OWNER="TO_BE_REPLACED",MODE="0666" +SUBSYSTEM=="tty", ATTRS{idVendor}=="0403", ATTRS{idProduct}=="6011", ENV{ID_USB_INTERFACE_NUM}=="03", SYMLINK+="MRS_MODULE3",OWNER="TO_BE_REPLACED",MODE="0666" diff --git a/subscripts/5Udev_rules/DISREGARD_udev_rules/robocore.rules b/subscripts/5Udev_rules/DISREGARD_udev_rules/robocore.rules new file mode 100644 index 0000000..1c73159 --- /dev/null +++ b/subscripts/5Udev_rules/DISREGARD_udev_rules/robocore.rules @@ -0,0 +1,2 @@ +SUBSYSTEM=="tty", KERNEL=="ttyTHS0", SYMLINK+="pixhawk", OWNER="TO_BE_REPLACED", MODE="0666" +