diff --git a/etc/smartdns/smartdns.conf b/etc/smartdns/smartdns.conf index 27b2212112..f6dcafd926 100644 --- a/etc/smartdns/smartdns.conf +++ b/etc/smartdns/smartdns.conf @@ -1,4 +1,4 @@ -# dns server name, defaut is host name +# dns server name, default is host name # server-name, # example: # server-name smartdns diff --git a/package/windows/install.bat b/package/windows/install.bat index 50782015ae..cde461acc7 100644 --- a/package/windows/install.bat +++ b/package/windows/install.bat @@ -1,16 +1,30 @@ @echo off set "CURR_PATH=%~dp0" set "STARTUP_PATH=%userprofile%\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup" +set "StartMenuDir=%userprofile%\AppData\Roaming\Microsoft\Windows\Start Menu\Programs" FOR /F %%i IN ('wsl pwd') DO @set DIR_IN_WSL=%%i -wsl sudo %DIR_IN_WSL%/../../install -i +bash "$(wslpath -u "%CURR_PATH%\script\init.sh")" +IF %ERRORLEVEL% == 0 ( + wsl sudo %DIR_IN_WSL%/../../install -i +)^ +ELSE IF %ERRORLEVEL% == 10 ( + wsl -d ubuntu sudo %DIR_IN_WSL%/../../install -i +)^ +ELSE echo error:%ERRORLEVEL% + IF NOT %ERRORLEVEL% == 0 ( echo Install smartdns failed. pause exit 1 ) -copy %CURR_PATH%\wsl-run.vbs "%STARTUP_PATH%/" +md "%StartMenuDir%\Smartdns" +copy %CURR_PATH%\script\init.sh "%StartMenuDir%\smartdns\" + +call %CURR_PATH%\script\startmenu.vbs + +copy %CURR_PATH%\wsl-run.vbs "%STARTUP_PATH%\" IF NOT %ERRORLEVEL% == 0 ( echo Install startupt script failed. pause diff --git a/package/windows/reload.bat b/package/windows/reload.bat index 12bbf73fd1..9955108ddf 100644 --- a/package/windows/reload.bat +++ b/package/windows/reload.bat @@ -3,14 +3,17 @@ set "CURR_PATH=%~dp0" set "STARTUP_PATH=%userprofile%\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup" FOR /F %%i IN ('wsl pwd') DO @set DIR_IN_WSL=%%i -wsl sudo cp -avf %DIR_IN_WSL%/../../etc/smartdns/* /etc/smartdns/ -IF NOT %ERRORLEVEL% == 0 ( - echo copy smartdns configuration file failed. - pause - exit 1 -) +bash "$(wslpath -u "%CURR_PATH%\script\init.sh")" +IF %ERRORLEVEL% == 0 ( + wsl sudo cp -avf %DIR_IN_WSL%/../../etc/smartdns/* /etc/smartdns/ + wsl sudo /etc/init.d/smartdns restart +)^ +ELSE IF %ERRORLEVEL% == 10 ( + wsl -d ubuntu sudo cp -avf %DIR_IN_WSL%/../../etc/smartdns/* /etc/smartdns/ + wsl -d ubuntu sudo /etc/init.d/smartdns restart +)^ +ELSE echo error:%ERRORLEVEL% -wsl sudo /etc/init.d/smartdns restart IF NOT %ERRORLEVEL% == 0 ( echo reload smartdns failed. pause diff --git a/package/windows/script/init.sh b/package/windows/script/init.sh new file mode 100644 index 0000000000..d96028ed68 --- /dev/null +++ b/package/windows/script/init.sh @@ -0,0 +1,19 @@ +#!/bin/bash + +source /etc/os-release +case $ID in +debian | ubuntu) + echo default wsl distro is debian or ubuntu. + echo + echo using default distro. + echo + exit 0 + ;; +*) + echo default wsl distro is not debian or ubuntu. + echo + echo try to use ubuntu now. + echo + exit 10 + ;; +esac diff --git a/package/windows/script/restart.bat b/package/windows/script/restart.bat new file mode 100644 index 0000000000..0f5f7008ba --- /dev/null +++ b/package/windows/script/restart.bat @@ -0,0 +1,10 @@ +@echo off +bash "$(wslpath -u "%~dp0\init.sh")" +IF %ERRORLEVEL% == 0 ( + wsl sudo /etc/init.d/smartdns restart +)^ +ELSE IF %ERRORLEVEL% == 10 ( + wsl -d ubuntu sudo /etc/init.d/smartdns restart +)^ +ELSE echo error:%ERRORLEVEL% +pause diff --git a/package/windows/script/startmenu.vbs b/package/windows/script/startmenu.vbs new file mode 100644 index 0000000000..35f5deae29 --- /dev/null +++ b/package/windows/script/startmenu.vbs @@ -0,0 +1,27 @@ +Set ws = WScript.CreateObject("WScript.Shell") +Set fs = WScript.CreateObject("Scripting.FileSystemObject") + +CURR_PATH =fs.GetParentFolderName(WScript.ScriptFullName) +USERPROFILE = ws.ExpandEnvironmentStrings("%USERPROFILE%") +SmartdnsDir = USERPROFILE + "\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\smartdns" + +Set lnk = ws.CreateShortcut(SmartdnsDir & "\restart.lnk") +lnk.TargetPath = CURR_PATH +"\restart.bat" +lnk.WindowStyle = "1" +lnk.WorkingDirectory = CURR_PATH +lnk.Save +Set lnk = Nothing + +Set lnk = ws.CreateShortcut(SmartdnsDir & "\stop.lnk") +lnk.TargetPath = CURR_PATH +"\stop.bat" +lnk.WindowStyle = "1" +lnk.WorkingDirectory = CURR_PATH +lnk.Save +Set lnk = Nothing + +Set lnk = ws.CreateShortcut(SmartdnsDir & "\test.lnk") +lnk.TargetPath = CURR_PATH +"\test.bat" +lnk.WindowStyle = "1" +lnk.WorkingDirectory = CURR_PATH +lnk.Save +Set lnk = Nothing diff --git a/package/windows/script/stop.bat b/package/windows/script/stop.bat new file mode 100644 index 0000000000..e35409bea7 --- /dev/null +++ b/package/windows/script/stop.bat @@ -0,0 +1,10 @@ +@echo off +bash "$(wslpath -u "%~dp0\init.sh")" +IF %ERRORLEVEL% == 0 ( + wsl sudo /etc/init.d/smartdns stop +)^ +ELSE IF %ERRORLEVEL% == 10 ( + wsl -d ubuntu sudo /etc/init.d/smartdns stop +)^ +ELSE echo error:%ERRORLEVEL% +pause \ No newline at end of file diff --git a/package/windows/script/test.bat b/package/windows/script/test.bat new file mode 100644 index 0000000000..cf13cf949d --- /dev/null +++ b/package/windows/script/test.bat @@ -0,0 +1,2 @@ +nslookup -querytype=ptr 127.0.0.1 +nslookup -querytype=ptr 0.0.0.0 \ No newline at end of file diff --git a/package/windows/uninstall.bat b/package/windows/uninstall.bat index af3d52b789..5bac5a7574 100644 --- a/package/windows/uninstall.bat +++ b/package/windows/uninstall.bat @@ -1,15 +1,29 @@ @echo off set "CURR_PATH=%~dp0" set "STARTUP_PATH=%userprofile%\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup" +set "StartMenuDir=%userprofile%\AppData\Roaming\Microsoft\Windows\Start Menu\Programs" FOR /F %%i IN ('wsl pwd') DO @set DIR_IN_WSL=%%i -wsl sudo %DIR_IN_WSL%/../../install -u +bash "$(wslpath -u "%CURR_PATH%\script\init.sh")" +IF %ERRORLEVEL% == 0 ( + wsl sudo %DIR_IN_WSL%/../../install -u +)^ +ELSE IF %ERRORLEVEL% == 10 ( + wsl -d ubuntu sudo %DIR_IN_WSL%/../../install -u +)^ +ELSE echo error:%ERRORLEVEL% + IF NOT %ERRORLEVEL% == 0 ( echo Uninstall smartdns failed. pause exit 1 ) +del "%StartMenuDir%\smartdns\init.sh" +del "%StartMenuDir%\smartdns\restart.lnk" +del "%StartMenuDir%\smartdns\stop.lnk" +del "%StartMenuDir%\smartdns\test.lnk" + del "%STARTUP_PATH%\wsl-run.vbs" IF NOT %ERRORLEVEL% == 0 ( echo Uninstall startup script failed. @@ -18,5 +32,4 @@ IF NOT %ERRORLEVEL% == 0 ( ) echo uninstall success - pause diff --git a/package/windows/wsl-run.vbs b/package/windows/wsl-run.vbs index adab40a340..ec49bcbe80 100644 --- a/package/windows/wsl-run.vbs +++ b/package/windows/wsl-run.vbs @@ -1,2 +1,18 @@ Set ws = WScript.CreateObject("WScript.Shell") -ws.run "wsl sudo /etc/init.d/smartdns restart", vbhide \ No newline at end of file + +USERPROFILE = ws.ExpandEnvironmentStrings("%USERPROFILE%") +initScriptPath = Chr(34) + USERPROFILE + "\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\smartdns\init.sh" + Chr(34) +tmp = replace(initScriptPath ,"\", "/") +unixPath = replace(tmp ,"C:", "/mnt/c") + +command = "bash " + unixPath + +returnCode = ws.run(command,0,True) + +if returnCode = 0 Then + ws.run "wsl sudo /etc/init.d/smartdns restart", vbhide +elseif returnCode = 10 Then + ws.run "wsl -d ubuntu sudo /etc/init.d/smartdns restart", vbhide +else + WScript.Echo "Start smartdns failed" +End If