Use install for certificate and key file installation
Replace separate cp and chmod operations with single install commands for certificate, key, and PEM file installation to ensure proper permissions and ownership are set in one operation
This commit is contained in:
parent
8d3291e01d
commit
ab59a58c55
1 changed files with 5 additions and 18 deletions
23
certman.sh
23
certman.sh
|
|
@ -185,33 +185,20 @@ install_certificate() {
|
||||||
|
|
||||||
# Install new certificate and key
|
# Install new certificate and key
|
||||||
if [ $needs_reload -eq 1 ]; then
|
if [ $needs_reload -eq 1 ]; then
|
||||||
if ! cp -f "$temp_cert" "$final_cert" || ! cp -f "$temp_key" "$final_key"; then
|
if ! install -m "$CERT_PERMISSIONS" -o "$CERT_OWNER" -g "$CERT_GROUP" "$temp_cert" "$final_cert"; then
|
||||||
echo -e "${RED}Failed to install certificate files for $domain${NC}"
|
echo -e "${RED}Failed to install certificate for $domain${NC}"
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
if ! install -m "$KEY_PERMISSIONS" -o "$CERT_OWNER" -g "$CERT_GROUP" "$temp_key" "$final_key"; then
|
||||||
# Set permissions and ownership for cert and key separately
|
echo -e "${RED}Failed to install private key for $domain${NC}"
|
||||||
if ! chown "$CERT_OWNER:$CERT_GROUP" "$final_cert" || \
|
|
||||||
! chmod "$CERT_PERMISSIONS" "$final_cert"; then
|
|
||||||
echo -e "${RED}Failed to set permissions for $final_cert${NC}"
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
if ! chown "$CERT_OWNER:$CERT_GROUP" "$final_key" || \
|
|
||||||
! chmod "$KEY_PERMISSIONS" "$final_key"; then
|
|
||||||
echo -e "${RED}Failed to set permissions for $final_key${NC}"
|
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "$FULLCHAIN_PEM" = "true" ]; then
|
if [ "$FULLCHAIN_PEM" = "true" ]; then
|
||||||
if ! cp -f "$temp_pem" "$final_pem"; then
|
if ! install -m "$KEY_PERMISSIONS" -o "$CERT_OWNER" -g "$CERT_GROUP" "$temp_pem" "$final_pem"; then
|
||||||
echo -e "${RED}Failed to install PEM file for $domain${NC}"
|
echo -e "${RED}Failed to install PEM file for $domain${NC}"
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
if ! chown "$CERT_OWNER:$CERT_GROUP" "$final_pem" || \
|
|
||||||
! chmod "$KEY_PERMISSIONS" "$final_pem"; then
|
|
||||||
echo -e "${RED}Failed to set permissions for $final_pem${NC}"
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo -e "${GREEN}Certificate updated for $domain${NC}"
|
echo -e "${GREEN}Certificate updated for $domain${NC}"
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue