-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.sh
147 lines (111 loc) · 5.16 KB
/
install.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#!/bin/bash
# Check for sudo
if [ "$EUID" -ne 0 ]; then
echo -e "\e[1;31mPlease run this script with sudo: sudo $0\e[0m"
exit 1
fi
# Check if Home Assistant Supervised is already installed
if [ -d "/usr/share/hassio" ]; then
echo -e "\e[1;31mHome Assistant Supervised is already installed. Exiting script.\e[0m"
exit 0
fi
# Function to check if a package is installed
function is_package_installed() {
local package_name="$1"
dpkg -s "$package_name" 2>/dev/null | grep -q "Status: install ok installed"
}
# List of packages to install
packages=("apparmor" "cifs-utils" "curl" "dbus" "jq" "libglib2.0-bin" "lsb-release" "network-manager" "nfs-common" "udisks2" "wget" "systemd-resolved" "systemd-journal-remote")
# Install only if the package is not installed
for package in "${packages[@]}"; do
if is_package_installed "$package"; then
echo -e "\e[1;32m$package is already installed.\e[0m"
else
sudo apt install "$package" -y
fi
done
#Install Docker-CE with the following command:
curl -fsSL get.docker.com | sh
# Determine system architecture
ARCHITECTURE=$(dpkg --print-architecture)
# Convert "amd64" to "x86_64" | "armhf" to "armv7" | "arm64" to "aarch64"
case $ARCHITECTURE in
amd64) ARCHITECTURE="x86_64" ;;
armhf) ARCHITECTURE="armv7" ;;
arm64) ARCHITECTURE="aarch64" ;;
*) echo "Unsupported architecture: $ARCHITECTURE" ; exit 1 ;;
esac
# Get the latest release URL
RELEASES_URL="https://api.github.com/repos/home-assistant/os-agent/releases/latest"
LATEST_RELEASE=$(curl -s "$RELEASES_URL" | jq -r '.assets[] | select(.name | endswith("'"_$ARCHITECTURE.deb"'")) | .browser_download_url')
if [ -z "$LATEST_RELEASE" ]; then
echo "Failed to fetch the latest release URL for os-agent_$ARCHITECTURE.deb"
exit 1
fi
# Extract package name from URL
PACKAGE_NAME=$(basename "$LATEST_RELEASE")
# Print package name
echo -e "\e[1;32mPackage Name: $PACKAGE_NAME\e[0m"
# Download the latest Home Assistant OS Agent
echo -e "\e[1;32mDownloading the latest Home Assistant OS Agent...\e[0m"
wget -O "$PACKAGE_NAME" "$LATEST_RELEASE"
# Install Home Assistant OS Agent
echo -e "\e[1;32mInstalling Home Assistant OS Agent...\e[0m"
sudo dpkg -i $PACKAGE_NAME
# Download Home Assistant Supervised
echo -e "\e[1;32mDownloading Home Assistant Supervised...\e[0m"
wget -O homeassistant-supervised.deb https://github.com/home-assistant/supervised-installer/releases/latest/download/homeassistant-supervised.deb
# Extract control.tar.xz
echo -e "\e[1;32mExtract control.tar.xz...\e[0m"
sudo ar x homeassistant-supervised.deb
sudo tar xf control.tar.xz
# Edit control file to remove systemd-resolved dependency
echo -e "\e[1;32mEdit control file to remove systemd-resolved dependency...\e[0m"
sed -i '/Depends:.*systemd-resolved/d' control
# Recreate control.tar.xz
echo -e "\e[1;32mRecreate control.tar.xz...\e[0m"
sudo tar cfJ control.tar.xz postrm postinst preinst control templates
# Recreate the .deb package
echo -e "\e[1;32mRecreate the .deb package...\e[0m"
sudo ar rcs homeassistant-supervised.deb debian-binary control.tar.xz data.tar.xz
# Install Home Assistant Supervised
echo -e "\e[1;32mInstalling Home Assistant Supervised...\e[0m"
sudo BYPASS_OS_CHECK=true dpkg -i ./homeassistant-supervised.deb
# Set the initial delay time
initial_delay=600 # 5 minutes in seconds
# Countdown loop with parallel execution of docker check
while [ $initial_delay -gt 0 ]; do
minutes=$(($initial_delay / 60))
seconds=$(($initial_delay % 60))
echo -ne "\e[1;33mWaiting for $minutes:$seconds minutes to check the installation of Home Assistant...\e[0m\r"
# Check if any container with "hassio" in the name is running
if sudo docker ps --format '{{.Names}}' | grep -q "hassio"; then
echo -e "\e[1;32mA Hassio-related container is running.\e[0m"
break
fi
sleep 1
((initial_delay--))
done
gdbus introspect --system --dest io.hass.os --object-path /io/hass/os
DATA_SHARE=/my/own/homeassistant dpkg --force-confdef --force-confold -i homeassistant-supervised.deb
# If no Hassio-related container is running, perform system reboot
if [ $initial_delay -eq 0 ]; then
echo -e "\e[1;31mNo Hassio-related container is running. Performing system reboot...\e[0m"
sudo reboot
fi
# Check if the directory exists and recreate it if needed
if [ -d "/usr/share/hassio/tmp/homeassistant_pulse" ]; then
echo -e "\e[1;32mDirectory /usr/share/hassio/tmp/homeassistant_pulse already exists.\e[0m"
else
echo -e "\e[1;31mDirectory /usr/share/hassio/tmp/homeassistant_pulse does not exist. Recreating...\e[0m"
sudo mkdir -p /usr/share/hassio/tmp/homeassistant_pulse
fi
# Clean up downloaded files
echo "Cleaning up downloaded files..."
rm -f "$PACKAGE_NAME" "./homeassistant-supervised.deb" "control" "data.tar.xz" "control.tar.xz"
echo -e "\e[1;33mHome Assistant installation completed successfully!\e[0m\n"
echo -e "\e[1;34mA system reboot will be performed to apply the changes.\e[0m\n"
echo -e "\e[1;32mAfter of Reboot Open the link: \e[0m\e[1;92mhttp://$(hostname -I | cut -d' ' -f1):8123\e[0m\n"
echo -e "\e[1;31mIf you see 'This site can�t be reached,' please check again after 10 minutes.\e[0m\n"
# Reboot System
sudo reboot