Skip to content

Commit 135c2b3

Browse files
committed
feat: add Win10-Initial-Setup-Script action
1 parent 3cca683 commit 135c2b3

File tree

14 files changed

+295
-266
lines changed

14 files changed

+295
-266
lines changed
Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,14 @@ rem Chocolatey action functions
22
@echo off
33

44
set batdir=%~dp0
5-
set batfile=%0
6-
set cliCmd=%batdir%cli.bat
7-
set configCmd=%batdir%config.bat
5+
set cliCmd=%batdir%../utils/cli.bat
6+
set configCmd=%batdir%../utils/config.bat
87
set chocolateyInstallUrl=https://chocolatey.org/install.ps1
98

10-
if "%~1" neq "" (
11-
2>nul >nul findstr /rc:"^ *:%~1\>" "%~f0" && (
12-
shift /1
13-
goto %1
14-
) || (
15-
>&2 call %cliCmd% fatalError "Function %~1 not found in %batfile%"
16-
)
17-
) else >&2 call %cliCmd% fatalError "No function name was given to %batfile%"
9+
goto execute
1810
exit /b
1911

20-
:executeChocolatey
12+
:execute
2113
setlocal EnableDelayedExpansion
2214

2315
call %cliCmd% processing "Checking if Chocolatey is installed"
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ rem Cleaner action functions
33

44
set batdir=%~dp0
55
set batfile=%0
6-
set cliCmd=%batdir%cli.bat
6+
set cliCmd=%batdir%../utils/cli.bat
77
set ccleanerExePath="%programfiles%\CCleaner\ccleaner.exe"
88

99
if "%~1" neq "" (
@@ -120,7 +120,7 @@ exit /b
120120
if defined ccleanerExe (
121121
echo.
122122
call %cliCmd% processing "Running CCleaner auto clean"
123-
call %cliCmd% execCmd "^!ccleanerExe^! /AUTO"
123+
call %cliCmd% execCmd "!ccleanerExe! /AUTO"
124124
call %cliCmd% success "CCleaner auto clean is done"
125125
)
126126
exit /b

src/lib/actions/dev.bat

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
rem Dev action functions
2+
@echo off
3+
4+
set batdir=%~dp0
5+
set batfile=%0
6+
set cliCmd=%batdir%../utils/cli.bat
7+
set configCmd=%batdir%../utils/config.bat
8+
9+
goto execute
10+
exit /b
11+
12+
:execute
13+
setlocal EnableDelayedExpansion
14+
15+
rem Add npm global packages if npm is available
16+
set errorlevel=
17+
call :npmExists
18+
if !errorlevel! equ 0 (
19+
set errorlevel=
20+
call %cliCmd% confirmPrompt "Do you want to install npm global packages"
21+
if !errorlevel! equ 0 (
22+
call :installGlobalNpmPackages %1
23+
)
24+
)
25+
26+
rem configure VSCode if installed
27+
set errorlevel=
28+
call :vscodeExists
29+
if !errorlevel! equ 0 (
30+
set errorlevel=
31+
call %cliCmd% confirmPrompt "Do you want to configure vscode"
32+
if !errorlevel! equ 0 (
33+
call :configureVSCode
34+
)
35+
)
36+
37+
endlocal
38+
exit /b
39+
40+
:npmExists
41+
setlocal EnableDelayedExpansion
42+
set errorlevel=
43+
call %cliCmd% cmdExists "npm.cmd"
44+
set npmExists=!errorlevel!
45+
set errorlevel=
46+
47+
endLocal
48+
exit /b %npmExists%
49+
50+
51+
:installGlobalNpmPackages
52+
setlocal EnableDelayedExpansion
53+
54+
set configPath=
55+
call %configCmd% useConfig "npm" %1
56+
57+
58+
call %cliCmd% processing "Installing NPM global packages from config file ^!configPath^!"
59+
set unsafeConfigPath=%configPath:"=%
60+
for /F "delims=" %%i in (%unsafeConfigPath%) do set packages=!packages! %%i
61+
call %cliCmd% execCmd "npm.cmd i -g %packages%"
62+
echo .
63+
call %cliCmd% success "Installation of NPM global packages is done"
64+
65+
endlocal
66+
exit /b
67+
68+
:vscodeExists
69+
setlocal EnableDelayedExpansion
70+
set errorlevel=
71+
call %cliCmd% cmdExists "code"
72+
set vscodeExists=!errorlevel!
73+
set errorlevel=
74+
endLocal
75+
exit /b %vscodeExists%
76+
77+
:configureVSCode
78+
setlocal EnableDelayedExpansion
79+
80+
call %cliCmd% processing "Configure VSCode"
81+
call %cliCmd% execCmd "code --install-extension Shan.code-settings-sync --force" >nul
82+
call %cliCmd% success "Configuration of VSCode is done"
83+
84+
endlocal
85+
exit /b
Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,17 @@ rem Driver cloud action functions
22
@echo off
33

44
set batdir=%~dp0
5-
set batfile=%0
6-
set cliCmd=%batdir%cli.bat
5+
set cliCmd=%batdir%../utils/cli.bat
76

87
set driverCloudUrl=https://www.driverscloud.com/plugins/DriversCloud_Win.exe
98
set driverCloudExe="%programfiles%\DriversCloud.com\DriversCloud.exe"
109
set driverCloudUninstall="%AllUsersProfile%\Microsoft\Windows\Start Menu\Programs\DriversCloud.com\Desinstaller.lnk"
1110
set tmpDrivercloud="%Tmp%\DriversCloud_Win.exe"
1211

13-
if "%~1" neq "" (
14-
2>nul >nul findstr /rc:"^ *:%~1\>" "%~f0" && (
15-
shift /1
16-
goto %1
17-
) || (
18-
>&2 call %cliCmd% fatalError "Function %~1 not found in %batfile%"
19-
)
20-
) else >&2 call %cliCmd% fatalError "No function name was given to %batfile%"
12+
goto execute
2113
exit /b
2214

23-
:executeDriverCloud
15+
:execute
2416
setlocal EnableDelayedExpansion
2517

2618
for %%X in (%driverCloudExe%) do (set driverCloudFound=%%~$PATH:X)
Lines changed: 20 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,29 @@ set "initialSetupSourcePath=%initialSetupPath%Win10-Initial-Setup-Script-%initia
1212
set "initialSetupExePath=%initialSetupSourcePath%Win10.ps1"
1313

1414
set batdir=%~dp0
15-
set batfile=%0
16-
set cliCmd=%batdir%cli.bat
17-
set configCmd=%batdir%config.bat
15+
set cliCmd=%batdir%../utils/cli.bat
16+
set configCmd=%batdir%../utils/config.bat
1817

19-
if "%~1" neq "" (
20-
2>nul >nul findstr /rc:"^ *:%~1\>" "%~f0" && (
21-
shift /1
22-
goto %1
23-
) || (
24-
>&2 call %cliCmd% fatalError "Function %~1 not found in %batfile%"
25-
)
26-
) else >&2 call %cliCmd% fatalError "No function name was given to %batfile%"
18+
goto execute
2719
exit /b
2820

21+
:execute
22+
set "initialSetupExe="
23+
call :getInitialSetupExe
24+
25+
if not defined initialSetupExe (
26+
call :installInitialSetup
27+
)
28+
29+
set configPath=
30+
call %configCmd% useConfig "initial-setup" %1
31+
32+
call %cliCmd% processing "Execute Initial setup"
33+
powershell -NoProfile -ExecutionPolicy Bypass -File %initialSetupExe% -include %initialSetupSourcePath%Win10.psm1 -preset %configPath%
34+
call %cliCmd% success "Initial setup execution is done"
35+
36+
exit /b
37+
2938
:getInitialSetupExe
3039
rem Check if optimizer exe exists
3140
for %%X in (%initialSetupExePath%) do (set initialSetupFound=%%~$PATH:X)
@@ -51,20 +60,3 @@ exit /b
5160
call %cliCmd% execPowershellCmd "Expand-Archive -Path '^!initialSetupDownloadPath^!' -DestinationPath '^!initialSetupPath^!'" >nul
5261
call %cliCmd% success "Unziping Win10-Initial-Setup-Script is done"
5362
exit /b 0
54-
55-
:executeInitialSetup
56-
set "initialSetupExe="
57-
call :getInitialSetupExe
58-
59-
if not defined initialSetupExe (
60-
call :installInitialSetup
61-
)
62-
63-
set configPath=
64-
call %configCmd% useConfig "initial-setup" %1
65-
66-
call %cliCmd% processing "Execute Initial setup"
67-
powershell -NoProfile -ExecutionPolicy Bypass -File %initialSetupExe% -include %initialSetupSourcePath%Win10.psm1 -preset %configPath%
68-
call %cliCmd% success "Initial setup execution is done"
69-
70-
exit /b
Lines changed: 35 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,30 @@ rem Interface action functions
22
@echo off
33

44
set batdir=%~dp0
5-
set batfile=%0
6-
set cliCmd=%batdir%cli.bat
7-
set configCmd=%batdir%config.bat
5+
set cliCmd=%batdir%../utils/cli.bat
6+
set configCmd=%batdir%../utils/config.bat
87
set cleanerCmd=%batdir%cleaner.bat
98

10-
if "%~1" neq "" (
11-
2>nul >nul findstr /rc:"^ *:%~1\>" "%~f0" && (
12-
shift /1
13-
goto %1
14-
) || (
15-
>&2 call %cliCmd% fatalError "Function %~1 not found in %batfile%"
16-
)
17-
) else >&2 call %cliCmd% fatalError "No function name was given to %batfile%"
9+
goto execute
1810
exit /b
1911

20-
:restartExplorer
21-
call %cliCmd% processing "Restarting explorer"
22-
call %cliCmd% execPowershellCmd "Stop-Process -ProcessName explorer"
23-
call %cliCmd% success "Explorer has been restarted"
12+
:execute
13+
rem Create desktop folders
14+
set errorlevel=
15+
call %cliCmd% confirmPrompt "Do you want to create desktop folders"
16+
if %errorlevel% equ 0 (
17+
call :createDesktopDirFolders %configDir%
18+
)
19+
20+
rem Create desktop "Maintenance" shortcut
21+
set errorlevel=
22+
call %cliCmd% confirmPrompt "Do you want to create a 'Maintenance' shortcut"
23+
if %errorlevel% equ 0 (
24+
call :createMaintenanceShortcut
25+
)
26+
27+
endlocal
28+
exit /b
2429

2530
:createDesktopDirFolders
2631
setlocal EnableDelayedExpansion
@@ -44,24 +49,24 @@ exit /b
4449
setlocal EnableDelayedExpansion
4550

4651
set dirName=%1
47-
set dirPath=%UserProfile%\Desktop\%dirName%
52+
set dirPath=%UserProfile%\Desktop\!dirName!
4853
set icon=%1
4954

50-
if not exist %dirPath% (
51-
mkdir %dirPath%
55+
if not exist !dirPath! (
56+
mkdir !dirPath!
5257
)
5358

5459
(
5560
echo [.ShellClassInfo]
56-
echo IconResource=C:\WINDOWS\System32\SHELL32.dll,%icon%
61+
echo IconResource=C:\WINDOWS\System32\SHELL32.dll,!icon!
5762
echo [ViewState]
5863
echo Mode=
5964
echo Vid=
6065
echo FolderType=Generic
61-
) > %dirPath%\desktop.ini
66+
) > !dirPath!\desktop.ini
6267

63-
attrib +r %dirPath%
64-
attrib +s +h %dirPath%\desktop.ini
68+
attrib +r !dirPath!
69+
attrib +s +h !dirPath!\desktop.ini
6570

6671
endlocal
6772
exit /b
@@ -70,20 +75,21 @@ exit /b
7075
setlocal EnableDelayedExpansion
7176

7277
call %cliCmd% processing "Creating 'Maintenance' shortcut..."
73-
set "maintenanceCmd=echo [93m[ [4mExecute maintenace[0m[93m ][0m&&echo.&&echo.&&echo =^> Upgrade Chocolatey packages&&echo.&&choco upgrade all --y&&echo."
78+
set "maintenanceCmd=echo [93m[ [4mExecute maintenace[0m[93m ][0m&echo.&echo.&echo =^> Upgrade Chocolatey packages&echo.&choco upgrade all --y&echo."
7479

75-
set "ccleanerExe="
80+
set ccleanerExe=
7681
call %cleanerCmd% getCCleanerExe
77-
if !ERRORLEVEL! equ 0 (
78-
set "maintenanceCmd=!maintenanceCmd!&&echo.&&(echo =^> Execute CCleaner)&&\"!ccleanerExe!\" /AUTO&&echo."
82+
if defined ccleanerExe (
83+
set "maintenanceCmd=!maintenanceCmd!&echo.&(echo =^> Execute CCleaner)&\"!ccleanerExe!\" /AUTO&echo."
7984
)
8085

86+
set errorlevel=
8187
where npm-check.cmd >nul 2>nul
82-
if !ERRORLEVEL! equ 0 (
83-
set "maintenanceCmd=!maintenanceCmd!&&echo.&&(echo =^> Upgade npm packages)&&echo.&&npm-check.cmd -u -g&&echo."
88+
if !errorlevel! equ 0 (
89+
set "maintenanceCmd=!maintenanceCmd!&echo.&(echo =^> Upgade npm packages)&echo.&npm-check.cmd -u -g&echo."
8490
)
8591

86-
set "maintenanceCmd=!maintenanceCmd!&&echo.&&echo.&&echo [92m=======================[0m&&echo [92m[ [4mMaintenance is done[0m[92m ][0m&&echo [92m=======================[0m&&echo.&&echo."
92+
set "maintenanceCmd=!maintenanceCmd!&echo.&echo.&echo [92m=======================[0m&echo [92m[ [4mMaintenance is done[0m[92m ][0m&echo [92m=======================[0m&echo.&echo."
8793

8894
call %cliCmd% execPowershellCmd "$ShortcutPath='%UserProfile%\Desktop\Maintenance.lnk';$s=(New-Object -COM WScript.Shell).CreateShortcut($ShortcutPath);$s.TargetPath='%SystemRoot%\System32\cmd.exe';$s.Arguments='/k ^!maintenanceCmd^!';$s.IconLocation='%SystemRoot%\System32\shell32.dll,46';$s.Save();$bytes = [System.IO.File]::ReadAllBytes($ShortcutPath);$bytes[0x15] = $bytes[0x15] -bor 0x20;[System.IO.File]::WriteAllBytes($ShortcutPath, $bytes);"
8995
call %cliCmd% success "Creation of desktop 'Maintenance' shortcut is done"
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ rem Optimizer action functions
33

44
set batdir=%~dp0
55
set batfile=%0
6-
set cliCmd=%batdir%cli.bat
6+
set cliCmd=%batdir%../utils/cli.bat
77
set optimizerConfigPath="%batdir%\..\config\windows10.conf"
88
set optimizerExePath="%tmp%\Optimizer.exe"
99

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ rem Driver cloud action functions
33

44
set batdir=%~dp0
55
set batfile=%0
6-
set cliCmd=%batdir%cli.bat
6+
set cliCmd=%batdir%../utils/cli.bat
77
set chocolateyInstallUrl=https://chocolatey.org/install.ps1
88

99
if "%~1" neq "" (

0 commit comments

Comments
 (0)