代码拉取完成,页面将自动刷新
从零开始构建我的家庭智能BOX
请大家支持:叮铃&叮当
(目前还在建设期,服务可能还不稳定,架构可能随时调整,请谅解)
软件架构说明:
可能包含的内容先在此记录下来:
硬件调整:
软件调整:
手工构建最新的debian操作系统(目前应该是debian9)
烧录到U盘中制作可启动
启动系统
配置IP、主机名,创建日常用户,配置中科大的apt镜像仓库,更新本地缓存
# TODO ip host user group apt-repo
apt install ntfs-3g
……
# 需要挂载的分区列表,多个之间用逗号分隔
partList="sda5,sda6,sda7,sda8"
oldIFS=$IFS
IFS=,
for part in ${partList}; do
devPath=/dev/${part}
mountPath=/media/disk/${part}
# 检查挂载点目录是否存在,不存在要自动创建
if ! [ -d ${mountPath} ]; then
echo "目录${mountPath}不存在,创建该目录"
mkdir -p ${mountPath}
fi
# 检查设备是否已按指定格式挂载了,没有的话要自动挂载
if [ "$(cat /etc/mtab | grep ${devPath} | grep ${mountPath})" == "" ]; then
echo "挂载设备${devPath}到${mountPath}"
mount -t ntfs ${devPath} ${mountPath}
fi
# 开机自动挂载
svcFile=/etc/init.d/minibox_automount
if ! [ -f ${svcFile} ]; then
cat > ${svcFile} << EOF
#!/bin/bash
### BEGIN INIT INFO
# Provides: minibox_automount
# Required-Start: \$remote_fs \$network
# Required-Stop: \$remote_fs \$network
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: MiniBox Auto-Mount Script
### END INIT INFO
partList=
case "\$1" in
start)
echo -n "Starting minibox-automount"
oldIFS=\$IFS
IFS=,
for i in \$partList; do
devPath=\$(echo \$i | awk -F@ '{print \$1}')
mountPath=\$(echo \$i | awk -F@ '{print \$2}')
if ! [ -d \${mountPath} ]; then
mkdir -p \${mountPath}
fi
if [ "\$(cat /etc/mtab | grep \${devPath} | grep \${mountPath})" == "" ]; then
mount -t ntfs \${devPath} \${mountPath}
fi
done
IFS=\$oldIFS
;;
stop)
echo -n "Shutting down minibox-automount"
oldIFS=\$IFS
IFS=,
for i in \$partList; do
devPath=\$(echo \$i | awk -F@ '{print \$1}')
mountPath=\$(echo \$i | awk -F@ '{print \$2}')
if [ "\$(cat /etc/mtab | grep \${devPath} | grep \${mountPath})" != "" ]; then
umount \${mountPath}
fi
done
IFS=\$oldIFS
;;
esac
exit
EOF
fi
if [ "$(cat ${svcFile} | grep -E '^partList=' | grep ${devPath} | grep ${mountPath})" == "" ]; then
sed -i "s#^partList=.*\$#\\0${devPath}@${mountPath},#" ${svcFile}
fi
done
IFS=$oldIFS
chmod +x ${svcFile}
update-rc.d -f $(basename ${svcFile}) remove
update-rc.d $(basename ${svcFile}) start 80 3 4 5 . stop 80 0 1 2 6 .
${svcFile} start
# 基本软件:
apt install sudo vim curl openssh-server telnet tree
# 开发工具(golang参考doc/install_golang.sh):
apt install gcc gcc-c++ make autoconf automake git
# WEB服务:
apt install php5-common ......
# NPM加速器:
cnpm
# 迅雷下载器:
......
echo 'PermitRootLogin yes' >> /etc/ssh/sshd_config
git config --global user.email "xxxx"
git config --global user.name "xxxx"
# x86-64架构:
wget https://github.com/iikira/BaiduPCS-Go/releases/download/v3.5.6/BaiduPCS-Go-v3.5.6-linux-amd64.zip
# ARM架构:
wget https://github.com/iikira/BaiduPCS-Go/releases/download/v3.5.6/BaiduPCS-Go-v3.5.6-linux-armv7.zip
mkdir /opt/soft
curpath=$PWD
cd /opt/soft
unzip $curpath/BaiduPCS-Go-v3.5.6-linux-amd64.zip
unzip $curpath/BaiduPCS-Go-v3.5.6-linux-armv7.zip
curl -sL https://deb.nodesource.com/setup_9.x | bash -
apt install -y nodejs
npm install -g cnpm --registry=https://registry.npm.taobao.org
# apt install apache2
# go -> pipe
# 废弃上面的apache2和go语言的pipe,改用下面的nginx+php7(手工编译)
wget ......nginx.tar.gz
wget ......php7.tar.gz
# 编译PHP7
./configure --prefix=/usr/local/php7 --exec-prefix=/usr/local/php7 \
--bindir=/usr/local/php7/bin --sbindir=/usr/local/php7/sbin \
--includedir=/usr/local/php7/include --libdir=/usr/local/php7/lib/php \
--mandir=/usr/local/php7/php/man \
--with-config-file-path=/usr/local/php7/etc \
--with-mysql-sock=/var/run/mysql/mysql.sock \
--with-mhash --with-zlib --enable-zip --enable-mysqlnd --with-mysqli=shared,mysqlnd \
--with-pdo-mysql=shared,mysqlnd --with-gd --with-iconv --enable-inline-optimization \
--disable-debug --disable-rpath --enable-shared --enable-xml --enable-bcmath \
--enable-shmop --enable-sysvsem --enable-mbregex --enable-mbstring --enable-ftp \
--enable-pcntl --enable-sockets --with-xmlrpc --enable-soap --without-pear \
--with-gettext --enable-session --with-curl --with-jpeg-dir --with-freetype-dir \
--enable-opcache --enable-fpm --with-fpm-user=apache --with-fpm-group=apache \
--without-gdbm --disable-fileinfo --with-bz2 --enable-maintainer-zts --with-openssl
make -j2
make install
# 完成后,进入php源码的ext目录下面,应该有gd、pdo_mysql、mysqli、exif等扩展目录,分别进入这些目录
# 执行/usr/local/php7/bin/phpize
# 然后./configure --with-php-config=/usr/local/php7/bin/php-config
# 最后make -j2 && make install
# 需要在/usr/local/php7/etc/php.ini文件中启用对应的扩展
# 注意:编译PHP过程中用with或enable编译过的模块,为内置模块,不需要再单独编译和启用
# 配置PHP服务
ln -s /usr/local/php7/sbin/php-fpm /usr/local/bin/php-fpm
# PHP服务设置为开机自动启动
svcFile=/etc/init.d/minibox_phpfpm
if ! [ -f ${svcFile} ]; then
cat > ${svcFile} << EOF
#!/bin/bash
### BEGIN INIT INFO
# Provides: minibox_phpfpm
# Required-Start: \$remote_fs \$network
# Required-Stop: \$remote_fs \$network
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: MiniBox Auto-Start-Nginx Script
### END INIT INFO
case "\$1" in
start)
echo -n "Starting minibox-php-fpm"
/usr/local/bin/php-fpm
;;
stop)
echo -n "Shutting down minibox-php-fpm"
killall php-fpm
;;
esac
exit
EOF
fi
chmod +x ${svcFile}
update-rc.d -f $(basename ${svcFile}) remove
update-rc.d $(basename ${svcFile}) start 80 3 4 5 . stop 80 0 1 2 6 .
${svcFile} start
# 编译nginx
./configure --prefix=/usr/local/nginx --sbin-path=/usr/local/nginx/sbin/nginx \
--conf-path=/usr/local/nginx/conf/nginx.conf \
--error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log \
--pid-path=/var/run/nginx/nginx.pid --lock-path=/var/lock/nginx.lock \
--user=nginx --group=nginx --with-http_ssl_module --with-http_stub_status_module \
--with-http_gzip_static_module --http-client-body-temp-path=/var/tmp/nginx/client/ --http-proxy-temp-path=/var/tmp/nginx/proxy/ --http-fastcgi-temp-path=/var/tmp/nginx/fcgi/ --http-uwsgi-temp-path=/var/tmp/nginx/uwsgi --http-scgi-temp-path=/var/tmp/nginx/scgi --with-pcre
make -j2
make install
# 配置NGINX服务
ln -s /usr/local/nginx/sbin/nginx /usr/local/bin/nginx
#TODO 调整WEB目录等配置信息
# NGINX服务设置为开机自动启动
svcFile=/etc/init.d/minibox_nginx
if ! [ -f ${svcFile} ]; then
cat > ${svcFile} << EOF
#!/bin/bash
### BEGIN INIT INFO
# Provides: minibox_nginx
# Required-Start: \$remote_fs \$network
# Required-Stop: \$remote_fs \$network
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: MiniBox Auto-Start-Nginx Script
### END INIT INFO
if ! [ -d /var/tmp/nginx/client ]; then
mkdir -p /var/tmp/nginx/client
fi
if ! [ -d /var/run/nginx ]; then
mkdir -p /var/run/nginx
fi
case "\$1" in
start)
echo -n "Starting minibox-nginx"
/usr/local/bin/nginx
;;
stop)
echo -n "Shutting down minibox-nginx"
killall nginx
;;
esac
exit
EOF
fi
chmod +x ${svcFile}
update-rc.d -f $(basename ${svcFile}) remove
update-rc.d $(basename ${svcFile}) start 80 3 4 5 . stop 80 0 1 2 6 .
${svcFile} start
# MARIADB10
# 注意,可以采用系统盘自带的版本,不过需要安装libmysqlclient-dev的开发包
# ……
# apt install nginx
# ……
# apt install openvpn
# ……
# 安装aria2
apt install aria2
# 准备配置文件(参考本仓库中aria2子目录中的配置文件自行修改)
# 创建开机启动脚本(调起命令:sudo -u 用户名 aria2c --conf-path /path/to/xxx.conf -D)
# 部署aria2的WEB管理工具
git clone https://github.com/ziahamza/webui-aria2.git
mv webui-aria2 /var/www/webui-aria2
# ……
apt install hdparm
……
apt install samba minidlna
# 部署博客、个人主页、离线下载、提醒、相册、打印、家电控制、文件备份等WEB系统
……
# 各类提醒主要有:
# 公网IP变化、局域网设备变动、异常天气提醒、代办事项提醒、信用卡还款、手机充值
# 提醒方式:
# 包括播放声音、调用自定义接口、调用tts转换后播放、调用微信接口、邮箱或短信接口
……
# 百度接口,图灵机器人,进门欢迎,叫外卖,水电用量和交费,手机充值,播报新闻和天气
# 参考悟空那个项目,用到snowboy实现离线语音短命令的感知
# 电动窗帘,蓝牙音箱,空调,新风,灯,电动窗户,扫地机器人
# 基于四轴或遥控车的移动监控
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。