mirror of
https://github.com/aljazceru/addons.git
synced 2026-02-23 05:44:24 +01:00
Add new CLI (#222)
* Add new CLI * Use bash as default shell * update cli version * fix docker file
This commit is contained in:
6
ssh/CHANGELOG.md
Normal file
6
ssh/CHANGELOG.md
Normal file
@@ -0,0 +1,6 @@
|
||||
# Changelog
|
||||
|
||||
## 3.0
|
||||
- Use new base images
|
||||
- Add hassio-cli version 1.0
|
||||
- Use bash as default shell
|
||||
@@ -5,13 +5,24 @@ FROM $BUILD_FROM
|
||||
ENV LANG C.UTF-8
|
||||
|
||||
# Setup base
|
||||
RUN apk add --no-cache jq openssh vim curl nano git mosquitto-clients tmux
|
||||
RUN apk add --no-cache \
|
||||
jq openssh vim curl nano git mosquitto-clients tmux \
|
||||
bash-completion
|
||||
|
||||
# Replace bash as default shell
|
||||
RUN sed -i "s/ash/bash/" /etc/passwd
|
||||
|
||||
# Hass.io CLI
|
||||
ARG BUILD_ARCH
|
||||
ARG CLI_VERSION
|
||||
RUN apk add --no-cache curl \
|
||||
&& curl -Lso /usr/bin/hassio https://github.com/home-assistant/hassio-cli/releases/download/${CLI_VERSION}/hassio_${BUILD_ARCH} \
|
||||
&& chmod a+x /usr/bin/hassio
|
||||
|
||||
# Copy data
|
||||
COPY run.sh /
|
||||
COPY motd /etc/
|
||||
COPY hassio /usr/bin/
|
||||
|
||||
RUN chmod a+x /run.sh /usr/bin/hassio
|
||||
RUN chmod a+x /run.sh
|
||||
|
||||
CMD [ "/run.sh" ]
|
||||
|
||||
5
ssh/build.json
Normal file
5
ssh/build.json
Normal file
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"args": {
|
||||
"CLI_VERSION": "1.0.1"
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "SSH server",
|
||||
"version": "2.9",
|
||||
"version": "3.0",
|
||||
"slug": "ssh",
|
||||
"description": "Allows connections over SSH",
|
||||
"url": "https://home-assistant.io/addons/ssh/",
|
||||
|
||||
103
ssh/hassio
103
ssh/hassio
@@ -1,103 +0,0 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
# helppage
|
||||
if [ "$1" == "help" ] || [ "$#" -lt 2 ]; then
|
||||
cat << EOF
|
||||
---- Hass.IO Cli ----
|
||||
|
||||
HomeAssistant:
|
||||
$ hassio homeassistant logs
|
||||
$ hassio homeassistant restart
|
||||
$ hassio homeassistant stop
|
||||
$ hassio homeassistant start
|
||||
$ hassio homeassistant update
|
||||
$ hassio homeassistant check
|
||||
|
||||
Host:
|
||||
$ hassio host hardware
|
||||
$ hassio host reboot
|
||||
$ hassio host shutdown
|
||||
$ hassio host update
|
||||
|
||||
Supervisor
|
||||
$ hassio supervisor logs
|
||||
$ hassio supervisor info
|
||||
$ hassio supervisor reload
|
||||
$ hassio supervisor update
|
||||
EOF
|
||||
fi
|
||||
|
||||
function call_api() {
|
||||
get_cmd=('info' 'logs' 'hardware')
|
||||
|
||||
command='POST'
|
||||
if [[ ${get_cmd[*]} =~ $2 ]]; then
|
||||
command='GET'
|
||||
fi
|
||||
|
||||
if ! api_ret="$(curl -s -X $command "http://hassio/$1/$2")"; then
|
||||
echo "API error: $api_ret"
|
||||
return 1
|
||||
fi
|
||||
|
||||
if [ "$2" == "logs" ]; then
|
||||
echo "$api_ret"
|
||||
return 0
|
||||
fi
|
||||
|
||||
result="$(echo "$api_ret" | jq --raw-output ".result")"
|
||||
|
||||
# On error
|
||||
if [ "$result" == "error" ]; then
|
||||
message="$(echo "$api_ret" | jq --raw-output ".message // empty")"
|
||||
echo "Error on $1/$2:" "$message"
|
||||
return 0
|
||||
fi
|
||||
|
||||
# On success
|
||||
data="$(echo "$api_ret" | jq 'if .data == {} then empty else .data end')"
|
||||
if [ ! -z "$data" ]; then
|
||||
echo "$data" | jq .
|
||||
else
|
||||
echo "Success $1/$2"
|
||||
fi
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
######
|
||||
# homeassistant functions
|
||||
if [ "$1" == "homeassistant" ]; then
|
||||
hass_cmd=('logs' 'restart' 'update' 'check' 'start' 'stop')
|
||||
if [[ ! ${hass_cmd[*]} =~ $2 ]]; then
|
||||
echo "No homeassistant command '$2' found!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
call_api "$1" "$2"
|
||||
fi
|
||||
|
||||
######
|
||||
# host functions
|
||||
if [ "$1" == "host" ]; then
|
||||
hass_cmd=('reboot' 'shutdown' 'update' 'hardware')
|
||||
if [[ ! ${hass_cmd[*]} =~ $2 ]]; then
|
||||
echo "No host command '$2' found!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
call_api "$1" "$2"
|
||||
fi
|
||||
|
||||
######
|
||||
# supervisor functions
|
||||
if [ "$1" == "supervisor" ]; then
|
||||
hass_cmd=('logs' 'reload' 'update' 'info')
|
||||
if [[ ! ${hass_cmd[*]} =~ $2 ]]; then
|
||||
echo "No supervisor command '$2' found!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
call_api "$1" "$2"
|
||||
fi
|
||||
@@ -45,9 +45,12 @@ else
|
||||
fi
|
||||
|
||||
# Persist shell history by redirecting .ash_history to /data
|
||||
touch /data/.ash_history
|
||||
chmod 600 /data/.ash_history
|
||||
ln -s -f /data/.ash_history /root/.ash_history
|
||||
touch /data/.bash_history
|
||||
chmod 600 /data/.bash_history
|
||||
ln -s -f /data/.bash_history /root/.bash_history
|
||||
|
||||
# Store token for hass.io API
|
||||
echo "export API_TOKEN=$API_TOKEN" >> /root/.bash_profile
|
||||
|
||||
# start server
|
||||
exec /usr/sbin/sshd -D -e < /dev/null
|
||||
|
||||
Reference in New Issue
Block a user