Last active
July 27, 2024 15:58
-
-
Save andronedev/df215f23fb405ba2938faef527798e0e to your computer and use it in GitHub Desktop.
TERMUX HOME ASSISTANT INSTALL
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/data/data/com.termux/files/usr/bin/bash | |
set -e | |
# Couleurs pour les messages | |
RED='\033[0;31m' | |
GREEN='\033[0;32m' | |
YELLOW='\033[1;33m' | |
NC='\033[0m' | |
# Fonction pour afficher les messages | |
print_message() { | |
echo -e "${2:-$GREEN}$1${NC}" | |
} | |
# Installation des dépendances | |
install_dependencies() { | |
print_message "Installation des dépendances..." | |
pkg update -y | |
pkg install -y proot-distro | |
} | |
# Installation d'Alpine Linux | |
install_alpine() { | |
print_message "Installation d'Alpine Linux..." | |
proot-distro install alpine | |
} | |
# Installation de Docker et Home Assistant dans Alpine | |
install_docker_and_ha() { | |
print_message "Installation de Docker et Home Assistant..." | |
proot-distro login alpine -- sh -c ' | |
apk update && apk add docker openrc | |
mkdir -p /run/openrc | |
touch /run/openrc/softlevel | |
rc-update add docker boot | |
/etc/init.d/docker start | |
# Attendre que Docker démarre | |
for i in {1..30}; do | |
if docker info >/dev/null 2>&1; then | |
break | |
fi | |
sleep 1 | |
done | |
if ! docker info >/dev/null 2>&1; then | |
echo "Erreur : Docker n'\''a pas démarré correctement" | |
exit 1 | |
fi | |
docker run -d --name homeassistant --restart=unless-stopped -e TZ=Europe/Paris -v /config:/config -p 8123:8123 ghcr.io/home-assistant/home-assistant:stable | |
' | |
} | |
# Création des commandes | |
create_commands() { | |
print_message "Création des commandes..." | |
echo '#!/data/data/com.termux/files/usr/bin/bash | |
proot-distro login alpine -- sh -c "/etc/init.d/docker start && docker start homeassistant"' > $PREFIX/bin/ha-start | |
echo '#!/data/data/com.termux/files/usr/bin/bash | |
proot-distro login alpine -- docker stop homeassistant' > $PREFIX/bin/ha-stop | |
echo '#!/data/data/com.termux/files/usr/bin/bash | |
ha-stop && sleep 5 && ha-start' > $PREFIX/bin/ha-restart | |
echo '#!/data/data/com.termux/files/usr/bin/bash | |
proot-distro login alpine -- docker stats homeassistant' > $PREFIX/bin/ha-stats | |
echo '#!/data/data/com.termux/files/usr/bin/bash | |
read -p "Êtes-vous sûr de vouloir désinstaller Home Assistant ? (o/n) " -n 1 -r | |
echo | |
if [[ $REPLY =~ ^[Oo]$ ]] | |
then | |
ha-stop | |
proot-distro login alpine -- docker rm homeassistant | |
proot-distro remove alpine | |
rm -f $PREFIX/bin/ha-start $PREFIX/bin/ha-stop $PREFIX/bin/ha-restart $PREFIX/bin/ha-stats $PREFIX/bin/ha-uninstall | |
print_message "Home Assistant a été désinstallé." | |
else | |
print_message "Désinstallation annulée." | |
fi' > $PREFIX/bin/ha-uninstall | |
chmod +x $PREFIX/bin/ha-start $PREFIX/bin/ha-stop $PREFIX/bin/ha-restart $PREFIX/bin/ha-stats $PREFIX/bin/ha-uninstall | |
} | |
# Installation principale | |
main() { | |
print_message "Début de l'installation de Home Assistant..." | |
install_dependencies | |
install_alpine | |
install_docker_and_ha | |
create_commands | |
print_message "Installation terminée !" | |
print_message "Utilisez 'ha-start' pour démarrer Home Assistant." | |
print_message "Accédez à Home Assistant sur http://localhost:8123 depuis votre navigateur Android." | |
print_message "Pour désinstaller, utilisez la commande 'ha-uninstall'." | |
} | |
# Exécution du script | |
main |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment