From 00e17281dc439c1e517671eeeb5bfc4e96f90104 Mon Sep 17 00:00:00 2001 From: claustromaniac <20734810+claustromaniac@users.noreply.github.com> Date: Thu, 30 Nov 2017 00:10:01 +0000 Subject: [PATCH 1/9] Updater 3.1a -updatebatch now will (or at least should): *Download new batch and name it [updater]*.bat *Open that script in a new CMD window. *Exit The [updated]*.bat script should: *Copy itself overwriting the original batch (without renaming). *Start that script in a new CMD instance. *Exit. The new script, with the original name, should: *Delete the [updated]*.bat script *Begin the normal script routine. @earthing do you think I should still rename the scripts to .old or something before overwriting/deleting? --- updater.bat | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/updater.bat b/updater.bat index 997f7d5..37b5867 100644 --- a/updater.bat +++ b/updater.bat @@ -3,7 +3,7 @@ TITLE ghacks user.js updater REM ### ghacks-user.js updater for Windows REM ## author: @claustromaniac -REM ## version: 3.0 +REM ## version: 3.1a SET _myname=%~n0 SET _myparams=%* @@ -37,36 +37,37 @@ GOTO parse ECHO. IF DEFINED _updateb ( IF NOT "!_myname:~0,9!"=="[updated]" ( + IF EXIST "[updated]!_myname!.bat" ( + DEL /F "[updated]!_myname!.bat" + GOTO begin + ) ECHO Checking updater version... ECHO. - IF EXIST "[updated]!_myname!.bat" ( DEL /F "[updated]!_myname!.bat" ) REM Uncomment the next line and comment the powershell call for testing. REM COPY /B /V /Y "!_myname!.bat" "[updated]!_myname!.bat" ( powershell -Command "(New-Object Net.WebClient).DownloadFile('https://github.com/ghacksuserjs/ghacks-user.js/raw/master/updater.bat', '[updated]!_myname!.bat')" ) >nul 2>&1 IF EXIST "[updated]!_myname!.bat" ( - START CMD /C "[updated]!_myname!.bat" !_myparams! + START /min CMD /C "[updated]!_myname!.bat" !_myparams! EXIT /B ) ELSE ( ECHO Failed. Make sure PowerShell is allowed internet access. ECHO. - TIMEOUT 300 + TIMEOUT 120 EXIT /B ) ) ELSE ( - IF EXIST "!_myname:~9!.bat" ( - REN "!_myname:~9!.bat" "!_myname:~9!.old" - CALL :begin - REN "!_myname!.bat" "!_myname:~9!.bat" - DEL /F "!_myname:~9!.old" - EXIT /B - ) ELSE ( + IF "!_myname!"=="[updated]" ( + ECHO. + ECHO The [updated] label is reserved. Rename this script and try again. ECHO. - ECHO The [updated] label is reserved. Do not run an [updated] script directly, or rename it to something else before you run it. TIMEOUT 300 - EXIT /B + ) ELSE ( + COPY /B /V /Y "!_myname!.bat" "!_myname:~9!.bat" + START CMD /C "!_myname:~9!.bat" !_myparams! ) + EXIT /B ) ) :begin From ac7ad78d1dda534b1904e0f62a0cecb7d5fb5f59 Mon Sep 17 00:00:00 2001 From: claustromaniac <20734810+claustromaniac@users.noreply.github.com> Date: Thu, 30 Nov 2017 18:22:18 +0000 Subject: [PATCH 2/9] 3.1a1 Just added a few lines to make batch updates more visible - which helps with testing. --- updater.bat | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/updater.bat b/updater.bat index 37b5867..bc95e4f 100644 --- a/updater.bat +++ b/updater.bat @@ -3,7 +3,7 @@ TITLE ghacks user.js updater REM ### ghacks-user.js updater for Windows REM ## author: @claustromaniac -REM ## version: 3.1a +REM ## version: 3.1a1 SET _myname=%~n0 SET _myparams=%* @@ -39,6 +39,9 @@ IF DEFINED _updateb ( IF NOT "!_myname:~0,9!"=="[updated]" ( IF EXIST "[updated]!_myname!.bat" ( DEL /F "[updated]!_myname!.bat" + ECHO Script updated^^! + ECHO. + ECHO. GOTO begin ) ECHO Checking updater version... @@ -211,7 +214,7 @@ REM ###### Merge function ###### :merge SETLOCAL disabledelayedexpansion ( - FOR /F "tokens=1,* delims=]" %%G IN ('find /n /v "" ^< "%~1"') DO ( + FOR /F "tokens=1,* delims=]" %%G IN ('FIND /n /v "" ^< "%~1"') DO ( SET "_pref=%%H" SETLOCAL enabledelayedexpansion SET "_temp=!_pref: =!" From e5d00be8f0b6ce276158b687a620b0f5b4ed84cc Mon Sep 17 00:00:00 2001 From: claustromaniac <20734810+claustromaniac@users.noreply.github.com> Date: Thu, 30 Nov 2017 22:11:42 +0000 Subject: [PATCH 3/9] Revert "3.1a1" This reverts commit ac7ad78d1dda534b1904e0f62a0cecb7d5fb5f59. --- updater.bat | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/updater.bat b/updater.bat index bc95e4f..37b5867 100644 --- a/updater.bat +++ b/updater.bat @@ -3,7 +3,7 @@ TITLE ghacks user.js updater REM ### ghacks-user.js updater for Windows REM ## author: @claustromaniac -REM ## version: 3.1a1 +REM ## version: 3.1a SET _myname=%~n0 SET _myparams=%* @@ -39,9 +39,6 @@ IF DEFINED _updateb ( IF NOT "!_myname:~0,9!"=="[updated]" ( IF EXIST "[updated]!_myname!.bat" ( DEL /F "[updated]!_myname!.bat" - ECHO Script updated^^! - ECHO. - ECHO. GOTO begin ) ECHO Checking updater version... @@ -214,7 +211,7 @@ REM ###### Merge function ###### :merge SETLOCAL disabledelayedexpansion ( - FOR /F "tokens=1,* delims=]" %%G IN ('FIND /n /v "" ^< "%~1"') DO ( + FOR /F "tokens=1,* delims=]" %%G IN ('find /n /v "" ^< "%~1"') DO ( SET "_pref=%%H" SETLOCAL enabledelayedexpansion SET "_temp=!_pref: =!" From fc47792df261e6ba3d4561d82614696ae5a84d3b Mon Sep 17 00:00:00 2001 From: claustromaniac <20734810+claustromaniac@users.noreply.github.com> Date: Thu, 30 Nov 2017 22:17:58 +0000 Subject: [PATCH 4/9] 3.1a1 --- updater.bat | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/updater.bat b/updater.bat index 37b5867..4c8f7a5 100644 --- a/updater.bat +++ b/updater.bat @@ -3,7 +3,7 @@ TITLE ghacks user.js updater REM ### ghacks-user.js updater for Windows REM ## author: @claustromaniac -REM ## version: 3.1a +REM ## version: 3.1a1 SET _myname=%~n0 SET _myparams=%* @@ -39,9 +39,14 @@ IF DEFINED _updateb ( IF NOT "!_myname:~0,9!"=="[updated]" ( IF EXIST "[updated]!_myname!.bat" ( DEL /F "[updated]!_myname!.bat" + ECHO Script updated^^! + ECHO. + TIMEOUT 3 >nul + CLS + ECHO. GOTO begin ) - ECHO Checking updater version... + ECHO Updating script... ECHO. REM Uncomment the next line and comment the powershell call for testing. REM COPY /B /V /Y "!_myname!.bat" "[updated]!_myname!.bat" @@ -54,15 +59,14 @@ IF DEFINED _updateb ( ) ELSE ( ECHO Failed. Make sure PowerShell is allowed internet access. ECHO. - TIMEOUT 120 + TIMEOUT 120 >nul EXIT /B ) ) ELSE ( IF "!_myname!"=="[updated]" ( - ECHO. ECHO The [updated] label is reserved. Rename this script and try again. ECHO. - TIMEOUT 300 + TIMEOUT 300 >nul ) ELSE ( COPY /B /V /Y "!_myname!.bat" "!_myname:~9!.bat" START CMD /C "!_myname:~9!.bat" !_myparams! @@ -211,7 +215,7 @@ REM ###### Merge function ###### :merge SETLOCAL disabledelayedexpansion ( - FOR /F "tokens=1,* delims=]" %%G IN ('find /n /v "" ^< "%~1"') DO ( + FOR /F "tokens=1,* delims=]" %%G IN ('FIND /n /v "" ^< "%~1"') DO ( SET "_pref=%%H" SETLOCAL enabledelayedexpansion SET "_temp=!_pref: =!" From 8a99bb350c0d2a66c2729fb4ea979e01b057bd1c Mon Sep 17 00:00:00 2001 From: claustromaniac <20734810+claustromaniac@users.noreply.github.com> Date: Fri, 1 Dec 2017 01:05:24 -0300 Subject: [PATCH 5/9] 3.1a2 --- updater.bat | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/updater.bat b/updater.bat index 4c8f7a5..5f01b8a 100644 --- a/updater.bat +++ b/updater.bat @@ -3,7 +3,7 @@ TITLE ghacks user.js updater REM ### ghacks-user.js updater for Windows REM ## author: @claustromaniac -REM ## version: 3.1a1 +REM ## version: 3.1a2 SET _myname=%~n0 SET _myparams=%* @@ -110,10 +110,10 @@ IF NOT DEFINED _ua ( ECHO. ECHO This batch should be run from your Firefox profile directory. It will download the latest version of ghacks user.js from github and then append any of your own changes from user-overrides.js to it. ECHO. - REM ECHO Visit the wiki for more detailed information. - REM ECHO. + ECHO Visit the wiki for more detailed information. + ECHO. CHOICE /M "Continue" - IF ERRORLEVEL 2 EXIT /B + IF ERRORLEVEL 2 ( EXIT /B ) ) CLS ECHO. @@ -129,8 +129,9 @@ IF DEFINED _log ( ECHO %date%, %time% ECHO. ) +IF EXIST user.js.old.bak ( DEL /F user.js.old.bak ) IF EXIST user.js ( - IF EXIST user.js.bak REN user.js.bak user.js.old.bak + IF EXIST user.js.bak ( REN user.js.bak user.js.old.bak ) REN user.js user.js.bak ECHO Current user.js file backed up. ECHO. @@ -198,8 +199,8 @@ IF EXIST user.js ( ) ECHO. ) ELSE ( - IF EXIST user.js.bak REN user.js.bak user.js - IF EXIST user.js.old.bak REN user.js.old.bak user.js.bak + IF EXIST user.js.bak ( REN user.js.bak user.js ) + IF EXIST user.js.old.bak ( REN user.js.old.bak user.js.bak ) ECHO. ECHO Update failed. Make sure PowerShell is allowed internet access. ECHO. @@ -213,6 +214,7 @@ EXIT /B REM ###### Merge function ###### :merge +IF EXIST updatertempfile1 ( DEL /F updatertempfile1 ) SETLOCAL disabledelayedexpansion ( FOR /F "tokens=1,* delims=]" %%G IN ('FIND /n /v "" ^< "%~1"') DO ( From ce3c077d0639f0771128c6ac67daf08774f8d6d0 Mon Sep 17 00:00:00 2001 From: claustromaniac <20734810+claustromaniac@users.noreply.github.com> Date: Sun, 3 Dec 2017 13:35:41 +0000 Subject: [PATCH 6/9] 3.1 --- updater.bat | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/updater.bat b/updater.bat index 5f01b8a..aee829f 100644 --- a/updater.bat +++ b/updater.bat @@ -3,7 +3,7 @@ TITLE ghacks user.js updater REM ### ghacks-user.js updater for Windows REM ## author: @claustromaniac -REM ## version: 3.1a2 +REM ## version: 3.1 SET _myname=%~n0 SET _myparams=%* @@ -36,9 +36,15 @@ GOTO parse :endparse ECHO. IF DEFINED _updateb ( + REM THe normal flow here goes from phase 1 to phase 2 and then phase 3. IF NOT "!_myname:~0,9!"=="[updated]" ( + REM Phase 3 + REM The new script, with the original name, should: + REM Delete the [updated]*.bat script + REM Begin the normal script routine. IF EXIST "[updated]!_myname!.bat" ( - DEL /F "[updated]!_myname!.bat" + REN [updated]!_myname!.bat [updated]!_myname!.bat.old + DEL /F "[updated]!_myname!.bat.old" ECHO Script updated^^! ECHO. TIMEOUT 3 >nul @@ -46,6 +52,11 @@ IF DEFINED _updateb ( ECHO. GOTO begin ) + REM Phase 1 + REM -updatebatch will: + REM Download new batch and name it [updated]*.bat + REM Open that script in a new CMD window. + REM Exit ECHO Updating script... ECHO. REM Uncomment the next line and comment the powershell call for testing. @@ -63,11 +74,20 @@ IF DEFINED _updateb ( EXIT /B ) ) ELSE ( + REM Phase 2 + REM The [updated]*.bat script will: + REM Copy itself overwriting the original batch. + REM Start that script in a new CMD instance. + REM Exit. IF "!_myname!"=="[updated]" ( ECHO The [updated] label is reserved. Rename this script and try again. ECHO. TIMEOUT 300 >nul ) ELSE ( + IF EXIST !_myname:~9!.bat ( + REN !_myname:~9!.bat !_myname:~9!.bat.old + DEL /F !_myname:~9!.bat.old + ) COPY /B /V /Y "!_myname!.bat" "!_myname:~9!.bat" START CMD /C "!_myname:~9!.bat" !_myparams! ) From ccaf06973bc5a13589da51979a8d501b3ed9563b Mon Sep 17 00:00:00 2001 From: claustromaniac <20734810+claustromaniac@users.noreply.github.com> Date: Sun, 3 Dec 2017 15:01:45 +0000 Subject: [PATCH 7/9] 3.1 Minor change suggested by earthing. --- updater.bat | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/updater.bat b/updater.bat index aee829f..9590acd 100644 --- a/updater.bat +++ b/updater.bat @@ -149,9 +149,8 @@ IF DEFINED _log ( ECHO %date%, %time% ECHO. ) -IF EXIST user.js.old.bak ( DEL /F user.js.old.bak ) IF EXIST user.js ( - IF EXIST user.js.bak ( REN user.js.bak user.js.old.bak ) + IF EXIST user.js.bak ( MOVE /Y user.js.bak user.js.old.bak >nul ) REN user.js user.js.bak ECHO Current user.js file backed up. ECHO. From a6c93b3982a41db00fcb08b2862820ac38d25877 Mon Sep 17 00:00:00 2001 From: claustromaniac <20734810+claustromaniac@users.noreply.github.com> Date: Sun, 3 Dec 2017 15:04:41 +0000 Subject: [PATCH 8/9] Revert "3.1" This reverts commit ccaf06973bc5a13589da51979a8d501b3ed9563b. --- updater.bat | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/updater.bat b/updater.bat index 9590acd..aee829f 100644 --- a/updater.bat +++ b/updater.bat @@ -149,8 +149,9 @@ IF DEFINED _log ( ECHO %date%, %time% ECHO. ) +IF EXIST user.js.old.bak ( DEL /F user.js.old.bak ) IF EXIST user.js ( - IF EXIST user.js.bak ( MOVE /Y user.js.bak user.js.old.bak >nul ) + IF EXIST user.js.bak ( REN user.js.bak user.js.old.bak ) REN user.js user.js.bak ECHO Current user.js file backed up. ECHO. From 457ef9ec2f100c052cce8fdcad51b0acfa487457 Mon Sep 17 00:00:00 2001 From: claustromaniac <20734810+claustromaniac@users.noreply.github.com> Date: Sun, 3 Dec 2017 15:07:15 +0000 Subject: [PATCH 9/9] 3.1 tidy up --- updater.bat | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/updater.bat b/updater.bat index aee829f..90a4080 100644 --- a/updater.bat +++ b/updater.bat @@ -36,13 +36,13 @@ GOTO parse :endparse ECHO. IF DEFINED _updateb ( - REM THe normal flow here goes from phase 1 to phase 2 and then phase 3. + REM The normal flow here goes from phase 1 to phase 2 and then phase 3. IF NOT "!_myname:~0,9!"=="[updated]" ( - REM Phase 3 - REM The new script, with the original name, should: - REM Delete the [updated]*.bat script - REM Begin the normal script routine. IF EXIST "[updated]!_myname!.bat" ( + REM Phase 3 + REM The new script, with the original name, should: + REM Delete the [updated]*.bat script + REM Begin the normal script routine. REN [updated]!_myname!.bat [updated]!_myname!.bat.old DEL /F "[updated]!_myname!.bat.old" ECHO Script updated^^! @@ -74,16 +74,16 @@ IF DEFINED _updateb ( EXIT /B ) ) ELSE ( - REM Phase 2 - REM The [updated]*.bat script will: - REM Copy itself overwriting the original batch. - REM Start that script in a new CMD instance. - REM Exit. IF "!_myname!"=="[updated]" ( ECHO The [updated] label is reserved. Rename this script and try again. ECHO. TIMEOUT 300 >nul ) ELSE ( + REM Phase 2 + REM The [updated]*.bat script will: + REM Copy itself overwriting the original batch. + REM Start that script in a new CMD instance. + REM Exit. IF EXIST !_myname:~9!.bat ( REN !_myname:~9!.bat !_myname:~9!.bat.old DEL /F !_myname:~9!.bat.old