hassio-addons / addon-ssh

Advanced SSH & Web Terminal - Home Assistant Community Add-ons
https://addons.community
MIT License
348 stars 95 forks source link

Init_Commands appear not to run #795

Closed zach6439 closed 3 weeks ago

zach6439 commented 3 weeks ago

Problem/Motivation

Trying to source aliases/shell scripts via init_command, however I cannot get it to load when the add on starts. This path was chosen as it is not over-written when the add-on reboots like the .zhrc file seems to be ( I suspect as this file is reloaded with the add_on).

Manually running the command source /config/.shellstuff/scriptsandaliases will allow these aliases/scripts to run as expected.

Example of file to be sourced

# Preffered LS Readout
alias ll="ls -lah --color=auto"

# Script for ESPHome logs
el() {
    docker exec -it addon_5c53de3b_esphome bash -c "esphome logs /config/esphome/$1"
}

Expected behavior

Add on starts, file is sourced, aliases and scripts are available via the CLI.

Actual behavior

Add on starts, commands are not available via CLI. Log (Trace) Output:

[discord-shield]: https://img.shields.io/discord/478094546522079232.svg
[discord]: https://discord.me/hassioaddons
[forum-shield]: https://img.shields.io/badge/community-forum-brightgreen.svg
[forum]: https://community.home-assistant.io/t/community-hass-io-add-on-ssh-web-terminal/33820?u=frenck
[github-sponsors-shield]: https://frenck.dev/wp-content/uploads/2019/12/github_sponsor.png
[github-sponsors]: https://github.com/sponsors/frenck
[hass-ssh]: https://home-assistant.io/addons/ssh/
[maintenance-shield]: https://img.shields.io/maintenance/yes/2024.svg
[ohmyzsh]: http://ohmyz.sh/
[openssh]: https://www.openssh.com/
[patreon-shield]: https://frenck.dev/wp-content/uploads/2019/12/patreon.png
[patreon]: https://www.patreon.com/frenck
[project-stage-shield]: https://img.shields.io/badge/project%20stage-production%20ready-brightgreen.svg
[release-shield]: https://img.shields.io/badge/version-v19.0.0-blue.svg
[release]: https://github.com/hassio-addons/addon-ssh/tree/v19.0.0
[screenshot]: https://github.com/hassio-addons/addon-ssh/raw/main/images/screenshot.png
[ssh-audit-image]: https://github.com/hassio-addons/addon-ssh/raw/main/images/ssh-audit.png
[ssh-audit]: https://github.com/jtesta/ssh-audit
[zsh]: https://en.wikipedia.org/wiki/Z_shell","advanced":false,"stage":"stable","repository":"a0d7b954","version_latest":"19.0.0","protected":false,"rating":1,"boot_config":"auto","boot":"auto","options":{"ssh":{"username":"root","password":"","authorized_keys":["ssh-ed25519 XXXXXX"],"sftp":false,"compatibility_mode":false,"allow_agent_forwarding":false,"allow_remote_port_forwarding":true,"allow_tcp_forwarding":true},"zsh":true,"share_sessions":false,"packages":[],"init_commands":["source /config/.shellstuff/scriptsandaliases"],"log_level":"trace"},"schema":[{"name":"log_level","optional":true,"type":"select","options":["trace","debug","info","notice","warning","error","fatal"]},{"name":"ssh","type":"schema","optional":true,"multiple":false,"schema":[{"name":"username","required":true,"type":"string"},{"name":"password","required":true,"type":"string","format":"password"},{"name":"authorized_keys","multiple":true,"required":true,"type":"string"},{"name":"sftp","required":true,"type":"boolean"},{"name":"compatibility_mode","required":true,"type":"boolean"},{"name":"allow_agent_forwarding","required":true,"type":"boolean"},{"name":"allow_remote_port_forwarding","required":true,"type":"boolean"},{"name":"allow_tcp_forwarding","required":true,"type":"boolean"}]},{"name":"zsh","required":true,"type":"boolean"},{"name":"share_sessions","required":true,"type":"boolean"},{"name":"packages","multiple":true,"required":true,"type":"string"},{"name":"init_commands","multiple":true,"required":true,"type":"string"}],"arch":["aarch64","amd64","armv7"],"machine":[],"homeassistant":"0.92.0b2","url":"https://github.com/hassio-addons/addon-ssh","detached":false,"available":true,"build":false,"network":{"22/tcp":2267},"network_description":{"22/tcp":"SSH server port (make empty to disable)"},"host_network":true,"host_pid":false,"host_ipc":false,"host_uts":false,"host_dbus":true,"privileged":["NET_ADMIN","SYS_ADMIN","SYS_RAWIO","SYS_TIME","SYS_NICE"],"full_access":false,"apparmor":"disable","icon":true,"logo":true,"changelog":true,"documentation":true,"stdin":false,"hassio_api":true,"hassio_role":"manager","auth_api":false,"homeassistant_api":true,"gpio":true,"usb":true,"uart":true,"kernel_modules":false,"devicetree":false,"udev":false,"docker_api":true,"video":false,"audio":true,"startup":"services","services":["mysql:want","mqtt:want"],"discovery":[],"translations":{},"ingress":true,"signed":true,"state":"started","webui":null,"ingress_entry":"/api/hassio_ingress/D1OySSi6o5uH6AYWqFZCCSaa83hiV2KSNgSlpCqhPqo","ingress_url":"/api/hassio_ingress/D1OySSi6o5uH6AYWqFZCCSaa83hiV2KSNgSlpCqhPqo/","ingress_port":65060,"ingress_panel":true,"audio_input":null,"audio_output":null,"auto_update":true,"ip_address":"172.30.32.1","version":"19.0.0","update_available":false,"watchdog":true,"devices":["/dev/mem"],"system_managed":false,"system_managed_config_entry":null} .ingress_port // empty
[10:31:13] TRACE: bashio::cache.set: addons.self.ingress_port 65060
[10:31:13] TRACE: bashio::fs.directory_exists: /tmp/.bashio
[10:31:13] TRACE: bashio::config.true: zsh
[10:31:13] TRACE: bashio::config: zsh
[10:31:13] TRACE: bashio::addon.config
[10:31:13] TRACE: bashio::cache.exists: addons.self.options.config
[10:31:13] TRACE: bashio::fs.file_exists: /tmp/.bashio/addons.self.options.config.cache
[10:31:13] TRACE: bashio::cache.get: addons.self.options.config
[10:31:13] TRACE: bashio::cache.exists: addons.self.options.config
[10:31:13] TRACE: bashio::fs.file_exists: /tmp/.bashio/addons.self.options.config.cache
[10:31:13] TRACE: bashio::jq: {"ssh":{"username":"root","password":"","authorized_keys":["ssh-ed25519 XXXX"],"sftp":false,"compatibility_mode":false,"allow_agent_forwarding":false,"allow_remote_port_forwarding":true,"allow_tcp_forwarding":true},"zsh":true,"share_sessions":false,"packages":[],"init_commands":["source /config/.shellstuff/scriptsandaliases"],"log_level":"trace"} if (.zsh == null) then
            null
        elif (.zsh | type == "string") then
            .zsh // empty
        elif (.zsh | type == "boolean") then
            .zsh // false
        elif (.zsh | type == "array") then
            if (.zsh == []) then
                empty
            else
                .zsh[]
            end
        elif (.zsh | type == "object") then`
            if (.zsh == {}) then
                empty
            else
                .zsh
            end
        else
            .zsh
        end
[10:31:13] TRACE: bashio::var.true: true
[2024/09/25 10:31:13:8474] N: ttyd 1.7.7-40e79c7 (libwebsockets 4.3.3-v4.3.3)
[2024/09/25 10:31:13:8475] N: tty configuration:
[2024/09/25 10:31:13:8475] N:   start command: tmux -u new -A -s homeassistant zsh -l
[2024/09/25 10:31:13:8475] N:   close signal: SIGHUP (1)
[2024/09/25 10:31:13:8475] N:   terminal type: xterm-256color
[2024/09/25 10:31:13:8529] N:    /usr/lib/libwebsockets-evlib_uv.so
[2024/09/25 10:31:13:8530] N: lws_create_context: LWS: 4.3.3-v4.3.3, NET CLI SRV H1 H2 WS ConMon IPV6-off
[2024/09/25 10:31:13:8530] W: lws_create_context: unreasonable ulimit -n workaround
[2024/09/25 10:31:13:8531] N: elops_init_pt_uv:  Using foreign event loop...
[2024/09/25 10:31:13:8537] N: __lws_lc_tag:  ++ [wsi|0|pipe] (1)
[2024/09/25 10:31:13:8548] N: __lws_lc_tag:  ++ [vh|0|netlink] (1)
[2024/09/25 10:31:13:8549] N: __lws_lc_tag:  ++ [vh|1|default|hassio|hassio|65060] (2)
[2024/09/25 10:31:13:8557] N: [vh|1|default|hassio|hassio|65060]: lws_socket_bind: source ads 172.30.32.1
[2024/09/25 10:31:13:8558] N: __lws_lc_tag:  ++ [wsi|1|listen|default|hassio|65060] (2)
[2024/09/25 10:31:13:8558] N:  Listening on port: 65060

Note: if the /config/.shellstuff/scriptsandaliases does not exist, it throws an error and won't start, so it seems to be able to access the file, its just not sourcing it.

Steps to reproduce

Create dir/file: /config/.shellstuff/scriptsandaliases Input into file

# Preffered LS Readout
alias ll="ls -lah --color=auto"

# Script for ESPHome logs
el() {
    docker exec -it addon_5c53de3b_esphome bash -c "esphome logs /config/esphome/$1"
}

Set init_command: source /config/.shellstuff/scriptsandaliases Restart Add-On

Proposed changes

zach6439 commented 3 weeks ago

I misunderstood the init_commands. This seems to be expected behavior.