Skip to content

Commit 8c7b823

Browse files
fix(makefile): install mkcert without needing sudo
Signed-off-by: Dusan Malusev <dusan@dusanmalusev.dev>
1 parent 9046be4 commit 8c7b823

1 file changed

Lines changed: 5 additions & 6 deletions

File tree

Makefile

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,26 +56,25 @@ security: ## Run basic security checks (gosec)
5656
# --- Mkcert -------------------------------
5757

5858
install-mkcert: ## Install mkcert binary to $(MKCERT_INSTALL_PATH) if missing
59-
@if command -v mkcert >/dev/null 2>&1; then \
60-
echo "mkcert already installed at $$(command -v mkcert)"; \
61-
else \
59+
@if [ ! -f "$(MKCERT_INSTALL_PATH)/mkcert" ]; then \
60+
mkdir -p $(MKCERT_INSTALL_PATH) 2>/dev/null || true; \
6261
echo "Downloading mkcert from $(MKCERT_URL)..."; \
6362
tmp=$$(mktemp -d); \
6463
curl -L --fail -o $$tmp/$(MKCERT_ASSET) "$(MKCERT_URL)"; \
6564
chmod +x $$tmp/$(MKCERT_ASSET); \
66-
sudo mv $$tmp/$(MKCERT_ASSET) $(MKCERT_INSTALL_PATH)/mkcert || { echo "Failed to move mkcert to $(MKCERT_INSTALL_PATH)"; exit 1; }; \
65+
mv $$tmp/$(MKCERT_ASSET) $(MKCERT_INSTALL_PATH)/mkcert || { echo "Failed to move mkcert to $(MKCERT_INSTALL_PATH)"; exit 1; }; \
6766
rm -rf $$tmp; \
6867
echo "mkcert installed to $(MKCERT_INSTALL_PATH)/mkcert"; \
6968
fi
7069

7170
mkcert-install-ca: install-mkcert ## Install mkcert CA into system trust stores
7271
@echo "Installing mkcert CA..."
73-
@mkcert -install
72+
@$(MKCERT_INSTALL_PATH)/mkcert -install
7473

7574
mkcert-generate: mkcert-install-ca ## Generate cert/key for HOSTS into $(CERT_DIR) (usage: make mkcert-generate HOSTS='example.test localhost')
7675
@mkdir -p $(CERT_DIR)
7776
@echo "Generating cert for: $(HOSTS)"
78-
@mkcert -cert-file $(CERT_DIR)/smtp.crt -key-file $(CERT_DIR)/smtp.key $(HOSTS)
77+
@$(MKCERT_INSTALL_PATH)/mkcert -cert-file $(CERT_DIR)/smtp.crt -key-file $(CERT_DIR)/smtp.key $(HOSTS)
7978
@echo "Created $(CERT_DIR)/smtp.crt and $(CERT_DIR)/smtp.key"
8079

8180
mkcert-uninstall-ca: install-mkcert ## Uninstall mkcert CA from system trust stores

0 commit comments

Comments
 (0)