Guest User

Untitled

a guest
Nov 12th, 2024
260
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.73 KB | None | 0 0
  1. /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
  2.  
  3.  
  4.  
  5.  
  6. brew install sleepwatcher
  7.  
  8.  
  9.  
  10.  
  11.  
  12. cat << 'EOF' > ~/.sleep
  13. #!/bin/bash
  14.  
  15. # Set up logging
  16. exec 1>> ~/Library/Logs/sleepwatcher/sleep.log 2>&1
  17.  
  18. date "+%Y-%m-%d %H:%M:%S Sleep script started"
  19.  
  20. # Define PATH
  21. PATH=/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/homebrew/bin
  22.  
  23. echo "Attempting to kill FortiClient processes..."
  24.  
  25. # Kill FortiClient processes without using sudo
  26. pkill -9 -f "FortiClient"
  27. pkill -9 -f "fctservctl"
  28. pkill -9 -f "fcconfig"
  29. pkill -9 -f "FctMiscAgent"
  30. pkill -9 -f "cscmd"
  31.  
  32. # Verify if any processes remain
  33. remaining=$(ps aux | grep -i 'forti' | grep -v 'grep')
  34. if [ -n "$remaining" ]; then
  35. echo "Some processes remain:"
  36. echo "$remaining"
  37. else
  38. echo "All FortiClient processes successfully terminated"
  39. fi
  40.  
  41. date "+%Y-%m-%d %H:%M:%S Sleep script completed"
  42. echo "----------------------------------------"
  43. EOF
  44.  
  45. chmod 755 ~/.sleep
  46.  
  47.  
  48.  
  49.  
  50.  
  51.  
  52.  
  53. cat << 'EOF' > ~/.wakeup
  54. #!/bin/bash
  55.  
  56. # Set up logging
  57. exec 1>> ~/Library/Logs/sleepwatcher/wake.log 2>&1
  58.  
  59. date "+%Y-%m-%d %H:%M:%S Wake script started"
  60.  
  61. # Define PATH
  62. PATH=/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/homebrew/bin
  63.  
  64. echo "Attempting to kill FortiClient processes..."
  65.  
  66. # Kill FortiClient processes without using sudo
  67. pkill -9 -f "FortiClient"
  68. pkill -9 -f "fctservctl"
  69. pkill -9 -f "fcconfig"
  70. pkill -9 -f "FctMiscAgent"
  71. pkill -9 -f "cscmd"
  72.  
  73. # Verify if any processes remain
  74. remaining=$(ps aux | grep -i 'forti' | grep -v 'grep')
  75. if [ -n "$remaining" ]; then
  76. echo "Some processes remain:"
  77. echo "$remaining"
  78. else
  79. echo "All FortiClient processes successfully terminated"
  80. fi
  81.  
  82. date "+%Y-%m-%d %H:%M:%S Wake script completed"
  83. echo "----------------------------------------"
  84. EOF
  85.  
  86. chmod 755 ~/.wakeup
  87.  
  88.  
  89.  
  90.  
  91.  
  92. mkdir -p ~/Library/LaunchAgents
  93.  
  94.  
  95.  
  96.  
  97.  
  98.  
  99. cat << 'EOF' > ~/Library/LaunchAgents/de.bernhard-baehr.sleepwatcher.plist
  100. <?xml version="1.0" encoding="UTF-8"?>
  101. <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
  102. <plist version="1.0">
  103. <dict>
  104. <key>Label</key>
  105. <string>de.bernhard-baehr.sleepwatcher</string>
  106. <key>ProgramArguments</key>
  107. <array>
  108. <string>/opt/homebrew/sbin/sleepwatcher</string>
  109. <string>-V</string>
  110. <string>-s ~/.sleep</string>
  111. <string>-w ~/.wakeup</string>
  112. </array>
  113. <key>RunAtLoad</key>
  114. <true/>
  115. <key>KeepAlive</key>
  116. <true/>
  117. </dict>
  118. </plist>
  119. EOF
  120.  
  121.  
  122.  
  123.  
  124.  
  125. launchctl unload ~/Library/LaunchAgents/de.bernhard-baehr.sleepwatcher.plist
  126. launchctl load ~/Library/LaunchAgents/de.bernhard-baehr.sleepwatcher.plist
  127.  
  128.  
  129.  
  130. brew services restart sleepwatcher
  131.  
Advertisement
Add Comment
Please, Sign In to add comment