|
本帖最后由 yunsean 于 2019-12-16 17:58 编辑
我是在NetGear R6300V2上先安装梅林固件,然后安装entware来完成的。整个安装过程颇费周折,其中最要命的是无法启动(折腾了两天后,发现是hass的插件编写有问题,导致了循环依赖),最后所有功能正常,只是内存太小,运行起来比较吃力,如果能找到那种1G内存的路由器应该是个不错的主意。下边说一下具体安装过程,有需要的同学自取(基本都是命令行,自行粘贴复制):
1、首先进入梅林ssh(如何进入我不说了),然后安装entware
entware-setup.sh
2、后续操作可能会遇到python创建线程失败的情况,是因为entware默认栈太小,执行下边解决(100可以设置大一点,我设置50足以):
limit -s 100
3、安装编译换环境,并且下载entware的编译依赖环境(论坛中有同学卡在找不到opensslv.h文件,就是因为这个步骤)
opkg install make gcc pkg-config
mkdir /opt/include
wget -qO- http://pkg.entware.net/binaries/armv7/include/include.tar.gz | tar xvz -C /opt/include
cat << EOF > /opt/bin/gcc_env.sh
#!/bin/sh
export LDFLAGS="-Wl,-rpath=/opt/lib -Wl,--dynamic-linker=/opt/lib/ld-linux.so.3 -L/opt/lib"
export CFLAGS="-O2 -pipe -march=armv7-a -mtune=cortex-a9 -fno-caller-saves -mfloat-abi=soft "
EOF
source /opt/bin/gcc_env.sh
4、顺便修改一下libxml文件,如果有同学要编译linxml2的时候可能会保存
cp -r /opt/include/libxml2/libxml /opt/include/
5、安装ffi,这货不装后续要出错
cd /tmp
wget ftp://sourceware.org/pub/libffi/libffi-3.2.1.tar.gz
tar -zxvf libffi-3.2.1.tar.gz
cd libffi-3.2.1
./configure
make
cp armv7l-unknown-linux-gnueabi/include/*.h /opt/include
cp armv7l-unknown-linux-gnueabi/.libs/* /opt/lib
6、设置一下pip的缓存目录,安装python和pip
mkdir /mnt/sdb1/.cache
ln -s /mnt/sdb1/.cache /root/.cache
opkg install python3 python3-pip libopenssl libffi python3-pyopenssl python3-openssl python3-dev libxml2 libxslt libexslt ffmpeg ffprobe mariadb-server mosquitto
7、这儿是个大坑(可能有其他更优雅的解,但我没找到,卡了半天),entware最新版本用的是python3.7,openssl升级到了1.1,但是但是但是但是但是安装完hass后,python的cryptography居然会依赖于openssl1.0,但在当前这个步骤下cryptography依赖的还是正确的openssl1.1,所以先把暂存起来(我估计应该是hass安装cryptography的时候不是编译安装的,导致下载的二进制版本不匹配,可以用命令cat /opt/lib/python3.7/site-packages/cryptography/hazmat/bindings/_openssl.abi3.so |grep libssl来检查),后续hass装完后拷贝回去覆盖:
cp -r /opt/lib/python3.7/site-packages/cryptography /opt/tmp/
8、更新pip、安装hass
pip3 install --upgrade setuptools pip
python3 -m pip install homeassistant
9、接续第七步,把cryptography拷贝回去
mv /opt/tmp/cryptography /opt/lib/python3.7/site-packages/
10、然后你就玩儿吧,调试期间可以使用命令行启动hass
hass -v --config /opt/etc/homeassistant --pid-file /opt/var/run/hass.pid --log-file /opt/var/log/homeassistant/home-assistant.log
11、配置自启动(随便创建一个文件不会被启动重置的目录,用chmod +x设置执行权限即可):
vi /koolshare/init.d/startent.sh
内容如下:
#!/bin/sh
rm -rf /tmp/opt
ln -s /tmp/mnt/sdb1/entware/ /tmp/opt
/opt/etc/init.d/rc.unslung start
source /opt/bin/gcc_env.sh
/koolshare/init.d/S65mosquitto start
/opt/etc/init.d/hass-daemon start
这里面的sdb1换成你安装entware所在目录哦。
12、/koolshare/init.d/S65mosquitto是为了启动mqtt,内容
#!/bin/sh
#=======================
start() {
if [ `ps |grep mosquitto|grep conf|wc|awk '{print $1}'` -ne 0 ]; then
echo 'Service already running' >&2
return 1
fi
echo -n 'Starting service… ' >&2
mosquitto -c /opt/etc/mosquitto/mosquitto.conf > /dev/null &
}
#=======================
stop() {
killall mosquitto > /dev/null
}
#=======================
restart() {
killall mosquitto > /dev/null
mosquitto -c /opt/etc/mosquitto/mosquitto.conf &
}
#=======================
enter() {
logger "Enter to some ssht..."
}
#======================
status() {
logger "SSHT status."
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
restart
;;
enter)
enter
;;
status) status
;;
*)
echo "Usage: (start|stop|restart|enter|status)"
exit 1
;;
esac
echo SSHT Done.
exit 0
EOF
cat: can't open 'start': No such file or directory
dylan@Router:/tmp# cat /koolshare/init.d/S65mosquitto
#!/bin/sh
#=======================
start() {
if [ `ps |grep mosquitto|grep conf|wc|awk '{print $1}'` -ne 0 ]; then
echo 'Service already running' >&2
return 1
fi
echo -n 'Starting service… ' >&2
mosquitto -c /opt/etc/mosquitto/mosquitto.conf > /dev/null &
}
#=======================
stop() {
killall mosquitto > /dev/null
}
#=======================
restart() {
killall mosquitto > /dev/null
mosquitto -c /opt/etc/mosquitto/mosquitto.conf &
}
#=======================
enter() {
logger "Enter to some ssht..."
}
#======================
status() {
logger "SSHT status."
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
restart
;;
enter)
enter
;;
status) status
;;
*)
echo "Usage: (start|stop|restart|enter|status)"
exit 1
;;
esac
echo SSHT Done.
exit 0
EOF
13、/opt/etc/init.d/hass-daemon内容
#!/bin/sh
### BEGIN INIT INFO
# Provides: hass
# Required-Start: $local_fs $network $named $time $syslog
# Required-Stop: $local_fs $network $named $time $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Description: Home\ Assistant
### END INIT INFO
# /etc/init.d Service Script for Home Assistant
# Created with: https://gist.github.com/naholyr/4275302#file-new-service-sh
PRE_EXEC=""
# Typically /usr/bin/hass
HASS_BIN="hass"
RUN_AS="dylan"
PID_DIR="/opt/var/run"
PID_FILE="$PID_DIR/hass.pid"
CONFIG_DIR="/opt/etc/homeassistant"
LOG_DIR="/opt/var/log/homeassistant"
LOG_FILE="$LOG_DIR/home-assistant.log"
FLAGS="-v --config $CONFIG_DIR --pid-file $PID_FILE --log-file $LOG_FILE --daemon"
start() {
create_piddir
if [ -f $PID_FILE ] && kill -0 $(cat $PID_FILE) 2> /dev/null; then
echo 'Service already running' >&2
return 1
fi
echo -n 'Starting service… ' >&2
local CMD="$PRE_EXEC $HASS_BIN $FLAGS"
$CMD
if [ $? -ne 0 ]; then
echo "Failed" >&2
else
echo 'Done' >&2
fi
}
stop() {
if [ ! -f "$PID_FILE" ] || ! kill -0 $(cat "$PID_FILE") 2> /dev/null; then
echo 'Service not running' >&2
return 1
fi
echo -n 'Stopping service… ' >&2
kill $(cat "$PID_FILE")
while ps -p $(cat "$PID_FILE") > /dev/null 2>&1; do sleep 1;done;
rm -f $PID_FILE
echo 'Done' >&2
}
install() {
echo "Installing Home Assistant Daemon (hass-daemon)"
#update-rc.d hass-daemon defaults
create_piddir
mkdir -p $CONFIG_DIR
chown $RUN_AS $CONFIG_DIR
mkdir -p $LOG_DIR
chown $RUN_AS $LOG_DIR
}
uninstall() {
echo "Are you really sure you want to uninstall this service? The INIT script will"
echo -n "also be deleted! That cannot be undone. [yes|No] "
local SURE
read SURE
if [ "$SURE" = "yes" ]; then
stop
remove_piddir
echo "Notice: The config directory has not been removed"
echo $CONFIG_DIR
echo "Notice: The log directory has not been removed"
echo $LOG_DIR
#update-rc.d -f hass-daemon remove
rm -fv "$0"
echo "Home Assistant Daemon has been removed. Home Assistant is still installed."
fi
}
create_piddir() {
if [ ! -d "$PID_DIR" ]; then
mkdir -p $PID_DIR
chown $RUN_AS "$PID_DIR"
fi
}
remove_piddir() {
if [ -d "$PID_DIR" ]; then
if [ -e "$PID_FILE" ]; then
rm -fv "$PID_FILE"
fi
rmdir -fv "$PID_DIR"
fi
}
case "$1" in
start)
start
;;
stop)
stop
;;
install)
install
;;
uninstall)
uninstall
;;
restart)
stop
start
;;
*)
echo "Usage: $0 {start|stop|restart|install|uninstall}"
esac
都记得要用chmod +x 添加可执行权限哦
参考文献:
在梅林上安装entware:https://www.jianshu.com/p/919e29010bc6
梅林搭建home-assistant:https://ghostcir.com/s/216.html
Using gcc (native compilation):https://github.com/Entware/Entware-ng/wiki/Using-gcc-%28native-compilation%29
|
|