本帖最后由 fireye 于 2024-7-4 19:41 编辑
[Bash shell] 纯文本查看 复制代码 @ECHO OFF&(PUSHD "%~DP0")&(REG QUERY "HKU\S-1-5-19">NUL 2>&1)||(powershell -Command "Start-Process '%~sdpnx0' -Verb RunAs"&&EXIT)
SETlocal enabledelayedexpansion
title Alist安裝助手 V1.0 by Fireye
Echo ========================== 使用說明,請仔細看清楚 =========================
Echo 南無大願地藏王菩薩 地獄不空 誓不成佛
Echo 1、第一次安裝系統會自動退出一次,不要驚慌,請重新再咝幸淮危?
Echo 2、WIN7、WIN10、WIN11都測試正常,可以說目前比較完善。
Echo 3、自動更新、首次安裝彈出後臺,密碼在桌面,如果不想用可以卸載。
Echo 4、自動識別是否安裝過ALIST,並且傻瓜化的方式引導安裝。
Echo 5、若有問題,請聯繫微信:858099909,郵箱:[email]jilefo@outlook.com[/email]
Echo 6、若需要遠程協助,請提前安裝好向日葵遠程工具。
Echo 7、Alist如何掛載,幫助等請看官方文檔,本人非Alist作者。
Echo 8、本人花了大量的時間和精力研究測試,前前後後花了差不多一個月來編寫、修復、並且遠程幫助網友,但有些人竟然拿去騙錢。這太不好吧?尊重一下別人的勞動成果。
Echo 9、希望有些人多看一下Alist官方文檔,養成一個好習慣,掛載相關的問題,文檔寫的清清楚楚,別啥都來要求別人幫忙。
Echo =========================================================================
::設置咝协h境
SET AppUp=AlistPlus
SET ServiceName=AlistDriveService
SET AppName=alist
SET ReposName=alist-org
SET ReleasesUrl=https://api.github.com/repos/%ReposName%/%AppName%/releases
SET RaiD=RaiDrive.Service
SET AppUPath=%ALLUSERSPROFILE%\%AppUp%
[url=home.php?mod=space&uid=251666]@rem[/url] SET Tools=%ALLUSERSPROFILE%\%AppUp%\Tools
SET RunPath=%~dp0
SET Gitee=https://gitee.com/jilefo/%AppUp%
SET AlistUrl=http://127.0.0.1:5244
cls
Echo ========================== Alist安裝管理器 V1.0 =========================
Echo 南無大願地藏王菩薩 地獄不空 誓不成佛
Echo =========================================================================
WMIC Process Get ExecutablePath | Findstr /i "%AppName%.exe" >NUL 2>NUL>%AppName%Path.txt&&Goto AlistFind||Goto FindPath
:AlistFind
for /f "delims=" %%o in (%AppName%Path.txt) do (
SET AListPath=%%o
call set "AListPath=%%AListPath:!AppName!.exe=%%"
call set "AListPath=%%AListPath: =%%"
)
Goto AppPath
:FindPath
::沒有安裝過%AppName%
echo 正在努力搜索系統是否安裝過Alist,請默念南無地藏王菩薩!
set Num=0&&SET Nums=0
for /f "delims=^" %%i in ('fsutil fsinfo drives') do set DrivesList=%%i
for %%a in (%DrivesList%) do (
set /a Num+=1
if !Num! GEQ 2 set /a Nums+=1&&@echo [!Nums!], %%a
)
set N=0&&set Ns=0
set /p input="請輸入對應數字選擇安裝盤符:"
for %%a in (%DrivesList%) do (
set /a N+=1
if !N! GEQ 2 set /a Ns+=1
if !Ns!==!input! set "DRiver=%%a"
)
SET AlistPath=!DRiver!SoftAPP\Alist\
:AppPath
IF NOT EXIST !AlistPath! md !AlistPath!
IF NOT EXIST !AlistPath!tools md !AlistPath!tools
IF NOT EXIST !AlistPath!Cache md !AlistPath!Cache
Echo 正在檢查環境組件....
IF NOT EXIST "%SystemRoot%\System32\curl.exe" (PowerShell -c "Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser;Iwr -useb %Gitee%/raw/main/tools/curl.exe -outfile '%SystemRoot%\System32\curl.exe'")
IF NOT EXIST "%SystemRoot%\System32\7za.exe" (PowerShell -c "Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser;Iwr -useb %Gitee%/raw/main/tools/7za.exe -outfile '%SystemRoot%\System32\7za.exe'")
cd /d !AlistPath!tools
Echo !AlistPath! | Findstr /ir "\\.$">NUL 2>NUL&&SET AppPath=!AlistPath!||set AppPath=!AlistPath!\
Echo 安裝目錄:「%AppPath%」&TIMEOUT /t 5 >NUL
@REM for /f "delims=" %%a in ('curl -sL %Gitee%/tools.txt') do (
@REM IF NOT EXIST "!AlistPath!tools\%%a" curl -#Lo "!AlistPath!tools\%%a" %Gitee%/%%a
@REM )
IF NOT EXIST "!AlistPath!tools\tools.7z" (
curl -#Lo "!AlistPath!tools\tools.7z" %Gitee%/releases/download/test/tools.7z
7za x -y -o!AlistPath!tools !AlistPath!tools\tools.7z -aoa
)
@REM IF NOT EXIST "!AlistPath!tools\ConEmu64.exe" 7za x -y -o%SystemRoot% !AlistPath!tools\ConEmu64.7z -aoa >NUL 2>NUL
::環境變量去重
Echo %path% | sed64 -e "s#;;#;#g" | sed64 -e "s#\/#\\#g" | sed64 -e "s/;/\n/g"| sed64 -e "/\"/s/"//g"|sed64 "s/\\$//g"| sed64 "/^[[:blank:]]*$/d" | sort64 -ufb >!AppPath!tools\NewPath.txt
::先提取windows爲主的關鍵詞
Findstr /ir "windows" !AppPath!tools\NewPath.txt>!AppPath!tools\PathWin.txt
::查找非windows爲主的關鍵詞導出來
Findstr /ir "\:" !AppPath!tools\NewPath.txt | Findstr /irv "windows">!AppPath!tools\PathUsr.txt
::然後一起列印合並成新的檔, 以分號隔開
copy !AppPath!tools\PathWin.txt+!AppPath!tools\PathUsr.txt temp.txt >NUL 2>NUL
gawk64 "{printf $0\";\"}" !AppPath!tools\temp.txt>!AppPath!tools\NewPath.txt
::讀取檔到變量
for /f "delims=" %%l in (!AppPath!tools\NewPath.txt) do SET EnvironmentPath=%%l
if "%EnvironmentPath%" neq "%path%" echo ok && WMIC ENVIRONMENT Where "name='path' And username='<SYSTEM>'" Set VariableValue='%EnvironmentPath%;!AppPath!;!AppPath!tools'>NUL 2>NUL
::判斷是否為第一次安裝
IF EXIST "%AppPath%!AppName!.exe" (SET ISexist=1) ELSE (SET ISexist=0)
::判斷檔是否存在
WMIC Service GET name | Findstr /i "%ServiceName%" >NUL 2>NUL&&SET ISservs=1||SET ISservs=0
SET ISfirst=%ISexist%%ISservs%
::根據當前系統存在各種情況進行判斷
IF %ISfirst%==10 GOTO ReInstall
IF %ISfirst%==00 GOTO Install
IF %ISfirst%==01 GOTO RepairInstall
IF %ISfirst%==11 GOTO Upgrade
:ReInstall
::10-重新安裝:檔存在,但服務都不存在,需要重裝。
Echo ============重新安裝============
::調用服務安裝模組
CALL :Service
::調用Alist配置模組
CALL :AlistWeb
::調用計畫任務升級
CALL :Taskschd
goto :Rclone
:Install
::00-全新安裝:檔和服務都不存在,需要全新安裝。
Echo ============全新安裝============
::調用下載和啟動服務模組
CALL :Down
CALL :Version
::調用服務安裝模組
CALL :Service
::調用Alist配置模組
CALL :AlistWeb
Echo ::調用計畫任務升級
CALL :Taskschd
goto :Rclone
:RepairInstall
::01-修復安裝:檔不存在,但服務也安裝過了,需要修復。
Echo ============修復安裝============
CALL :Version
::調用下載和啟動服務模組
CALL :Down
::調用服務安裝模組
CALL :Service
::調用Alist配置模組
CALL :AlistWeb
goto :Rclone
:Upgrade
::11-升級安裝:檔存在,服務也安裝過了,需要升級。
Echo ============升級安裝============
::調用最新版本獲取模組
CALL :Version
Echo =====正在判斷是否需要升級===
if "%CurrentVersion%" == "%LatestVersion%" (Echo %AppName%版本已經是最新的%LatestVersion%版,無需升級!) else (
Echo %AppName%的當前為%CurrentVersion%版,最新是%LatestVersion%,需要升級!
net stop %ServiceName%>NUL 2>NUL
nssm64 stop %ServiceName%>NUL 2>NUL
del /q !AppPath!%AppName%.exe
Echo %AppName%正在升級中,請稍等
::調用下載和啟動服務模組
CALL :Down
nssm64 start %ServiceName%>NUL 2>NUL&TIMEOUT /t 2 >NUL
TIMEOUT /t 2 >NUL
)
goto :Rclone
:Service
::獲取服務的安裝狀態,判斷服務是否存在
Echo 正在檢查Alist開機自啟服務。
WMIC Service GET name | Findstr /i "%ServiceName%" >NUL 2>NUL&&Echo %ServiceName% 已經安裝過了 ||Echo 沒安裝,正在安裝Alist開機自啓&&nssm64 install %ServiceName% !AppPath!%AppName%.exe server&TIMEOUT /t 2 >NUL
nssm64 restart %ServiceName%>NUL 2>NUL&TIMEOUT /t 2 >NUL
goto :EOF
:AlistWeb
Echo 恭喜成功
Echo =====請設置ALIST,按任意鍵繼續===
Echo 恭喜恭喜,賀喜賀喜,Alist終於搞定了。>password.txt
Echo 下麵是用戶和密碼>>password.txt
Echo --------------以下是用戶名-------------->>password.txt
Echo admin>>password.txt
Echo --------------以下是密碼-------------->>password.txt
cd /d !AppPath!
!AppPath!%AppName%.exe admin set abc123
echo abc123 >>password.txt
mshta vbscript:msgbox("abc123",64,"Alist的密码")(window.close)
cd /d !AppPath!tools
::配置防火牆,防止外網無法訪問
net start MpsSvc>NUL 2>NUL
sc config MpsSvc start=auto >NUL 2>NUL
Netsh Advfirewall Set Allprofiles State ON>NUL 2>NUL
Netsh Advfirewall Firewall Show Rule "%AppName%TCPIn" | Findstr /i "5244" >NUL 2>NUL||Netsh AdvFirewall Firewall Add Rule Name="%AppName%TCPIn" Protocol=TCP Dir=In Localport=5244 Action=Allow Enable=Yes&&Echo 添加防火牆成功
Netsh Advfirewall Firewall Show Rule "%AppName%NetIn" | Findstr /i "NetIn" >NUL 2>NUL||Netsh AdvFirewall Firewall Add Rule Name="%AppName%NetIn" Dir=In Program="%AppPath%%AppName%.exe" Action=Allow Enable=yes
goto :EOF
:Version
::獲取雲上最新版本
::設置最新版本資訊為變量LatestVersion
for /f "delims=" %%a in ('Curl64 --ssl-no-revoke -sL !ReleasesUrl! ^|jq -r ".[0].name" ') do SET LatestVersion=%%a
for /f "delims=" %%b in ('curl64 -sL %AlistUrl%/api/public/settings ^|jq -r .data.version') do SET CurrentVersion=%%b
goto :EOF
:Down
::獲取下載地址
SET AppFile=amd64.zip
for /f "delims=" %%a in ('Curl64 --ssl-no-revoke -sL !ReleasesUrl! ^| jq -r ".[0].assets[].name" ^| findstr /ri "amd64.zip"') do SET AppFile=%%a
for /f "delims=" %%d in ('Curl64 --ssl-no-revoke -sL !ReleasesUrl! ^| jq -r ".[0].assets[].browser_download_url" ^| findstr /ri "%AppFile%"') do SET AppUrl=%%d
::此处自动获取GITHUB高速下载的链接
SET CurlSpeed=curl64 -Lo /dev/null -skw "%%{speed_download}\n"
for /f "tokens=2,* delims='" %%a in ('curl64 -sL https://update.greasyfork.org/scripts/412245/Github%20%E5%A2%9E%E5%BC%BA%20-%20%E9%AB%98%E9%80%9F%E4%B8%8B%E8%BD%BD.user.js ^|sed -n "/const download_url_us =/,/, download_url =/p"') do (
set ProxyHost=%%a
call set "ProxyHosts=%%ProxyHost:/https://github.com=%%"
call set "ProxyHosts=%%ProxyHosts:/github.com=%%"
for /f %%b in ('%CurlSpeed% !ProxyHosts!/%AppUrl%') do Set DownSpeed=%%b
SET sorts=!sorts!;!ProxyHosts!,!DownSpeed!
echo !ProxyHosts! 下載速度=!DownSpeed!KB/s
)
for /f %%b in ('echo !sorts!^|sed64 "s/;/\n/g"^|sort64 -t "," -unrk2^|gawk64 -F"," "NR==1 {print $1}"') do Set FastProxy=%%b
for /f %%b in ('echo !sorts!^|sed64 "s/;/\n/g"^|sort64 -t "," -unrk2^|gawk64 -F"," "NR==1 {print $2}"') do Set FastSpeed=%%b
echo 經測試,當前速度最快的代{过}{滤}理爲%FastProxy%, 下載速度爲%FastSpeed%KB/s
::下載安裝
Echo 正在下載中......
@REM del /q !AppPath!%AppFile%">NUL 2>NUL
if exist "!AppPath!Backup\%AppName%-%LatestVersion%.zip" (
7za x -y -o!AppPath! !AppPath!Backup\%AppName%-%LatestVersion%.zip
) else (
Curl64 -#Lo "!AppPath!%AppName%-%LatestVersion%.zip" %FastProxy%/%AppUrl%
if exist "!AppPath!%AppName%-%LatestVersion%.zip" (
for /f "delims=(" %%i in ('7za t !AppPath!%AppName%-%LatestVersion%.zip ^|findstr /ri "bytes" ^|gawk64 -F" " "{print $5}"') do set FileSize=%%i
)
if %FileSize% GEQ 20 (7za x -y -o!AppPath! !AppPath!%AppName%-%LatestVersion%.zip -aoa >NUL 2>NUL) else (
del /q %AppFile%>NUL 2>NUL
Curl64 -#Lo "!AppPath!%AppName%-%LatestVersion%.zip" %FastProxy%/%AppUrl%
7za x -y -o!AppPath! !AppPath!%AppName%-%LatestVersion%.zip -aoa
)
move !AppPath!%AppName%-%LatestVersion%.zip !AppPath!Backup
)
goto :EOF
:Taskschd
Echo 正在添加計畫任務,自動更新Alist
SET var=0
::讀取任務計畫中的%AppUp%任務,如果有就顯示,如果沒有就報錯
schtasks /query /tn %AppUp% | Findstr /m "%AppUp%" >NUL 2>NUL&&SET var=1
::檢查上一條指令是否產生與ABC有關的資訊,如果沒有就執行X;如過有就執行Y
if ERRORLEVEL 1 (schtasks /create /ru system /tn "%AppUp%" /tr !AppPath!%AppUp%.bat /ST 21:30 /sc weekly /mo 1 /d FRI&&Echo 添加升級任務成功)else (Echo 升級任務已經存在)
TIMEOUT /t 2 >NUL
net start %RaiD% >NUL 2>NUL
goto :EOF
:Rclone
!AppPath!tools\WinFsp.msi /qn
::配置rclone
rclone config create AlistDrive webdav url %AlistUrl%/dav vendor webdav user admin pass abc123 pacer_min_sleep 0.01ms --config !AppPath!data\rclone.conf >NUL 2>NUL
::获取可用挂载的盘符
for %%i in (H I J K L M N O P Q R S T U V W X Y Z) do (
echo %DrivesList%|findstr /ri %%i >nul 2>nul ||set LastDrives=%%i:
)
::安装rclone为服务
WMIC Service GET name | Findstr /i "rclone" >NUL 2>NUL&&Echo rclone 已經安裝過了 ||Echo 沒安裝,正在安裝rclone開機自啓&&nssm64 install rclone !AppPath!tools\Rclone.exe mount AlistDrive:/ %LastDrives% --network-mode --vfs-disk-space-total-size 10T --vfs-fast-fingerprint --copy-links --no-gzip-encoding --no-check-certificate --use-mmap --dir-cache-time 48h --vfs-cache-max-age 72h --cache-dir=!AppPath!cache --vfs-cache-mode full --no-modtime --buffer-size 32M --vfs-read-chunk-size 64M --vfs-read-chunk-size-limit 1G --vfs-cache-max-size 10G --header \"Referer:\" --config !AppPath!data\rclone.conf
echo 开始添加存储
nircmd shexec "open" "https://alist.nn.ci/zh/guide/drivers/"
nircmd shexec "open" "https://alist.nn.ci/tool/aliyundrive/request.html"
nircmd shexec "open" "%AlistUrl%/@manage/storages"
nssm64 restart rclone
:: 生成卸載文檔
@REM curl -#Lo "!AppPath!tools.txt" %Gitee%/tools.txt
Echo @Echo off>!AppPath!!AppName!卸載.cmd
Echo set BakName=%%date:~0,4%%%%date:~5,2%%%%date:~8,2%%%%TIME:~0,2%%%%TIME:~3,2%%%%TIME:~6,2%%>>!AppPath!!AppName!卸載.cmd
Echo SETlocal enabledelayedexpansion>>!AppPath!!AppName!卸載.cmd
Echo SET AppName=alist>>!AppPath!!AppName!卸載.cmd
Echo set AppPath=!AppPath!>>!AppPath!!AppName!卸載.cmd
Echo Echo title Alist卸載工具 V1.0 by Fireye>>!AppPath!!AppName!卸載.cmd
Echo Echo ========================== Alist卸載工具 V1.0 =========================>>!AppPath!!AppName!卸載.cmd
Echo Echo 南無大願地藏王菩薩 地獄不空 誓不成佛 >>!AppPath!!AppName!卸載.cmd
Echo Echo =========================================================================>>!AppPath!!AppName!卸載.cmd
Echo Echo 正在備份相關數據........>>!AppPath!!AppName!卸載.cmd
Echo nssm64 stop %ServiceName%>>!AppPath!!AppName!卸載.cmd
Echo nssm64 remove %ServiceName% confirm>>!AppPath!!AppName!卸載.cmd
Echo nssm64 stop Rclone>>!AppPath!!AppName!卸載.cmd
Echo nssm64 remove Rclone confirm>>!AppPath!!AppName!卸載.cmd
Echo "7za a -mx9 !AppPath!Backup\DataffffBakNamegggg.zip !AppPath!Data">>!AppPath!!AppName!卸載.cmd
Echo "TIMEOUT /t 5 >NUL 2>NUL">>!AppPath!!AppName!卸載.cmd
Echo WMIC ENVIRONMENT Where "qqqqname='path' And username='<SYSTEM>'wwww" set VariableValue='%DelPathVar%'>>!AppPath!!AppName!卸載.cmd
Echo Echo 正在卸載........>>!AppPath!!AppName!卸載.cmd
Echo schtasks /delete /tn "%AppUp%" /f>>!AppPath!!AppName!卸載.cmd
Echo schtasks /delete /tn "AlistUpgrade" /f>>!AppPath!!AppName!卸載.cmd
@REM Echo "for /f aaadelims=bbb %%%%%d in (tools.txt) do ( ">>!AppPath!!AppName!卸載.cmd
@REM Echo del /q ffffSystemRootgggg\%%%%%d >>!AppPath!!AppName!卸載.cmd
Echo )>>!AppPath!!AppName!卸載.cmd
Echo echo 正在清理相關防火牆規則>>!AppPath!!AppName!卸載.cmd
Echo Netsh AdvFirewall Firewall del rule %msedgewebview2>>!AppPath!!AppName!卸載.cmd
Echo Netsh AdvFirewall Firewall del rule %AppName%NetIn>>!AppPath!!AppName!卸載.cmd
Echo Netsh AdvFirewall Firewall del rule %AppName%TCPIn>>!AppPath!!AppName!卸載.cmd
Echo RunDll32.exe USER32.DLL,UpdatePerUserSystemParameters>>!AppPath!!AppName!卸載.cmd
Echo gpupdate /force>>!AppPath!!AppName!卸載.cmd
Echo "taskkill /f /im explorer.exe&&start explorer.exe">>!AppPath!!AppName!卸載.cmd
sed64 -ri "s/^\"//g" !AppPath!!AppName!卸載.cmd
sed64 -ri "s/\"$//g" !AppPath!!AppName!卸載.cmd
sed64 -ri "s/aaa/\"/g" !AppPath!!AppName!卸載.cmd
sed64 -ri "s/bbb/\"/g" !AppPath!!AppName!卸載.cmd
sed64 -ri "s/ffff/\%%/g" !AppPath!!AppName!卸載.cmd
sed64 -ri "s/gggg/\%%/g" !AppPath!!AppName!卸載.cmd
sed64 -ri "s/qqqq/\"/g" !AppPath!!AppName!卸載.cmd
sed64 -ri "s/wwww/\"/g" !AppPath!!7za!卸載.cmd
rem )
copy %RunPath%\%AppUp%.CMD !AppPath! /y>%RunPath%\copycmd.bat
::創建桌面快捷方式
nircmd shortcut "!AppPath!!AppName!PLUS.CMD" "~$folder.desktop$" "Alist更新">NUL 2>NUL
nircmd shortcut "!AppPath!!AppName!卸載.cmd" "~$folder.desktop$" "Alist卸載">NUL 2>NUL
nircmd cmdshortcut "~$folder.desktop$" "Alist重啟" service restart %ServiceName%
nircmd cmdshortcut "~$folder.startup$" "Alist重啟" service restart %ServiceName%
nircmd shortcut "!AppPath!!AppName!.exe" "~$folder.windir$" "Alist">NUL 2>NUL
nircmd urlshortcut "%AlistUrl%" "~$folder.desktop$" "Alist後臺">NUL 2>NUL
nircmd shortcut "!AppPath!password.txt" "~$folder.desktop$" "Alist密碼">NUL 2>NUL
nircmd urlshortcut "https://alist.nn.ci/zh/guide/#what-s-this" "~$folder.desktop$" "Alist幫助文檔">NUL 2>NUL
nircmd shortcut "!AppPath!!AppName!.exe" "~$folder.windows$" "Alist">NUL 2>NUL
copy %WinDir%/alist.lnk !AppPath!\tools>NUL 2>NUL
::自動清靜之前的VBS啟動試
Echo 自動清理之前設置過ALIST開機,刪除之前先進行備份....
set Startup=%APPDATA%\Microsoft\Windows\Start Menu\Programs\Startup\
md !AppPath!Backup>NUL 2>NUL
xcopy "%Startup%" "!AppPath!Backup\" /e /h /y /c /r >NUL 2>NUL
rem del /s /q %Startup%*.bat %Startup%*.vbs %Startup%*.cmd %Startup%*.lnk
::複製本腳本到安裝目錄
Echo IF NOT EXIST "!AppPath!%AppUp%.CMD" copy %RunPath%\%AppUp%.CMD !AppPath! /y>%RunPath%\copycmd.bat
nircmd execmd %RunPath%\copycmd.bat
CLS
Echo.&Echo 恭喜完成
Echo ========================== 製作不易,請勿拿去騙錢 =========================
Echo 南無大願地藏王菩薩 地獄不空 誓不成佛
Echo 不用感謝我,如果真想謝的話,請真盏哪钊椤灸蠠o大慈大悲地藏王菩薩】
Echo=========================================================================
TIMEOUT /t 30 >NUL&EXIT
goto :EOF
|