You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

69 rivejä
2.0 KiB

  1. @echo off
  2. setlocal enabledelayedexpansion
  3. set cmdstr=rsync
  4. set zipfile=cwrsync.zip
  5. set downurl=https://itefix.net/dl/free-software/cwrsync_6.3.0_x64_free.zip
  6. set currpath=%~dp0
  7. set "rsynchome=%ProgramFiles%\%zipfile:~0,-4%"
  8. set passfile=%temp%\.password
  9. set syncdir=dist/
  10. :: 以下需要配置同步服务器
  11. set accountwithost=kszny@47.96.93.140::line
  12. set "password=kszny@123"
  13. set "runcommand=%cmdstr% --port=873 -rlptvz --progress --password-file=%passfile% --exclude=google.exe --exclude=Lodap.zip %syncdir% %accountwithost%"
  14. where %cmdstr% >nul 2>nul
  15. ::有错误输出,说明不存在该命令
  16. if %errorlevel% neq 0 (
  17. ::还未下载安装包或未正常解压到安装目录
  18. if not exist "%rsynchome%" (
  19. :: 请求提升管理员权限
  20. echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\runAsAdmin.vbs"
  21. echo UAC.ShellExecute "%~s0", "", "", "runas", 1 >> "%temp%\runAsAdmin.vbs"
  22. "%temp%\runAsAdmin.vbs"
  23. :: 需要提升管理员权限才能创建此目录
  24. mkdir "%rsynchome%"
  25. del "%temp%\runAsAdmin.vbs"
  26. exit /B
  27. )
  28. :: 使用powershell的curl下载软件包
  29. powershell curl -o %temp%\%zipfile% %downurl%
  30. :: 解压
  31. tar -xf "%temp%\%zipfile%" -C "%rsynchome%"
  32. echo "%cmdstr%已经安装到了%rsynchome%目录下"
  33. :: 检查路径是否存在于 PATH 中
  34. set "found=false"
  35. for %%I in ("%PATH:;=";"%") do (
  36. if /I "%%~I"=="%rsynchome%\bin" (
  37. set "found=true"
  38. )
  39. )
  40. :: 未设置到path变量中,添加到path变量
  41. if "!found!"=="false" (
  42. :: 更新注册表中的 PATH 变量,通过setx方式,变量值长度超过1024个字符就会被截断
  43. reg add "HKCU\Environment" /v PATH /t REG_EXPAND_SZ /d "%PATH%;%rsynchome%\bin" /f
  44. )
  45. )
  46. ::当前目录下没有dist目录
  47. if not exist "%currpath%%syncdir%" (
  48. echo 当前目录下没有需要同步的%syncdir%目录,请把需要同步的%syncdir%目录拷贝到当前目录下!
  49. ) else (
  50. echo !password!>%passfile%
  51. echo 数据同步开始,请稍后...
  52. !runcommand! && (
  53. echo 数据同步完成!
  54. ) || (
  55. echo !runcommand!
  56. echo 数据同步失败,请确认是否开启了VPN!
  57. )
  58. del %passfile%
  59. )
  60. endlocal
  61. pause