如何利用onedrive加packerpebuilder实现本地网络统一装机

86次阅读
没有评论

共计 9273 个字符,预计需要花费 24 分钟才能阅读完成。

如何利用 onedrive 加 packerpebuilder 实现本地网络统一装机,相信很多没有经验的人对此束手无策,为此本文总结了问题出现的原因和解决方法,通过这篇文章希望你能解决这个问题。

今天,我们将用 onedrve 结合 packerpebuilder 实现本地也能像云主机一样装机,使远程成为本地装机 app,实际上这个思路自 packerpebuilder 一开始就有了,只是一直没有找到合适能用的网盘。

前置改动

把 tmpmirror 也消除了。调整了一些注释,如整合 checkdeps 和 selectmirror 为 prepare prerequisites,selectmirror 经过重构变成 select1stvalidmirrorfrom3():

function Select1stValidMirrorFrom3(){ [ $# -ge 1 ] || exit 1
 declare -A MirrorTocheck
 MirrorTocheck=([Debian0]=  [Debian1]=  [Debian2]= )
 
 echo  $1  |sed  s/\ //g  |grep -q  ^http://\|^https://\|^ftp://    MirrorTocheck[Debian0]=$(echo  $1  |sed  s/\ //g 
 echo  $2  |sed  s/\ //g  |grep -q  ^http://\|^https://\|^ftp://    MirrorTocheck[Debian1]=$(echo  $2  |sed  s/\ //g 
 echo  $3  |sed  s/\ //g  |grep -q  ^http://\|^https://\|^ftp://    MirrorTocheck[Debian2]=$(echo  $3  |sed  s/\ //g 
 for mirror in $(echo  ${!MirrorTocheck[@]}  |sed  s/\ /\n/g  |sort -n |grep  ^Debian )
 do
 CurMirror= ${MirrorTocheck[$mirror]} 
 [ -n  $CurMirror  ] || continue
 # CheckPass1= 0 
 # DistsList= $(wget --no-check-certificate -qO-  $CurMirror/dists/  |grep -o  href=.*/  |cut -d  -f2 |sed  /-\|old\|Debian\|experimental\|stable\|test\|sid\|devel/d  |grep  ^[^/]  |sed -n  1!H;$g;s/\n//g;s/\//\;/g;$p ) 
 # for DIST in `echo  $DistsList  |sed  /\n/g `
 # do
 # [[  $DIST  ==  jessie  ]]   CheckPass1= 1    break;
 # done
 # [[  $CheckPass1  ==  0  ]]   {
 # echo -ne  \njessie not find in $CurMirror/dists/, Please check it! \n\n 
 # bash $0 error;
 # exit 1;
 # }
 CheckPass2=0
 ImageFile= SUB_MIRROR/dists/jessie/main/installer-amd64/current/images/netboot/debian-installer/amd64/initrd.gz 
 [ -n  $ImageFile  ] || exit 1
 URL=`echo  $ImageFile  |sed  s#SUB_MIRROR#${CurMirror}#g `
 wget --no-check-certificate --spider --timeout=3 -o /dev/null  $URL 
 [ $? -eq 0 ]   CheckPass2=1   echo  $CurMirror    break
 done
 [[ $CheckPass2 == 0 ]]   {
 echo -ne  \033[31mError! \033[0minitrd.gz not find in $CurMirror/jessie/main/installer-amd64/current/images/netboot/debian-installer/amd64/! \n 
 bash $0 error;
 exit 1;
 }
MIRROR=$(Select1stValidMirrorFrom3  http://httpredir.debian.org/debian   http://www.shalol.com/cn/d/debian   http://http://archive.debian.org/debian)
[ -n  $MIRROR  ]   echo -en  Select Mirror ......:    echo -en  [\033[32m ${MIRROR} \033[0m]\n  || exit 1

主体改动

整合 prepare parepare dist files 包括 downloading basic kernel and rootfs files(将它提前,逻辑更合理。)和 downloading repo pkgs files,,以及接下来的 PrepareDDessentials(其原来内部下载 deb 的逻辑整合到与下载 full udeb 一起),,并将它们都变成可复用的函数和函数调用 buildrepo()和 PrepareDDessentials().

prepare parepare dist files 与 prepare others 是并列的:前三者是大资源文件,后三者是小参数文件,将二者中间延时变量变成 2s,各内部延时 3s(内部还去掉了细节方面,肯定情况下的一些 echo 输出,改为直接 exit 1,改为由主要的几句话来 echo,界面输出更清),共 5s

wget 要调用 ssl client 才能 tls certificate 已完善,buildrepo()更强大,支持 sed s/(+|~)/-/g 处理链接中的 + 号和~ 号(tcb 上的 onemanager 不支持这类特殊符号),和更强大更逻辑清楚的拉取安装 deb pkgs 支持:

IncPkgrepo= 1 
declare -A OPTPKGS
OPTPKGS=( [ libc1]= pool/main/g/glibc/libc6_2.28-10_amd64.deb 
 [fmtlibc]= xz 
 [binlibc]= 
 [common1]= pool/main/g/gnutls28/libgnutls30_3.6.7-4+deb10u3_amd64.deb 
 [common2]= pool/main/p/p11-kit/libp11-kit0_0.23.15-2_amd64.deb 
 [common3]= pool/main/libt/libtasn1-6/libtasn1-6_4.13-3_amd64.deb 
 [common4]= pool/main/n/nettle/libnettle6_3.4.1-1_amd64.deb 
 [common5]= pool/main/n/nettle/libhogweed4_3.4.1-1_amd64.deb 
 [common6]= pool/main/g/gmp/libgmp10_6.1.2+dfsg-4_amd64.deb 
 [fmtcommon]= xz 
 [bincommon]= 
 [busybox1]= pool/main/b/busybox/busybox_1.30.1-4_amd64.deb 
 [fmtbusybox]= xz 
 [binbusybox]= bin/busybox 
 [wgetssl1]= pool/main/libi/libidn2/libidn2-0_2.0.5-1+deb10u1_amd64.deb 
 [wgetssl2]= pool/main/libp/libpsl/libpsl5_0.20.2-2_amd64.deb 
 [wgetssl3]= pool/main/p/pcre2/libpcre2-8-0_10.32-5_amd64.deb 
 [wgetssl4]= pool/main/u/util-linux/libuuid1_2.33.1-0.1_amd64.deb 
 [wgetssl5]= pool/main/z/zlib/zlib1g_1.2.11.dfsg-1_amd64.deb 
 [wgetssl6]= pool/main/o/openssl/libssl1.0.0_1.0.1t-1+deb8u8_amd64.deb 
 [wgetssl7]= pool/main/o/openssl/openssl_1.0.1t-1+deb8u8_amd64.deb 
 [wgetssl8]= pool/main/w/wget/wget_1.20.1-1.1_amd64.deb 
 [fmtwgetssl]= xz 
 [binwgetssl]= usr/bin/wget 
 [webfs1]= pool/main/libf/libffi/libffi6_3.2.1-9_amd64.deb 
 [webfs2]= pool/main/m/mime-support/mime-support_3.62_all.deb 
 [webfs3]= pool/main/libu/libunistring/libunistring2_0.9.10-1_amd64.deb 
 [webfs4]= pool/main/w/webfs/webfs_1.21-ds1-12_amd64.deb 
 [fmtwebfs]= xz 
 [binwebfs]= 
function buildrepo(){ if [[  $IncPkgrepo  ==  1  ]]; then
 echo -e  Downloading full udebs pkg files..... [\033[32m ${MIRROR}/dists/jessie/main/debian-installer/binary-amd64/Packages.gz \033[0m]\n 
 repodir= /tmp/boot/var/log/debian 
 mkdir -p $repodir
 udeburl= .*pool\/main\(.*\)udeb.* 
 wget --no-check-certificate -qO-  $MIRROR/dists/jessie/main/debian-installer/binary-amd64/Packages.gz  |gunzip -dc|sed  /$udeburl/!d |sed  s/Filename: //g |while read line
 do
 path=${line%/*}
 mkdir -p $repodir/$path
 file=${line##*/}
 wget --no-check-certificate -qO $repodir/$path/$(echo $file|sed  s/\(+\|~\)/-/g ) $MIRROR/$line
 done
 mkdir -p $repodir/dists/jessie/main/binary-amd64/
 mkdir -p $repodir/dists/jessie/main/debian-installer/binary-amd64/
 mkdir -p $repodir/dists/jessie/main/installer-amd64/current/images/
 wget --no-check-certificate -qO $repodir/dists/jessie/Release $MIRROR/dists/jessie/Release
 wget --no-check-certificate -qO $repodir/dists/jessie/main/binary-amd64/Release $MIRROR/dists/jessie/main/binary-amd64/Release
 wget --no-check-certificate -qO $repodir/dists/jessie/main/debian-installer/binary-amd64/Release $MIRROR/dists/jessie/main/debian-installer/binary-amd64/Release
 wget --no-check-certificate -qO $repodir/dists/jessie/main/debian-installer/binary-amd64/Packages.gz $MIRROR/dists/jessie/main/debian-installer/binary-amd64/Packages.gz; \
 orisize=$(cat $repodir/dists/jessie/main/debian-installer/binary-amd64/Packages.gz | wc -c); \
 orimd5=$(md5sum $repodir/dists/jessie/main/debian-installer/binary-amd64/Packages.gz| awk  { print $1 }  \
 orisha1=$(sha1sum $repodir/dists/jessie/main/debian-installer/binary-amd64/Packages.gz| awk  { print $1 }  \
 orisha256=$(sha256sum $repodir/dists/jessie/main/debian-installer/binary-amd64/Packages.gz| awk  { print $1 }  \
 gunzip -c $repodir/dists/jessie/main/debian-installer/binary-amd64/Packages.gz   $repodir/dists/jessie/main/debian-installer/binary-amd64/Packages; \
 rm -rf $repodir/dists/jessie/main/debian-installer/binary-amd64/Packages.gz; \
 sed -i  s/\(+\|~\)/-/g  $repodir/dists/jessie/main/debian-installer/binary-amd64/Packages; \
 gzip -c $repodir/dists/jessie/main/debian-installer/binary-amd64/Packages   $repodir/dists/jessie/main/debian-installer/binary-amd64/Packages.gz; \
 rm -rf $repodir/dists/jessie/main/debian-installer/binary-amd64/Packages; \
 cursize=$(cat $repodir/dists/jessie/main/debian-installer/binary-amd64/Packages.gz | wc -c); \
 curmd5=$(md5sum $repodir/dists/jessie/main/debian-installer/binary-amd64/Packages.gz| awk  { print $1 }  \
 cursha1=$(sha1sum $repodir/dists/jessie/main/debian-installer/binary-amd64/Packages.gz| awk  { print $1 }  \
 cursha256=$(sha256sum $repodir/dists/jessie/main/debian-installer/binary-amd64/Packages.gz| awk  { print $1 } )
 toreplace= main\/debian-installer\/binary-amd64\/Packages.gz 
 linenoarray=($(grep -n $toreplace $repodir/dists/jessie/Release |cut -f1 -d:))
 sed -i ${linenoarray[0]}s/$orimd5/$curmd5/ $repodir/dists/jessie/Release
 sed -i ${linenoarray[0]}s/$orisize/$cursize/ $repodir/dists/jessie/Release
 sed -i ${linenoarray[1]}s/$orisha1/$cursha1/ $repodir/dists/jessie/Release
 sed -i ${linenoarray[1]}s/$orisize/$cursize/ $repodir/dists/jessie/Release
 sed -i ${linenoarray[2]}s/$orisha256/$cursha256/ $repodir/dists/jessie/Release
 sed -i ${linenoarray[2]}s/$orisize/$cursize/ $repodir/dists/jessie/Release
 wget --no-check-certificate -qO $repodir/dists/jessie/main/installer-amd64/current/images/udeb.list $MIRROR/dists/jessie/main/installer-amd64/current/images/udeb.list
 chmod -R 0644 $repodir/
 fi
 echo -e  Downloading optional deb pkg files...... [\033[32m ${MIRROR}/dists/jessie/main/binary-amd64/Packages.gz \033[0m]\n 
 for pkg in `echo  $1  |sed  s/,/\n/g `
 do
 
 [[ -n  ${OPTPKGS[$pkg 1]}  ]]   { for subpkg in $(echo  ${!OPTPKGS[@]}  |sed  s/\ /\n/g  |sort -n |grep  ^$pkg )
 do
 cursubpkgfile= ${OPTPKGS[$subpkg]} 
 [ -n  $cursubpkgfile  ] || continue
 cursubpkgfilepath=${cursubpkgfile%/*}
 mkdir -p $repodir/$cursubpkgfilepath
 cursubpkgfilename=${cursubpkgfile##*/}
 cursubpkgfilename2=$(echo $cursubpkgfilename|sed  s/\(+\|~\)/-/g )
 wget --no-check-certificate -qO $repodir/$cursubpkgfilepath/$cursubpkgfilename2 $MIRROR/$cursubpkgfile; \
 [[  ${OPTPKGS[ fmt $pkg]}  ==  tar  ]]   ar x $repodir/$cursubpkgfilepath/$cursubpkgfilename2 data.tar.gz   tar xzf data.tar.gz   rm -rf data.tar.gz
 [[  ${OPTPKGS[ fmt $pkg]}  ==  xz  ]]   ar x $repodir/$cursubpkgfilepath/$cursubpkgfilename2 data.tar.xz   xz -d data.tar.xz   tar xf data.tar   rm -rf data.tar
 done
 [[ -n  ${OPTPKGS[ bin $pkg]}  ]]   mv -f /tmp/boot/${OPTPKGS[ bin $pkg]} /tmp/boot/${OPTPKGS[ bin $pkg]}2
 # [[ ! -f /tmp/boot/${OPTPKGS[ bin $pkg]}2 ]]   echo  Error! $1 SUPPORT ERROR.    exit 1;
 }
 done
buildrepo libc,common,busybox,wgetssl;

PrepareDDessentials()也更强大,支持 sharepoint 和 office365 个人的 302 跳转风格,强化《利用 installnet 制作一个云装机 packerpe》2 中关于仅支持 office365style 相关方面功能 — 其实 sharepointstyle 和 office365 style 也可自动公判断,但是我不想折腾了。

UNZIP= 
DDURL= 
OFFICE365 > 使用方法 

中途提示备份, 会给你 30s 上传 /tmp/boot/var/log/debian 仓库到 onedrive 或其它服务器创建镜像,。

 [[  $tmpINSTANTWITHOUTVNC  ==  0  ]]   echo  finished, auto reboot after 30s...(if needed, you can press ctrl c to interrupt to bak the repodir:$repodir, then manually reboot to continue) sleep 30s

preseed 中的 mirrorhost 换成你的 od 上传地址。

看完上述内容,你们掌握如何利用 onedrive 加 packerpebuilder 实现本地网络统一装机的方法了吗?如果还想学到更多技能或想了解更多相关内容,欢迎关注丸趣 TV 行业资讯频道,感谢各位的阅读!

正文完
 
丸趣
版权声明:本站原创文章,由 丸趣 2023-08-17发表,共计9273字。
转载说明:除特殊说明外本站除技术相关以外文章皆由网络搜集发布,转载请注明出处。
评论(没有评论)