Skip to content

Instantly share code, notes, and snippets.

@zoeeechu
Last active May 15, 2023 17:05
Show Gist options
  • Save zoeeechu/9a72e455eb3bac8844bfa21fea3a50f5 to your computer and use it in GitHub Desktop.
Save zoeeechu/9a72e455eb3bac8844bfa21fea3a50f5 to your computer and use it in GitHub Desktop.
Install all certificates in a DIR as root ----- [[ mac and windows ]]
#!/bin/bash
function pause(){
read -s -n 1 -p "Press any key to continue . . ."
echo ""
}
#print in yellow
pYellow() {
printf "\e[33;1m%s\n" "$1"
}
#print in green
pGreen() {
printf "\e[32m$1\e[m\n"
}
#print in red
pRed() {
echo -e "\033[1;31m$1\033[0m"
}
#reset colors
r() {
tput init
}
#if not root throw error
if [ $USER != "root" ]; then
sudo "$0" "$@"
exit $?
fi
#Get DIR
BASEDIR=$(dirname $0)
cd ${BASEDIR}
for i in *.cer; do
sudo security add-trusted-cert -d -r trustRoot -k /Library/Keychains/System.keychain "$i"
done
pGreen "done."
pause
@echo off
:: BatchGotAdmin
::-------------------------------------
REM --> Check for permissions
>nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system"
REM --> If error flag set, we do not have admin.
if '%errorlevel%' NEQ '0' (
echo Requesting administrative privileges...
goto UACPrompt
) else ( goto gotAdmin )
:UACPrompt
echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadmin.vbs"
set params = %*:"="
echo UAC.ShellExecute "cmd.exe", "/c %~s0 %params%", "", "runas", 1 >> "%temp%\getadmin.vbs"
"%temp%\getadmin.vbs"
del "%temp%\getadmin.vbs"
exit /B
:gotAdmin
pushd "%CD%"
CD /D "%~dp0"
::--------------------------------------
SETLOCAL EnableDelayedExpansion
for /F "tokens=1,2 delims=#" %%a in ('"prompt #$H#$E# & echo on & for %%b in (1) do rem"') do (
set "DEL=%%a"
)
set scriptpath=%~dp0
cd %scriptpath%
FOR /F "tokens=1 delims=" %%A in ('DIR /b *.cer') do (
certutil -addstore root %%A
)
call :ColorText 0A "done."
echo.
pause
goto :eof
:ColorText
echo off
<nul set /p ".=%DEL%" > "%~2"
findstr /v /a:%1 /R "^$" "%~2" nul
del "%~2" > nul 2>&1
goto :eof
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment