Add support for new audo layer (#1153)

* Add support for new audo layer

* Add layer

* restucture

* better struct

* Improve devcontainer

* Fix container

* Fix LN

* disable lint

* ignore
This commit is contained in:
Pascal Vizeli
2020-03-01 13:08:12 +01:00
committed by GitHub
parent 9f04efe3fa
commit c853fcef65
30 changed files with 238 additions and 187 deletions

View File

@@ -1,31 +1,36 @@
# Changelog
## 8.4
## 8.5.0
- Add support for PulseAudio with new Audio backend
- Migrate to s6-overlay
## 8.4.0
- Support to use only web terminal without SSH server
**ATTENTION:** If you want access with SSH, you need maybe add the Port setting option back.
## 8.3
## 8.3.0
- Update Home Assistant CLI to 4.0.1
- Add backward compatibility with the hassio command
- Update Web terminal to ttyd 1.6.0 with Libwebsockets 3.2.2
- Rename HASSIO_TOKEN to SUPERVISOR_TOKEN in shell profile
## 8.2
## 8.2.0
- Fix creation of new tmux terminal windows
- Add add-on icon
- Update welcome logo
- Fix SSH folder issue with authorized keys
## 8.1
## 8.1.0
- Fix for non existing .bash_profile startup error
- Add current, short, path to command line prompt
## 8.0
## 8.0.0
- Add support for a web-based terminal via Ingress
- Upgrade Alpine Linux to 3.11
@@ -33,100 +38,100 @@
- Persist .ssh folder across restarts
- Add helper symlink folders to user home folder
## 7.1
## 7.1.0
- Update Hass.io CLI to 3.1.1
## 7.0
## 7.0.0
- Added bash_profile as a persistent file
## 6.4
## 6.4.0
- Changed logging from DEBUG -> INFO
## 6.3
## 6.3.0
- Update Hass.io CLI to 3.1.0
## 6.2
## 6.2.0
- Update Hass.io CLI to 3.0.0
## 6.1
## 6.1.0
- Update Hass.io CLI to 2.3.0
## 6.0
## 6.0.0
- Update and pin base image to Alpine 3.10
## 5.6
## 5.6.0
- Fixes crash when using authorized keys
## 5.5
## 5.5.0
- Rewrite add-on onto Bashio
- Added documentation to add-on repository
- Code styling improvements
## 5.4
## 5.4.0
- Update Hass.io CLI to 2.2.0
## 5.3
## 5.3.0
- Fix: User root not allowed because account is locked
## 5.2
## 5.2.0
- Update Hass.io CLI to 2.1.0
## 5.1
## 5.1.0
- Map all serial devices into container for manual adjustments
## 5.0
## 5.0.0
- Update Hass.io CLI to 2.0.1, include bash completion
## 4.0
## 4.0.0
- Update Hass.io CLI to 1.4.0
- Add new API role profile
- Update OpenSSH to 7.7
## 3.7
## 3.7.0
- Add YAML highlighting for nano
## 3.6
## 3.6.0
- Update Hass.io CLI to 1.3.1
## 3.5
## 3.5.0
- Update Hass.io CLI to 1.3.0
## 3.4
## 3.4.0
- Update Hass.io CLI to 1.2.1
## 3.3
## 3.3.0
- Update Hass.io CLI to 1.1.2
## 3.2
## 3.2.0
- Downgrade Hass.io CLI to 1.0.1
## 3.1
## 3.1.0
- Update Hass.io CLI to 1.1.1
- Change internal token handling for Hass.io API
## 3.0
## 3.0.0
- Use new base images
- Add hassio-cli version 1.0

View File

@@ -16,6 +16,8 @@ RUN \
\
&& apk add --no-cache \
bash-completion \
pulseaudio-utils \
alsa-plugins-pulse \
git \
libuv \
mosquitto-clients \
@@ -77,11 +79,4 @@ RUN curl -Lso /usr/bin/ha \
&& /usr/bin/ha completion > /usr/share/bash-completion/completions/ha
# Copy data
COPY data/.tmux.conf /root/
COPY data/hassio /usr/bin/
COPY data/homeassistant.sh /etc/profile.d/
COPY data/motd /etc/
COPY data/run.sh /
COPY data/sshd_config /etc/ssh/
CMD [ "/run.sh" ]
COPY rootfs /

View File

@@ -1,10 +1,11 @@
{
"name": "Terminal & SSH",
"version": "8.4",
"version": "8.5.0",
"slug": "ssh",
"description": "Allow logging in remotely to Home Assistant using SSH",
"url": "https://github.com/home-assistant/hassio-addons/tree/master/ssh",
"arch": ["armhf", "armv7", "aarch64", "amd64", "i386"],
"init": false,
"advanced": true,
"startup": "services",
"ingress": true,
@@ -13,6 +14,7 @@
"boot": "auto",
"hassio_api": true,
"hassio_role": "manager",
"audio": true,
"auto_uart": true,
"ports": {
"22/tcp": null

View File

@@ -1,114 +0,0 @@
#!/usr/bin/env bashio
set -e
KEYS_PATH=/data/host_keys
WAIT_PIDS=()
bashio::log.info "Initializing add-on for use..."
USE_SSHD=true
if bashio::config.has_value 'authorized_keys'; then
bashio::log.info "Setup authorized_keys"
mkdir -p /data/.ssh
chmod 700 /data/.ssh
rm -f /data/.ssh/authorized_keys
while read -r line; do
echo "$line" >> /data/.ssh/authorized_keys
done <<< "$(bashio::config 'authorized_keys')"
chmod 600 /data/.ssh/authorized_keys
sed -i s/#PasswordAuthentication.*/PasswordAuthentication\ no/ /etc/ssh/sshd_config
# Unlock account
PASSWORD="$(pwgen -s 64 1)"
echo "root:${PASSWORD}" | chpasswd 2&> /dev/null
elif bashio::config.has_value 'password'; then
bashio::log.info "Setup password login"
PASSWORD=$(bashio::config 'password')
echo "root:${PASSWORD}" | chpasswd 2&> /dev/null
sed -i s/#PasswordAuthentication.*/PasswordAuthentication\ yes/ /etc/ssh/sshd_config
sed -i s/#PermitEmptyPasswords.*/PermitEmptyPasswords\ no/ /etc/ssh/sshd_config
elif bashio::var.has_value "$(bashio::addon.port 22)"; then
bashio::exit.nok "You need to setup a login!"
else
USE_SSHD=false
bashio::log.info "Disable SSH remote access because of missing login credential!"
fi
# Generate host keys
if ! bashio::fs.directory_exists "${KEYS_PATH}"; then
bashio::log.info "Generating host keys..."
mkdir -p "${KEYS_PATH}"
ssh-keygen -A || bashio::exit.nok "Failed to create host keys!"
cp -fp /etc/ssh/ssh_host* "${KEYS_PATH}/"
else
bashio::log.info "Restoring host keys..."
cp -fp "${KEYS_PATH}"/* /etc/ssh/
fi
# Persist shell history by redirecting .bash_history to /data
touch /data/.bash_history
chmod 600 /data/.bash_history
ln -s -f /data/.bash_history /root/.bash_history
# Make Home Assistant TOKEN available on the CLI
echo "export SUPERVISOR_TOKEN=${SUPERVISOR_TOKEN}" >> /etc/profile.d/homeassistant.sh
# Remove old HASSIO_TOKEN from bash profile (if exists)
if bashio::fs.file_exists /data/.bash_profile; then
sed -i "/export HASSIO_TOKEN=.*/d" /data/.bash_profile
fi
# Persist .bash_profile by redirecting .bash_profile to /data
touch /data/.bash_profile
chmod 600 /data/.bash_profile
ln -s -f /data/.bash_profile /root/.bash_profile
# Links some common directories to the user's home folder for convenience
DIRECTORIES=(addons backup config share ssl)
for dir in "${DIRECTORIES[@]}"; do
ln -s "/${dir}" "${HOME}/${dir}" \
|| bashio::log.warning "Failed linking common directory: ${dir}"
done
# Sets up the users .ssh folder to be persistent
if ! bashio::fs.directory_exists /data/.ssh; then
mkdir -p /data/.ssh \
|| bashio::exit.nok 'Failed to create a persistent .ssh folder'
chmod 700 /data/.ssh \
|| bashio::exit.nok \
'Failed setting permissions on persistent .ssh folder'
fi
ln -s /data/.ssh /root/.ssh
# Register stop
function stop_addon() {
bashio::log.debug "Kill Processes..."
kill -15 "${WAIT_PIDS[@]}"
wait "${WAIT_PIDS[@]}"
bashio::log.debug "Done."
}
trap "stop_addon" SIGTERM SIGHUP
# Start SSH server
if bashio::var.true "${USE_SSHD}"; then
bashio::log.info "Starting SSH daemon..."
/usr/sbin/sshd -D -e < /dev/null &
WAIT_PIDS+=($!)
fi
# Start ttyd server
bashio::log.info "Starting Web Terminal..."
cd /root
ttyd -p 8099 tmux -u new -A -s homeassistant bash -l &
WAIT_PIDS+=($!)
# Wait until all is done
bashio::log.info "SSH add-on is set up and running!"
wait "${WAIT_PIDS[@]}"

View File

@@ -0,0 +1,16 @@
#!/usr/bin/with-contenv bashio
# ==============================================================================
# SSH Host keys
# ==============================================================================
KEYS_PATH=/data/host_keys
if ! bashio::fs.directory_exists "${KEYS_PATH}"; then
bashio::log.info "Generating host keys..."
mkdir -p "${KEYS_PATH}"
ssh-keygen -A || bashio::exit.nok "Failed to create host keys!"
cp -fp /etc/ssh/ssh_host* "${KEYS_PATH}/"
else
bashio::log.info "Restoring host keys..."
cp -fp "${KEYS_PATH}"/* /etc/ssh/
fi

View File

@@ -0,0 +1,40 @@
#!/usr/bin/with-contenv bashio
# ==============================================================================
# Setup persistent user settings
# ==============================================================================
DIRECTORIES=(addons backup config share ssl)
# Persist shell history by redirecting .bash_history to /data
touch /data/.bash_history
chmod 600 /data/.bash_history
ln -s -f /data/.bash_history /root/.bash_history
# Make Home Assistant TOKEN available on the CLI
echo "export SUPERVISOR_TOKEN=${SUPERVISOR_TOKEN}" >> /etc/profile.d/homeassistant.sh
# Remove old HASSIO_TOKEN from bash profile (if exists)
if bashio::fs.file_exists /data/.bash_profile; then
sed -i "/export HASSIO_TOKEN=.*/d" /data/.bash_profile
fi
# Persist .bash_profile by redirecting .bash_profile to /data
touch /data/.bash_profile
chmod 600 /data/.bash_profile
ln -s -f /data/.bash_profile /root/.bash_profile
# Links some common directories to the user's home folder for convenience
for dir in "${DIRECTORIES[@]}"; do
ln -s "/${dir}" "${HOME}/${dir}" \
|| bashio::log.warning "Failed linking common directory: ${dir}"
done
# Sets up the users .ssh folder to be persistent
if ! bashio::fs.directory_exists /data/.ssh; then
mkdir -p /data/.ssh \
|| bashio::exit.nok 'Failed to create a persistent .ssh folder'
chmod 700 /data/.ssh \
|| bashio::exit.nok \
'Failed setting permissions on persistent .ssh folder'
fi
ln -s /data/.ssh /root/.ssh

View File

@@ -0,0 +1,31 @@
#!/usr/bin/with-contenv bashio
# ==============================================================================
# SSH setup & user
# ==============================================================================
if bashio::config.has_value 'authorized_keys'; then
bashio::log.info "Setup authorized_keys"
mkdir -p /data/.ssh
chmod 700 /data/.ssh
rm -f /data/.ssh/authorized_keys
while read -r line; do
echo "$line" >> /data/.ssh/authorized_keys
done <<< "$(bashio::config 'authorized_keys')"
chmod 600 /data/.ssh/authorized_keys
sed -i s/#PasswordAuthentication.*/PasswordAuthentication\ no/ /etc/ssh/sshd_config
# Unlock account
PASSWORD="$(pwgen -s 64 1)"
echo "root:${PASSWORD}" | chpasswd 2&> /dev/null
elif bashio::config.has_value 'password'; then
bashio::log.info "Setup password login"
PASSWORD=$(bashio::config 'password')
echo "root:${PASSWORD}" | chpasswd 2&> /dev/null
sed -i s/#PasswordAuthentication.*/PasswordAuthentication\ yes/ /etc/ssh/sshd_config
sed -i s/#PermitEmptyPasswords.*/PermitEmptyPasswords\ no/ /etc/ssh/sshd_config
elif bashio::var.has_value "$(bashio::addon.port 22)"; then
bashio::exit.nok "You need to setup a login!"
fi

View File

@@ -0,0 +1,2 @@
/usr/bin/hassio false root 0755 0755
/usr/bin/ha false root 0755 0755

View File

@@ -0,0 +1,2 @@
/data/.bash_history false root 0600 0755
/data/.bash_profile false root 0600 0755

View File

@@ -0,0 +1,3 @@
/data/.ssh false root 0644 0700
/data/.ssh/authorized_keys false root 0600 0755
/etc/ssh false root 0644 0755

View File

@@ -0,0 +1,8 @@
#!/usr/bin/execlineb -S0
# ==============================================================================
# Take down the S6 supervision tree when sshd fails
# ==============================================================================
if { s6-test ${1} -ne 0 }
if { s6-test ${1} -ne 256 }
s6-svscanctl -t /var/run/s6/services

View File

@@ -0,0 +1,12 @@
#!/usr/bin/with-contenv bashio
# ==============================================================================
# Start sshd service if enabled
# ==============================================================================
# If SSH is disabled, use a fake sleep process
if ! bashio::var.has_value "$(bashio::addon.port 22)"; then
exec sleep 864000
fi
bashio::log.info "Starting the SSH daemon..."
exec /usr/sbin/sshd -D -e

View File

@@ -0,0 +1,8 @@
#!/usr/bin/execlineb -S0
# ==============================================================================
# Take down the S6 supervision tree when ttyd fails
# ==============================================================================
if { s6-test ${1} -ne 0 }
if { s6-test ${1} -ne 256 }
s6-svscanctl -t /var/run/s6/services

View File

@@ -0,0 +1,8 @@
#!/usr/bin/with-contenv bashio
# ==============================================================================
# Start ttyd service for ingress
# ==============================================================================
bashio::log.info "Starting Web Terminal..."
cd /root
exec ttyd -p 8099 tmux -u new -A -s homeassistant bash -l

0
ssh/data/hassio → ssh/rootfs/usr/bin/hassio Executable file → Normal file
View File