Nekmo / amazon-dash

Hack your Amazon Dash to run what you want.
MIT License
828 stars 67 forks source link

Fix OSX Compatibility Issues (workarounds included) #63

Closed frankamp closed 6 years ago

frankamp commented 6 years ago

Description

I tried to run this on OSX. It errors during the install step trying to determine whether I have systemd and during the run step trying to write an error message about the write permissions of the config file, because root is not a valid group.

What I Did

During install it bombs here:

return check_output(['ps', '--no-headers', '-o', 'comm', '1']).strip(b'\n ').decode('utf-8')

So I commented out line 99 in the init of the install path re: #if get_init_system() != 'systemd' or not get_systemd_services_path(): which makes it just raise an exception raise IsInstallableException('Systemd is not available'). This is fine though, because that exception is still a successful installation path re: "You must run it manually". I'm just developing on this machine, I'll run everything manually.

Then I discovered my dash button mac, and wrote a config file.

When I ran it, it complained about being unable to read a group, which turns out to be in the error handling code. I don't think I care about file permissions at all, least of all write perms. Maybe this should just be a warning?

I commented out all the write permissions error code

#   if (not os.getuid() and not only_root_write(file)) or oth_w_perm(file):
        #     file = os.path.abspath(file)
        #     raise SecurityException(
        #         'There should be no permissions for other users in the file "{file}". '
        #         'Current permissions: {user}:{group} {perms}. {msg}. '
        #         'Run "sudo chmod 660 \'{file}\' && sudo chown root:root \'{file}\'"'.format(
        #             file=file, user=get_file_owner(file),
        #             group=get_file_group(file), perms=os.stat(file).st_mode & 0o777,
        #             msg='Removes write permission for others' if os.getuid()
        #             else 'Only root must be able to write to file'))

It works fine.

Thanks for the program yo.

Nekmo commented 6 years ago

Amazon-dash has not been tested on OS X. The Amazon-dash installer does not support OSX. The installer is for Linux so you can ignore the installation step.

frankamp commented 6 years ago

It has now and it works great! I made it turn on my spotify on my machine for fun. With a couple of tweaks and a bit of docs, it would be usable by a lot of devs.

Nekmo commented 6 years ago

In a next version I will make sure that there is no error in the installation process. Thank you.

Does it work in OS X then? Does the discovery command work for you?

frankamp commented 6 years ago

Yep! I had a dash button make spotify play (using hnarayanan/shpotify cli project).

Nekmo commented 6 years ago

Thank you :)

Nekmo commented 6 years ago

Can you please give me the exception traceback of this code in OSX?

(not os.getuid() and not only_root_write(file)) or oth_w_perm(file):
frankamp commented 6 years ago

Traceback (most recent call last): File "/usr/local/bin/amazon-dash", line 6, in catch(cli)() File "/usr/local/lib/python2.7/site-packages/amazon_dash/exceptions.py", line 91, in wrap return fn(*args, kwargs) File "/usr/local/lib/python2.7/site-packages/click/core.py", line 722, in call return self.main(args, kwargs) File "/usr/local/lib/python2.7/site-packages/click/core.py", line 697, in main rv = self.invoke(ctx) File "/usr/local/lib/python2.7/site-packages/click/core.py", line 1066, in invoke return _process_result(sub_ctx.command.invoke(sub_ctx)) File "/usr/local/lib/python2.7/site-packages/click/core.py", line 895, in invoke return ctx.invoke(self.callback, ctx.params) File "/usr/local/lib/python2.7/site-packages/click/core.py", line 535, in invoke return callback(args, kwargs) File "/usr/local/lib/python2.7/site-packages/amazon_dash/management.py", line 100, in run Listener(config).run(root_allowed=root_allowed) File "/usr/local/lib/python2.7/site-packages/amazon_dash/listener.py", line 119, in init self.config = Config(config_path) File "/usr/local/lib/python2.7/site-packages/amazon_dash/config.py", line 206, in init group=get_file_group(file), perms=os.stat(file).st_mode & 0o777, File "/usr/local/lib/python2.7/site-packages/amazon_dash/config.py", line 141, in get_file_group return getgrgid(os.stat(file).st_uid)[0] KeyError: 'getgrgid(): gid not found: 502'

On Wed, Jul 18, 2018 at 11:04 AM, Nekmo notifications@github.com wrote:

Can you please give me the exception traceback of this code in OSX?

(not os.getuid() and not only_root_write(file)) or oth_w_perm(file):

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/Nekmo/amazon-dash/issues/63#issuecomment-406022452, or mute the thread https://github.com/notifications/unsubscribe-auth/AA4YTu-Qq_eXn7tUhHDOeDeFg4ccQqtkks5uH3jLgaJpZM4VU5m3 .

Nekmo commented 6 years ago

OK thanks. I'm going to submit a patched version in the development branch. Please tell me if it works for you.

frankamp commented 6 years ago

Thanks!

On Wed, Jul 18, 2018 at 11:14 AM, Nekmo notifications@github.com wrote:

OK thanks. I'm going to launch a patched version in the development branch. Please tell me if it works for you.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/Nekmo/amazon-dash/issues/63#issuecomment-406025390, or mute the thread https://github.com/notifications/unsubscribe-auth/AA4YTsrfF88xf6PsOUJ3PXKf3LCFa7UYks5uH3sGgaJpZM4VU5m3 .

Nekmo commented 6 years ago

Please install It using:

pip install https://github.com/Nekmo/amazon-dash/archive/develop.zip

Remember to fix the permissions of the Amazon-dash configuration file:

chmod 660 amazon-dash.yml && chown root:root amazon-dash.yml

Thanks.

frankamp commented 6 years ago
chown: root: illegal group name

this is the issue, the group on osx can't be root. If we're being this specific, wouldn't 600 suffice? Ignore the group?

On Wed, Jul 18, 2018 at 11:22 AM, Nekmo notifications@github.com wrote:

Please install It using:

pip install https://github.com/Nekmo/amazon-dash/archive/develop.zip

Remember to fix the permissions of the Amazon-dash configuration file:

chmod 660 amazon-dash.yml && chown root:root amazon-dash.yml

Thanks.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/Nekmo/amazon-dash/issues/63#issuecomment-406028044, or mute the thread https://github.com/notifications/unsubscribe-auth/AA4YTqbdfSZfCGV3xg_WQh6C-JtJ48bUks5uH3z9gaJpZM4VU5m3 .

Nekmo commented 6 years ago

Yes, change chmod 660 amazon-dash.yml to chmod 600 amazon-dash.yml and chown root:root amazon-dash.yml to chown root amazon-dash.yml

frankamp commented 6 years ago

Ok pip install goes:


error in amazon-dash setup command: 'install_requires' must be a string or list of strings containing valid project/version requirement specifiers; Expected version spec in scapy;python_version<"3.0" at ;python_version<"3.0"

Command "python setup.py egg_info" failed with error code 1 in /private/var/folders/2g/5dgtldh178x86fr0zrc09kf40000gp/T/pip-iqjbSG-build/
You are using pip version 9.0.1, however version 10.0.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.```
Nekmo commented 6 years ago

I just launched a new release. I'm going to check it, thanks.

Nekmo commented 6 years ago

Please run in your system:

easy_install --version
frankamp commented 6 years ago

➜ tmpluceedockerwgroovy python --version Python 2.7.10 ➜ tmpluceedockerwgroovy easy_install --version

setuptools 18.0.1 ➜ tmpluceedockerwgroovy pip --version pip 9.0.1 from /usr/local/lib/python2.7/site-packages (python 2.7)

On Wed, Jul 18, 2018 at 4:30 PM, Nekmo notifications@github.com wrote:

Please run in your system:

easy_install --version

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/Nekmo/amazon-dash/issues/63#issuecomment-406105680, or mute the thread https://github.com/notifications/unsubscribe-auth/AA4YTogGe2vIopf4_XyG2MtLLtQVG09dks5uH8UkgaJpZM4VU5m3 .

Nekmo commented 6 years ago

Your Setuptools version is old (24 Jun 2015), you can upgrade It using:

pip install -U setuptools

Thanks for notifying.

frankamp commented 6 years ago
sudo pip install https://github.com/Nekmo/amazon-dash/archive/develop.zip

Password:
The directory '/Users/jfrankamp/Library/Caches/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/Users/jfrankamp/Library/Caches/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Collecting https://github.com/Nekmo/amazon-dash/archive/develop.zip
  Downloading https://github.com/Nekmo/amazon-dash/archive/develop.zip
     / 1.4MB 4.4MB/s
Requirement already satisfied: PyYAML>=3.0 in /usr/local/lib/python2.7/site-packages (from amazon-dash==1.1.0)
Requirement already satisfied: jsonschema in /usr/local/lib/python2.7/site-packages (from amazon-dash==1.1.0)
Requirement already satisfied: requests in /usr/local/lib/python2.7/site-packages (from amazon-dash==1.1.0)
Requirement already satisfied: click in /usr/local/lib/python2.7/site-packages (from amazon-dash==1.1.0)
Requirement already satisfied: click-default-group in /usr/local/lib/python2.7/site-packages (from amazon-dash==1.1.0)
Requirement already satisfied: scapy in /usr/local/lib/python2.7/site-packages (from amazon-dash==1.1.0)
Requirement already satisfied: subprocess32 in /usr/local/lib/python2.7/site-packages (from amazon-dash==1.1.0)
Requirement already satisfied: functools32; python_version == "2.7" in /usr/local/lib/python2.7/site-packages (from jsonschema->amazon-dash==1.1.0)
Installing collected packages: amazon-dash
  Running setup.py install for amazon-dash ... done
Successfully installed amazon-dash-1.1.0

then to run

➜  ~ chown root amazon-dash.yml
➜  ~ sudo chmod 600 amazon-dash.yml
➜  ~ sudo amazon-dash
Welcome to Amazon-dash v1.1.0 using Python 2.7.10
Listening for events. Amazon-dash will execute the events associated with the registered buttons.
ifconfig: interface vboxnet does not exist
ifconfig: interface vboxnet does not exist
ifconfig: interface vboxnet does not exist

(daemon running)

hit the Cascade button and spotify played my song.

Thanks! Looks good!

Nekmo commented 6 years ago

Thanks for your help :)