Compare commits

...

4 Commits

Author SHA1 Message Date
bin456789
81081873df windows: 查找到的链接是 / 开头时,补全域名 2026-02-13 00:03:36 +08:00
bin456789
4cf8e81fc7 windows: 修复查找 windows server 2025 iso 失效 2026-02-12 22:54:47 +08:00
bin456789
ff4b6de258 fnos: 修复飞牛链接失效
fixes #555
fixes #557
2026-02-12 22:27:20 +08:00
Heng lu
fc7bdc5711 dd 引入cloud-data 提供 nocloud自动配置 (#551) 2026-02-12 22:14:04 +08:00
2 changed files with 99 additions and 28 deletions

View File

@@ -305,6 +305,10 @@ get_host_by_url() {
cut -d/ -f3 <<<$1
}
get_scheme_and_host_by_url() {
cut -d/ -f1-3 <<<$1
}
get_function() {
declare -f "$1"
}
@@ -882,8 +886,14 @@ find_windows_iso() {
full_lang=$(english)
case "$basearch" in
x86_64) arch_win=x64 ;;
aarch64) arch_win=arm64 ;;
x86_64)
arch_win=x64
arch_win_vlsc=64bit
;;
aarch64)
arch_win=arm64
arch_win_vlsc=arm64
;;
esac
get_windows_iso_link
@@ -1009,6 +1019,9 @@ get_windows_iso_link() {
pro | education | enterprise | 'pro education' | 'pro for workstations') echo pro ;;
esac
;;
2025)
echo SrvSTDCORE
;;
esac
}
@@ -1086,10 +1099,17 @@ get_windows_iso_link() {
if [ -n "$label_msdl" ]; then
iso=$(curl -L "$page_url" | grep -ioP 'https://[^ ]+?#[0-9]+' | head -1 | grep .)
else
http_to_host=$(get_scheme_and_host_by_url "$page_url")
http_to_current_dir=$(dirname "$page_url")
curl -L "$page_url" |
tr -d '\n' | sed -e 's,<a ,\n<a ,g' -e 's,</a>,</a>\n,g' | # 使每个 <a></a> 占一行
grep -Ei '\.(iso|img)</a>$' | # 找出是 iso 或 img 的行
sed -E 's,<a href="?([^" ]+)"?.+>(.+)</a>,\2 \1,' >$tmp/win.list # 提取文件名和链接
tr -d '\n' | sed -e 's,<a ,\n<a ,g' -e 's,</a>,</a>\n,g' | # 使每个 <a></a> 占一行
grep -Ei '\.(iso|img)</a>$' | # 找出是 iso 或 img 的行
# 提取文件名和链接
# 如果链接是 / 开头,则补全域名
# 如果链接非 https:// 开头,则补全域名和目录
sed -E -e 's,<a href="?([^" ]+)"?.+>(.+)</a>,\2 \1,' \
-e "s, (/), $http_to_host\1," |
awk '{if ($2 !~ /^https?:\/\//) $2 = "'$http_to_current_dir/'" $2; print}' >$tmp/win.list
# 如果不是 ltsc ,应该先去除 ltsc 链接,否则最终链接有 ltsc 的
# 例如查找 windows 10 iot enterprise会得到
@@ -1136,8 +1156,11 @@ get_windows_iso_link_inner() {
fi
# vlsc
# SW_DVD5_Win_10_IOT_Enterprise_2015_LTSB_64Bit_EMB_English_OEM_X20-20063.IMG
# SW_DVD9_Win_Pro_10_22H2.15_Arm64_English_Pro_Ent_EDU_N_MLF_X23-67223.ISO
# SWDVD9_WinSrvSTDCORE2025_24H2.16_64Bit_English_DC_STD_MLF_RTMUpdJan26_X24-26760.iso
if [ -n "$label_vlsc" ]; then
regex="sw_dvd[59]_win_${label_vlsc}_${version}.*${arch_win}_${full_lang}.*.(iso|img)"
regex="sw_?dvd[59]_win_?${label_vlsc}_?${version}.*${arch_win_vlsc}_${full_lang}.*.(iso|img)"
regexs+=("$regex")
fi
@@ -1654,25 +1677,18 @@ Continue with DD?
fi
done
if [ "$basearch" = aarch64 ]; then
if [ -z "$iso" ]; then
IFS= read -r -p "ISO Link: " iso
if [ -z "$iso" ]; then
error_and_exit "ISO Link is empty."
fi
fi
else
iso=$(curl -L https://fnnas.com/ | grep -o -m1 'https://[^"]*\.iso')
# 对于同一行有多个成功匹配grep -m1 无效
iso=$(curl -L "https://fnnas.com/download$([ "$basearch" = aarch64 ] && echo -arm)" |
grep -o 'https://[^"]*\.iso' | head -1 | grep .)
# curl 7.82.0+
# curl -L --json '{"url":"'$iso'"}' https://www.fnnas.com/api/download-sign
# curl 7.82.0+
# curl -L --json '{"url":"'$iso'"}' https://www.fnnas.com/api/download-sign
iso=$(curl -L \
-d '{"url":"'$iso'"}' \
-H 'Content-Type: application/json' \
https://www.fnnas.com/api/download-sign |
grep -o 'https://[^"]*')
fi
iso=$(curl -L \
-d '{"url":"'$iso'"}' \
-H 'Content-Type: application/json' \
https://www.fnnas.com/api/download-sign |
grep -o 'https://[^"]*')
test_url "$iso" iso
eval "${step}_iso='$iso'"
@@ -3746,6 +3762,22 @@ This script is outdated, please download reinstall.sh again.
cat "$frpc_config" >$initrd_dir/configs/frpc.toml
fi
# 收集 cloud-data 打包进 initrd
if [ -n "$cloud_data" ]; then
mkdir -p $initrd_dir/configs/cloud-data
if [ -d "$cloud_data" ]; then
# 本地目录:直接复制
cp "$cloud_data"/* $initrd_dir/configs/cloud-data/
else
# URL在 host 下载
for f in user-data meta-data network-config; do
curl -fsSL "$cloud_data/$f" -o "$initrd_dir/configs/cloud-data/$f" 2>/dev/null || true
done
fi
# 校验:至少要有 user-data
[ -f $initrd_dir/configs/cloud-data/user-data ] || error_and_exit "--cloud-data must contain user-data"
fi
if is_distro_like_debian $nextos_distro; then
mod_initrd_debian_kali
else
@@ -3912,6 +3944,7 @@ for o in ci installer debug minimal allow-ping force-cn help \
image-name: \
boot-wim: \
img: \
cloud-data: \
lang: \
passwd: password: \
ssh-port: \
@@ -4147,6 +4180,10 @@ EOF
img=$2
shift 2
;;
--cloud-data)
cloud_data=$2
shift 2
;;
--iso)
iso=$2
shift 2

View File

@@ -3793,14 +3793,40 @@ EOF
rm -f $os_dir/swapfile
}
setup_nocloud() {
os_dir=$1
info "Setup NoCloud"
# 1. 配置 NoCloud-only datasource
mkdir -p "$os_dir/etc/cloud/cloud.cfg.d"
cat > "$os_dir/etc/cloud/cloud.cfg.d/99-datasource.cfg" << 'EOF'
datasource_list: [ NoCloud, None ]
datasource:
NoCloud:
seedfrom: /var/lib/cloud/seed/nocloud/
fs_label: null
EOF
# 2. 复制 seed 文件(已在 host 上准备好,打包在 initrd 中)
mkdir -p "$os_dir/var/lib/cloud/seed/nocloud"
cp /configs/cloud-data/* "$os_dir/var/lib/cloud/seed/nocloud/"
# 3. 确保 cloud-init 没有被禁用
rm -f "$os_dir/etc/cloud/cloud-init.disabled"
# 4. 清除 cloud-init 旧状态,确保首次启动重新执行
rm -rf "$os_dir/var/lib/cloud/instance"
rm -rf "$os_dir/var/lib/cloud/instances"
}
modify_os_on_disk() {
only_process=$1
info "Modify disk if is $only_process"
update_part
# dd linux 的时候不用修改硬盘内容
if [ "$distro" = "dd" ] && ! lsblk -f /dev/$xda | grep ntfs; then
# dd linux 的时候不用修改硬盘内容nocloud 模式除外)
if [ "$distro" = "dd" ] && [ "$only_process" != "nocloud" ] && ! lsblk -f /dev/$xda | grep ntfs; then
return
fi
@@ -3810,12 +3836,16 @@ modify_os_on_disk() {
# btrfs挂载的是默认子卷如果没有默认子卷挂载的是根目录
# fedora 云镜像没有默认子卷且系统在root子卷中
if mount -o ro /dev/$part /os; then
if [ "$only_process" = linux ]; then
if [ "$only_process" = linux ] || [ "$only_process" = nocloud ]; then
if etc_dir=$({ ls -d /os/etc/ || ls -d /os/*/etc/; } 2>/dev/null); then
os_dir=$(dirname $etc_dir)
# 重新挂载为读写
mount -o remount,rw /os
modify_linux $os_dir
if [ "$only_process" = nocloud ]; then
setup_nocloud $os_dir
else
modify_linux $os_dir
fi
return
fi
elif [ "$only_process" = windows ]; then
@@ -7229,7 +7259,11 @@ trans() {
# windows 扩容在 windows 下完成
resize_after_install_cloud_image
fi
modify_os_on_disk windows
if [ -d /configs/cloud-data ]; then
modify_os_on_disk nocloud
else
modify_os_on_disk windows
fi
;;
qemu) # dd qemu 不可能到这里,因为上面已处理
;;