Compare commits

..

No commits in common. "master" and "20230326" have entirely different histories.

6 changed files with 68 additions and 434 deletions

View File

@ -1,4 +1,4 @@
# GL-iNet 系列路由器 一键iStoreOS风格化脚本
# Gl-iNet 系列路由器 一键iStoreOS风格化脚本
[![GitHub](https://img.shields.io/github/license/wukongdaily/gl-inet-onescript.svg?label=LICENSE&logo=github&logoColor=%20)](https://github.com/wukongdaily/gl-inet-onescript/blob/master/LICENSE)
![GitHub Stars](https://img.shields.io/github/stars/wukongdaily/gl-inet-onescript.svg?style=flat&logo=appveyor&label=Stars&logo=github)
![GitHub Forks](https://img.shields.io/github/forks/wukongdaily/gl-inet-onescript.svg?style=flat&logo=appveyor&label=Forks&logo=github)
@ -17,16 +17,15 @@
- 💻 支持`一键安装紫色的Argon主题`
- 💻 支持`一键安装文件管理器`
- 🔑 支持`一键设置MT-3000风扇开始工作的温度`
- 🌏 支持`一键部署Docker运行环境`
- 🌏 支持`一键安装docker-compose`
- 🌏 支持`一键部署Docker运行环境(开发中)`
- 🌏 支持`一键安装Docker Compose(开发中)`
- 🐋 支持`一键安装GL原厂adguardhome`
- 📕 支持`一键恢复原厂的OPKG软件源`
- 🔑 支持`MT-3000 一键更换分区到U盘`
- 💡 使用条件GL-iNet 原厂固件(非测试版、预览版)
- ❓ 其他功能和特点会持续迭代
- GL-inet MT-6000✅
- GL-inet MT-3000 ✅
- GL-inet MT-2500 ✅ 固件版本4.5.0(最好降级到此版本)
- OrangePi Zero3(官方Openwrt镜像)
- GL-inet MT-2500 ✅
## 🚀 快速上手
@ -34,20 +33,22 @@
### 1. SSH连接到路由器,或者在路由器终端执行如下命令
```bash
wget -O gl-inet.sh https://cafe.cpolar.top/wkdaily/gl-inet-onescript/raw/branch/master/gl-inet.sh && chmod +x gl-inet.sh && ./gl-inet.sh
wget -O gl-inet.sh https://raw.githubusercontent.com/wukongdaily/gl-inet-onescript/master/gl-inet.sh?$(date +%s) && chmod +x gl-inet.sh && ./gl-inet.sh
```
### 或者是备用仓库地址(内地可用)
### 下次如何调用? 输入快捷键 g 即可
```bash
g
wget -O gl-inet.sh https://gitee.com/wukongdaily/gl_onescript/raw/master/gl-inet.sh?$(date +%s) && chmod +x gl-inet.sh && ./gl-inet.sh
```
### 下次如何调用,在当前目录下执行
```bash
sh gl-inet.sh
```
### 2.单独安装Docker
```bash
wget -O do_docker.sh https://cafe.cpolar.top/wkdaily/gl-inet-onescript/raw/branch/master/docker/do_docker.sh && chmod +x do_docker.sh && ./do_docker.sh
wget -O do_docker.sh https://raw.githubusercontent.com/wukongdaily/gl-inet-onescript/master/docker/do_docker.sh?$(date +%s) && chmod +x do_docker.sh && ./do_docker.sh
```
### 3.单独安装iStore商店
```bash
wget -O /tmp/reinstall_istore.sh https://gitee.com/wukongdaily/gl_onescript/raw/master/reinstall_istore.sh && chmod +x /tmp/reinstall_istore.sh && /tmp/reinstall_istore.sh
@ -64,30 +65,20 @@ wget -O /tmp/reinstall_istore.sh https://gitee.com/wukongdaily/gl_onescript/raw/
### 5.新手ssh连接注意事项
https://github.com/wukongdaily/HowToUseSSH
### 6.使用独立版docker-compose
```bash
docker-compose version
```
```bash
# 注意上述代码中使用的是独立版docker-compose并非标准安装的docker compose
# 区别就是中间没有空格是一个独立的可执行文件。当然这个叫做docker-compose的可执行文件
# 你可以任意命名不过就是习惯这样写还有的人重命名为docker_compose之类的都可以。
```
### 辅助视频教程⬇️
https://www.bilibili.com/video/BV1YJ4m1L7A3/
# Docker面板的选择
## 🔑 安装1panel 面板 来管理Docker 容器
### 可以使用 docker离线包加载
```bash
国内地址 https://pan.baidu.com/s/1Zh913sP6rZWXmhC_rKjWQA?pwd=1111
https://pan.baidu.com/s/1Lm9dkXhvPionZPVXOBXCjw?pwd=1111
备选地址 https://drive.google.com/drive/folders/15HL-lHxW9J74Fwwebrg0lMjRsenScWnO
```
### 上传到U盘其他空间(这里注意是/mnt/upan_data)
### 上传到U盘其他空间
```bash
docker load < /mnt/upan_data/1panel-arm64.tar.gz
docker load < /mnt/upan_data/1panel.tar
```
```bash
@ -96,11 +87,11 @@ docker run -d \
--restart always \
--network host \
-v /var/run/docker.sock:/var/run/docker.sock \
-v /www/data/1panel-data:/mnt/data_sda2/1panel_data \
-v /www/data/1panel-data:/opt \
-e TZ=Asia/Shanghai \
moelin/1panel:latest
```
`其中 /mnt/data_sda2/ 可以换成自己实际的路径,最好是空间大点的`
- 默认端口10086
- 默认账户1panel
- 默认密码1panel_password
@ -135,24 +126,6 @@ https://pan.baidu.com/s/1S5jxahCzE-HyIa-mUvOcZQ?pwd=1111
### istore
https://github.com/linkease/istore
![mt3000](https://github.com/wukongdaily/gl-inet-onescript/assets/143675923/0ff6cb12-0812-4198-b97b-30698da6a8c4)
# 其他docker举例 盒子助手docker版
```bash
docker run -d \
--restart unless-stopped \
--name tvhelper \
-p 2299:22 \
-p 2288:80 \
-v "/mnt/upan_data/tvhelper_data:/tvhelper/shells/data" \
-e PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/lib/android-sdk/platform-tools \
wukongdaily/box:latest
```
# 常见问题
- 1、如果你发现运行容器后,访问docker容器的web界面之后路由器的指示灯发生闪烁不用慌其实没有断网。
wan口网线拔了再插上就好了。其实不处理也无所谓的。闪烁也不代表没有网络。不准确的。
- 2、如果你发现运行容器后,访问不了docker容器的web界面。一般重启路由器就能解决。
- 3、请注意为了节省路由器空间,平时上传文件 最好是上传到 /mnt/upan_data 这个目录下。因为这是U盘空间比较大。
# 💰打赏作者💰
<img src="https://github.com/wukongdaily/tvhelper-docker/assets/143675923/1f92c5ba-1b6b-4967-a1ab-20697159badc" width="30%" />

View File

@ -8,7 +8,6 @@ blue() { echo -e "\033[34m\033[01m[MESSAGE] $1\033[0m"; }
light_magenta() { echo -e "\033[95m\033[01m[NOTICE] $1\033[0m"; }
light_yellow() { echo -e "\033[93m\033[01m[NOTICE] $1\033[0m"; }
# 获取路由器型号信息
get_router_name() {
cat /tmp/sysinfo/model
@ -34,7 +33,7 @@ install_depends_apps() {
# 备份 /etc/opkg/distfeeds.conf
cp /etc/opkg/distfeeds.conf /etc/opkg/distfeeds.conf.backup
# 先替换为 mt3000 的软件源来安装 lsblk 和 fdisk 工具
mt3000_opkg="https://cafe.cpolar.top/wkdaily/gl-inet-onescript/raw/branch/master/mt-3000/distfeeds.conf"
mt3000_opkg="https://raw.githubusercontent.com/wukongdaily/gl-inet-onescript/master/mt-3000/distfeeds.conf"
wget -O /etc/opkg/distfeeds.conf ${mt3000_opkg}
green "正在更新为 mt3000 的软件源"
cat /etc/opkg/distfeeds.conf

View File

@ -1,18 +1,20 @@
#!/bin/sh
# 定义颜色输出函数
red() { echo -e "\033[31m\033[01m$1\033[0m"; }
green() { echo -e "\033[32m\033[01m$1\033[0m"; }
yellow() { echo -e "\033[33m\033[01m$1\033[0m"; }
blue() { echo -e "\033[34m\033[01m$1\033[0m"; }
light_magenta() { echo -e "\033[95m\033[01m$1\033[0m"; }
light_yellow() { echo -e "\033[93m\033[01m$1\033[0m"; }
cyan() { echo -e "\033[38;2;0;255;255m$1\033[0m"; }
red() {
echo -e "\033[31m\033[01m$1\033[0m"
}
green() {
echo -e "\033[32m\033[01m$1\033[0m"
}
yellow() {
echo -e "\033[33m\033[01m$1\033[0m"
}
blue() {
echo -e "\033[34m\033[01m$1\033[0m"
}
light_magenta() {
echo -e "\033[95m\033[01m$1\033[0m"
}
third_party_source="https://istore.linkease.com/repo/all/nas_luci"
# 设置全局命令 g
cp -f "$0" /usr/bin/g
chmod +x /usr/bin/g
setup_base_init() {
#添加出处信息
@ -37,19 +39,15 @@ install_istore_os_style() {
do_install_argon_skin
#增加首页终端图标
opkg install ttyd
#默认使用体积很小的文件传输:系统——文件传输
do_install_filetransfer
#默认安装必备工具SFTP 方便下载文件 比如finalshell等工具可以直接浏览路由器文件
is-opkg install app-meta-sftp
is-opkg install 'app-meta-ddnsto'
#安装首页需要的文件管理功能
is-opkg install 'app-meta-linkease'
# 安装磁盘管理
is-opkg install 'app-meta-diskman'
FILE_PATH="/etc/openwrt_release"
NEW_DESCRIPTION="Openwrt like iStoreOS Style by wukongdaily"
CONTENT=$(cat $FILE_PATH)
UPDATED_CONTENT=$(echo "$CONTENT" | sed "s/DISTRIB_DESCRIPTION='[^']*'/DISTRIB_DESCRIPTION='$NEW_DESCRIPTION'/")
echo "$UPDATED_CONTENT" >$FILE_PATH
# 若已安装iStore商店则在概览中追加iStore字样
if ! grep -q " like iStoreOS" /tmp/sysinfo/model; then
sed -i '1s/$/ like iStoreOS/' /tmp/sysinfo/model
fi
}
# 安装iStore 参考 https://github.com/linkease/istore
do_istore() {
@ -78,7 +76,6 @@ do_istore() {
/tmp/is-opkg opkg install --force-reinstall luci-app-store || exit $?
[ -s "/etc/init.d/tasks" ] || /tmp/is-opkg opkg install --force-reinstall taskd
[ -s "/usr/lib/lua/luci/cbi.lua" ] || /tmp/is-opkg opkg install luci-compat >/dev/null 2>&1
}
#设置风扇工作温度
@ -163,7 +160,7 @@ add_dhcp_domain() {
add_author_info() {
uci set system.@system[0].description='wukongdaily'
uci set system.@system[0].notes='文档说明:
https://tvhelper.cpolar.top/'
https://github.com/wukongdaily/gl-inet-onescript'
uci commit system
}
@ -282,12 +279,12 @@ recovery_opkg_settings() {
case "$router_name" in
*3000*)
echo "Router name contains '3000'."
mt3000_opkg="https://cafe.cpolar.top/wkdaily/gl-inet-onescript/raw/branch/master/mt-3000/distfeeds.conf"
mt3000_opkg="https://raw.githubusercontent.com/wukongdaily/gl-inet-onescript/master/mt-3000/distfeeds.conf"
wget -O /etc/opkg/distfeeds.conf ${mt3000_opkg}
;;
*2500*)
echo "Router name contains '2500'."
mt2500a_opkg="https://cafe.cpolar.top/wkdaily/gl-inet-onescript/raw/branch/master/mt-2500a/distfeeds.conf"
mt2500a_opkg="https://raw.githubusercontent.com/wukongdaily/gl-inet-onescript/master/mt-2500a/distfeeds.conf"
wget -O /etc/opkg/distfeeds.conf ${mt2500a_opkg}
;;
*6000*)
@ -304,14 +301,14 @@ update_opkg_config() {
echo "MT-6000 kernel version: $kernel_version"
case $kernel_version in
5.4*)
mt6000_opkg="https://cafe.cpolar.top/wkdaily/gl-inet-onescript/raw/branch/master/mt-6000/distfeeds-5.4.conf"
mt6000_opkg="https://raw.githubusercontent.com/wukongdaily/gl-inet-onescript/master/mt-6000/distfeeds-5.4.conf"
wget -O /etc/opkg/distfeeds.conf ${mt6000_opkg}
# 更换5.4.238 内核之后 缺少的依赖
mkdir -p /tmp/mt6000
wget -O /tmp/mt6000/script-utils.ipk "https://cafe.cpolar.top/wkdaily/gl-inet-onescript/raw/branch/master/mt-6000/script-utils.ipk"
wget -O /tmp/mt6000/mdadm.ipk "https://cafe.cpolar.top/wkdaily/gl-inet-onescript/raw/branch/master/mt-6000/mdadm.ipk"
wget -O /tmp/mt6000/lsblk.ipk "https://cafe.cpolar.top/wkdaily/gl-inet-onescript/raw/branch/master/mt-6000/lsblk.ipk"
wget -O /tmp/mt6000/script-utils.ipk "https://raw.githubusercontent.com/wukongdaily/gl-inet-onescript/master/mt-6000/script-utils.ipk?$(date +%s)"
wget -O /tmp/mt6000/mdadm.ipk "https://raw.githubusercontent.com/wukongdaily/gl-inet-onescript/master/mt-6000/mdadm.ipk?$(date +%s)"
wget -O /tmp/mt6000/lsblk.ipk "https://raw.githubusercontent.com/wukongdaily/gl-inet-onescript/master/mt-6000/lsblk.ipk?$(date +%s)"
opkg update
if [ -f "/tmp/mt6000/lsblk.ipk" ]; then
# 先卸载之前安装过的lsblk,确保使用的是正确的lsblk
@ -320,7 +317,7 @@ update_opkg_config() {
opkg install /tmp/mt6000/*.ipk
;;
5.15*)
mt6000_opkg="https://cafe.cpolar.top/wkdaily/gl-inet-onescript/raw/branch/master/mt-6000/distfeeds.conf"
mt6000_opkg="https://raw.githubusercontent.com/wukongdaily/gl-inet-onescript/master/mt-6000/distfeeds.conf"
wget -O /etc/opkg/distfeeds.conf ${mt6000_opkg}
;;
*)
@ -332,9 +329,10 @@ update_opkg_config() {
do_luci_app_adguardhome() {
setup_software_source 0
opkg remove gl-sdk4-adguardhome --force-removal-of-dependent-packages
green "请访问 https://github.com/wukongdaily/RunFilesBuilder/"
green "自行生成带内核最新版luci-app-adguradhome的run安装包 然后在iStore安装"
opkg remove gl-sdk4-ui-adguardhome
opkg remove gl-sdk4-adguardhome
opkg install adguardhome
echo "请访问 http://"$(uci get network.lan.ipaddr)":3000 初始化设置adguardhome "
}
do_luci_app_wireguard() {
@ -349,30 +347,17 @@ update_luci_app_quickstart() {
# 如果 /bin/is-opkg 存在,则执行 is-opkg update
is-opkg update
is-opkg install luci-i18n-quickstart-zh-cn --force-depends >/dev/null 2>&1
opkg install iptables-mod-tproxy
opkg install iptables-mod-socket
opkg install iptables-mod-iprange
yellow "恭喜您!现在你的路由器已经变成iStoreOS风格啦!"
green "现在您可以访问8080端口 查看是否生效 http://192.168.8.1:8080"
green "更多up主项目和动态 请务必收藏我的导航站 https://tvhelper.cpolar.top "
green "赞助本项目作者 https://wkdaily.cpolar.top/01 "
addr_hostname=$(uci get system.@system[0].hostname)
green "如果没有首页和网络向导,可以执行第8项 更新luci_app_quickstart"
else
red "请先执行第一项 一键iStoreOS风格化"
fi
}
# 安装体积非常小的文件传输软件 默认上传位置/tmp/upload/
do_install_filetransfer() {
mkdir -p /tmp/luci-app-filetransfer/
cd /tmp/luci-app-filetransfer/
wget -O luci-app-filetransfer_all.ipk "https://cafe.cpolar.top/wkdaily/gl-inet-onescript/raw/branch/master/luci-app-filetransfer/luci-app-filetransfer_all.ipk"
wget -O luci-lib-fs_1.0-14_all.ipk "https://cafe.cpolar.top/wkdaily/gl-inet-onescript/raw/branch/master/luci-app-filetransfer/luci-lib-fs_1.0-14_all.ipk"
opkg install *.ipk --force-depends
}
do_install_depends_ipk() {
wget -O "/tmp/luci-lua-runtime_all.ipk" "https://cafe.cpolar.top/wkdaily/gl-inet-onescript/raw/branch/master/theme/luci-lua-runtime_all.ipk"
wget -O "/tmp/libopenssl3.ipk" "https://cafe.cpolar.top/wkdaily/gl-inet-onescript/raw/branch/master/theme/libopenssl3.ipk"
wget -O "/tmp/luci-lua-runtime_all.ipk" "https://raw.githubusercontent.com/wukongdaily/gl-inet-onescript/master/theme/luci-lua-runtime_all.ipk"
wget -O "/tmp/libopenssl3.ipk" "https://raw.githubusercontent.com/wukongdaily/gl-inet-onescript/master/theme/libopenssl3.ipk"
opkg install "/tmp/luci-lua-runtime_all.ipk"
opkg install "/tmp/libopenssl3.ipk"
}
@ -385,9 +370,9 @@ do_install_argon_skin() {
# 所以这里安装上一个版本2.2.9,考虑到主题皮肤并不需要长期更新,因此固定版本没问题
opkg update
opkg install luci-lib-ipkg
wget -O "/tmp/luci-theme-argon.ipk" "https://cafe.cpolar.top/wkdaily/gl-inet-onescript/raw/branch/master/theme/luci-theme-argon-master_2.2.9.4_all.ipk"
wget -O "/tmp/luci-app-argon-config.ipk" "https://cafe.cpolar.top/wkdaily/gl-inet-onescript/raw/branch/master/theme/luci-app-argon-config_0.9_all.ipk"
wget -O "/tmp/luci-i18n-argon-config-zh-cn.ipk" "https://cafe.cpolar.top/wkdaily/gl-inet-onescript/raw/branch/master/theme/luci-i18n-argon-config-zh-cn.ipk"
wget -O "/tmp/luci-theme-argon.ipk" "https://raw.githubusercontent.com/wukongdaily/gl-inet-onescript/master/theme/luci-theme-argon-master_2.2.9.4_all.ipk"
wget -O "/tmp/luci-app-argon-config.ipk" "https://raw.githubusercontent.com/wukongdaily/gl-inet-onescript/master/theme/luci-app-argon-config_0.9_all.ipk"
wget -O "/tmp/luci-i18n-argon-config-zh-cn.ipk" "https://raw.githubusercontent.com/wukongdaily/gl-inet-onescript/master/theme/luci-i18n-argon-config-zh-cn.ipk"
cd /tmp/
opkg install luci-theme-argon.ipk luci-app-argon-config.ipk luci-i18n-argon-config-zh-cn.ipk
# 检查上一个命令的返回值
@ -413,76 +398,12 @@ do_install_filemanager() {
}
#更新脚本
update_myself() {
wget -O gl-inet.sh "https://cafe.cpolar.top/wkdaily/gl-inet-onescript/raw/branch/master/gl-inet.sh" && chmod +x gl-inet.sh
wget -O gl-inet.sh https://raw.githubusercontent.com/wukongdaily/gl-inet-onescript/master/gl-inet.sh?$(date +%s) && chmod +x gl-inet.sh
echo "脚本已更新并保存在当前目录 gl-inet.sh,现在将执行新脚本。"
./gl-inet.sh
exit 0
}
#根据release地址和命名前缀获取apk地址
get_docker_compose_url() {
if [ $# -eq 0 ]; then
echo "需要提供GitHub releases页面的URL作为参数。"
return 1
fi
local releases_url=$1
# 使用curl获取重定向的URL
latest_url=$(curl -Ls -o /dev/null -w "%{url_effective}" "$releases_url")
# 使用sed从URL中提取tag值,并保留前导字符'v'
tag=$(echo $latest_url | sed 's|.*/v|v|')
# 检查是否成功获取到tag
if [ -z "$tag" ]; then
echo "未找到最新的release tag。"
return 1
fi
# 拼接docker-compose下载链接
local repo_path=$(echo "$releases_url" | sed -n 's|https://github.com/\(.*\)/releases/latest|\1|p')
docker_compose_download_url="https://github.com/${repo_path}/releases/download/${tag}/docker-compose-linux-aarch64"
echo "$docker_compose_download_url"
}
# 下载并安装Docker Compose
do_install_docker_compose() {
# https://github.com/docker/compose/releases/download/v2.26.0/docker-compose-linux-aarch64
# 检查/usr/bin/docker是否存在并且可执行
if [ -f "/usr/bin/docker" ] && [ -x "/usr/bin/docker" ]; then
echo "Docker is installed and has execute permissions."
else
red "警告 您还没有安装Docker"
exit 1
fi
if [[ "$gl_name" == *3000* ]]; then
red "警告 docker-compose 组件的大小将近60MB,请谨慎安装"
yellow "确定要继续安装吗(y|n)"
read -r answer
if [ "$answer" = "y" ] || [ -z "$answer" ]; then
green "正在获取最新版docker-compose下载地址"
else
yellow "已退出docker-compose安装流程"
exit 1
fi
fi
local github_releases_url="https://github.com/docker/compose/releases/latest"
local docker_compose_url=$(get_docker_compose_url "$github_releases_url")
echo "最新版docker-compose 地址:$docker_compose_url"
wget -O /usr/bin/docker-compose $docker_compose_url
if [ $? -eq 0 ]; then
green "docker-compose下载并安装成功,你可以使用啦"
chmod +x /usr/bin/docker-compose
else
red "安装失败,请检查网络连接.或者手动下载到 /usr/bin/docker-compose 记得赋予执行权限"
yellow "刚才使用的地址是:$docker_compose_url"
exit 1
fi
}
#mt3000更换分区
mt3000_overlay_changed() {
wget -O mt3000.sh "https://cafe.cpolar.top/wkdaily/gl-inet-onescript/raw/branch/master/mt-3000/mt3000.sh" && chmod +x mt3000.sh
sh mt3000.sh
}
while true; do
clear
gl_name=$(get_router_name)
@ -497,7 +418,7 @@ while true; do
green "*******GL-iNet MT-2500A"
green "*******GL-iNet MT-3000 "
green "*******GL-iNet MT-6000 "
echo "******************下次调用 直接输入快捷键 g *****************************"
echo "**********************************************************************"
echo
light_magenta " 1. $result"
echo
@ -507,15 +428,14 @@ while true; do
echo " 4. 设置风扇开始工作的温度(仅限MT3000)"
echo " 5. 恢复原厂OPKG配置软件包"
echo
echo " 6. 卸载GL原厂Adguardhome(10MB)"
echo " 6. 安装GL原厂Adguardhome(10MB)"
echo " 7. 安装luci-app-wireguard"
echo " 8. 更新luci-app-quickstart"
echo " 9. 安装Argon紫色主题"
echo "10. 安装文件管理器"
light_magenta "11. 安装Docker"
light_magenta "12. 安装docker-compose"
echo "12. 安装Docker Compose(开发中)"
light_magenta "13. 更新脚本"
cyan "14. MT3000一键更换分区"
echo
echo " Q. 退出本程序"
echo
@ -579,21 +499,17 @@ while true; do
red "确定要继续吗(y|n)"
read -r answer
if [ "$answer" = "y" ] || [ -z "$answer" ]; then
wget -q -O do_docker.sh "https://cafe.cpolar.top/wkdaily/gl-inet-onescript/raw/branch/master/docker/do_docker.sh" && chmod +x do_docker.sh
./do_docker.sh
wget -q -O do_docker.sh https://raw.githubusercontent.com/wukongdaily/gl-inet-onescript/master/docker/do_docker.sh && chmod +x do_docker.sh && ./do_docker.sh
else
yellow "已退出Docker安装流程"
fi
;;
12)
do_install_docker_compose
yellow "开发中......"
;;
13)
update_myself
;;
14)
mt3000_overlay_changed
;;
q | Q)
echo "退出"
exit 0

View File

@ -1,254 +0,0 @@
#!/bin/sh
# 定义颜色输出函数
red() { echo -e "\033[31m\033[01m$1\033[0m"; }
green() { echo -e "\033[32m\033[01m$1\033[0m"; }
greeninfo() { echo -e "\033[32m\033[01m[INFO] $1\033[0m"; }
blueinfo() { echo -e "\033[32m\033[01m$1\033[0m"; }
yellow() { echo -e "\033[33m\033[01m$1\033[0m"; }
blue() { echo -e "\033[34m\033[01m$1\033[0m"; }
light_magenta() { echo -e "\033[95m\033[01m$1\033[0m"; }
light_yellow() { echo -e "\033[93m\033[01m$1\033[0m"; }
purple() { echo -e "\033[38;5;141m$1\033[0m"; }
cyan() { echo -e "\033[38;2;0;255;255m$1\033[0m"; }
install_depends_apps() {
cyan "正在安装必备工具...."
opkg update >/dev/null 2>&1
for pkg in lsblk fdisk; do
if opkg list-installed | grep -qw "$pkg"; then
cyan "$pkg 已安装。"
else
if opkg install "$pkg" >/dev/null 2>&1; then
green "$pkg 安装成功。"
else
red "$pkg 安装失败。"
exit 1
fi
fi
done
}
# 卸载USB设备
unmount_usb_device() {
for mount in $(mount | grep "$1" | awk '{print $3}'); do
yellow "正在尝试卸载U盘挂载点$mount"
umount $mount || {
red "警告:无法卸载挂载点 $mount。可能有文件正在被访问或权限不足。"
exit 1
}
blueinfo "U盘挂载点 $mount 卸载成功。"
done
}
create_and_format_partitions() {
local device=$1
# 使用fdisk -l获取设备的总容量以字节为单位并转换为GB
local total_bytes=$(fdisk -l $device | grep "Disk $device:" | awk '{print $5}')
local total_gb=$(echo "$total_bytes" | awk '{print int($1/(1024*1024*1024))}')
if [ -n "$CUSTOM_OPKG_SIZE" ]; then
part1_gb=$CUSTOM_OPKG_SIZE
yellow "U盘总容量约为 $total_gb GB,您设置的自定义软件包大小为 ${part1_gb}GB。"
else
# 计算10%的大小以GB为单位
part1_gb=$((total_gb / 10))
yellow "U盘总容量约为 $total_gb GB,第一分区大小设置为U盘容量的10% 即 ${part1_gb}GB。"
fi
green "计划将第一分区分配给软件包 其大小为 ${part1_gb}GB"
cyan "没错~你没有看错,让我们任性的告别 容 量 焦 虑!"
# 创建分区并分配空间
{
echo g # 创建一个新的空DOS分区表
echo n # 添加一个新分区
echo p # 主分区
echo 1 # 分区号1
echo # 第一个可用扇区(默认)
echo +${part1_gb}G # 为第一个分区分配计算出的GB数
echo n # 添加第二个新分区
echo p # 主分区
echo 2 # 分区号2
echo # 第一个可用扇区(默认,自动)
echo # 最后一个扇区(默认,使用剩余空间)
echo w # 写入并退出
} | fdisk $device >/dev/null 2>&1
# 给系统一点时间来识别新分区
sleep 5
# 格式化第一个分区为EXT4
local new_partition1="${device}1"
cyan "正在将 $new_partition1 格式化为EXT4文件系统..."
mkfs.ext4 -F $new_partition1 >/dev/null 2>&1
cyan "$new_partition1 已成功格式化为EXT4文件系统。"
green "第2分区 ${device}2 暂不格式化,未来您可分配给docker使用"
}
# 换区到U盘
change_overlay_usb() {
install_depends_apps
blueinfo "现在开始查找USB设备分区 请稍后......"
local USB_PARTITION=$(lsblk -dn -o NAME,TRAN | awk '$2=="usb" {print "/dev/"$1; exit}')
if [ -z "$USB_PARTITION" ]; then
red "未找到USB磁盘。"
exit 1
fi
yellow "找到USB磁盘 $USB_PARTITION"
# 清零磁盘开始部分以清除分区表和文件系统签名
dd if=/dev/zero of=$USB_PARTITION bs=1M count=10
sync
# 卸载所有与该磁盘相关的挂载点
unmount_usb_device "$USB_PARTITION"
red "正在将U盘${USB_PARTITION}分为2个区 ..."
create_and_format_partitions "$USB_PARTITION"
# U盘分区的挂载点
MOUNT_POINT="/mnt/usb_overlay"
# 临时目录用于复制数据
TMP_DIR="/tmp/overlay_backup"
# 创建挂载点目录
mkdir -p $MOUNT_POINT
# 挂载U盘分区
cyan "重新挂载第一分区 ${USB_PARTITION}1 到 $MOUNT_POINT"
mount ${USB_PARTITION}1 $MOUNT_POINT >/dev/null 2>&1
# 创建临时目录用于备份overlay数据
mkdir -p $TMP_DIR
# 复制当前overlay到临时目录
cp -a /overlay/. $TMP_DIR
# 将临时目录的数据复制到U盘
blueinfo "正在拷贝 当前系统文件到U盘"
cp -a $TMP_DIR/. $MOUNT_POINT
# 更新fstab配置以便在启动时自动挂载U盘为overlay
blueinfo "正在更新启动时的配置文件"
uci set fstab.overlay=mount
uci set fstab.overlay.uuid="$(blkid -o value -s UUID ${USB_PARTITION}1)"
uci set fstab.overlay.target="/overlay"
uci commit fstab
# 清理临时目录
rm -rf $TMP_DIR
cp /etc/config/fstab $MOUNT_POINT/fstab.bak
cyan "overlay更换分区完成 重启验证是否成功."
red "是否立即重启?(y/n)"
read -r answer
if [ "$answer" = "y" ] || [ -z "$answer" ]; then
red "正在重启..."
reboot
else
yellow "您选择了不重启"
fi
}
check_overlay_size() {
# 使用df命令获取/overlay分区的总大小以1K块为单位
OVERLAY_SIZE=$(df /overlay | awk '/\/overlay/{print $2}')
# 将1GB转换为1K块单位即1GB = 1*1024*1024 1K块
ONE_GB_IN_1K_BLOCKS=$((1024 * 1024))
# 比较/overlay分区的大小是否大于1GB
if [ "$OVERLAY_SIZE" -gt "$ONE_GB_IN_1K_BLOCKS" ]; then
yellow "检测到您已经换区到U盘啦,可以继续"
else
echo "您还没有换区到U盘,请先执行选项1."
exit 1
fi
}
# 安装 Docker 和 dockerd
install_docker() {
check_overlay_size
green "正在更新 OPKG 软件包..."
opkg update >/dev/null 2>&1
cyan "正在安装 Docker 及相关服务...请耐心等待一会...大约需要1-2分钟\n"
opkg install luci-app-dockerman >/dev/null 2>&1
opkg install luci-i18n-dockerman-zh-cn >/dev/null 2>&1
opkg install dockerd --force-depends >/dev/null 2>&1
cyan "Docker 运行环境部署完成 重启后生效\n"
red "正在重启..."
reboot
}
# 重新绑定
rebind_usb_overlay() {
cyan "正在重新绑定U盘设备...."
if opkg list-installed | grep -qw "lsblk"; then
echo
else
opkg update >/dev/null 2>&1
if opkg install "lsblk" >/dev/null 2>&1; then
echo
else
red "$pkg 安装失败。"
exit 1
fi
fi
local USB_DEVICE=$(lsblk -dn -o NAME,RM,TYPE | awk '$2=="1" && $3=="disk" {print "/dev/"$1; exit}')
if [ -z "$USB_DEVICE" ]; then
red "未找到USB磁盘。"
exit 1
fi
uci set fstab.overlay=mount
uci set fstab.overlay.uuid="$(blkid -o value -s UUID ${USB_DEVICE}1)"
uci set fstab.overlay.target="/overlay"
uci commit fstab
green "重新绑定成功! 重启后生效"
red "正在重启..."
reboot
}
#自定义软件包的大小
#默认为U盘容量的10%
custom_package_size() {
while :; do
echo "请输入想分配的软件包的大小(数字,单位:GB):"
read size
# 检查输入是否为数字
if [[ $size =~ ^[0-9]+$ ]]; then
CUSTOM_OPKG_SIZE=$size
yellow "已设置软件包大小为:$CUSTOM_OPKG_SIZE GB"
green "接下来,您可以执行第一项啦"
break # 跳出循环
else
red "错误: 请输入一个有效的数字。"
fi
done
}
while true; do
clear
echo "***********************************************************************"
green " MT-3000 软件包更换分区助手 "
echo "**********************************************************************"
echo
cyan " 1. MT-3000 一键更换overlay分区到U盘"
cyan " 2. MT-3000 安装Docker"
cyan " 3. 自定义设置软件包大小(GB)"
light_yellow " 4. 重新绑定U盘"
echo
echo " Q. 退出本程序"
echo
read -p "请选择一个选项: " choice
echo
case $choice in
1)
change_overlay_usb
;;
2)
install_docker
;;
3)
custom_package_size
;;
4)
rebind_usb_overlay
;;
q | Q)
echo "退出"
exit 0
;;
*)
echo "无效选项,请重新选择。"
;;
esac
read -p "按 Enter 键继续..."
done