Skip to content

Commit

Permalink
HAOS: adjust module options to match changes
Browse files Browse the repository at this point in the history
  • Loading branch information
igorpecovnik committed Dec 23, 2024
1 parent 71382ca commit 9ee888e
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 31 deletions.
18 changes: 14 additions & 4 deletions tools/json/config.software.json
Original file line number Diff line number Diff line change
Expand Up @@ -842,7 +842,7 @@
},
{
"id": "HA003",
"description": "Install Home Assistant",
"description": "Home Assistant Install",
"command": [
"module_haos install"
],
Expand All @@ -852,13 +852,23 @@
},
{
"id": "HA004",
"description": "Remove Home Assistant",
"description": "Home Assistant Remove",
"command": [
"module_haos uninstall"
"module_haos remove"
],
"status": "Preview",
"author": "@igorpecovnik",
"condition": "pkg_installed homeassistant-supervised"
"condition": "! module_haos status"
},
{
"id": "HA005",
"description": "Home Assistant purge",
"command": [
"module_haos purge"
],
"status": "Preview",
"author": "@igorpecovnik",
"condition": "! module_haos status"
}
]
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,44 +1,36 @@
declare -A module_options
module_options+=(
["module_haos,author"]="@igorpecovnik"
["module_haos,maintainer"]="@igorpecovnik"
["module_haos,feature"]="module_haos"
["module_haos,example"]="help install uninstall"
["module_haos,desc"]="Hos container install and configure"
["module_haos,example"]="install remove purge status help"
["module_haos,desc"]="Install HA supervised container"
["module_haos,status"]="Active"
["module_haos,doc_link"]="https://github.com/home-assistant/supervised-installer"
["module_haos,group"]="HomeAutomation"
["module_haos,port"]="8123"
["module_haos,status"]="review"
["module_haos,arch"]="x86-64 arm64 armhf"
)
#
# Install haos container
# Install haos supervised
#
module_haos() {


local title="haos"
local condition=$(which "$title" 2>/dev/null)

if pkg_installed docker-ce; then
local container=$(docker container ls -a | mawk '/home-assistant/{print $1}')
local image=$(docker image ls -a | mawk '/home-assistant/{print $3}')
fi

# Convert the example string to an array
local commands
IFS=' ' read -r -a commands <<< "${module_options["module_haos,example"]}"

HAOS_BASE="${SOFTWARE_FOLDER}/haos"

case "$1" in
"${commands[0]}")
## help/menu options for the module
echo -e "\nUsage: ${module_options["module_haos,feature"]} <command>"
echo -e "Commands: ${module_options["module_haos,example"]}"
echo "Available commands:"
if [[ "${container}" ]] || [[ "${image}" ]]; then
echo -e "\tstatus\t- Show the status of the $title service."
echo -e "\tremove\t- Remove $title."
else
echo -e " install\t- Install $title."
fi
echo
;;
install)
pkg_installed docker-ce || install_docker
pkg_installed docker-ce || module_docker install
[[ -d "$HAOS_BASE" ]] || mkdir -p "$HAOS_BASE" || { echo "Couldn't create storage directory: $HAOS_BASE"; exit 1; }

# this hack will allow running it on minimal image, but this has to be done properly in the network section, to allow easy switching
systemctl disable systemd-networkd
Expand Down Expand Up @@ -119,8 +111,9 @@ module_haos() {

# show that its done
$DIALOG --msgbox "Home assistant is available at\n\nhttps://${LOCALIPADD}:8123 " 10 38

;;
uninstall)
"${commands[1]}")
# disable service
systemctl disable supervisor-fix >/dev/null 2>&1
systemctl stop supervisor-fix >/dev/null 2>&1
Expand All @@ -140,10 +133,28 @@ module_haos() {
# restore os-release
sed -i "s/^PRETTY_NAME=\".*/PRETTY_NAME=\"${VENDOR} ${REVISION} ($VERSION_CODENAME)\"/g" "/etc/os-release"
;;
status)
[[ "${container}" ]] || [[ "${image}" ]] && return 0
"${commands[2]}")
[[ -n "${BAZARR_BASE}" && "${HAOS_BASE}" != "/" ]] && rm -rf "${HAOS_BASE}"
;;
"${commands[3]}")
if [[ "${container}" && "${image}" ]]; then
return 0
else
return 1
fi
;;
"${commands[4]}")
echo -e "\nUsage: ${module_options["module_haos,feature"]} <command>"
echo -e "Commands: ${module_options["module_haos,example"]}"
echo "Available commands:"
echo -e "\tinstall\t- Install $title."
echo -e "\tstatus\t- Installation status $title."
echo -e "\tremove\t- Remove $title."
echo -e "\tremove\t- Purge $title."
echo
;;
*)
${module_options["module_haos,feature"]} ${commands[4]}
;;
esac
}

module_haos "$1"

0 comments on commit 9ee888e

Please sign in to comment.