-
Notifications
You must be signed in to change notification settings - Fork 7
/
StopNsurl.sh
executable file
·133 lines (101 loc) · 2.5 KB
/
StopNsurl.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#! /bin/sh
## Description -----------
# Anti nsurlsessiond for macOS
# Looking for new 'nsurlsessiond' processus and killing it by getting his PID
# Made by Lucas Tarasconi
# 07/04/2017
# @Farnots
## Spinner function -----------
# Source of the function : http://fitnr.com/showing-a-bash-spinner.html
spinner()
{
local pid=$!
local delay=0.4
local spinstr='|/-\'
while [ "$(ps a | awk '{print $1}' | grep $pid)" ]; do
local temp=${spinstr#?}
printf " [%c] " "$spinstr"
local spinstr=$temp${spinstr%"$temp"}
sleep $delay
printf "\b\b\b\b\b\b"
done
printf " \b\b\b\b"
}
## Color ---------
RED='\033[1;31m'
BLUE='\033[1;34m'
GREEN='\033[1;32m'
ORANGE='\033[0;33m'
NC='\033[0m'
PROCESS="${BLUE}[PROCESS]${NC}"
INFO="${GREEN}[INFO]${NC}"
WARNING="${ORANGE}[WARNING]${NC}"
## Welcome pannel -----------
echo "+----------------------------------------+"
echo "| Starting annihilation of nsurlsessiond |"
echo "| Made by Lucas Tarasconi |"
echo "+----------------------------------------+"
## Testing verbose mode -----------
verbose=0
if [ $# -eq 1 ]; then
if [ $1 == "-v" ]; then
verbose=1
fi
fi
## Removing the tempory file when exiting -----------
quitting () {
echo "\n"
echo "${INFO} Removing tempory file"
rm ./.nsurlsessiond
echo "+----------------------------------------+"
echo "| Stoping annihilation of nsurlsessiond |"
echo "+----------------------------------------+"
exit 0
}
## Core of the script : kill all nsurlsession and show them -----------
killIt () {
n=$(expr $line)
sudo kill $n
}
speaking (){
printf "\n"
killIt
current_time="`date +%H:%M:%S`"
printf "${PROCESS} ${current_time}"
printf " - killing nsurlsessiond number : $n"
}
killNsurl () {
pgrep -x nsurlsessiond>./.nsurlsessiond
while read line ; do
if [ $verbose -eq 1 ] ; then
speaking
else
killIt
fi
done <./.nsurlsessiond
if [ $verbose -eq 1 ] ; then
printf "\n"
printf "${INFO} Probing for new nsurlsessiond process"
fi
}
## To avoid to use too many GPU just to kill processus -----------
function waiting {
sleep 1
}
## While function -----------
trap "quitting" SIGTERM SIGINT
printf "${WARNING} Password could be asked once to have the right to kill 'nsurlsessiond' \n"
if [ $verbose -eq 1 ] ; then
printf "${INFO} Probing for new nsurlsessiond process "
else
printf "${INFO} Script is in progess ( '-v' to the verbose mode) : "
fi
sleep 1
while [[ 1 ]]; do
pgrep -x nsurlsessiond>./.nsurlsessiond
if [ $? -eq 0 ]; then
killNsurl
else
waiting & spinner
fi
done