# MiniBoxBuilder **Repository Path**: yanjingtu/MiniBoxBuilder ## Basic Information - **Project Name**: MiniBoxBuilder - **Description**: 从零开始构建我的家庭智能BOX - **Primary Language**: Shell - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 2 - **Forks**: 0 - **Created**: 2018-08-18 - **Last Updated**: 2025-04-19 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # MiniBoxBuilder #### 项目介绍 从零开始构建我的家庭智能BOX 请大家支持:[叮铃&叮当](http://jingles.top) (目前还在建设期,服务可能还不稳定,架构可能随时调整,请谅解) #### 软件架构 软件架构说明: 可能包含的内容先在此记录下来: 硬件调整: 1. 足安电源(给BOX和移动硬盘/3.5存机械硬盘供电) 2. RJ45以太网络(最好升级到千兆网卡) 3. 相关固定装置(防尘/阻光/散热好) 软件调整: 1. 手工构建最新的debian操作系统(目前应该是debian9) 2. 烧录到U盘中制作可启动 3. 启动系统 4. 配置IP、主机名,创建日常用户,配置中科大的apt镜像仓库,更新本地缓存 ```bash # TODO ip host user group apt-repo ``` 5. 对NTFS磁盘增加支持(默认已包含) ```bash apt install ntfs-3g …… ``` 6. 挂载外部硬盘 ```bash # 需要挂载的分区列表,多个之间用逗号分隔 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 ``` 7. 安装常用软件: ```bash # 基本软件: 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 # 迅雷下载器: ...... ``` 8. 配置SSH服务: ```bash echo 'PermitRootLogin yes' >> /etc/ssh/sshd_config ``` 9. 配置git ```bash git config --global user.email "xxxx" git config --global user.name "xxxx" ``` 10. 百度高速下载器: ```bash # 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 ``` 11. NODEJS环境: ```bash curl -sL https://deb.nodesource.com/setup_9.x | bash - apt install -y nodejs npm install -g cnpm --registry=https://registry.npm.taobao.org ``` 12. WEB服务(静态博客、照片墙) ```bash # 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的开发包 # …… ``` 13. HTTP网关(nginx代理)(合并到上面这一步中处理) ```bash # apt install nginx # …… ``` 14. 科学上网(在路由器中实现) ```bash # apt install openvpn # …… ``` 15. 实现基于WEB管理页面的HTTP/BT/磁力链等下载工具 ```bash # 安装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 # …… ``` 16. 磁盘自动休眠 ```bash apt install hdparm …… ``` 17. 实现家庭多媒体播放(DLNA/SAMBA) ```bash apt install samba minidlna # 部署博客、个人主页、离线下载、提醒、相册、打印、家电控制、文件备份等WEB系统 …… ``` 18. 自助提醒服务 ```bash # 各类提醒主要有: # 公网IP变化、局域网设备变动、异常天气提醒、代办事项提醒、信用卡还款、手机充值 # 提醒方式: # 包括播放声音、调用自定义接口、调用tts转换后播放、调用微信接口、邮箱或短信接口 …… ``` 19. 语音互动助理 ```bash # 百度接口,图灵机器人,进门欢迎,叫外卖,水电用量和交费,手机充值,播报新闻和天气 # 参考悟空那个项目,用到snowboy实现离线语音短命令的感知 ``` 20. 家电控制 ```bash # 电动窗帘,蓝牙音箱,空调,新风,灯,电动窗户,扫地机器人 ``` 21. 监控查看 ```bash # 基于四轴或遥控车的移动监控 ``` 22. 待续 #### 参考资料 1. [用树莓派搭建家庭NAS下载机](https://blog.csdn.net/lakeheart879/article/details/52982966) 2. 待补充