Skip to content

Commit b640d88

Browse files
committed
Trap Control C. Add more logic to recieve a correct Sudo password.
1 parent 9a94a07 commit b640d88

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

system-info

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,21 @@ wrn_lvl=3
6464
inf_lvl=4
6565
dbg_lvl=5
6666

67+
# Trap Control-C
68+
stty -echoctl # hide ^C
69+
trap 'other_commands' SIGINT
70+
6771
########################################################################
6872
#### Functions:
6973
########################################################################
74+
function other_commands()
75+
{
76+
tput setaf 1
77+
printf "You can 'not' exit this script by pressing Control-C..."
78+
tput sgr0
79+
printf "Continue with last 'asked' input..."
80+
}
81+
7082
function CheckRoot()
7183
{
7284
clear;
@@ -76,7 +88,16 @@ function CheckRoot()
7688
echo -e "$redback Do not run this script with sudo or as root$resetvid"
7789
exit
7890
else
79-
sudo echo "Running Script: ${sname} $version"
91+
echo -e "This script needs some parts of it to run with elevated permissions."
92+
echo -e "Please enter your password for that to happen."
93+
sudo -k # revoke previously cached sudo password
94+
if sudo true
95+
then
96+
echo "Running Script: ${sname} $version"
97+
else
98+
echo "Password was incorrect for sudo elevated rights. Exiting Script."
99+
exit 1
100+
fi
80101
fi
81102
}
82103

0 commit comments

Comments
 (0)