From b18546086ae91db485ed5fa33d46232a4d6e92d0 Mon Sep 17 00:00:00 2001 From: Jeff Date: Wed, 18 Nov 2020 17:06:48 -0500 Subject: [PATCH] make macos uninstaller actually kill and uninstall lokinet (#1484) * macos fluff * make uninstaller work, the uninstall script needs to be called with /usr/bin/sudo to work because god know why it needs that even though it's already root. * add logrotation * make the uninstall script kill all the things * revert * use correct regular expression * remove logrotate configs rename logrotate config file name to be more descriptive --- cmake/macos_installer_deps.cmake | 1 + contrib/macos/lokinet-newsyslog.conf | 1 + contrib/macos/lokinet_uninstall.sh | 30 ++++++++++++++-------------- contrib/macos/postinstall | 4 ++++ contrib/macos/uninstaller/main.cpp | 11 +++++----- 5 files changed, 27 insertions(+), 20 deletions(-) create mode 100644 contrib/macos/lokinet-newsyslog.conf diff --git a/cmake/macos_installer_deps.cmake b/cmake/macos_installer_deps.cmake index 66b7cc68d..5b02f8f8c 100644 --- a/cmake/macos_installer_deps.cmake +++ b/cmake/macos_installer_deps.cmake @@ -54,6 +54,7 @@ install(DIRECTORY ${PROJECT_BINARY_DIR}/LokinetGUI.app # copy files that will be later moved by the postinstall script to proper locations install(FILES ${CMAKE_SOURCE_DIR}/contrib/macos/lokinet_macos_daemon_script.sh ${CMAKE_SOURCE_DIR}/contrib/macos/network.loki.lokinet.daemon.plist + ${CMAKE_SOURCE_DIR}/contrib/macos/lokinet-newsyslog.conf DESTINATION "extra/" COMPONENT lokinet) diff --git a/contrib/macos/lokinet-newsyslog.conf b/contrib/macos/lokinet-newsyslog.conf new file mode 100644 index 000000000..69c30ffd3 --- /dev/null +++ b/contrib/macos/lokinet-newsyslog.conf @@ -0,0 +1 @@ +/var/log/lokinet.log 644 5 5M $D0 J \ No newline at end of file diff --git a/contrib/macos/lokinet_uninstall.sh b/contrib/macos/lokinet_uninstall.sh index 0916776d3..e094f5884 100755 --- a/contrib/macos/lokinet_uninstall.sh +++ b/contrib/macos/lokinet_uninstall.sh @@ -1,4 +1,6 @@ -#!/bin/sh +#!/bin/bash +set -x +test `whoami` == root || exit 1 # this is for dns tomfoolery scutil_query() @@ -26,22 +28,20 @@ SERVICE_NAME=`scutil_query Setup:/Network/Service/$SERVICE_GUID \ # tell dns to be "empty" so that it's reset networksetup -setdnsservers "$SERVICE_NAME" empty -# kill the gui -killall LokinetGUI +# shut off exit if it's up +pgrep lokinet$ && /opt/lokinet/bin/lokinet-vpn --down # Prevent restarting on exit -[ -e /var/lib/lokinet ] && touch /var/lib/lokinet/suspend-launchd-service -# kill it -killall lokinet || true -# Give it some time to shut down before we bring launchd into this -sleep 2 -# make sure it's dead -killall -9 lokinet || true +touch /var/lib/lokinet/suspend-launchd-service +# kill the gui and such +killall LokinetGUI +killall lokinet # if the launch daemon is there kill it -[ -e /Library/LaunchDaemons/network.loki.lokinet.daemon.plist ] && ( - launchctl stop network.loki.lokinet.daemon ; - launchctl unload /Library/LaunchDaemons/network.loki.lokinet.daemon.plist -) +/bin/launchctl stop network.loki.lokinet.daemon +/bin/launchctl unload /Library/LaunchDaemons/network.loki.lokinet.daemon.plist + +# kill it and make sure it's dead +killall -9 lokinet rm -rf /Library/LaunchDaemons/network.loki.lokinet.daemon.plist rm -rf /Applications/Lokinet/ @@ -49,4 +49,4 @@ rm -rf /Applications/LokinetGUI.app rm -rf /var/lib/lokinet rm -rf /usr/local/lokinet/ rm -rf /opt/lokinet - +rm -f /etc/newsyslog.d/lokinet.conf diff --git a/contrib/macos/postinstall b/contrib/macos/postinstall index 6e8f1638a..ac2674f7f 100644 --- a/contrib/macos/postinstall +++ b/contrib/macos/postinstall @@ -18,6 +18,10 @@ mv /opt/lokinet/extra/network.loki.lokinet.daemon.plist /Library/LaunchDaemons/ chown $CHOWN /Library/LaunchDaemons/network.loki.lokinet.daemon.plist chmod 640 /Library/LaunchDaemons/network.loki.lokinet.daemon.plist +mv /opt/lokinet/extra/lokinet-newsyslog.conf /etc/newsyslog.d/lokinet.conf +chown $CHOWN /etc/newsyslog.d/lokinet.conf +chmod 640 /etc/newsyslog.d/lokinet.conf + # clean up by removing 'extra/' (so long as it's empty) rmdir /opt/lokinet/extra/ diff --git a/contrib/macos/uninstaller/main.cpp b/contrib/macos/uninstaller/main.cpp index a069a7f05..a58b116c8 100644 --- a/contrib/macos/uninstaller/main.cpp +++ b/contrib/macos/uninstaller/main.cpp @@ -33,11 +33,12 @@ int uninstall() AuthorizationRef authorizationRef; OSStatus status; - status = AuthorizationCreate(NULL, kAuthorizationEmptyEnvironment, kAuthorizationFlagDefaults, &authorizationRef); - - char* tool = "/opt/lokinet/bin/lokinet_uninstall.sh"; - char* args[] = {nullptr}; - FILE* pipe = NULL; + status = AuthorizationCreate(nullptr, kAuthorizationEmptyEnvironment, kAuthorizationFlagDefaults, &authorizationRef); + if(status != 0) + return status; + char* tool = "/bin/sh"; + char* args[] = {"/opt/lokinet/bin/lokinet_uninstall.sh", nullptr}; + FILE* pipe = stdout; return AuthorizationExecuteWithPrivileges(authorizationRef, tool, kAuthorizationFlagDefaults, args, &pipe); }