Skip to content
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

Add function to add user to dialout/uucp #22

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion REVHubInterface/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@
# print(platform.system)
# tkinter.messagebox.showerror('Drivers Not Detected', 'Please verify the correct drivers are installed. Without the correct dirvers, firmware update functionality will be unavailable.\n\n - Windows 10 and above should automatically install the correct drivers when the Expansion Hub is plugged in.\n\n - Windows 7 requires a manual install. Please see this link for the correct driver (FTDI D2xx): https://www.ftdichip.com/Drivers/CDM/CDM21228_Setup.zip\n\n - On macOS, install libftdi via Homebrew: "brew install libftdi"\n\n - On Linux, install libftdi. On Debian/Ubuntu-based systems, install it via "sudo apt install libftdi1"\n\nException Message:\n' + str(e))
if not serialaccess.hasAccess():
tkinter.messagebox.showerror("User does not have serial access", "Your user does not have access to serial. Switch to a user that does, or add your user to a group that has serial access.\nhttps://github.com/unofficial-rev-port/REVHubInterface/blob/main/README.md#access-to-serial-on-linux")
if tkinter.messagebox.askyesno("User does not have serial access", "Your user likely does not have access to serial. Switch to a user that does, or add your user to a group that has serial access. For more details, see our documentation:\n\nhttps://github.com/unofficial-rev-port/REVHubInterface/blob/main/README.md#access-to-serial-on-linux\n\nWould you like to configure your user to have serial access?"):
try:
serialaccess.getAccess()
except Exception as e:
tkinter.messagebox.showerror(message = "Failed to add the user to the group! Please report this error to the developers:\n\n" + str(e))

def error(windowName: str, error: Exception) -> None:
errName = str(error)
Expand Down
25 changes: 25 additions & 0 deletions REVHubInterface/serialaccess.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,28 @@ def hasAccess():
except KeyError:
return False
else: return True

def getAccess():
# Get all groups that exist on the system
all_groups = grp.getgrall()

# Check if 'dialout' or 'uucp' is in any of the available group names, and set it as the group to use if so
group_to_use = 'unknown'
for group in all_groups:
if 'dialout' in group.gr_name.lower():
group_to_use = 'dialout'
break
if 'uucp' in group.gr_name.lower():
group_to_use = 'uucp'
break

if group_to_use == 'unknown':
raise Exception("Neither dialout or uucp seem to exist.")

if os.path.exists("/usr/bin/flatpak-spawn"):
command_result = os.system("/usr/bin/flatpak-spawn --host pkexec usermod $USER -a -G dialout")
else:
command_result = os.system("pkexec usermod $USER -a -G dialout")

if command_result != 0:
raise Exception("Unexpected command exit code: " + str(command_result))