OttPeterR / addon-babybuddy

BabyBuddy, wrapped into a Home Assistant addon
31 stars 12 forks source link

How can I access the baby buddy command line? #38

Closed nbanderso closed 1 year ago

nbanderso commented 1 year ago

Hi,

I am hosting Baby Buddy as a Home Assistant Add-on and I stupidly made all users have the decreased access of "standard." Apparently the only way I can revert this back js by creating a user via command line.

How can I run a python script in command line under the Baby Buddy Add-on?

Thanks

OttPeterR commented 1 year ago

that doesn't sound fun! I think I know how to help though:

  1. install the SSH addon for HA, then run docker ps | grep baby to find the docker name of the baby buddy addon, copy it to use in this next command.
  2. ssh into the addon like this docker exec -it addon_????_baby_buddy /bin/bash then you can do whatever you need to do inside there.

Let me know if this does it for you!

nbanderso commented 1 year ago

@OttPeterR Thanks! That got me into the docker container but I'm not sure how to proceed from there.

Specifically, I am trying to run the following command:

python manage.py createuser --username <username> --is-staff

when doing so (within the docker container), I get the following error message:

"bash: python: command not found"

I also tried running in python3 using the following command:

python3 manage.py createuser --username <username> --is-staff

when running this I get the following message:

"python3: can't open file '/manage.py': [Errno 2] No such file or directory"

any ideas on how to proceed? Thanks in advance for your help!

OttPeterR commented 1 year ago

I'm not too familiar with how to run those baby buddy utilities, but I looked around inside the container and I found the file you want. It's located at /app/babybuddy/manage.py so try cding into that directory and running the command again with python3 😄

cdubz commented 1 year ago

As @OttPeterR notes you'll need to cd /app/babybuddy and run the command from there. And just want to add -- you may also need to run export DJANGO_SETTINGS_MODULE="babybuddy.settings.base" before executing the command.

nbanderso commented 1 year ago

You guys are seriously awesome! @cdubz this got me closer but I am running into a new snag now. I ran the following:

export DJANGO_SETTINGS_MODULE="babybuddy.settings.base"

cd /app/babybuddy

python3 manage.py createuser --username onetimeuse --is-staff

this gave me the following:

Traceback (most recent call last):
  File "/usr/lib/python3.10/site-packages/django/template/utils.py", line 69, in __getitem__
    return self._engines[alias]
KeyError: 'django'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/app/babybuddy/manage.py", line 27, in <module>
    execute_from_command_line(sys.argv)
  File "/usr/lib/python3.10/site-packages/django/core/management/__init__.py", line 446, in execute_from_command_line
    utility.execute()
  File "/usr/lib/python3.10/site-packages/django/core/management/__init__.py", line 440, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/usr/lib/python3.10/site-packages/django/core/management/base.py", line 402, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/usr/lib/python3.10/site-packages/django/core/management/base.py", line 443, in execute
    self.check()
  File "/usr/lib/python3.10/site-packages/django/core/management/base.py", line 475, in check
    all_issues = checks.run_checks(
  File "/usr/lib/python3.10/site-packages/django/core/checks/registry.py", line 88, in run_checks
    new_errors = check(app_configs=app_configs, databases=databases)
  File "/usr/lib/python3.10/site-packages/django/contrib/admin/checks.py", line 78, in check_dependencies
    for engine in engines.all():
  File "/usr/lib/python3.10/site-packages/django/template/utils.py", line 94, in all
    return [self[alias] for alias in self]
  File "/usr/lib/python3.10/site-packages/django/template/utils.py", line 94, in <listcomp>
    return [self[alias] for alias in self]
  File "/usr/lib/python3.10/site-packages/django/template/utils.py", line 85, in __getitem__
    engine = engine_cls(params)
  File "/usr/lib/python3.10/site-packages/django/template/backends/django.py", line 25, in __init__
    options["libraries"] = self.get_templatetag_libraries(libraries)
  File "/usr/lib/python3.10/site-packages/django/template/backends/django.py", line 43, in get_templatetag_libraries
    libraries = get_installed_libraries()
  File "/usr/lib/python3.10/site-packages/django/template/backends/django.py", line 117, in get_installed_libraries
    return {
  File "/usr/lib/python3.10/site-packages/django/template/backends/django.py", line 117, in <dictcomp>
    return {
  File "/usr/lib/python3.10/site-packages/django/template/backends/django.py", line 106, in get_template_tag_modules
    for name in get_package_libraries(pkg):
  File "/usr/lib/python3.10/site-packages/django/template/backends/django.py", line 129, in get_package_libraries
    module = import_module(entry[1])
  File "/usr/lib/python3.10/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 883, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "/usr/lib/python3.10/site-packages/qr_code/templatetags/qr_code.py", line 6, in <module>
    from qr_code.qrcode.maker import make_qr_code_with_args, make_qr_code_url_with_args
  File "/usr/lib/python3.10/site-packages/qr_code/qrcode/maker.py", line 12, in <module>
    from qr_code.qrcode.serve import make_qr_code_url
  File "/usr/lib/python3.10/site-packages/qr_code/qrcode/serve.py", line 67, in <module>
    _RANDOM_TOKEN = _make_random_token()
  File "/usr/lib/python3.10/site-packages/qr_code/qrcode/serve.py", line 63, in _make_random_token
    url_protection_options = get_url_protection_options()
  File "/usr/lib/python3.10/site-packages/qr_code/qrcode/serve.py", line 55, in get_url_protection_options
    options = _get_default_url_protection_options()
  File "/usr/lib/python3.10/site-packages/qr_code/qrcode/serve.py", line 23, in _get_default_url_protection_options
    constants.SIGNING_KEY: settings.SECRET_KEY,
  File "/usr/lib/python3.10/site-packages/django/conf/__init__.py", line 101, in __getattr__
    raise ImproperlyConfigured("The SECRET_KEY setting must not be empty.")
django.core.exceptions.ImproperlyConfigured: The SECRET_KEY setting must not be empty.
cdubz commented 1 year ago

I think you can take this straight from the run file --

export SECRET_KEY="${SECRET_KEY:-`cat /config/.secretkey`}"
nbanderso commented 1 year ago

That worked! Thanks @OttPeterR and @cdubz

Is there some way I can show my gratitude for everything you guys are doing to help clueless dads like me? I seriously appreciate it!

OttPeterR commented 1 year ago

I'm just happy to help! If you wanna give a star to each of our GitHub repos that'd be nice though 😊