1 Star 1 Fork 0

叮当他爸 / MiniBoxBuilder

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

MiniBoxBuilder

项目介绍

从零开始构建我的家庭智能BOX

请大家支持:叮铃&叮当

(目前还在建设期,服务可能还不稳定,架构可能随时调整,请谅解)

软件架构

软件架构说明:

可能包含的内容先在此记录下来:

硬件调整:

  1. 足安电源(给BOX和移动硬盘/3.5存机械硬盘供电)
  2. RJ45以太网络(最好升级到千兆网卡)
  3. 相关固定装置(防尘/阻光/散热好)

软件调整:

  1. 手工构建最新的debian操作系统(目前应该是debian9)

  2. 烧录到U盘中制作可启动

  3. 启动系统

  4. 配置IP、主机名,创建日常用户,配置中科大的apt镜像仓库,更新本地缓存

# TODO ip host user group apt-repo
  1. 对NTFS磁盘增加支持(默认已包含)
apt install ntfs-3g
……
  1. 挂载外部硬盘
# 需要挂载的分区列表,多个之间用逗号分隔
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
  1. 安装常用软件:
# 基本软件:
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

# 迅雷下载器:
......
  1. 配置SSH服务:
echo 'PermitRootLogin yes' >> /etc/ssh/sshd_config
  1. 配置git
git config --global user.email "xxxx"
git config --global user.name "xxxx"
  1. 百度高速下载器:
# 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
  1. NODEJS环境:
curl -sL https://deb.nodesource.com/setup_9.x | bash -
apt install -y nodejs
npm install -g cnpm --registry=https://registry.npm.taobao.org
  1. WEB服务(静态博客、照片墙)
# 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的开发包

# ……
  1. HTTP网关(nginx代理)(合并到上面这一步中处理)
# apt install nginx
# ……
  1. 科学上网(在路由器中实现)
# apt install openvpn
# ……
  1. 实现基于WEB管理页面的HTTP/BT/磁力链等下载工具
# 安装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
# ……
  1. 磁盘自动休眠
apt install hdparm
……
  1. 实现家庭多媒体播放(DLNA/SAMBA)
apt install samba minidlna

# 部署博客、个人主页、离线下载、提醒、相册、打印、家电控制、文件备份等WEB系统
……
  1. 自助提醒服务
# 各类提醒主要有:
# 公网IP变化、局域网设备变动、异常天气提醒、代办事项提醒、信用卡还款、手机充值

# 提醒方式:
# 包括播放声音、调用自定义接口、调用tts转换后播放、调用微信接口、邮箱或短信接口
……
  1. 语音互动助理
# 百度接口,图灵机器人,进门欢迎,叫外卖,水电用量和交费,手机充值,播报新闻和天气
# 参考悟空那个项目,用到snowboy实现离线语音短命令的感知
  1. 家电控制
# 电动窗帘,蓝牙音箱,空调,新风,灯,电动窗户,扫地机器人
  1. 监控查看
# 基于四轴或遥控车的移动监控
  1. 待续

参考资料

  1. 用树莓派搭建家庭NAS下载机
  2. 待补充
MIT License Copyright (c) 2022 叮当他爸 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

从零开始构建我的家庭智能BOX 展开 收起
Shell
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
Shell
1
https://gitee.com/yanjingtu/MiniBoxBuilder.git
git@gitee.com:yanjingtu/MiniBoxBuilder.git
yanjingtu
MiniBoxBuilder
MiniBoxBuilder
master

搜索帮助