Fix some scripting issues

This commit is contained in:
Reinier Criel 2025-11-19 13:15:39 -08:00
parent 2158478894
commit 97bbc77162
11 changed files with 129 additions and 53 deletions

View file

@ -3,36 +3,54 @@ set -e
echo "Uninstalling Safe Chain..."
USER_HOME="${HOME}"
if [ -z "${USER_HOME}" ]; then
USER_HOME=~
# Get the actual user
if [ -n "${SUDO_USER}" ]; then
ACTUAL_USER="${SUDO_USER}"
else
ACTUAL_USER=$(stat -f '%Su' /dev/console)
fi
# Get the home directory of the actual user
USER_HOME=$(eval echo "~${ACTUAL_USER}")
echo "Detected user: ${ACTUAL_USER}"
echo "User home: ${USER_HOME}"
# Stop and unload the LaunchAgent
PLIST_PATH="${USER_HOME}/Library/LaunchAgents/com.aikido.safe-chain.plist"
SERVICE_LABEL="com.aikido.safe-chain"
echo "Stopping Safe Chain service..."
if [ -f "${PLIST_PATH}" ]; then
echo "Stopping Safe Chain service..."
launchctl unload "${PLIST_PATH}" 2>/dev/null || true
# Run launchctl as the user
sudo -u "${ACTUAL_USER}" launchctl unload "${PLIST_PATH}" 2>/dev/null || true
rm -f "${PLIST_PATH}"
fi
# Ensure service is removed even if plist is gone
sudo -u "${ACTUAL_USER}" launchctl remove "${SERVICE_LABEL}" 2>/dev/null || true
# Remove system-wide environment variables
echo "Removing proxy environment variables..."
launchctl unsetenv HTTPS_PROXY 2>/dev/null || true
launchctl unsetenv GLOBAL_AGENT_HTTP_PROXY 2>/dev/null || true
launchctl unsetenv NODE_EXTRA_CA_CERTS 2>/dev/null || true
# Run launchctl as the user
sudo -u "${ACTUAL_USER}" launchctl unsetenv HTTPS_PROXY 2>/dev/null || true
sudo -u "${ACTUAL_USER}" launchctl unsetenv GLOBAL_AGENT_HTTP_PROXY 2>/dev/null || true
sudo -u "${ACTUAL_USER}" launchctl unsetenv NODE_EXTRA_CA_CERTS 2>/dev/null || true
# Remove binary
rm -f /usr/local/bin/safe-chain
# Remove certificate from system keychain
CERT_PATH="${USER_HOME}/.safe-chain/certs/ca-cert.pem"
if [ -f "${CERT_PATH}" ]; then
CERT_DIR="/usr/local/share/safe-chain/certs"
if [ -f "${CERT_DIR}/ca-cert.pem" ]; then
echo "Removing certificate from system trust store..."
# Find and delete the certificate by common name
security delete-certificate -c "safe-chain proxy" /Library/Keychains/System.keychain 2>/dev/null || true
fi
# Remove system-wide configuration and certificates
rm -rf /usr/local/share/safe-chain
# Optionally remove the .safe-chain directory (commented out to preserve user data)
# echo "Remove ~/.safe-chain directory? (y/N)"
# read -r response