allow to customize prefix and sysconfdir
Follow GNU directory variable names and allow to specify PREFIX (by default /usr) and sysconfdir (by default /etc). This allows to install hassio scripts and service to alternative locations.
This commit is contained in:
parent
b7fa6c0030
commit
b53d0d8e5f
4 changed files with 38 additions and 19 deletions
|
@ -32,9 +32,11 @@ curl -sL https://raw.githubusercontent.com/home-assistant/hassio-installer/maste
|
||||||
|
|
||||||
### Command line arguments
|
### Command line arguments
|
||||||
| argument | default | description |
|
| argument | default | description |
|
||||||
|--------------------|-------------------|--------------------------------------------------------|
|
|--------------------|----------------------|--------------------------------------------------------|
|
||||||
| -m \| --machine | | On a special platform they need set a machine type use |
|
| -m \| --machine | | On a special platform they need set a machine type use |
|
||||||
| -d \| --data-share | /usr/share/hassio | data folder for hass.io installation |
|
| -d \| --data-share | $PREFIX/share/hassio | data folder for hass.io installation |
|
||||||
|
| -p \| --prefix | /usr | Binary prefix for hass.io installation |
|
||||||
|
| -s \| --sysconfdir | /etc | Configuration directory for hass.io installation |
|
||||||
|
|
||||||
you can set these parameters by appending ` -- <parameter> <value>` like:
|
you can set these parameters by appending ` -- <parameter> <value>` like:
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,7 @@ Before=%%DOCKER_SERVICE%% hassio-supervisor.service
|
||||||
[Service]
|
[Service]
|
||||||
Type=oneshot
|
Type=oneshot
|
||||||
RemainAfterExit=true
|
RemainAfterExit=true
|
||||||
ExecStart=/usr/sbin/hassio-apparmor
|
ExecStart=%%HASSIO_APPARMOR_BINARY%%
|
||||||
|
|
||||||
[Install]
|
[Install]
|
||||||
WantedBy=multi-user.target
|
WantedBy=multi-user.target
|
||||||
|
|
|
@ -8,7 +8,8 @@ Type=simple
|
||||||
Restart=always
|
Restart=always
|
||||||
RestartSec=5s
|
RestartSec=5s
|
||||||
ExecStartPre=-%%DOCKER_BINARY%% stop hassio_supervisor
|
ExecStartPre=-%%DOCKER_BINARY%% stop hassio_supervisor
|
||||||
ExecStart=/usr/sbin/hassio-supervisor
|
ExecStartPre=-%%DOCKER_BINARY%% stop hassio_supervisor
|
||||||
|
ExecStart=%%HASSIO_BINARY%%
|
||||||
ExecStop=-%%DOCKER_BINARY%% stop hassio_supervisor
|
ExecStop=-%%DOCKER_BINARY%% stop hassio_supervisor
|
||||||
|
|
||||||
[Install]
|
[Install]
|
||||||
|
|
|
@ -6,8 +6,6 @@ DOCKER_DAEMON_CONFIG=/etc/docker/daemon.json
|
||||||
DOCKER_BINARY=/usr/bin/docker
|
DOCKER_BINARY=/usr/bin/docker
|
||||||
DOCKER_REPO=homeassistant
|
DOCKER_REPO=homeassistant
|
||||||
DOCKER_SERVICE=docker.service
|
DOCKER_SERVICE=docker.service
|
||||||
DATA_SHARE=/usr/share/hassio
|
|
||||||
CONFIG=/etc/hassio.json
|
|
||||||
URL_VERSION="https://version.home-assistant.io/stable.json"
|
URL_VERSION="https://version.home-assistant.io/stable.json"
|
||||||
URL_BIN_HASSIO="https://raw.githubusercontent.com/home-assistant/hassio-installer/master/files/hassio-supervisor"
|
URL_BIN_HASSIO="https://raw.githubusercontent.com/home-assistant/hassio-installer/master/files/hassio-supervisor"
|
||||||
URL_BIN_APPARMOR="https://raw.githubusercontent.com/home-assistant/hassio-installer/master/files/hassio-apparmor"
|
URL_BIN_APPARMOR="https://raw.githubusercontent.com/home-assistant/hassio-installer/master/files/hassio-apparmor"
|
||||||
|
@ -49,6 +47,14 @@ while [[ $# -gt 0 ]]; do
|
||||||
DATA_SHARE=$2
|
DATA_SHARE=$2
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
|
-p|--prefix)
|
||||||
|
PREFIX=$2
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
-s|--sysconfdir)
|
||||||
|
SYSCONFDIR=$2
|
||||||
|
shift
|
||||||
|
;;
|
||||||
*)
|
*)
|
||||||
echo "[Error] Unrecognized option $1"
|
echo "[Error] Unrecognized option $1"
|
||||||
exit 1
|
exit 1
|
||||||
|
@ -57,6 +63,11 @@ while [[ $# -gt 0 ]]; do
|
||||||
shift
|
shift
|
||||||
done
|
done
|
||||||
|
|
||||||
|
PREFIX=${PREFIX:-/usr}
|
||||||
|
SYSCONFDIR=${SYSCONFDIR:-/etc}
|
||||||
|
DATA_SHARE=${DATA_SHARE:-$PREFIX/share/hassio}
|
||||||
|
CONFIG=$SYSCONFDIR/hassio.json
|
||||||
|
|
||||||
# Generate hardware options
|
# Generate hardware options
|
||||||
case $ARCH in
|
case $ARCH in
|
||||||
"i386" | "i686")
|
"i386" | "i686")
|
||||||
|
@ -115,7 +126,7 @@ HASSIO_VERSION=$(curl -s $URL_VERSION | jq -e -r '.supervisor')
|
||||||
|
|
||||||
##
|
##
|
||||||
# Write config
|
# Write config
|
||||||
cat > $CONFIG <<- EOF
|
cat > "$CONFIG" <<- EOF
|
||||||
{
|
{
|
||||||
"supervisor": "${HASSIO_DOCKER}",
|
"supervisor": "${HASSIO_DOCKER}",
|
||||||
"homeassistant": "${HOMEASSISTANT_DOCKER}",
|
"homeassistant": "${HOMEASSISTANT_DOCKER}",
|
||||||
|
@ -128,7 +139,7 @@ EOF
|
||||||
DOCKER_VERSION="$(docker --version | grep -Po "\d{2}\.\d{2}\.\d")"
|
DOCKER_VERSION="$(docker --version | grep -Po "\d{2}\.\d{2}\.\d")"
|
||||||
if version_gt "18.09.0" "${DOCKER_VERSION}" && [ ! -e "$DOCKER_DAEMON_CONFIG" ]; then
|
if version_gt "18.09.0" "${DOCKER_VERSION}" && [ ! -e "$DOCKER_DAEMON_CONFIG" ]; then
|
||||||
echo "[Warning] Create DNS settings for Docker to avoid systemd bug!"
|
echo "[Warning] Create DNS settings for Docker to avoid systemd bug!"
|
||||||
mkdir -p $(dirname ${DOCKER_DAEMON_CONFIG})
|
mkdir -p "$(dirname ${DOCKER_DAEMON_CONFIG})"
|
||||||
echo '{"dns": ["8.8.8.8", "8.8.4.4"]}' > $DOCKER_DAEMON_CONFIG
|
echo '{"dns": ["8.8.8.8", "8.8.4.4"]}' > $DOCKER_DAEMON_CONFIG
|
||||||
|
|
||||||
echo "[Info] Restart Docker and wait 30 seconds"
|
echo "[Info] Restart Docker and wait 30 seconds"
|
||||||
|
@ -144,13 +155,16 @@ docker tag "$HASSIO_DOCKER:$HASSIO_VERSION" "$HASSIO_DOCKER:latest" > /dev/null
|
||||||
##
|
##
|
||||||
# Install Hass.io Supervisor
|
# Install Hass.io Supervisor
|
||||||
echo "[Info] Install supervisor startup scripts"
|
echo "[Info] Install supervisor startup scripts"
|
||||||
curl -sL ${URL_BIN_HASSIO} > /usr/sbin/hassio-supervisor
|
curl -sL ${URL_BIN_HASSIO} > "${PREFIX}"/sbin/hassio-supervisor
|
||||||
curl -sL ${URL_SERVICE_HASSIO} > /etc/systemd/system/hassio-supervisor.service
|
curl -sL ${URL_SERVICE_HASSIO} > "${SYSCONFDIR}"/systemd/system/hassio-supervisor.service
|
||||||
|
|
||||||
sed -i "s,%%HASSIO_CONFIG%%,${CONFIG},g" /usr/sbin/hassio-supervisor
|
sed -i "s,%%HASSIO_CONFIG%%,${CONFIG},g" "${PREFIX}"/sbin/hassio-supervisor
|
||||||
sed -i "s,%%DOCKER_BINARY%%,${DOCKER_BINARY},g; s,%%DOCKER_SERVICE%%,${DOCKER_SERVICE},g" /etc/systemd/system/hassio-supervisor.service
|
sed -i -e "s,%%DOCKER_BINARY%%,${DOCKER_BINARY},g" \
|
||||||
|
-e "s,%%DOCKER_SERVICE%%,${DOCKER_SERVICE},g" \
|
||||||
|
-e "s,%%HASSIO_BINARY%%,${PREFIX}/sbin/hassio-supervisor,g" \
|
||||||
|
"${SYSCONFDIR}"/systemd/system/hassio-supervisor.service
|
||||||
|
|
||||||
chmod a+x /usr/sbin/hassio-supervisor
|
chmod a+x "${PREFIX}"/sbin/hassio-supervisor
|
||||||
systemctl enable hassio-supervisor.service
|
systemctl enable hassio-supervisor.service
|
||||||
|
|
||||||
#
|
#
|
||||||
|
@ -158,14 +172,16 @@ systemctl enable hassio-supervisor.service
|
||||||
if command -v apparmor_parser > /dev/null 2>&1; then
|
if command -v apparmor_parser > /dev/null 2>&1; then
|
||||||
echo "[Info] Install AppArmor scripts"
|
echo "[Info] Install AppArmor scripts"
|
||||||
mkdir -p "${DATA_SHARE}"/apparmor
|
mkdir -p "${DATA_SHARE}"/apparmor
|
||||||
curl -sL ${URL_BIN_APPARMOR} > /usr/sbin/hassio-apparmor
|
curl -sL ${URL_BIN_APPARMOR} > "${PREFIX}"/sbin/hassio-apparmor
|
||||||
curl -sL ${URL_SERVICE_APPARMOR} > /etc/systemd/system/hassio-apparmor.service
|
curl -sL ${URL_SERVICE_APPARMOR} > "${SYSCONFDIR}"/systemd/system/hassio-apparmor.service
|
||||||
curl -sL ${URL_APPARMOR_PROFILE} > "${DATA_SHARE}"/apparmor/hassio-supervisor
|
curl -sL ${URL_APPARMOR_PROFILE} > "${DATA_SHARE}"/apparmor/hassio-supervisor
|
||||||
|
|
||||||
sed -i "s,%%HASSIO_CONFIG%%,${CONFIG},g" /usr/sbin/hassio-apparmor
|
sed -i "s,%%HASSIO_CONFIG%%,${CONFIG},g" "${PREFIX}"/sbin/hassio-apparmor
|
||||||
sed -i "s,%%DOCKER_SERVICE%%,${DOCKER_SERVICE},g" /etc/systemd/system/hassio-apparmor.service
|
sed -i -e "s,%%DOCKER_SERVICE%%,${DOCKER_SERVICE},g" \
|
||||||
|
-e "s,%%HASSIO_APPARMOR_BINARY%%,${PREFIX}/sbin/hassio-apparmor,g" \
|
||||||
|
"${SYSCONFDIR}"/systemd/system/hassio-apparmor.service
|
||||||
|
|
||||||
chmod a+x /usr/sbin/hassio-apparmor
|
chmod a+x "${PREFIX}"/sbin/hassio-apparmor
|
||||||
systemctl enable hassio-apparmor.service
|
systemctl enable hassio-apparmor.service
|
||||||
systemctl start hassio-apparmor.service
|
systemctl start hassio-apparmor.service
|
||||||
fi
|
fi
|
||||||
|
|
Loading…
Reference in a new issue