install-cert.sh 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. #!/usr/bin/env bash
  2. set -euo pipefail
  3. CERT_PATH="/usr/local/share/ca-certificates/minica/minica.pem"
  4. CERT_NAME="minica"
  5. TRUST_FLAGS="C,,"
  6. FIREFOX_DIR="$HOME/.mozilla/firefox"
  7. PALEMOON_DIR="$HOME/.moonchild productions/pale moon"
  8. echo "🔄 Updating system CA certificates..."
  9. update-ca-certificates
  10. # 🌀 Trigger Pale Moon to create its profile if needed
  11. if command -v palemoon &>/dev/null; then
  12. echo "🚀 Launching Pale Moon to initialize profile..."
  13. palemoon &>/dev/null &
  14. PALEMOON_PID=$!
  15. # Wait up to 20 seconds for prefs.js to be created
  16. for i in {1..20}; do
  17. set +e
  18. PROFILE_DIR=$(grep Path ~/.moonchild\ productions/pale\ moon/profiles.ini | cut -d= -f2)
  19. PREFS_FILE="$HOME/.moonchild productions/pale moon/$PROFILE_DIR/prefs.js"
  20. if [[ -f "$PREFS_FILE" ]]; then
  21. set -e
  22. echo "✅ prefs.js found at: $PREFS_FILE"
  23. break
  24. fi
  25. sleep 5
  26. done
  27. kill $PALEMOON_PID 2>/dev/null || true
  28. wait $PALEMOON_PID 2>/dev/null || true
  29. if [[ ! -f "$PREFS_FILE" ]]; then
  30. echo "❌ prefs.js not found. Pale Moon did not fully initialize."
  31. exit 1
  32. fi
  33. else
  34. echo "⚠️ Pale Moon is not installed or not in PATH. Skipping profile bootstrap."
  35. fi
  36. echo 'user_pref("security.cert_pinning.enforcement_level", 0);' >>"$PREFS_FILE"
  37. echo "✅ TLS cert validation disabled in Pale Moon profile: $PROFILE_DIR"
  38. # 🔧 Ensure certutil is installed
  39. if ! command -v certutil &>/dev/null; then
  40. if [ -f /etc/debian_version ]; then
  41. echo "🔧 'certutil' not found. Installing via apt..."
  42. apt-get update
  43. apt-get install -y libnss3-tools
  44. else
  45. echo "❌ 'certutil' not found and install is only supported on Debian-based systems."
  46. exit 1
  47. fi
  48. fi
  49. import_cert_to_profiles() {
  50. local base_dir="$1"
  51. local browser_name="$2"
  52. local profile_glob="$3"
  53. if [ ! -d "$base_dir" ]; then
  54. echo "⚠️ $browser_name profile directory not found: $base_dir"
  55. return
  56. fi
  57. echo "📌 Searching for $browser_name profiles in: $base_dir"
  58. local found=0
  59. for profile in "$base_dir"/$profile_glob; do
  60. if [ ! -d "$profile" ]; then
  61. continue
  62. fi
  63. found=1
  64. local db_path="sql:$profile"
  65. echo "🔍 Processing $browser_name profile: $profile"
  66. if certutil -L -d "$db_path" | grep -q "^$CERT_NAME"; then
  67. echo " ✅ Certificate '$CERT_NAME' already exists in profile."
  68. continue
  69. fi
  70. certutil -A -n "$CERT_NAME" -t "$TRUST_FLAGS" -i "$CERT_PATH" -d "$db_path"
  71. echo " ➕ Added certificate '$CERT_NAME' to $browser_name profile."
  72. done
  73. if [ "$found" -eq 0 ]; then
  74. echo "⚠️ No $browser_name profiles found in: $base_dir"
  75. fi
  76. }
  77. import_cert_to_profiles "$FIREFOX_DIR" "Firefox" "*.default*"
  78. import_cert_to_profiles "$PALEMOON_DIR" "Pale Moon" "*.*"
  79. echo "✅ Done. Firefox and Pale Moon profiles updated with '$CERT_NAME' certificate."