Use apt-get commands

arent you missing the bash instruction here?

like : setup: bash /config/scripts/setup.sh

you could add the bash command indd but I works without here as well

if you make your scripts executable chmod +x setup. sh should work as well
it depends on your system

Yeah, it works, but I also need to load modules with modprobe, that doesn’t work :frowning:

hmm, tried it today, with automation, but then it fails

created an requirements.sh with this as content and did a chmod +x on it :slight_smile:

#!/bin/bash
sudo apk add can-utils

if i run it from putty, then it works, it installs that package

bash /config/python_scripts/requirements.sh

if i run it from the automation

- alias: Dobiss Server
  initial_state: 'on'
  trigger:
    - platform: homeassistant
      event: start
  action:
    - service: shell_command.requirements

shell_command:
requirements: bash /config/python_scripts/requirements.sh

then i receve error below

2021-02-17 09:35:51 ERROR (MainThread) [homeassistant.components.shell_command] Error running command: bash /config/python_scripts/requirements.sh, return code: 127

if i remove the sudo from the .sh script, i get error 1 instead of error 127

any idea?

it has todo with environment, i know the yaml code is correct, because if i try something simple in the bash script, it creates the abc.txt file, so everything is fired

it has something todo with rights i think of installing an file , with maybe the user that runs teh script not able to install apk files? with or without sudo gives me another error 1 or 127

#!/bin/bash
apk add can-utils
#echo abc > abc.txt

return code: 1 

############

#!/bin/bash
sudo apk add can-utils
#echo abc > abc.txt

return code: 127

chmod a+x doesnt help either

Hi, not sure what the problem is, but you can try executing the command with exec myScript.sh to test. Follow it with echo $? to get the exit status. Exec will close your terminal session so maybe wrap it $(exec myScript.sh)

The Shebang(#!) must be on the first line of the file with no whitespace between the start of the file and the Shebang.

Try a space between the Shebang and the /bin/bash. Most of the time it doesn’t matter because it’s launched from a shell and processed by that shell also exec is usually smart enough. In this case it may be that the exec command processor is looking for the area between the first space and the end of the line. I’ve seen this happen on a Linux system before. Not HA, but others.

BTW. HA default is #!/usr/bin/with-contenv bashio. Try this one.

Here’s a list of valid Shebangs I found on the terminal addon. Run On Startup.d

I have solved it, all command were actually fine, but I opened an session in docker itself, to see what went wrong, because it worked in an ssh session from ssh addon … Seems ssh add-on is running alpine 3.13 and HassOs is running 3.12 and that apk is not part of 3.12 …
So I needed to modify script to download another apk version

Hmm I’m having a small issue: Where do you put the following:

shell_command: 
setup: /config/scripts/setup.sh

Does this go in /config/configuration.yaml or another location?

I put the following in the /config/configuration.yaml file:

shell_command:
  setup: /config/shell/setup.sh

My /config/automations

- id: '1635091517986'
  alias: startup
  description: Adds APK packages to HomeAssistant through apk package manager at boot
  trigger:
  - platform: homeassistant
    event: start
  action:
  - service: shell_command.setup
  initial_state: 'on'

Here is /config/shell/setup.sh:

#! /bin/sh

# apk_add_packages_at_boot.sh
# Script taken from: https://community.home-assistant.io/t/use-apt-get-commands/236873/4

apk update
apk add git-lfs

My log files however say this:

startup: Error executing script. Service not found for call_service at pos 1: Unable to find service shell_command.setup

try to do it manually first

3 Likes

@elRadix

OK - I tried manually. I could install the package. Being this is a docker image however, the added file isn’t going to stay after reboot.

In doing some reading – I think I’m approaching things a little wrong, With what you’re telling me to do I’m adding git-lfs package inside the docker container – homeassistant. I think however I want to add git lfs inside the Home Assistant OS – not the container. I can add this package inside the OS – however after a reboot it’s gone as well.

Based on the information I’m gathering, it looks like there is a great method to add permanent packages inside the homeassistant OS :frowning:

I have the script running at each reboot executing the shell command
you can also execute the the shell command manually in dev tools

automation:

- id: hass_1
  initial_state: true
  alias: System Startup Notification
  trigger:
    platform: homeassistant
    event: start
  action:
    - service: notify.telegram
      data:
        message: Home Assistant back online! at {{now().strftime("%H:%M:%S")}}
    - service: shell_command.setup

setup: !secret shell_command_setup
shell_command_setup: "/config/scripts/setup.sh"

setup. sh

#!/bin/sh
echo "Updating Image with Easyplus Tools"
apk update
apk add -u busybox
apk add busybox-extras
apk add expect
apk add sshpass
pip3 install pexpect
echo "Easyplus Tools Installed"
sh /config/scripts/ssh-login-alert-telegram/deploy.sh
1 Like

What files are you putting the following commands in:

setup: !secret shell_command_setup

shell_command_setup: "/config/scripts/setup.sh"

How do you add packages to the HassOS system? When I access it, I get “apk add…” Apk not found …

Is there also a way to make it permanent after a reboot?

I need to compile something, inside the HassOS itself, I need to add the linux-headers

1 Like

any idea here? having the same issue,
trying to install htop inside haas OS

HassOS is based on buildroot, not possible to add packages there… You can however add packages in the homeassistant container

@pergola.fabio yes, so it means i cant install htop inside HassOS?

no, not inside hassos, only inside homeassistant container

see below

remember, you need todo it again on an HA update, or just add in an automation

image

@pergola.fabio yes got it, but sometimes you need analyze hassos instead of homeassistant container. my homeassistant was eating 50% cpu constantly and to find out the issue i need to login into hassos and find out the problematic process… it wont be possible on container level.

HassOS isnt alpine, its buildroot, there is no package installer there