feat: 增加交互式变量.

This commit is contained in:
Olia Lisa
2026-07-12 18:18:58 +08:00
parent 76015e9cb5
commit 40c631166a
4 changed files with 85 additions and 6 deletions
+20 -1
View File
@@ -141,12 +141,31 @@ build() {
echo -e "固件输出: ${PROJECT_OUTPUT_DIR}" echo -e "固件输出: ${PROJECT_OUTPUT_DIR}"
} }
# =============================================================
# 交互输入函数
# 参数1: 提示信息
# 参数2: 默认值
# 返回: 用户输入值,直接回车返回默认值
# =============================================================
ask_input() {
local prompt="$1"
local default="$2"
read -p "${prompt} [默认: ${default}]: " value
if [ -z "$value" ]; then
echo "$default"
else
echo "$value"
fi
}
project_dir="$(cd "$(dirname "$0")" && pwd)" project_dir="$(cd "$(dirname "$0")" && pwd)"
cd "$project_dir" cd "$project_dir"
# 要构建的 ImmortalWrt 版本 # 要构建的 ImmortalWrt 版本
version="25.12.1" default_version="25.12.1"
version=$(ask_input "请输入 ImmortalWrt 版本" "$default_version")
install_dependencies install_dependencies
+21 -1
View File
@@ -32,6 +32,25 @@ download_imagebuilder() {
echo "$(pwd)/$folder" echo "$(pwd)/$folder"
} }
# =============================================================
# 交互输入函数
# 参数1: 提示信息
# 参数2: 默认值
# 返回: 用户输入值,直接回车返回默认值
# =============================================================
ask_input() {
local prompt="$1"
local default="$2"
read -p "${prompt} [默认: ${default}]: " value
if [ -z "$value" ]; then
echo "$default"
else
echo "$value"
fi
}
build() { build() {
# ============================================================= # =============================================================
# 设备 Profile(必须与 ImageBuilder 支持的设备一致) # 设备 Profile(必须与 ImageBuilder 支持的设备一致)
@@ -146,7 +165,8 @@ project_dir="$(cd "$(dirname "$0")" && pwd)"
cd "$project_dir" cd "$project_dir"
# 要构建的 ImmortalWrt 版本, 可以在 https://github.com/immortalwrt/immortalwrt 查询版本号 # 要构建的 ImmortalWrt 版本, 可以在 https://github.com/immortalwrt/immortalwrt 查询版本号
version="25.12.1" default_version="25.12.1"
version=$(ask_input "请输入 ImmortalWrt 版本" "$default_version")
# 安装依赖 # 安装依赖
install_dependencies install_dependencies
+22 -2
View File
@@ -188,16 +188,36 @@ build(){
fi fi
} }
# =============================================================
# 交互输入函数
# 参数1: 提示信息
# 参数2: 默认值
# 返回: 用户输入值,直接回车返回默认值
# =============================================================
ask_input() {
local prompt="$1"
local default="$2"
read -p "${prompt} [默认: ${default}]: " value
if [ -z "$value" ]; then
echo "$default"
else
echo "$value"
fi
}
# 项目根目录,保证从任意位置执行 r2s.sh 都能找到其他资源 # 项目根目录,保证从任意位置执行 r2s.sh 都能找到其他资源
project_dir="$(cd "$(dirname "$0")" && pwd)" project_dir="$(cd "$(dirname "$0")" && pwd)"
cd "$project_dir" cd "$project_dir"
# 要构建的 ImmortalWrt 版本 # 要构建的 ImmortalWrt 版本
version="25.12.1" default_version="25.12.1"
version=$(ask_input "请输入 ImmortalWrt 版本" "$default_version")
# 根分区大小(单位: MB) # 根分区大小(单位: MB)
rootfs_partsize=600 default_rootfs_partsize="600"
rootfs_partsize=$(ask_input "请输入根分区大小(MB)" "$default_rootfs_partsize")
install_dependencies install_dependencies
+22 -2
View File
@@ -214,16 +214,36 @@ build(){
} }
# =============================================================
# 交互输入函数
# 参数1: 提示信息
# 参数2: 默认值
# 返回: 用户输入值,直接回车返回默认值
# =============================================================
ask_input() {
local prompt="$1"
local default="$2"
read -p "${prompt} [默认: ${default}]: " value
if [ -z "$value" ]; then
echo "$default"
else
echo "$value"
fi
}
# 项目根目录,用来保证从任意位置执行 main.sh 都能找到其他脚本 # 项目根目录,用来保证从任意位置执行 main.sh 都能找到其他脚本
project_dir="$(cd "$(dirname "$0")" && pwd)" project_dir="$(cd "$(dirname "$0")" && pwd)"
cd "$project_dir" cd "$project_dir"
# 要构建的 ImmortalWrt 版本, 可以在 https://github.com/immortalwrt/immortalwrt 查询版本号 # 要构建的 ImmortalWrt 版本, 可以在 https://github.com/immortalwrt/immortalwrt 查询版本号
version="25.12.1" default_version="25.12.1"
version=$(ask_input "请输入 ImmortalWrt 版本" "$default_version")
# 根分区大小(单位: MB) # 根分区大小(单位: MB)
rootfs_partsize=600 default_rootfs_partsize="600"
rootfs_partsize=$(ask_input "请输入根分区大小(MB)" "$default_rootfs_partsize")
# 安装依赖 # 安装依赖
install_dependencies install_dependencies