-
Notifications
You must be signed in to change notification settings - Fork 0
Udev fixes #9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
vidvidex
wants to merge
13
commits into
ros2
Choose a base branch
from
udev_fixes
base: ros2
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Udev fixes #9
Changes from 10 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
a5b212e
fix x500 udev
1b6cc3d
robocore udev rules
Recepkoca b72fe9c
Fix title
vidvidex 1c6ba0e
Do not show error when deleting file that doesn't exist
vidvidex 728c467
Delete unused vars
vidvidex 0bd50cc
Reformat
vidvidex 8135d25
Fix typos
vidvidex bf86b34
Fix owner
vidvidex 804789b
Apply new rules immediately
vidvidex 846770c
New menu for adding udev rules
vidvidex 76714ef
Apply suggestions from code review
vidvidex b8696bc
Add execute permission
vidvidex f2f799d
Redesign udev menu
vidvidex File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| #!/bin/bash | ||
|
|
||
| source "$(dirname "$0")/DISREGARD_common/udev_rules_common.sh" | ||
|
|
||
| # 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_template_file) | ||
|
|
||
| # If no template file was found or selected, exit the script | ||
| if [ -z "$template_file" ]; then | ||
| exit 1 | ||
| fi | ||
|
|
||
| # 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 the selected 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 [ $ret_val -eq 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 | ||
|
|
||
| # Replace placeholder values in the rules template | ||
| template_contents=$(sed -e "s/TO_BE_REPLACED/$USER/g" "$template_file") | ||
|
|
||
| # Confirm before writing | ||
| yesno_def_yes "Write the selected rules to this file?\n\nTarget: $target_file\n\nTemplate: $(basename "$template_file")\n\nContents:\n\n$template_contents" | ||
| ret_val=$? | ||
|
|
||
| if [ ! $ret_val -eq 1 ]; then | ||
| exit 1 | ||
| fi | ||
|
|
||
| write_text_to_target "$target_file" "$write_mode" "$template_contents" | ||
| ret_val=$? | ||
| if [ $ret_val -eq 1 ]; then | ||
| exit 1 | ||
| fi | ||
|
|
||
| sudo chown root:root "$target_file" | ||
| sudo chmod 644 "$target_file" | ||
|
|
||
| sudo udevadm control --reload-rules | ||
| sudo udevadm trigger |
This file was deleted.
Oops, something went wrong.
89 changes: 89 additions & 0 deletions
89
subscripts/5Udev_rules/2Add_from_currently_connected_devices.sh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| #!/bin/bash | ||
|
|
||
| source "$(dirname "$0")/DISREGARD_common/udev_rules_common.sh" | ||
|
|
||
| # 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 the device 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") | ||
| target_file=$(resolve_rules_target_path "$target_file_name") | ||
|
|
||
| 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 [ $ret_val -eq 0 ]; then | ||
| exit 1 | ||
| fi | ||
| fi | ||
| else | ||
| target_file=$(list_existing_udev_rules_file) | ||
| if [ -z "$target_file" ]; then | ||
| exit 1 | ||
| fi | ||
| fi | ||
|
|
||
| # 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 | ||
| error_msg "No devices matching the ttyUSBx, ttyACMx, or ttyTHS pattern found." | ||
| exit 1 | ||
| fi | ||
|
|
||
| wrote_anything=false | ||
| 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=$? | ||
|
|
||
| if [ ! $ret_val -eq 1 ]; then | ||
| continue | ||
| fi | ||
|
|
||
| symlink=$(input_box "What should this device be named?") | ||
|
|
||
| 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\"" | ||
|
|
||
| if [ "$wrote_anything" = false ]; then | ||
| generated_rules="# Following line was added by MRS UAV System Install utility:\n${rule_line}" | ||
| wrote_anything=true | ||
| else | ||
| generated_rules="${generated_rules}\n\n# Following line was added by MRS UAV System Install utility:\n${rule_line}" | ||
| fi | ||
|
vidvidex marked this conversation as resolved.
Outdated
|
||
| done | ||
|
|
||
| if [ "$wrote_anything" = false ]; then | ||
| error_msg "No udev rules were added." | ||
| exit 1 | ||
| fi | ||
|
|
||
| yesno_def_yes "Write the generated rules to this file?\n\nTarget: $target_file\n\nGenerated rules:\n\n$generated_rules" | ||
| ret_val=$? | ||
|
|
||
| if [ ! $ret_val -eq 1 ]; then | ||
| exit 1 | ||
| fi | ||
|
|
||
| write_text_to_target "$target_file" "$write_mode" "$generated_rules" | ||
|
|
||
| sudo chown root:root "$target_file" | ||
| sudo chmod 644 "$target_file" | ||
|
|
||
| sudo udevadm control --reload-rules | ||
| sudo udevadm trigger | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.