Skip to content

Commit

Permalink
Improving user interface
Browse files Browse the repository at this point in the history
- Adding a 'normal' mode and a 'verbose' mode of the script ! 
- Improving apparence of the script with less line show
  • Loading branch information
farnots committed Apr 19, 2017
1 parent 2ddb31f commit bbba5f2
Showing 1 changed file with 86 additions and 10 deletions.
96 changes: 86 additions & 10 deletions StopNsurl.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#! /bin/sh


## Description
## Description -----------

# Anti nsurlsessiond for macOS
# Looking for new 'nsurlsessiond' processus and killing it by getting his PID
Expand All @@ -10,14 +10,47 @@
# 07/04/2017
# @Farnots

## Welcome pannel
## 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"
}


## 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 -----------

function quitting {
echo "\n"
echo "Removing tempory file"
Expand All @@ -28,18 +61,61 @@ function quitting {
exit 0
}

## Core of the script : kill all nsurlsession and show them -----------

trap "quitting" SIGTERM SIGINT
function killIt {
n=$(expr $line)
sudo kill $n
}

while [[ 1 ]]; do
echo "... Probing for new nsurlsessiond process ..."

function speaking {
printf "\n"
killIt
current_time="`date +%H:%M:%S`"
printf $current_time;
printf " - killing nsurlsessiond number : $n"
}

function killNsurl {
pgrep -x nsurlsessiond>./.nsurlsessiond
while read line ; do
n=$(expr $line)
echo "killing nsurlsessiond number : $n"
sudo kill $n
done <./.nsurlsessiond
sleep 1;
if [ $verbose -eq 1 ] ; then
speaking
else
killIt
fi
done <./.nsurlsessiond
if [ $verbose -eq 1 ] ; then
printf "\n"
printf "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 "Note : Password could be asked once to have the right to kill 'nsurlsessiond' \n"
if [ $verbose -eq 1 ] ; then
printf "Probing for new nsurlsessiond process "
else
printf "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


Expand Down

0 comments on commit bbba5f2

Please sign in to comment.