From 619cf4d5cd9a48fb5646e7d99cc0c567611d8cdb Mon Sep 17 00:00:00 2001
From: liaronce <liaronce@hotmail.com>
Date: Fri, 8 Oct 2021 13:55:25 +0800
Subject: [PATCH] Support with parameters, please check the latest document

---
 README.md                        | 24 ++++++++++++++++++---
 add-certificates-to-phone-wsl.sh | 37 +++++++++++++++++++++++++-------
 add-certificates-to-phone.bat    | 12 +++++++++--
 add-certificates-to-phone.sh     | 37 +++++++++++++++++++++++++-------
 4 files changed, 89 insertions(+), 21 deletions(-)

diff --git a/README.md b/README.md
index 641c9f1..5b6805f 100644
--- a/README.md
+++ b/README.md
@@ -4,6 +4,18 @@ A shell script to add root certificates to Firefox OS
 
 [Original README](README-original.md)
 
+## Usage
+For Linux shell:
+```bash
+Usage: add-certificates-to-phone.sh [-r] (dir) | [-d] | [-h]
+
+-r (dir) Enter the NSS DB root directory ( Such as Nokia, enter /data/b2g/mozilla )
+         Some phones may be different.
+         For more information, please visit: https://github.com/openGiraffes/b2g-certificates
+-d Use default directory (/data/b2g/mozilla)
+-h Output this help.
+```
+
 Linux (Debian & Ubuntu): 
 
 ```bash
@@ -12,17 +24,23 @@ git clone https://github.com/openGiraffes/b2g-certificates
 cd b2g-certificates
 
 chmod +x ./add-certificates-to-phone.sh
-./add-certificates-to-phone.sh
+./add-certificates-to-phone.sh -d # For Nokia user
 
 # If you are using WSL, please run this (Need to add Android Platform Tools directory to PATH)
 chmod +x ./add-certificates-to-phone-wsl.sh
-./add-certificates-to-phone-wsl.sh
+./add-certificates-to-phone-wsl.sh -d # For Nokia user
 ```
 
 Windows Batch(Need to add Android Platform Tools directory to PATH):
 
-```batch
+```
 add-certificates-to-phone.bat
+
+Enter the NSS DB root directory ( Such as Nokia, enter /data/b2g/mozilla )
+Some phones may be different.
+For more information, please visit: https://github.com/openGiraffes/b2g-certificates
+
+(Enter the path here)
 ```
 
 NSS certutil compiled by myself.
diff --git a/add-certificates-to-phone-wsl.sh b/add-certificates-to-phone-wsl.sh
index 7dbc897..366818b 100644
--- a/add-certificates-to-phone-wsl.sh
+++ b/add-certificates-to-phone-wsl.sh
@@ -1,7 +1,35 @@
 #!/bin/bash
 
+function log
+{
+    GREEN="\E[32m"
+    RESET="\033[00;00m"
+    echo -e "${GREEN}$1${RESET}"
+}
+
+usage() {
+  echo "Usage: ${0} [-r] (dir) | [-d] | [-h]" 1>&2
+  echo ""
+  echo "-r (dir) Enter the NSS DB root directory ( Such as Nokia, enter /data/b2g/mozilla )"
+  echo "         Some phones may be different."
+  echo "         For more information, please visit: https://github.com/openGiraffes/b2g-certificates"
+  echo "-d Use default directory (/data/b2g/mozilla)"
+  echo "-h Output this help."
+  exit 1
+}
+
+ROOT_DIR_DB=
+
+while getopts "dhr:" options
+do
+    case ${options} in
+        d) ROOT_DIR_DB=/data/b2g/mozilla;;
+        r) ROOT_DIR_DB=$OPTARG;;
+        h) usage;;
+    esac
+done
+
 CERT_DIR=certs
-ROOT_DIR_DB=/data/b2g/mozilla
 CERT=cert9.db
 KEY=key4.db
 PKCS11=pkcs11.txt
@@ -13,13 +41,6 @@ least once before running this script."
   exit 1
 fi
 
-function log
-{
-    GREEN="\E[32m"
-    RESET="\033[00;00m"
-    echo -e "${GREEN}$1${RESET}"
-}
-
 # cleanup
 rm -f ./$CERT
 rm -f ./$KEY
diff --git a/add-certificates-to-phone.bat b/add-certificates-to-phone.bat
index f3b57ef..ca8db72 100644
--- a/add-certificates-to-phone.bat
+++ b/add-certificates-to-phone.bat
@@ -1,13 +1,21 @@
 @echo off
 :: Set environment variable
+@echo Enter the NSS DB root directory ( Such as Nokia, enter /data/b2g/mozilla )
+@echo Some phones may be different.
+@echo For more information, please visit: https://github.com/openGiraffes/b2g-certificates
+@echo:
+set /p ROOT_DIR_DB=
+
 set CERT_DIR=certs
 set TEMP=tmp
 set CERT=cert9.db
 set KEY=key4.db
 set PKCS11=pkcs11.txt
-for /f %%i in ('adb shell "ls -d /data/b2g/mozilla/*.default 2>/dev/null" ^|^| "bin/sed.exe" "s/default.*$/default/g"') do set DB_DIR=%%i
+for /f %%i in ('adb shell "ls -d %ROOT_DIR_DB%/*.default 2>/dev/null" ^|^| "bin/sed.exe" "s/default.*$/default/g"') do set DB_DIR=%%i
+@echo %DB_DIR%
 
 if DB_DIR == "" (
+    @echo:
     echo "Profile directory does not exists. Please start the b2g process at least once before running this script."
     pause
 )
@@ -30,7 +38,7 @@ adb pull %DB_DIR%/%PKCS11% ./%TEMP%/
 @echo Set password (hit enter twice to set an empty password)
 "bin/nss/certutil.exe" -d %TEMP% -N
 
-@echo Adding certificats
+@echo Adding certificates
 for %%i in (%CERT_DIR%/*) do (
     echo Adding certificate %%i
     "bin/nss/certutil.exe" -d %TEMP% -A -n "`basename %%i`" -t "C,C,TC" -i %CERT_DIR%/%%i
diff --git a/add-certificates-to-phone.sh b/add-certificates-to-phone.sh
index 22c8fe3..e9b0f18 100755
--- a/add-certificates-to-phone.sh
+++ b/add-certificates-to-phone.sh
@@ -1,7 +1,35 @@
 #!/bin/bash
 
+function log
+{
+    GREEN="\E[32m"
+    RESET="\033[00;00m"
+    echo -e "${GREEN}$1${RESET}"
+}
+
+usage() {
+  echo "Usage: ${0} [-r] (dir) | [-d] | [-h]" 1>&2
+  echo ""
+  echo "-r (dir) Enter the NSS DB root directory ( Such as Nokia, enter /data/b2g/mozilla )"
+  echo "         Some phones may be different."
+  echo "         For more information, please visit: https://github.com/openGiraffes/b2g-certificates"
+  echo "-d Use default directory (/data/b2g/mozilla)"
+  echo "-h Output this help."
+  exit 1
+}
+
+ROOT_DIR_DB=
+
+while getopts "dhr:" options
+do
+    case ${options} in
+        d) ROOT_DIR_DB=/data/b2g/mozilla;;
+        r) ROOT_DIR_DB=$OPTARG;;
+        h) usage;;
+    esac
+done
+
 CERT_DIR=certs
-ROOT_DIR_DB=/data/b2g/mozilla
 CERT=cert9.db
 KEY=key4.db
 PKCS11=pkcs11.txt
@@ -13,13 +41,6 @@ least once before running this script."
   exit 1
 fi
 
-function log
-{
-    GREEN="\E[32m"
-    RESET="\033[00;00m"
-    echo -e "${GREEN}$1${RESET}"
-}
-
 # cleanup
 rm -f ./$CERT
 rm -f ./$KEY