P*tches for B*tches (#483)

* replace /V with global VERIFY ON

* change working dir to script dir
The working dir doesn't necessarily match the script's path, depending on how the script is called. All relative paths and conditional statements using EXIST will fail whenever the working dir is not the script's own location. This fixes that.

* minimal stuff, mostly cosmetic

* prompt to run prefsCleaner under very specific circumstances

* improve -updatebatch option

* add version variable + display new script version on update
This commit is contained in:
claustromaniac 2018-08-12 11:56:47 +00:00 committed by earthlng
parent 0145ccfec3
commit f39112f914
2 changed files with 39 additions and 17 deletions

View File

@ -3,7 +3,9 @@ TITLE prefs.js cleaner
REM ### prefs.js cleaner for Windows REM ### prefs.js cleaner for Windows
REM ## author: @claustromaniac REM ## author: @claustromaniac
REM ## version: 2.1 REM ## version: 2.2
CD /D "%~dp0"
:begin :begin
ECHO: ECHO:
@ -11,7 +13,7 @@ ECHO:
ECHO ######################################## ECHO ########################################
ECHO #### prefs.js cleaner for Windows #### ECHO #### prefs.js cleaner for Windows ####
ECHO #### by claustromaniac #### ECHO #### by claustromaniac ####
ECHO #### v2.1 #### ECHO #### v2.2 ####
ECHO ######################################## ECHO ########################################
ECHO: ECHO:
CALL :message "This script should be run from your Firefox profile directory." CALL :message "This script should be run from your Firefox profile directory."

View File

@ -3,11 +3,16 @@ TITLE ghacks user.js updater
REM ## ghacks-user.js updater for Windows REM ## ghacks-user.js updater for Windows
REM ## author: @claustromaniac REM ## author: @claustromaniac
REM ## version: 4.5 REM ## version: 4.6
REM ## instructions: https://github.com/ghacksuserjs/ghacks-user.js/wiki/3.3-Updater-Scripts REM ## instructions: https://github.com/ghacksuserjs/ghacks-user.js/wiki/3.3-Updater-Scripts
SET v=4.6
VERIFY ON
CD /D "%~dp0"
SET _myname=%~n0 SET _myname=%~n0
SET _myparams=%* SET _myparams=%*
:parse :parse
IF "%~1"=="" (GOTO endparse) IF "%~1"=="" (GOTO endparse)
IF /I "%~1"=="-unattended" (SET _ua=1) IF /I "%~1"=="-unattended" (SET _ua=1)
@ -20,6 +25,7 @@ IF /I "%~1"=="-singlebackup" (SET _singlebackup=1)
SHIFT SHIFT
GOTO parse GOTO parse
:endparse :endparse
IF DEFINED _updateb ( 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]" ( IF NOT "!_myname:~0,9!"=="[updated]" (
@ -27,10 +33,13 @@ IF DEFINED _updateb (
REM ## Phase 3 ##: The new script, with the original name, will: REM ## Phase 3 ##: The new script, with the original name, will:
REM * Delete the [updated]*.bat script REM * Delete the [updated]*.bat script
REM * Begin the normal routine REM * Begin the normal routine
FC "[updated]!_myname!.bat" "!_myname!.bat" >nul
IF ERRORLEVEL 1 (
CALL :message "Script updated to version !v!"
TIMEOUT 3 >nul
)
REN "[updated]!_myname!.bat" "[updated]!_myname!.bat.old" REN "[updated]!_myname!.bat" "[updated]!_myname!.bat.old"
DEL /F "[updated]!_myname!.bat.old" DEL /F "[updated]!_myname!.bat.old"
CALL :message "Script updated^!"
TIMEOUT 3 >nul
GOTO begin GOTO begin
) )
REM ## Phase 1 ## REM ## Phase 1 ##
@ -38,10 +47,10 @@ IF DEFINED _updateb (
REM * Start that script in a new CMD window REM * Start that script in a new CMD window
REM * Exit REM * Exit
CALL :message "Updating script..." CALL :message "Updating script..."
REM Uncomment the next line and comment the powershell call for testing. REM Uncomment the next line and comment out the PowerShell call for testing.
REM COPY /B /V /Y "!_myname!.bat" "[updated]!_myname!.bat" REM COPY /B /Y "!_myname!.bat" "[updated]!_myname!.bat" >nul
( (
powershell -Command "(New-Object Net.WebClient).DownloadFile('https://raw.githubusercontent.com/ghacksuserjs/ghacks-user.js/master/updater.bat', '[updated]!_myname!.bat')" PowerShell -Command "(New-Object Net.WebClient).DownloadFile('https://raw.githubusercontent.com/ghacksuserjs/ghacks-user.js/master/updater.bat', '[updated]!_myname!.bat')"
) >nul 2>&1 ) >nul 2>&1
IF EXIST "[updated]!_myname!.bat" ( IF EXIST "[updated]!_myname!.bat" (
START /min CMD /C "[updated]!_myname!.bat" !_myparams! START /min CMD /C "[updated]!_myname!.bat" !_myparams!
@ -62,12 +71,13 @@ IF DEFINED _updateb (
REN "!_myname:~9!.bat" "!_myname:~9!.bat.old" REN "!_myname:~9!.bat" "!_myname:~9!.bat.old"
DEL /F "!_myname:~9!.bat.old" DEL /F "!_myname:~9!.bat.old"
) )
COPY /B /V /Y "!_myname!.bat" "!_myname:~9!.bat" COPY /B /Y "!_myname!.bat" "!_myname:~9!.bat"
START CMD /C "!_myname:~9!.bat" !_myparams! START CMD /C "!_myname:~9!.bat" !_myparams!
) )
) )
EXIT /B EXIT /B
) )
:begin :begin
CLS CLS
ECHO: ECHO:
@ -75,7 +85,7 @@ ECHO:
ECHO: ######################################## ECHO: ########################################
ECHO: #### user.js Updater for Windows #### ECHO: #### user.js Updater for Windows ####
ECHO: #### by claustromaniac #### ECHO: #### by claustromaniac ####
ECHO: #### v4.5 #### ECHO: #### v!v! ####
ECHO: ######################################## ECHO: ########################################
ECHO: ECHO:
SET /A "_line=0" SET /A "_line=0"
@ -121,7 +131,7 @@ IF DEFINED _log (
IF EXIST user.js.new (DEL /F "user.js.new") IF EXIST user.js.new (DEL /F "user.js.new")
CALL :message "Retrieving latest user.js file from github repository..." CALL :message "Retrieving latest user.js file from github repository..."
( (
powershell -Command "(New-Object Net.WebClient).DownloadFile('https://raw.githubusercontent.com/ghacksuserjs/ghacks-user.js/master/user.js', 'user.js.new')" PowerShell -Command "(New-Object Net.WebClient).DownloadFile('https://raw.githubusercontent.com/ghacksuserjs/ghacks-user.js/master/user.js', 'user.js.new')"
) >nul 2>&1 ) >nul 2>&1
IF EXIST user.js.new ( IF EXIST user.js.new (
IF DEFINED _multi ( IF DEFINED _multi (
@ -129,18 +139,18 @@ IF EXIST user.js.new (
IF NOT ERRORLEVEL 1 ( IF NOT ERRORLEVEL 1 (
IF DEFINED _merge ( IF DEFINED _merge (
CALL :message "Merging..." CALL :message "Merging..."
COPY /B /V /Y user.js-overrides\*.js user-overrides-merged.js COPY /B /Y user.js-overrides\*.js user-overrides-merged.js
CALL :merge user-overrides-merged.js CALL :merge user-overrides-merged.js
COPY /B /V /Y user.js.new+user-overrides-merged.js user.js.new COPY /B /Y user.js.new+user-overrides-merged.js user.js.new
CALL :merge user.js.new CALL :merge user.js.new
) ELSE ( ) ELSE (
CALL :message "Appending..." CALL :message "Appending..."
COPY /B /V /Y user.js.new+"user.js-overrides\*.js" user.js.new COPY /B /Y user.js.new+"user.js-overrides\*.js" user.js.new
) )
) ELSE (CALL :message "No override files found.") ) ELSE (CALL :message "No override files found.")
) ELSE ( ) ELSE (
IF EXIST "user-overrides.js" ( IF EXIST "user-overrides.js" (
COPY /B /V /Y user.js.new+"user-overrides.js" "user.js.new" COPY /B /Y user.js.new+"user-overrides.js" "user.js.new"
IF DEFINED _merge ( IF DEFINED _merge (
CALL :message "Merging user-overrides.js..." CALL :message "Merging user-overrides.js..."
CALL :merge user.js.new CALL :merge user.js.new
@ -169,6 +179,7 @@ IF EXIST user.js.new (
) ELSE ( ) ELSE (
REN user.js.new user.js REN user.js.new user.js
CALL :message "Update complete." CALL :message "Update complete."
SET "_changed=true"
) )
) )
) ELSE ( ) ELSE (
@ -176,7 +187,15 @@ IF EXIST user.js.new (
ECHO: No changes were made. ECHO: No changes were made.
) )
IF NOT DEFINED _log ( IF NOT DEFINED _log (
IF NOT DEFINED _ua (PAUSE) IF NOT DEFINED _ua (
IF EXIST prefsCleaner.bat (
IF "!_changed!"=="true" (
CALL :message "Would you like to run the prefsCleaner now?"
CHOICE /C YN /N /M "(Y/N) "
IF "1"=="!errorlevel!" ( START "" cmd.exe /C "prefsCleaner.bat" )
) ELSE (PAUSE)
) ELSE (PAUSE)
)
) )
EXIT /B EXIT /B
@ -188,6 +207,7 @@ ECHO: %~1
IF NOT "2"=="%_log%" (ECHO:) IF NOT "2"=="%_log%" (ECHO:)
ENDLOCAL ENDLOCAL
GOTO :EOF GOTO :EOF
REM ############ Merge function ############ REM ############ Merge function ############
:merge :merge
SETLOCAL DisableDelayedExpansion SETLOCAL DisableDelayedExpansion
@ -226,6 +246,7 @@ FOR /F tokens^=2^,^*^ delims^=^' %%G IN ('FINDSTR /R /C:"^//// --- comment-out -
MOVE /Y updatertempfile "%~1" >nul MOVE /Y updatertempfile "%~1" >nul
ENDLOCAL ENDLOCAL
GOTO :EOF GOTO :EOF
REM ############### Help ################## REM ############### Help ##################
:showhelp :showhelp
MODE 80,46 MODE 80,46
@ -260,4 +281,3 @@ CALL :message ""
PAUSE PAUSE
MODE 80,25 MODE 80,25
GOTO :begin GOTO :begin
REM #####################################