1+ 1 > 1/* :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
2+ :: by bajins https://www.bajins.com
3+
4+ @ echo off
5+ md " %~dp0 $testAdmin$" 2 > nul
6+ if not exist " %~dp0 $testAdmin$" (
7+ echo bajins不具备所在目录的写入权限! >& 2
8+ exit /b 1
9+ ) else rd " %~dp0 $testAdmin$"
10+
11+ :: 开启延迟环境变量扩展
12+ setlocal enabledelayedexpansion
13+
14+ :: 执行7z命令,但是不输出,这是为了判断
15+ 7za > nul
16+ :: 如果7z压缩命令行不存在,则下载
17+ if not " %errorlevel% " == " 0" (
18+ :: cscript -nologo -e:jscript "%~f0" 这一段是执行命令,后面的是参数(组成方式:/key:value)
19+ :: %~f0 表示当前批处理的绝对路径,去掉引号的完整路径
20+ cscript -nologo -e:jscript " %~f0 " https://github.com/woytu/woytu.github.io/releases/download/v1.0/7za.exe C:\Windows
21+ )
22+ :: 需要打包的文件或文件夹根目录
23+ set root = %~dp0
24+ :: 需要打包的文件或文件夹
25+ set files = data
26+
27+ :: 仅将 %0 扩充到一个路径
28+ set currentPath = %~p0
29+ :: 替换\为,号,也可以替换为空格
30+ set currentPath = %currentPath:\ =, %
31+ :: 顺序循环,设置最后一个为当前目录
32+ for %%a in (%currentPath% ) do set CurrentDirectoryName = %%a
33+ :: 打包完成的文件命名前一部分
34+ set project = %CurrentDirectoryName%
35+ :: 打包完成的文件命名后一部分,与前一部分进行组合
36+ set allList = _darwin_386,_darwin_amd64,_freebsd_386,_freebsd_amd64,_freebsd_arm,_netbsd_386,_netbsd_amd64,_netbsd_arm,
37+ set allList = %allList% _openbsd_386,_openbsd_amd64,_windows_386.exe,_windows_amd64.exe,
38+ set allList = %allList% _linux_386,_linux_amd64,_linux_arm,_linux_mips,_linux_mips64,_linux_mips64le,_linux_mipsle,_linux_s390x
39+
40+ :GETGOX
41+ set GOPROXY = https://goproxy.io
42+ go get github.com/mitchellh/gox
43+
44+ for %%i in (%allList% ) do (
45+ :: 如果二进制文件不存在则重新打包
46+ if not exist " %project% %%i " (
47+ gox
48+ if not %errorlevel% == 0 (
49+ goto :GETGOX
50+ )
51+ :: 删除旧的压缩包文件
52+ del *.zip *.tar *.gz
53+ )
54+ )
55+
56+
57+ :: 使用7z压缩
58+ for %%i in (%allList% ) do (
59+ set runFile = %project% %%i
60+ :: !!和%%都是取变量的值,用这种方法的批处理文件前面一般有setlocal EnableDelayedExpansion(延迟环境变量扩展)语句
61+ if exist " !runFile! " (
62+ :: 判断变量字符串中是否包含字符串
63+ echo %%i | findstr linux > nul && (
64+ :: 用7z压缩成tar
65+ 7za a -ttar %project% %%i .tar %files% !runFile!
66+ :: 用7z把tar压缩成gz
67+ 7za a -tgzip %project% %%i .tar.gz %project% %%i .tar
68+ :: 删除tar文件和二进制文件
69+ del *.tar !runFile!
70+
71+ ) || (
72+ :: 用7z压缩文件为zip
73+ 7za a %project% %%i .zip %files% !runFile!
74+ :: 删除二进制文件
75+ del !runFile!
76+ )
77+ )
78+ )
79+
80+
81+
82+ goto :EXIT
83+
84+ :EXIT
85+ :: 结束延迟环境变量扩展和命令执行
86+ endlocal& exit /b %errorlevel%
87+ */
88+
89+ // **************************** JavaScript *******************************
90+
91+
92+ var iRemote = WScript.Arguments(0);
93+ iRemote = iRemote.toLowerCase();
94+ var iLocal = WScript.Arguments(1);
95+ iLocal = iLocal.toLowerCase()+" \\" + iRemote.substring(iRemote.lastIndexOf(" /" ) + 1);
96+ var xPost = new ActiveXObject(" Microsoft.XMLHTTP" );
97+ xPost.Open(" GET" , iRemote, 0);
98+ xPost.Send();
99+ var sGet = new ActiveXObject(" ADODB.Stream" );
100+ sGet.Mode = 3;
101+ sGet.Type = 1;
102+ sGet.Open();
103+ sGet.Write(xPost.responseBody);
104+ sGet.SaveToFile(iLocal, 2);
105+ sGet.Close();
0 commit comments