Update generic installation to new variable / better log output

This commit is contained in:
pvizeli 2017-04-26 11:47:12 +02:00
parent 6a706c91db
commit e726054097
3 changed files with 80 additions and 6 deletions

69
generic-hc/0.2 Normal file
View file

@ -0,0 +1,69 @@
#!/bin/bash
set -e
VERSION=0.2
URL_VERSION="https://raw.githubusercontent.com/pvizeli/hassio/master/version.json"
URL_GENERIC_HC="https://raw.githubusercontent.com/pvizeli/hassio-build/master/generic-hc"
# Check system options
if [ -x $(command -v systemctl) ]; then
INIT_SYSTEM=systemd
else
INIT_SYSTEM=sysvinit
fi
#
# MAIN loop
#
while read cmd
do
IFS=" " read -r -a parse <<< $cmd
if [ ${parse[0]} == "info" ]; then
HOSTNAME=$(hostname)
LAST=$(curl -s $URL_VERSION | jq -e -r '.generic')
FEATURES="[\"shutdown\", \"reboot\", \"update\"]"
echo "{ \"type\": \"generic\", \"version\": \"$VERSION\", \"last_version\": \"$LAST\", \"hostname\": \"$HOSTNAME\", \"features\": $FEATURES }"
continue
fi
if [ ${parse[0]} == "reboot" ]; then
if [ "$INIT_SYSTEM" == "systemd"]; then
systemctl reboot && echo "OK" || echo "ERROR"
else
nohup reboot > /dev/null 2>&1 && echo "OK" || echo "ERROR"
fi
continue
fi
if [ ${parse[0]} == "shutdown" ]; then
if [ "$INIT_SYSTEM" == "systemd"]; then
systemctl poweroff && echo "OK" || echo "ERROR"
else
nohup halt -p > /dev/null 2>&1 && echo "OK" || echo "ERROR"
fi
continue
fi
if [ ${parse[0]} == "update" ]; then
if [ ! -z ${parse[1]} ]; then
VERSION=${parse[1]}
else
VERSION=$(curl -s $URL_VERSION | jq -e -r '.generic')
fi
CMD_BIN=$(command -v hassio-hc)
if [ curl -sL "$URL_GENERIC_HC/$VERSION" > "$CMD_BIN" ]; then
chmod a+x "$CMD_BIN"
echo "OK"
# restart service
if [ "$INIT_SYSTEM" == "systemd"]; then
nohup systemctl restart hassio-hc.service > /dev/null 2>&1
fi
else
echo "ERROR"
fi
continue
fi
echo "WRONG"
done

View file

@ -93,22 +93,25 @@ if [ ! -d "$DATA_SHARE" ]; then
fi
# Read infos from web
HASSIO_VERSION=$(curl -s $URL_VERSION | jq -e -r '.hassio_tag')
GENERIC_HC_VERSION=$(curl -s $URL_VERSION | jq -e -r '.generic_hc_version')
HASSIO_VERSION=$(curl -s $URL_VERSION | jq -e -r '.hassio')
GENERIC_HC_VERSION=$(curl -s $URL_VERSION | jq -e -r '.generic')
##
# Install supervisor
docker pull "$HASSIO_DOCKER:$HASSIO_VERSION"
docker tag "$HASSIO_DOCKER:$HASSIO_VERSION" "$HASSIO_DOCKER:latest"
echo "[INFO] Install supervisor docker"
docker pull "$HASSIO_DOCKER:$HASSIO_VERSION" > /dev/null
docker tag "$HASSIO_DOCKER:$HASSIO_VERSION" "$HASSIO_DOCKER:latest" > /dev/null
##
# install generic hostcontroll
# install generic hostcontrol
echo "[INFO] Install generic HostControl"
curl -sL "$URL_GENERIC_HC/$GENERIC_HC_VERSION" > "$BIN_DIR/hassio-hc"
chmod a+x "$BIN_DIR/hassio-hc"
##
# install start-hassio
echo "[INFO] Install startup scripts"
curl -sL "$URL_START_HASSIO" > "$BIN_DIR/hassio-start"
sed -i "s|%%SUPERVISOR_IMAGE%%|$HASSIO_DOCKER|g" "$BIN_DIR/hassio-start"
@ -120,6 +123,7 @@ chmod a+x "$BIN_DIR/hassio-start"
##
# Init system
if [ "$INIT_SYSTEM" == "systemd" ]; then
echo "[INFO] Init systemd"
curl -sL "$URL_SERVICE_HASSIO" > "/etc/systemd/system/hassio-supervisor.service"
curl -sL "$URL_SERVICE_HOSTCONTROLL" > "/etc/systemd/system/hassio-hc.service"
@ -128,6 +132,7 @@ if [ "$INIT_SYSTEM" == "systemd" ]; then
systemctl enable hassio-supervisor.service
echo "[INFO] Start services"
systemctl start hassio-hc.service
systemctl start hassio-supervisor.service
fi

View file

@ -1,5 +1,5 @@
[Unit]
Description=HassIO HostControll
Description=HassIO HostControl
Before=hassio-supervisor.service
[Service]