1 Star 0 Fork 16

我只看看不说话/hassio_install

forked from hassiocn/hassio_install 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
install.sh 25.36 KB
一键复制 编辑 原始数据 按行查看 历史
彭文杰 提交于 2022-11-21 22:54 . install fix
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648
#!/bin/bash
# 颜色
red='\033[0;31m'
green='\033[0;32m'
yellow='\033[0;33m'
plain='\033[0m'
script_version="2021.09.08.0"
function info { echo -e "\e[32m[info] $*\e[39m"; }
function warn { echo -e "\e[33m[warn] $*\e[39m"; }
function version_lt() { test "$(echo "$@" | tr " " "\n" | sort -rV | head -n 1)" != "$1"; }
# 变量
## 安装必备依赖
Ubunt_Debian_Requirements="curl socat jq avahi-daemon net-tools network-manager qrencode apparmor apparmor-utils"
## 获取系统用户用作添加至 docker 用户组
users=($(cat /etc/passwd | awk -F: '$3>=500' | cut -f 1 -d :| grep -v nobody))
users_num=${#users[*]}
title_num=1
check_massage=()
dns_ipaddress=""
## 检查系统架构以区分 machine
if [[ $(getconf LONG_BIT) == "64" ]]; then
machine_map=(intel-nuc odroid-c2 odroid-xu orangepi-prime qemuarm-64 qemux86-64 raspberrypi3-64 raspberrypi4-64 tinker)
machine_info=("英特尔的nuc小主机" "韩国odroid-c2" "韩国odroid-xu" "香橙派" "通用arm设备(例如斐讯N1) 64位系统" "通用X86(普通的PC机电脑)64位系统" "树莓派三代64位系统" "树莓派四代64位系统" "华硕tinker")
default_machine="qemux86-64"
elif [[ $(getconf LONG_BIT) == "32" ]]; then
machine_map=(intel-nuc odroid-c2 odroid-xu orangepi-prime qemuarm qemux86 raspberrypi raspberrypi2 raspberrypi3 raspberrypi4 tinker)
machine_info=("英特尔的nuc小主机" "韩国odroid-c2" "韩国odroid-xu" "香橙派" "通用arm设备(例如斐讯N1)" "通用X86(普通的PC机电脑)" "树莓派一代" "树莓派二代" "树莓派三代" "树莓派四代" "华硕tinker")
default_machine="qemux86"
else
machine_map=(intel-nuc odroid-c2 odroid-xu orangepi-prime qemuarm qemuarm-64 qemux86 qemux86-64 raspberrypi raspberrypi2 raspberrypi3 raspberrypi4 raspberrypi3-64 raspberrypi4-64 tinker)
machine_info=("英特尔的nuc小主机" "韩国odroid-c2" "韩国odroid-xu" "香橙派" "通用arm设备(例如斐讯N1)" "通用arm设备(例如斐讯N1) 64位系统" "通用X86 64位系统(普通的PC机电脑)" "通用X86(普通的PC机电脑)64位系统" "树莓派一代" "树莓派二代" "树莓派三代" "树莓派四代" "树莓派三代64位系统" "树莓派四代64位系统" "华硕tinker")
default_machine="qemux86-64"
fi
machine_num=${#machine_map[*]}
# Function
## 这个方法抄袭自 https://github.com/teddysun/shadowsocks_install
check_sys(){
if [[ -f /etc/redhat-release ]]; then
release="centos"
systemPackage="yum"
elif grep -Eqi "raspbian" /etc/*-release ; then
kernel_version=$(uname -r | grep -oP '\d+\.\d+\.\d+')
if version_lt "${kernel_version}" "5.4.79";then
error "当前 ${kernel_version} 内核系统暂不支持 apparmor 内核模块需要更新内核(≥ 5.4.79)。"
fi
release="raspbian"
systemPackage="apt"
systemCodename=$(grep "VERSION_CODENAME" /etc/*-release | awk -F '=' '{print $2}')
elif grep -Eqi "ubuntu" /etc/issue; then
release="ubuntu"
systemPackage="apt"
systemCodename=$(grep "VERSION_CODENAME" /etc/*-release | awk -F '=' '{print $2}')
elif grep -Eqi "debian" /etc/issue; then
release="debian"
systemPackage="apt"
systemCodename=$(grep "VERSION_CODENAME" /etc/*-release | awk -F '=' '{print $2}')
elif grep -Eqi "centos|red hat|redhat" /etc/issue; then
release="centos"
systemPackage="yum"
elif grep -Eqi "centos|red hat|redhat" /proc/version; then
release="centos"
systemPackage="yum"
fi
}
## 下载文件方法
download_file(){
local url=$1
local file_name=$2
if [ -z ${file_name} ];then
if which curl > /dev/null 2>&1 ; then
curl -# -O ${url}
else
wget ${url}
fi
else
if which curl > /dev/null 2>&1 ; then
curl -# -o ${file_name} ${url}
else
wget --output-document=${file_name} ${url}
fi
fi
if [[ $? -ne 0 ]];then
error "下载 ${url} 失败,请检查网络与其连接是否正常。"
fi
}
## 切换安装源
replace_source(){
if [[ -z ${systemCodename} ]]; then
error "由于无法确定系统版本,故请手动切换系统源,切换方法参考清华源使用方法:http://mirrors.ustc.edu.cn/help/"
fi
[[ ! -f /etc/apt/sources.list.bak ]] && warn "备份系统源文件为 /etc/apt/sources.list.bak" && mv /etc/apt/sources.list /etc/apt/sources.list.bak
# 清华源
case $(uname -m) in
"x86_64" | "i686" | "i386" )
# debian from x86_64
if [[ ${release} == "debian" ]]; then
{
echo "deb http://mirrors.tuna.tsinghua.edu.cn/debian/ ${systemCodename} main contrib non-free"
echo "deb http://mirrors.tuna.tsinghua.edu.cn/debian/ ${systemCodename}-updates main contrib non-free"
echo "deb http://mirrors.tuna.tsinghua.edu.cn/debian/ ${systemCodename}-backports main contrib non-free"
echo "deb http://mirrors.tuna.tsinghua.edu.cn/debian-security ${systemCodename}/updates main contrib non-free"
} > /etc/apt/sources.list
fi
# Ubuntu from x86_64
if [[ ${release} == "ubuntu" ]]; then
{
echo "deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ ${systemCodename} main restricted universe multiverse"
echo "deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ ${systemCodename}-updates main restricted universe multiverse"
echo "deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ ${systemCodename}-backports main restricted universe multiverse"
echo "deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ ${systemCodename}-security main restricted universe multiverse"
} > /etc/apt/sources.list
fi
;;
"arm" | "armv7l" | "armv6l" | "aarch64" | "armhf" | "arm64" | "ppc64el")
if [[ -f /etc/apt/sources.list.d/armbian.list ]] ;then
warn "发现 armbian 源,替换清华源,如需要恢复请自行到 /etc/apt/sources.list.d/ 文件夹中删除后缀名 \".bak\""
cp /etc/apt/sources.list.d/armbian.list /etc/apt/sources.list.d/armbian.list.bak
sed -i 's|http[s]*://apt.armbian.com|http://mirrors.tuna.tsinghua.edu.cn/armbian|g' /etc/apt/sources.list.d/armbian.list
fi
# debian from ARM
if [[ ${release} == "debian" ]]; then
{
echo "deb http://mirrors.tuna.tsinghua.edu.cn/debian/ ${systemCodename} main contrib non-free"
echo "deb http://mirrors.tuna.tsinghua.edu.cn/debian/ ${systemCodename}-updates main contrib non-free"
echo "deb http://mirrors.tuna.tsinghua.edu.cn/debian/ ${systemCodename}-backports main contrib non-free"
echo "deb http://mirrors.tuna.tsinghua.edu.cn/debian-security ${systemCodename}/updates main contrib non-free"
} > /etc/apt/sources.list
fi
# Ubuntu from ARM
if [[ ${release} == "ubuntu" ]]; then
{
echo "deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ ${systemCodename} main restricted universe multiverse"
echo "deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ ${systemCodename}-updates main restricted universe multiverse"
echo "deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ ${systemCodename}-backports main restricted universe multiverse"
echo "deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ ${systemCodename}-security main restricted universe multiverse"
} > /etc/apt/sources.list
fi
if [[ ${release} == "raspbian" ]]; then
{
echo "deb http://mirrors.tuna.tsinghua.edu.cn/raspbian/raspbian/ ${systemCodename} main non-free contrib rpi"
echo "deb-src http://mirrors.tuna.tsinghua.edu.cn/raspbian/raspbian/ ${systemCodename} main non-free contrib rpi"
} > /etc/apt/sources.list
if [[ -f "/etc/apt/sources.list.d/raspi.list" ]]; then
echo "deb http://mirrors.tuna.tsinghua.edu.cn/raspberrypi/ ${systemCodename} main" > "/etc/apt/sources.list.d/raspi.list"
fi
fi
;;
*) error "[ERROR]: 由于无法获取系统架构,故此无法切换系统源,请跳过系统源切换。"
;;
esac
apt update
if [[ $? -ne 0 ]]; then
mv /etc/apt/sources.list.bak /etc/apt/sources.list
error "[ERROR]: 系统源切换错误,请检查网络连接是否正常,脚本退出"
fi
}
## 更新系统
update_system(){
if [[ ${release} == "debian" ]] || [[ ${release} == "ubuntu" ]] || [[ ${release} == "raspbian" ]]; then
apt upgrade -y
if [[ $? != 0 ]]; then
error "[ERROR]: 系统更新失败,脚本退出。"
fi
info "系统更新成功。"
fi
if [[ ${release} == "ubuntu" ]] ; then
add-apt-repository main
add-apt-repository universe
add-apt-repository restricted
add-apt-repository multiverse
apt update
fi
}
## 安装 docker
docker_install(){
download_file 'https://get.docker.com' 'get-docker.sh'
sed -i 's/DEFAULT_CHANNEL_VALUE="test"/DEFAULT_CHANNEL_VALUE="stable"/' get-docker.sh
chmod u+x get-docker.sh
./get-docker.sh --mirror Aliyun
if ! systemctl status docker > /dev/null 2>&1 ;then
error "Docker 安装失败,请检查上方安装错误信息。 你也可以选择通过搜索引擎,搜索你系统安装docker的方法,安装后重新执行脚本。"
else
info "Docker 安装成功。"
fi
if [[ ! -z ${add_User_Docker} ]];then
warn "添加用户 ${add_User_Docker} 到 Docker 用户组"
usermod -aG docker ${add_User_Docker}
fi
}
## apt 安装依赖方法
apt_install(){
apt update
apt install -y ${*}
if [[ $? -ne 0 ]];then
error "安装${*}失败,请将检查上方安装错误信息。"
fi
}
## 修改 docker 源
change_docker_registry(){
if [ ! -d /etc/docker ];then
mkdir -p /etc/docker
fi
cat << EOF > /etc/docker/daemon.json
{
"log-driver": "journald",
"storage-driver": "overlay2",
"registry-mirrors": [
"https://hub-mirror.c.163.com",
"https://docker.mirrors.ustc.edu.cn"
]
}
EOF
systemctl daemon-reload
systemctl restart docker > /dev/null
info "切换国内源完成"
}
## hassio 安装
hassio_install(){
local i=10
while true;do
stable_json=$(curl -Ls https://gitee.com/hassiocn/version/raw/master/stable.json)
if [[ ! -z ${stable_json} ]]; then
break;
fi
if [[ $i -eq 0 ]]; then
error "获取 hassio 版本号失败,请检查你系统网络与 https://gitee.com 的连接是否正常。"
fi
let i--
done
hassio_version=$(echo ${stable_json} |jq -r '.supervisor')
homeassistant_version=$(echo ${stable_json} |jq -r '.homeassistant.default')
if [ -z ${hassio_version} ] || [ -z ${homeassistant_version} ];then
error "获取 hassio 版本号失败,请检查你网络与 https://gitee.com 连接是否畅通。"
fi
local x=1
while true ; do
[[ $x -eq 10 ]] && error "获取 hassio 官方一键脚本失败,请检查你系统网络与 https://gitee.com 的连接是否正常。"
warn "下载 hassio_install.sh 官方脚本 第${x}次"
download_file 'https://gitee.com/hassiocn/supervised-installer/raw/master/installer.sh' 'hassio_install.sh'
grep -q '#!/usr/bin/env bash' hassio_install.sh && break
((x++))
done
chmod u+x hassio_install.sh
sed -i "s/HASSIO_VERSION=.*/HASSIO_VERSION=${hassio_version}/g" ./hassio_install.sh
# interfaces 不替换ip设置
sed -i 's@read answer < /dev/tty@answer=n@' ./hassio_install.sh
# 清除警告等待
sed -i 's/sleep 10//' ./hassio_install.sh
# 等待 NetworkManager 重启完毕
reset_network_line_num=$(grep -n 'systemctl restart "${SERVICE_NM}"' ./hassio_install.sh | awk -F ':' '{print $1}')
add_shell='i=20\ninfo "Wait for networkmanages to start."\nwhile ! systemctl status ${SERVICE_NM} >/dev/null 2>&1; do\n sleep 1\nlet i--\n [[ i -eq 0 ]] && warn "networkmanages failed to start" && break\ndone'
sed -i "${reset_network_line_num} a${add_shell}" ./hassio_install.sh
warn "从 hub.docker.com 下载 homeassistant/${machine}-homeassistant:${homeassistant_version}......"
local i=10
while true ;do
docker pull homeassistant/${machine}-homeassistant:${homeassistant_version}
if [[ $? -eq 0 ]]; then
docker tag homeassistant/${machine}-homeassistant:${homeassistant_version} homeassistant/${machine}-homeassistant:latest
break;
else
warn "[WARNING]: 从 docker hub 下载 homeassistant/${machine}-homeassistant:${homeassistant_version} 失败,第 ${i} 次重试."
if [[ ${i} -eq 0 ]]; then
error "从 docker 下载 homeassistant/${machine}-homeassistant:${homeassistant_version} 失败,请检查上方失败信息。"
fi
fi
let i--
done
warn "开始 hassio 安装流程。(如出现 [Warning] 请忽略,无须理会)"
./hassio_install.sh -m ${machine} --data-share ${data_share_path}
if ! systemctl status hassio-supervisor > /dev/null ; then
error "安装 hassio 失败,请将上方安装信息发送到论坛询问。脚本退出..."
fi
}
ubuntu_docker_install(){
apt install docker.io -y
}
error(){
echo -e "${red}"
echo "################# 发到论坛时,请把上方日志也一并粘贴发送 ################"
echo "########################### Script Version: ${script_version}###########################"
echo "########################### System version ###########################"
lsb_release -a 2>/dev/null
echo "########################### System version 2 ###########################"
cat /proc/version
echo "########################### System info ###########################"
uname -a
echo "########################### END ###########################"
echo "${1}"
echo -e "${plain}"
warn " 相关问题可以访问https://gitee.com/hassiocn,提出问题"
exit 1
}
wait_homeassistant_run(){
info "等待 homeassistant 启动(由于 hassio 启动需要从 github pull addons 的库,所以启动速度视 pull 速度而定。)"
while true; do
if docker ps| grep -q hassio_supervisor; then
docker logs -f hassio_supervisor &
logs_pid=$!
break;
fi
done
supervisor_log_file=$(docker inspect --format='{{.LogPath}}' hassio_supervisor)
for ((i=0;i<=3000;i++));do
if netstat -napt |grep 8123 > /dev/null ;then
kill ${logs_pid}
return 0
fi
sleep 1
done
kill ${logs_pid}
return 1
}
#检查 IP 合法性
check_ip()
{
IP=$1
if [[ $IP =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then
FIELD1=$(echo $IP|cut -d. -f1)
FIELD2=$(echo $IP|cut -d. -f2)
FIELD3=$(echo $IP|cut -d. -f3)
FIELD4=$(echo $IP|cut -d. -f4)
if [ $FIELD1 -le 255 -a $FIELD2 -le 255 -a $FIELD3 -le 255 -a $FIELD4 -le 255 ]; then
return 0
else
return 1
fi
else
return 1
fi
}
#通过默认网关的网卡接口获取本机有效的IP地址
get_ipaddress(){
local device_name=$(netstat -rn | grep -e '^0\.0\.0\.0' | awk '{print $8}' | head -n1)
ipaddress=$(ifconfig ${device_name} | grep "inet"| grep -v "inet6" | awk '{ print $2}')
if ! check_ip ${ipaddress} ;then
ipaddress='你的服务器的IP地址'
fi
}
# 打印赞赏二维码
print_sponsor(){
local url='https://qr.alipay.com/fkx16030bqmbsoauc8ezmce'
echo ''
warn " [支付宝]: 如果你觉得本脚本帮到您,可以选择请我喝杯咖啡喔~😊 "
qrencode -t UTF8 "${url}"
}
# Main
## 检查脚本运行环境
if ! id | grep -q 'root' 2>/dev/null ;then
error "请输入 \"sudo -s\" 切换至 root 账户运行本脚本...脚本退出"
fi
## 检查环境变量
if ! echo $PATH | grep sbin > /dev/null 2>&1 ;then
error "请使用 sudo -s 切换 root 账号,或者 sudo ./install.sh 运行脚本, su 环境变量不符合脚本要求."
fi
## 检查是否运行于 systemd 环境
if ! ps --no-headers -o comm 1 | grep systemd > /dev/null 2>&1 ;then
error "你的系统不是运行在 systemd 环境下,本脚本不支持此系统!(如 android 之类的虚拟 Linux)"
fi
## 检查系统版本
check_sys
## 配置安装选项
### 警告信息
echo -e "本次安装版本为homeassistant国内定制版,本版本是基于官方版本适配的国内版本,主要去除github/ghcr.io等海外地址访问"
echo -e "本版本为开源免费版本,不提供技术支持和售后保障,您若选择安装,表示您知晓风险,定制者不承担任何法律责任。"
## 1. 配置安装源
echo -e "(${title_num}). 是否将系统源切换为清华源(目前支持 Debian Ubuntu Raspbian 三款系统)"
while true; do
read -p "请输入 y or n(默认 yes):" selected
case ${selected} in
''|yes|y|YES|Y|Yes )
apt_sources=true
break;
;;
no|n|NO|N|No)
apt_sources=false
break;
;;
*)
echo "输入错误,请重新输入。"
;;
esac
done
check_massage+=(" # ${title_num}. 是否将系统源切换为清华源: ${yellow}$(if ${apt_sources};then echo "是";else echo "否";fi)${plain}")
let title_num++
### 2. 选择是否更新系统软件到最新
echo ''
echo ''
echo -e "(${title_num}).是否更新系统软件到最新?"
warn "如果系统依赖版本低于 supervisor 要求,会导致 supervisor 显示系统不健康,最终导致无法安装 addons."
while true; do
read -p '请输入 yes 或者 no(默认:no):' selected
case ${selected} in
Yes|YES|yes|y|Y)
is_upgrade_system=true
break;
;;
''|No|NO|no|n|N)
is_upgrade_system=false
break;
;;
*)
echo -e "输入错误,请重新输入。"
esac
done
check_massage+=(" # ${title_num}. 是否更新系统软件到最新: ${yellow}$(if ${is_upgrade_system};then echo "是,更新系统:${chack_massage_text}"; else echo "否";fi)${plain}")
let title_num++
### 3. 是否将用户添加至 docker 用户组
echo ''
echo ''
while true;do
if [[ ${users_num} -ne 1 ]];then
echo -e "($title_num). 找到该系统中有以下用户名"
echo -e "如下方列表未显示你的用户名,请切换回你用户账号后输入 sudo usermod -aG docker \$USER 添加用户到 docker 用户组。"
i=1
while [[ $i -le ${users_num} ]]; do
echo -e " [${i}]: ${users[$((($i-1)))]}"
let i++
done
echo -e " [s]: 跳过"
read -p '请输入你需要使用 docker 的用户名序号,以加入 docker 用户组:' selected
case ${selected} in
[0-9]*)
if [[ ${users[$(((${selected}-1)))]} != "" ]]; then
echo -e "将${users[$(((${selected}-1)))]}用户添加至 docker 用户组。"
add_User_Docker=${users[$(((${selected}-1)))]}
break;
else
echo -e "输入数字错误请重新选择。"
fi
;;
s|S)
echo -e "跳过添加用户到 docker 用户组。"
break;
;;
*)
echo -e "请输入列表中的数字后按回车,如无数字请输入 s 跳过。"
;;
esac
else
echo -e "(${title_num}). 在你系统内找到 ${users[0]} 用户,是否将其添加至 docker 用户组。"
read -p "请输入 yes 或者 no (默认 yes):" selected
case ${selected} in
''|Yes|YES|yes|y|Y)
echo -e "将${users[0]}用户添加至 docker 用户组。"
add_User_Docker=${users[0]}
break;
;;
No|NO|no|n|N)
echo -e "跳过添加用户到 docker 用户组。"
break;
;;
*)
echo -e "请输入 Yes 或者 No 后按回车确认。"
;;
esac
fi
done
check_massage+=(" # ${title_num}. 是否将用户添加至 Docker 用户组: ${yellow}$(if [ -z ${add_User_Docker} ];then echo "否";else echo "是,添加用户为 ${add_User_Docker}";fi) ${plain}")
let title_num++
### 4. 选择是否切换 Docker 国内源
echo ''
echo ''
echo -e "(${title_num}).是否需要替换 docker 默认源?"
while true; do
read -p '请输入 yes 或者 no(默认:yes):' selected
case ${selected} in
''|Yes|YES|yes|y|Y)
CDR=true
break;
;;
No|NO|no|n|N)
CDR=false
break;
;;
*)
echo -e "输入错误,请重新输入。"
esac
done
check_massage+=(" # ${title_num}. 是否将 Docker 源切换至国内源: ${yellow}$(if ${CDR};then echo "是,切换源选择:${chack_massage_text}"; else echo "否";fi)${plain}")
let title_num++
### 5. 选择设备类型,用于选择 hassio 拉取 homeassistant 容器之用。
echo ''
echo ''
while true;do
echo -e "(${title_num}).请选择你设备类型(默认:${default_machine})"
for (( i = 0; i < ${machine_num}; i++ )); do
echo -e " [$[${i}+1]]: ${machine_map[$i]}: ${machine_info[$i]}"
done
read -p "输入数字 (1-${machine_num}):" selected
case ${selected} in
*[0-9]*)
if [[ ${selected} -le ${machine_num} && ${selected} -gt 0 ]]; then
machine="${machine_map[((${selected}-1))]}"
echo -e "你选择了 ${machine}"
break;
else
echo -e "输入错误,请重新输入"
fi
;;
'')
machine=${default_machine}
echo -e "你选择了 ${machine}"
break;
;;
*)
echo -e "输入错误,请重新输入"
;;
esac
done
check_massage+=(" # ${title_num}. 您的设备类型为: ${yellow}${machine}${plain}")
let title_num++
### 6. 选择 hassio 数据保存路径。
echo ''
echo ''
while true;do
echo -e "(${title_num}).是否需要设置 hassio 数据保存路径(默认:/usr/share/hassio)"
read -p "请输入 yes 或 no (默认:no):" selected
case ${selected} in
Yes|YES|yes|y|Y)
while true; do
read -p "请输入路径:" data_share_path
if [[ ! -d ${data_share_path} ]]; then
mkdir -p ${data_share_path}
if [[ $? -ne 0 ]];then
echo -e "[ERROR] 无法设置改目录为 hassio 数据目录,权限不够。"
else
echo -e "[INFO] 设置路径 ${data_share_path} 成功。"
break;
fi
else
break;
fi
done
break;
;;
''|No|NO|no|n|N)
echo -e "hassio 数据路径为默认路径: /usr/share/hassio"
data_share_path="/usr/share/hassio"
break;
;;
*)
echo -e "请输入 Yes 或者 No 后按回车确认。"
;;
esac
done
check_massage+=(" # ${title_num}. 您的 hassio 数据路径为: ${yellow}${data_share_path}${plain}")
let title_num++
echo " ################################################################################"
for (( i = 0; i < ${#check_massage[@]}; i++ )); do echo -e "${check_massage[$i]}"; done
echo " ################################################################################"
echo "请确认以上信息,继续请按任意键,如需修改请输入 Ctrl+C 结束任务重新执行脚本。"
read selected
## 切换安装源
if [[ ${apt_sources} == true ]]; then
info "切换系统网络源....."
replace_source
else
info "跳过切换系统源。"
fi
## 更新系统至最新
if [[ ${is_upgrade_system} == true ]]; then
info "更新系统至最新....."
update_system
fi
## 定义 Ubuntu 和 Debian 依赖
info "安装 hassio 必要依赖....."
apt_install ${Ubunt_Debian_Requirements}
## 安装 Docker 引擎
if ! command -v docker;then
info "安装 Docker 引擎....."
if [[ ${release} == "ubuntu" ]]; then
ubuntu_docker_install
else
docker_install
fi
else
info "发现系统已安装 docker,跳过 docker 安装"
fi
## 切换 Docker 源为国内源
if [[ ${CDR} == true ]]; then
info "切换 Docker 源为国内源...."
change_docker_registry
else
info "跳过切换 Docker 源...."
fi
get_ipaddress
## 安装 hassio
info "安装 hassio......"
hassio_install
if wait_homeassistant_run ;then
info "hassio 安装完成,请输入 http://${ipaddress}:8123 访问你的 HomeAssistant"
warn " 相关问题可以访问https://bbs.iobroker.cn或者加QQ群776817275咨询"
print_sponsor
else
error "等待 hassio 启动超时!"
fi
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/fack188/hassio_install.git
git@gitee.com:fack188/hassio_install.git
fack188
hassio_install
hassio_install
master

搜索帮助