@echo off

set CONFIG=config\firefox
set SCRIPTS=..\scripts
set SOFTWARE=..\software
set EXE=firefox-setup.exe
if not defined browser_homepage set browser_homepage=google.com

if NOT EXIST %SOFTWARE%\%EXE% (
  echo ERROR: %SOFTWARE%\%EXE% not found!
  exit /b
)

set FIREFOXBASE="%ProgramFiles%\Mozilla Firefox"

set BADGERFILE=%SOFTWARE%\privacybadger-addon.xpi
set BADGERTARGET=jid1-MnnxcxisBPnSXQ-eff@jetpack.xpi

set UBLOCKFILE=%SOFTWARE%\ublockorigin-addon.xpi
set UBLOCKTARGET=uBlock0@raymondhill.net.xpi

set TPMFILE=%SOFTWARE%\tpm-addon.xpi
set TPMTARGET=info@teampasswordmanager.com.xpi

echo ####### %0 #######

echo killing firefox ...
taskkill /f /im firefox.exe 1>nul 2>nul

cd %SOFTWARE%
@echo on
firefox-setup.exe /S /MaintenanceService=false /TaskbarShortcut=false /RegisterDefaultAgent=false
@echo off
echo sleeping 5 seconds ...
ping 127.0.0.1 -n 5 > NUL 2>&1
cd %SCRIPTS%

rem copy config ...
copy /Y %CONFIG%\local-settings.js %FIREFOXBASE%\defaults\pref
copy /Y %CONFIG%\mozilla.cfg %FIREFOXBASE%

rem set browser homepage ...
searchreplace "%ProgramFiles%\Mozilla Firefox\mozilla.cfg" ___HOMEPAGE___ %browser_homepage%

echo disabling FireFox updates (all users) ...
reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Mozilla\Firefox" ^
  /v DisableAppUpdate ^
  /t REG_DWORD ^
  /d 1 ^
  /f

echo enabling FireFox Bookmarks-bar for all users ...
reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Mozilla\Firefox" ^
  /v DisplayBookmarksToolbar ^
  /t REG_DWORD ^
  /d 1 ^
  /f

echo creating extensions directory ...
mkdir %FIREFOXBASE%\distribution\extensions 1>nul 2>nul

echo installing badger(eff) to fight internet bullshit ...
copy /Y %BADGERFILE% %FIREFOXBASE%\distribution\extensions\%BADGERTARGET%

echo installing uBlock to fight even more internet bullshit ...
copy /Y %UBLOCKFILE% %FIREFOXBASE%\distribution\extensions\%UBLOCKTARGET%

echo installing Team Password Manager plugin ...
copy /Y %TPMFILE% %FIREFOXBASE%\distribution\extensions\%TPMTARGET%

echo setting firefox as default browser ...
SetDefaultBrowser.exe HKLM "Firefox-308046B0AF4A39CB"

echo ####### %0 #######

