搜索
查看: 5700|回复: 2

[折腾] 基于树莓派3b+和OpenMedaiVault的网络存储系统搭建

[复制链接]
发表于 2021-1-1 05:26:17 | 显示全部楼层 |阅读模式
本帖最后由 viploser 于 2021-1-1 05:40 编辑

手里有个树莓派3b+,在我手里很久了,刚出品的时候买的(话说现在都出到4b了是吧),一直没怎么用起来,很心疼,我一直都主张善待设备的。

然后想起了我一直以来的独立网盘梦,我之前用这个树莓派搭建过给予owncloud的网盘,但是因为技术有限吧,每次硬件重启之后需要ssh进去手动重新搭建(严格说只是再执行一次搭建代码,文件检测之后就启动服务了、并不是真的彻底重新搭建),自动重启服务的方法尝试多次都失败了,这个owncloud并没有没有真正用起来,我也就没发帖。这个owncloud服务搭建起来的并不是NAS,而是类似网盘那种东西,借助网页上传下载(还没有割韭菜时代的百度网盘大家知道吧,就是那种东西),并没有ftp和smb。

这次我准备搭建一个支持ftp和smb的网盘。我一直用网盘这个词,帖子标题也说的是网络存储系统,而不是NAS,因为我搭建的东西并不是NAS,无论是空间、速度、稳定性、RAID系统内数据自我热备份,哪个角度来说,我这套东西都不是NAS。只是一个配置了ftp+smb的私人网盘而已,一个可以用Finder.app(访达)或者Explorer.exe(资源管理器)做客户端做磁盘映射的网络存储。对我个人来说,我不需要共享、不需要协作、不需要版本管理、不需要hTB级的存储空间、不需要冗余备份、不需要流媒体解码、不需要macOS Time Machine接口,只需要服务器和文件完全在我自己手里。仅此而已。

OpenMedaiVault平台我之前就听说过,我第一次着手看文档的时候恰逢官方下架了所有针对树莓派的img包,取消了img刷机的安装方法,新的安装方法又没有正式发布。我就一直在观望,半个月前,我又找到了官方手册,用了5个小时搭建成功,这十几天来一直稳定运行。今天恰逢新年,图个新气象,就写了这个东西。

硬件上:我用的是树莓派3b+,一张128GB闪迪U1C10的TF卡,电源用的是5V3A的官方电源。我是有外界屏幕和外接键鼠的。


下面开搞。

01.在树莓派官网下载Respberry Pi OS,地址https://www.raspberrypi.org/software/operating-systems/,这个系统分三个版本:如果派不仅仅用来做OpenMedaiVault还偶尔当个arm的linux电脑用一用建议下载Raspberry Pi OS with desktop and recommended software,这里面有全套办公软件还有各种IDE;如果只是当作OpenMedaiVault而且有外接的显示屏和键鼠建议下载Raspberry Pi OS with desktop,有图形界面在树莓派初始设置会简单很多;如果只是当作OpenMedaiVault而且没有外接屏幕建议下载Raspberry Pi OS Lite,当然就需要有一些ssh技能并且熟悉Debian了。浏览器下载系统镜像速度会很慢,这个是可以用torrent或者迅雷的,而且速度还不错。下载后记得用Hash校验一下。
02.下载写卡工具BalenaEtcher,地址https://www.balena.io/etcher/。Windows和macOS都有对应版本。不需要担心macOS下搞Linux会不会出问题,放心,我全程macOS下操作没有出问题。
03.写卡,BalenaEtcher就三个按钮,选择镜像,选择目标硬件,烧写。下载的Respberry Pi OS是有可能是tz文件的,并不需要手动做两次解压,BalenaEtcher已经很智能了。
04.写卡之后macOS下会识别一个boot磁盘,弹出即可;Windows下会提示磁盘需要格式化,不要格式化;然后把卡拿下来。
下面的操作我先按照有显示屏的来写,后面我会补充没有显示屏的操作。
05.把TF卡插在树莓派里,树莓派连好HDMI显示屏,连好键盘鼠标,最后插电。
06.开机选择地区(China)、语言(Chinese Simplified)、时区(Shanghai GMT+8.00)、键盘布局(US Keyboard),连接Wi-Fi或者LAN(注意连接网络的时候跳过系统更新),重设密码,分辨率(图像外是否有黑框);然后重启。
07.重启进入桌面后左上角树莓logo——Preference——Raspberry Pi Configuration,进入树莓派高级设置,在Interfaces将SSH设置为Enable(就是打开SSH)。
08.菜单栏点击Terminal,输入sudo -i,切换到root账户。输入apt-get update,拉取更新列表。输入apt-get upgrade更新当前软件。
09.根据更新情况,必要时重启树莓派。
10.在Terminal输入sudo -i,切换到root账户。输入wget -O - https://github.com/OpenMediaVaul ... /raw/master/install | sudo bash。
  1. wget -O - https://github.com/OpenMediaVault-Plugin-Developers/installScript/raw/master/install | sudo bash
复制代码
11.跑脚本的过程异常漫长,期间不要关闭Terminal,不要打开新的Terminal窗口,不要断电。坐和放宽。
12.跑完脚本会有一个DONE,然后出新可以输入命令的行。这时候脚本的输出会建议重启树莓派,不要重启!
13.从路由器拉取当前树莓派的IP地址,并将MAC和IP实现DHCP内的绑定。
14.从和树莓派同局域网段的电脑访问树莓派IP地址,弹出OpenMedaiVault管理界面,语言下拉菜单选择简体中文,登陆用户名admin,密码openmedaivault,登陆后进入左侧“访问权限管理——用户”选项卡,在右侧详情中新建用户。在“常规”面板名称不能是pi、不能是admin、必须为英文,设置并确认密码,Shell选择/bin/bash,取消勾选“不允许用户修其他账户”;在“用户组”中全选所有的系统账户,不勾选用户账户pi;在“公钥”面板不做处理;新建账户。在上方拉出的“配置已经改变,你必须应用才能使他们生效。”条中选择“应用”建立新账户。
/*我看到过两条视频都说此处要删除原有的“pi”用户,但是删除pi之后会导致树莓派重启后无法登陆SSH、omv也无法加载或维护,树莓派无法进行任何后期维护。所以,pi账户一定要保留。*/
15.在树莓派里按脚本提示重启树莓派,可能需要输入yes,可能需要输入reboot手动重启(脚本也在更新)。
16.从和树莓派同局域网段的电脑访问树莓派IP地址,用第14步新建的用户名登陆。(登陆后应该是和admin一样的管理页面,如果不是,则是“不允许用户修其他账户”没有勾选。)登陆后进入左侧“系统——插件”选项卡安装“openmediavault-sharerootfs”插件。这个插件可以在树莓派系统所在的TF卡里建立共享文件夹,而不是仅能在外接磁盘建立共享文件夹。
17.进入左侧“访问权限管理——共享文件夹”选项卡,右侧点击“添加”,“名称”建议设置为英文,“设备”选择rootfs,“路径”保持不动(默认为系统TF卡非引导分区根目录),“权限”设为根据需要来设置,“其他”代表不登陆时文件的读写权限。添加共享文件夹后选中,在“特权”菜单中勾选第14步所建用户的读写权限。(如果着套东西只是一人用的话,“权限”建议设为“管理员:读/写,用户:无权限,其它:无权限”更为安全)(如果添加共享文件夹时权限设置不满意,修改在“ACL”按钮下)
18.进入左侧“服务——FTP”选项卡,右侧“设置”下点击“启用”,“共享”下添加第17步建立的共享文件夹。
19.进入左侧“服务——SMB/CIFS”选项卡,右侧“设置”下点击“启用”,“共享”下添加第17步建立的共享文件夹。
20.在上方拉出的“配置已经改变,你必须应用才能使他们生效。”条中选择“应用”建立新账户。之后退出当前账户,进入admin账户,修改密码。
21.在浏览器中输入ftp://树莓派IP,查看是否可以访问。
22.Windows系统下进入“网络”或者“网上邻居”可以查看到RESPBERRYPI设备,在“这台电脑”、“计算机”或者“我的电脑”右键调出映射网络驱动器选项,地址为ftp://树莓派IP/第17步建立的共享文件夹名称。之后输入第14步的用户名和密码登录。
23.macOS系统下用Safari浏览器访问ftp://树莓派IP/,会提示在Finder访达中打开,输入第14步的用户名和密码登录。特别注意,macOS内Finder对ftp是只读的,是macOS的权限问题,不是omv的问题。


对于没有外接屏幕和键鼠的用户,只是需要通过SSH访问并操作树莓派。
a.下载系统和写卡操作不变。写卡后在TF卡的boot分区新建一个ssh文件(一个没有内容没有扩展名的的ssh文件),Windows下可以用新建文本文档改成ssh,macOS下可以用文本编辑器新建一个空文档。
b.从macOS连接到树莓派不需要其他软件,macOS自带的Terminal支持SSH;从Windows连接到树莓派建议用PuTTY或者XShell(我自己的Surface Go+Win10_20H2里cmd支持SSH,但我部署过Git所以我不确定是否是系统支持)。
c.SSH连接到树莓派需要先从路由器拉取树莓派的IP地址,之后在Terminal或者PuTTY输入ssh pi@树莓派IP,提示当前密钥,输入yes(完整的yes而不是y)接入,登陆初始密码是respberry。
d.因为没有图形界面进行树莓派初始设置。需要在SSH内完成。登陆进树莓派后输入sudo -i切换为root用户。输入raspi-config进入高级设置。这个界面类似早期没有图形化操作的BIOS,全键盘操作。需要完成地区、时区、网络接入方式的设置。pi用户的密码也在raspi-config中修改。
e.OpenMedaiVault安装脚本的命令也是需要在SSH输入的。
不要把SSH想的很复杂,你就把电脑上的SSH界面理解成树莓派接入显示器键盘鼠标后的Terminal界面就可以了。唯一的不同就是需要用“ssh pi@树莓派IP”的命令建立连接,仅此而已。


关于公网访问的问题。不要在树莓派里设置ddns!正确做法是在路由器设置ddns和端口转发。然后公网访问的地址就是指定端口号的ftp了。
这个应该不需要解释了吧。路由器里的ddns是哪家的就去看哪家的官网;自己挑一个顺眼的小众端口转发到树莓派内网IP的21端口即可。


多唠叨两句。apt-get update和apt-get upgrade更新速度非常慢,但是我不建议换软件源,换源后update和upgrade确实快了,但是OpenMedaiVault依赖的东西不一定源里都有。树莓派的Raspberry Pi OS是基于Debian的,哪怕是全图形界面也是需要一定的Linux基础的,全小白很难上手,或者说是学习曲线很陡。我自己虽然把Ubuntu当作主力系统用过半年多,也是很依赖图形界面的,并没有太高的代码水平,我主业工作也不是程序员或者网络工程,所以我自己也不是Linux水平多高的人。这个东西是我自己的一个分享,也是摸着石头过河,我过来了,便写下来了。太高深的我也不懂、太刁钻的我也回答不上来。大家共同进步。


今天是2021年第一天。愿诸事顺利,诸神护佑。



viploser
https://arcice.org
UTC+8.00 2021-01-01 05:40
回复

使用道具 举报

 楼主| 发表于 2021-1-1 05:29:15 | 显示全部楼层

脚本我贴在这 大家一起学习


  1. #!/bin/bash
  2. #
  3. # shellcheck disable=SC1090,SC1091,SC1117,SC2016,SC2046,SC2086,SC2174
  4. #
  5. # Copyright (c) 2015-2020 OpenMediaVault Plugin Developers
  6. # Copyright (c) 2017-2020 Armbian Developers
  7. #
  8. # This file is licensed under the terms of the GNU General Public
  9. # License version 2. This program is licensed "as is" without any
  10. # warranty of any kind, whether express or implied.
  11. #
  12. # Ideas/code used from:
  13. # https://github.com/armbian/config/blob/master/debian-software
  14. # https://forum.openmediavault.org/index.php/Thread/25062-Install-OMV5-on-Debian-10-Buster/
  15. #
  16. # version: 1.2.11
  17. #

  18. if [[ $(id -u) -ne 0 ]]; then
  19.   echo "This script must be executed as root or using sudo."
  20.   exit 99
  21. fi

  22. systemd="$(ps --no-headers -o comm 1)"
  23. if [ ! "${systemd}" = "systemd" ]; then
  24.   echo "This system is not running systemd.  Exiting..."
  25.   exit 100
  26. fi

  27. declare -i cfg=0
  28. declare -i ipv6=0
  29. declare -i skipFlash=0
  30. declare -i skipNet=0
  31. declare -i version

  32. declare -l codename
  33. declare -l omvCodename
  34. declare -l omvInstall=""
  35. declare -l omvextrasInstall=""

  36. cpuFreqDef="/etc/default/cpufrequtils"
  37. crda="/etc/default/crda"
  38. defaultGovSearch="^CONFIG_CPU_FREQ_DEFAULT_GOV_"
  39. forceIpv4="/etc/apt/apt.conf.d/99force-ipv4"
  40. ioniceCron="/etc/cron.d/make_nas_processes_faster"
  41. ioniceScript="/usr/sbin/omv-ionice"
  42. keyserver="hkp://keyserver.ubuntu.com:80"
  43. omvKey="/etc/apt/trusted.gpg.d/openmediavault-archive-keyring.asc"
  44. omvRepo="http://packages.openmediavault.org/public"
  45. omvSources="/etc/apt/sources.list.d/openmediavault.list"
  46. rfkill="/usr/sbin/rfkill"
  47. smbOptions="min receivefile size = 16384\nwrite cache size = 524288\ngetwd cache = yes\nsocket options = TCP_NODELAY IPTOS_LOWDELAY"
  48. url="https://github.com/OpenMediaVault-Plugin-Developers/packages/raw/master/"
  49. wpaConf="/etc/wpa_supplicant/wpa_supplicant.conf"

  50. export DEBIAN_FRONTEND=noninteractive
  51. export APT_LISTCHANGES_FRONTEND=none
  52. export LANG=C.UTF-8

  53. if [ -f /etc/armbian-release ]; then
  54.   . /etc/armbian-release
  55. fi

  56. while getopts "fhin" opt; do
  57.   echo "option ${opt}"
  58.   case "${opt}" in
  59.     f)
  60.       skipFlash=1
  61.       ;;
  62.     h)
  63.       echo "Use the following flags:"
  64.       echo "  -f"
  65.       echo "    to skip the installation of the flashmemory plugin"
  66.       echo "  -i"
  67.       echo "    enable using IPv6 for apt"
  68.       echo "  -n"
  69.       echo "    to skip the network setup"
  70.       echo ""
  71.       echo "Examples:"
  72.       echo "  install"
  73.       echo "  install -f"
  74.       echo "  install -n"
  75.       exit 100
  76.       ;;
  77.     i)
  78.       ipv6=1
  79.       ;;
  80.     n)
  81.       skipNet=1
  82.       ;;
  83.     \?)
  84.       echo "Invalid option: -${OPTARG}"
  85.       ;;
  86.   esac
  87. done

  88. # Fix permissions on / if wrong
  89. echo "Current / permissions = $(stat -c %a /)"
  90. chmod g-w,o-w /
  91. echo "New / permissions = $(stat -c %a /)"

  92. # if ipv6 is not enabled, create apt config file to force ipv4
  93. if [ ${ipv6} -ne 1 ]; then
  94.   echo "Forcing IPv4 only for apt..."
  95.   echo 'Acquire::ForceIPv4 "true";' > ${forceIpv4}
  96. fi

  97. echo "Updating repos before installing..."
  98. apt-get update

  99. echo "Installing lsb_release..."
  100. apt-get --yes --no-install-recommends --reinstall install lsb-release

  101. arch="$(dpkg --print-architecture)"
  102. codename="$(lsb_release --codename --short)"

  103. case ${codename} in
  104.   stretch)
  105.     confCmd="omv-mkconf"
  106.     network="interfaces"
  107.     ntp="ntp"
  108.     omvCodename="arrakis"
  109.     phpfpm="php-fpm"
  110.     version=4
  111.     ;;
  112.   buster)
  113.     confCmd="omv-salt deploy run"
  114.     network="systemd-networkd"
  115.     ntp="chrony"
  116.     omvCodename="usul"
  117.     phpfpm="phpfpm"
  118.     version=5
  119.     ;;
  120.   *)
  121.     echo "Unsupported version.  Exiting..."
  122.     exit 1
  123.   ;;
  124. esac
  125. echo "${omvCodename} :: ${version}"

  126. hostname=$(</etc/hostname)
  127. tz=$(</etc/timezone)

  128. # Add Debian signing keys to raspbian to prevent apt-get update failures
  129. # when OMV adds security and/or backports repos
  130. if grep -q raspberrypi.org /etc/apt/sources.list.d/*; then
  131.   echo "Adding Debian signing keys..."
  132.   for key in AA8E81B4331F7F50 112695A0E562B32A 04EE7237B7D453EC 648ACFD622F3D138; do
  133.     apt-key adv --no-tty --keyserver ${keyserver} --recv-keys "${key}"
  134.   done
  135.   echo "Installing monit from raspberrypi repo..."
  136.   apt-get --yes --no-install-recommends install -t ${codename} monit
  137. fi

  138. echo "Install prerequisites..."
  139. apt-get --yes --no-install-recommends install dirmngr gnupg

  140. # install openmediavault if not installed already
  141. omvInstall=$(dpkg -l | awk '$2 == "openmediavault" { print $1 }')
  142. if [[ ! "${omvInstall}" == "ii" ]]; then
  143.   echo "Installing openmediavault required packages..."
  144.   if ! apt-get --yes --no-install-recommends install postfix; then
  145.     echo "failed installing postfix"
  146.     exit 2
  147.   fi

  148.   echo "Adding openmediavault repo and key..."
  149.   echo "deb ${omvRepo} ${omvCodename} main" > ${omvSources}
  150.   wget -O "${omvKey}" ${omvRepo}/archive.key
  151.   apt-key add "${omvKey}"

  152.   echo "Updating repos..."
  153.   if ! apt-get update; then
  154.     echo "failed to update apt repos."
  155.     exit 2
  156.   fi

  157.   echo "Install openmediavault-keyring..."
  158.   if ! apt-get --yes install openmediavault-keyring; then
  159.     echo "failed to install openmediavault-keyring package."
  160.     exit 2
  161.   fi

  162.   monitInstall=$(dpkg -l | awk '$2 == "monit" { print $1 }')
  163.   if [[ ! "${monitInstall}" == "ii" ]]; then
  164.     if ! apt-get --yes --no-install-recommends install monit; then
  165.       echo "failed installing monit"
  166.       exit 2
  167.     fi
  168.   fi

  169.   echo "Installing openmediavault..."
  170.   aptFlags="--yes --auto-remove --show-upgraded --allow-downgrades --allow-change-held-packages --no-install-recommends"
  171.   cmd="apt-get ${aptFlags} install openmediavault"
  172.   if ! ${cmd}; then
  173.     echo "failed to install openmediavault package."
  174.     exit 2
  175.   fi

  176.   if [ ${version} -gt 4 ]; then
  177.     omv-confdbadm populate
  178.   else
  179.     omv-initsystem
  180.     omv-mkconf interfaces
  181.     omv-mkconf issue
  182.   fi
  183. fi

  184. # check if openmediavault is install properly
  185. omvInstall=$(dpkg -l | awk '$2 == "openmediavault" { print $1 }')
  186. if [[ ! "${omvInstall}" == "ii" ]]; then
  187.   echo "openmediavault package failed to install or is in a bad state."
  188.   exit 3
  189. fi

  190. . /etc/default/openmediavault
  191. . /usr/share/openmediavault/scripts/helper-functions

  192. # remove backports from sources.list to avoid duplicate sources warning
  193. sed -i "/\(stretch\|buster\)-backports/d" /etc/apt/sources.list

  194. if [ "${codename}" = "eoan" ]; then
  195.   omv_set_default "OMV_APT_USE_KERNEL_BACKPORTS" false true
  196. fi

  197. # install omv-extras
  198. echo "Downloading omv-extras.org plugin for openmediavault ${version}.x ..."
  199. file="openmediavault-omvextrasorg_latest_all${version}.deb"

  200. if [ -f "${file}" ]; then
  201.   rm ${file}
  202. fi
  203. wget ${url}/${file}
  204. if [ -f "${file}" ]; then
  205.   if ! dpkg --install ${file}; then
  206.     echo "Installing other dependencies ..."
  207.     apt-get --yes --fix-broken install
  208.     omvextrasInstall=$(dpkg -l | awk '$2 == "openmediavault-omvextrasorg" { print $1 }')
  209.     if [[ ! "${omvextrasInstall}" == "ii" ]]; then
  210.       echo "omv-extras failed to install correctly.  Trying to fix with ${confCmd} ..."
  211.       if ${confCmd} omvextras; then
  212.         echo "Trying to fix apt ..."
  213.         apt-get --yes --fix-broken install
  214.       else
  215.         echo "${confCmd} failed and openmediavault-omvextrasorg is in a bad state."
  216.         exit 3
  217.       fi
  218.     fi
  219.     omvextrasInstall=$(dpkg -l | awk '$2 == "openmediavault-omvextrasorg" { print $1 }')
  220.     if [[ ! "${omvextrasInstall}" == "ii" ]]; then
  221.       echo "openmediavault-omvextrasorg package failed to install or is in a bad state."
  222.       exit 3
  223.     fi
  224.   fi

  225.   echo "Updating repos ..."
  226.   apt-get update
  227. else
  228.   echo "There was a problem downloading the package."
  229. fi

  230. # disable armbian log services if found
  231. for service in log2ram armbian-ramlog armbian-zram-config; do
  232.   if systemctl list-units --full -all | grep ${service}; then
  233.     systemctl stop ${service}
  234.     systemctl disable ${service}
  235.   fi
  236. done
  237. rm -f /etc/cron.daily/armbian-ram-logging
  238. if [ -f "/etc/default/armbian-ramlog" ]; then
  239.   sed -i "s/ENABLED=.*/ENABLED=false/g" /etc/default/armbian-ramlog
  240. fi
  241. if [ -f "/etc/default/armbian-zram-config" ]; then
  242.   sed -i "s/ENABLED=.*/ENABLED=false/g" /etc/default/armbian-zram-config
  243. fi
  244. if [ -f "/etc/systemd/system/logrotate.service" ]; then
  245.   rm -f /etc/systemd/system/logrotate.service
  246.   systemctl daemon-reload
  247. fi

  248. # install flashmemory plugin unless disabled
  249. if [ ${skipFlash} -eq 1 ]; then
  250.   echo "Skipping installation of the flashmemory plugin."
  251. else
  252.   echo "Install folder2ram..."
  253.   if apt-get --yes --fix-missing --no-install-recommends install folder2ram; then
  254.     echo "Installed folder2ram."
  255.   else
  256.     echo "Failed to install folder2ram."
  257.   fi
  258.   echo "Install flashmemory plugin..."
  259.   if apt-get --yes install openmediavault-flashmemory; then
  260.     echo "Installed flashmemory plugin."
  261.   else
  262.     echo "Failed to install flashmemory plugin."
  263.     ${confCmd} flashmemory
  264.     apt-get --yes --fix-broken install
  265.   fi
  266. fi

  267. # change default OMV settings
  268. omv_config_update "/config/services/smb/extraoptions" "$(echo -e "${smbOptions}")"
  269. omv_config_update "/config/services/ssh/enable" "1"
  270. omv_config_update "/config/services/ssh/permitrootlogin" "1"
  271. omv_config_update "/config/system/time/ntp/enable" "1"
  272. omv_config_update "/config/system/time/timezone" "${tz}"
  273. omv_config_update "/config/system/network/dns/hostname" "${hostname}"

  274. # disable monitoring and apply changes
  275. echo "Disabling data collection ..."
  276. /usr/sbin/omv-rpc -u admin "perfstats" "set" '{"enable":false}'
  277. /usr/sbin/omv-rpc -u admin "config" "applyChanges" '{ "modules": ["monit","rrdcached","collectd"],"force": true }'

  278. # set min/max frequency and watchdog for RPi boards
  279. if [[ $(awk '$1 == "Model" { print $3 }' /proc/cpuinfo) = "Raspberry" ]]; then
  280.   omv_set_default "OMV_WATCHDOG_DEFAULT_MODULE" "bcm2835_wdt"
  281.   omv_set_default "OMV_WATCHDOG_CONF_WATCHDOG_TIMEOUT" "14"

  282.   MIN_SPEED="$(</sys/devices/system/cpu/cpufreq/policy0/cpuinfo_min_freq)"
  283.   MAX_SPEED="$(</sys/devices/system/cpu/cpufreq/policy0/cpuinfo_max_freq)"
  284.   # Determine if RPi4 (for future use)
  285.   if [[ $(awk '$1 == "Revision" { print $3 }' /proc/cpuinfo) =~ [a-c]03111 ]]; then
  286.     BOARD="rpi4"
  287.   fi
  288.   cat << EOF > ${cpuFreqDef}
  289. GOVERNOR="ondemand"
  290. MIN_SPEED="${MIN_SPEED}"
  291. MAX_SPEED="${MAX_SPEED}"
  292. EOF
  293. fi

  294. if [ -f "${cpuFreqDef}" ]; then
  295.   . ${cpuFreqDef}
  296. else
  297.   # set cpufreq settings if no defaults
  298.   if [ -f "/proc/config.gz" ]; then
  299.     defaultGov="$(zgrep "${defaultGovSearch}" /proc/config.gz | sed -e "s/${defaultGovSearch}\(.*\)=y/\1/")"
  300.   elif [ -f "/boot/config-$(uname -r)" ]; then
  301.     defaultGov="$(grep "${defaultGovSearch}" /boot/config-$(uname -r) | sed -e "s/${defaultGovSearch}\(.*\)=y/\1/")"
  302.   fi
  303.   if [ -z "${DEFAULT_GOV}" ]; then
  304.     defaultGov="ondemand"
  305.   fi
  306.   GOVERNOR=${defaultGov,,}
  307.   MIN_SPEED="0"
  308.   MAX_SPEED="0"
  309. fi

  310. # set defaults in /etc/default/openmediavault
  311. omv_set_default "OMV_CPUFREQUTILS_GOVERNOR" "${GOVERNOR}"
  312. omv_set_default "OMV_CPUFREQUTILS_MINSPEED" "${MIN_SPEED}"
  313. omv_set_default "OMV_CPUFREQUTILS_MAXSPEED" "${MAX_SPEED}"

  314. if [ ${version} -gt 4 ]; then
  315.   # update pillar default list - /srv/pillar/omv/default.sls
  316.   omv-salt stage run prepare
  317. fi

  318. # update config files
  319. for service in nginx ${phpfpm} samba flashmemory ssh ${ntp} timezone monit rrdcached collectd cpufrequtils apt watchdog; do
  320.   ${confCmd} ${service}
  321. done

  322. # create php directories if they don't exist
  323. modDir="/var/lib/php/modules"
  324. if [ ! -d "${modDir}" ]; then
  325.   mkdir --parents --mode=0755 ${modDir}
  326. fi
  327. sessDir="/var/lib/php/sessions"
  328. if [ ! -d "${sessDir}" ]; then
  329.   mkdir --parents --mode=1733 ${sessDir}
  330. fi

  331. if [ -f "${forceIpv4}" ]; then
  332.   rm ${forceIpv4}
  333. fi

  334. if [ -f "/etc/init.d/proftpd" ]; then
  335.   systemctl disable proftpd.service
  336.   systemctl stop proftpd.service
  337. fi

  338. if [[ "${arch}" == "amd64" ]] || [[ "${arch}" == "i386" ]]; then
  339.   # skip ionice on x86 boards
  340.   echo "Done."
  341.   exit 0
  342. fi

  343. # Add a cron job to make NAS processes more snappy and silence rsyslog
  344. cat << EOF > /etc/rsyslog.d/omv-armbian.conf
  345. :msg, contains, "omv-ionice" ~
  346. :msg, contains, "action " ~
  347. :msg, contains, "netsnmp_assert" ~
  348. :msg, contains, "Failed to initiate sched scan" ~
  349. EOF
  350. systemctl restart rsyslog

  351. # add taskset to ionice cronjob for biglittle boards
  352. case ${BOARD} in
  353.   odroidxu4|bananapim3|nanopifire3|nanopct3plus|nanopim3)
  354.     taskset='; taskset -c -p 4-7 ${srv}'
  355.     ;;
  356.   *rk3399*|*edge*|nanopct4|nanopim4|nanopineo4|renegade-elite|rockpi-4*|rockpro64|helios64)
  357.     taskset='; taskset -c -p 4-5 ${srv}'
  358.     ;;
  359.   odroidn2)
  360.     taskset='; taskset -c -p 2-5 ${srv}'
  361.     ;;
  362. esac

  363. # create ionice script
  364. cat << EOF > ${ioniceScript}
  365. #!/bin/sh
  366. for srv in \$(pgrep "ftpd|nfsiod|smbd"); do
  367.   ionice -c1 -p \${srv} ${taskset};
  368. done
  369. EOF
  370. chmod 755 ${ioniceScript}

  371. # create ionice cronjob
  372. cat << EOF > ${ioniceCron}
  373. * * * * * root ${ioniceScript} >/dev/null 2>&1
  374. EOF
  375. chmod 600 ${ioniceCron}

  376. # add pi user to ssh group if it exists
  377. if getent passwd pi > /dev/null; then
  378.   echo "Adding pi user to ssh group ..."
  379.   usermod -a -G ssh pi
  380. fi

  381. # add user running the script to ssh group if not pi or root
  382. if [ -n "${USER}" ] && [ ! "${USER}" = "root" ] && [ ! "${USER}" = "pi" ]; then
  383.   if getent passwd ${USER} > /dev/null; then
  384.     echo "Adding ${USER} to the ssh group ..."
  385.     usermod -a -G ssh ${USER}
  386.   fi
  387. fi

  388. # remove networkmanager and dhcpcd5 then configure networkd
  389. if [ ${version} -gt 4 ] && [ ${skipNet} -ne 1 ]; then

  390.   if [ "${BOARD}" = "helios64" ]; then
  391.     echo -e '#!/bin/sh\n/usr/sbin/ethtool --offload eth1 rx off tx off' > /usr/lib/networkd-dispatcher/routable.d/10-disable-offloading
  392.   fi

  393.   defLink="/etc/systemd/network/99-default.link"
  394.   if [ -e "${defLink}" ]; then
  395.     rm -fv "${defLink}"
  396.   fi

  397.   echo "Removing network-manager and dhcpcd5 ..."
  398.   apt-get -y --autoremove purge network-manager dhcpcd5

  399.   echo "Enable and start systemd-resolved ..."
  400.   systemctl enable systemd-resolved
  401.   systemctl start systemd-resolved
  402.   rm /etc/resolv.conf
  403.   ln -s /run/systemd/resolve/resolv.conf /etc/resolv.conf

  404.   if [ -f "${rfkill}" ]; then
  405.     echo "Unblocking wifi with rfkill ..."
  406.     ${rfkill} unblock all
  407.   fi

  408.   for nic in $(ls /sys/class/net | grep -vE "br-|docker|dummy|lo|tun|virbr"); do
  409.     if grep -q "<devicename>${nic}</devicename>" ${OMV_CONFIG_FILE}; then
  410.       echo "${nic} already found in database.  Skipping..."
  411.       continue
  412.     fi

  413.     if udevadm info /sys/class/net/${nic} | grep -q wlan; then
  414.       if [ -f "${wpaConf}" ]; then
  415.         country=$(awk -F'=' '/country=/{gsub(/["\r]/,""); print $NF}' ${wpaConf})
  416.         wifiName=$(awk -F'=' '/ssid="/{st=index($0,"="); ssid=substr($0,st+1); gsub(/["\r]/,"",ssid); print ssid; exit}' ${wpaConf})
  417.         wifiPass=$(awk -F'=' '/psk="/{st=index($0,"="); pass=substr($0,st+1); gsub(/["\r]/,"",pass); print pass; exit}' ${wpaConf})

  418.         if [ -n "${country}" ] && [ -n "${wifiName}" ] && [ -n "${wifiPass}" ]; then
  419.           if [ -f "${crda}" ]; then
  420.             awk -i inplace -F'=' -v country="$country" '/REGDOMAIN=/{$0=$1"="country} {print $0}' ${crda}
  421.           fi
  422.           echo "Adding ${nic} to openmedivault database ..."
  423.           jq --null-input --compact-output \
  424.             "{uuid: "${OMV_CONFIGOBJECT_NEW_UUID}", devicename: "${nic}", type: "wifi", method: "dhcp", method6: "dhcp", wpassid: "${wifiName}", wpapsk: "${wifiPass}"}" | \
  425.             omv-confdbadm update "conf.system.network.interface" -
  426.           if grep -q "<devicename>${nic}</devicename>" ${OMV_CONFIG_FILE}; then
  427.             cfg=1
  428.           fi
  429.         fi
  430.       fi
  431.     else
  432.       echo "Adding ${nic} to openmedivault database ..."
  433.       jq --null-input --compact-output \
  434.         "{uuid: "${OMV_CONFIGOBJECT_NEW_UUID}", devicename: "${nic}", method: "dhcp", method6: "dhcp"}" | \
  435.         omv-confdbadm update "conf.system.network.interface" -
  436.       if grep -q "<devicename>${nic}</devicename>" ${OMV_CONFIG_FILE}; then
  437.         cfg=1
  438.       fi
  439.     fi
  440.   done

  441.   if [ ${cfg} -eq 1 ]; then
  442.     echo "IP address may change and you could lose connection if running this script via ssh."

  443.     # create config files
  444.     ${confCmd} ${network}

  445.     echo "Network setup for DHCP.  Rebooting..."
  446.     reboot
  447.   else
  448.     echo "It is recommended to reboot and then setup the network adapter in the openmediavault web interface."
  449.   fi

  450. fi

  451. exit 0
复制代码


回复

使用道具 举报

发表于 2021-1-1 16:33:28 | 显示全部楼层
棒呆
回复

使用道具 举报

发表于 2021-7-27 09:46:34 | 显示全部楼层
回复

使用道具 举报

联系我们(Contact)|手机版|萝卜头IT论坛 ( 苏ICP备15050961号-1 )

GMT+8, 2024-12-22 16:11 , Processed in 0.098008 second(s), 19 queries , Gzip On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表