Skip to content
This repository was archived by the owner on Apr 20, 2023. It is now read-only.

Commit 957ff39

Browse files
juergenpfPiotr Puszkiewicz
authored and
Piotr Puszkiewicz
committed
- Never check agains username, that's bad practice. Always use effective UID (#4894)
- Never write error messages and tracing info to stdout, that's bad practice too.
1 parent 5195aad commit 957ff39

File tree

2 files changed

+15
-15
lines changed

2 files changed

+15
-15
lines changed

scripts/obtain/uninstall/dotnet-uninstall-debian-packages.sh

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66

77
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
88

9-
current_user=$(whoami)
10-
if [ $current_user != "root" ]; then
9+
current_userid=$(id -u)
10+
if [ $current_userid -ne 0 ]; then
1111
echo "$(basename "$0") uninstallation script requires superuser privileges to run"
1212
exit 1
1313
fi
@@ -24,16 +24,16 @@ is_dotnet_host_installed(){
2424
}
2525

2626
is_dotnet_host_installed
27-
[ "$?" -eq 0 ] && echo "Unable to find dotnet installation to remove." \
27+
[ "$?" -eq 0 ] && echo "Unable to find dotnet installation to remove." >&2 \
2828
&& exit 0
2929

3030
remove_all
31-
[ "$?" -ne 0 ] && echo "Failed to remove dotnet packages." && exit 1
31+
[ "$?" -ne 0 ] && echo "Failed to remove dotnet packages." >&2 && exit 1
3232

3333
is_dotnet_host_installed
3434
[ "$?" -ne 0 ] && \
35-
echo "dotnet package removal succeeded but appear to still be installed. Please file an issue at https://github.com/dotnet/cli" && \
35+
echo "dotnet package removal succeeded but appear to still be installed. Please file an issue at https://github.com/dotnet/cli" >&2 && \
3636
exit 1
3737

38-
echo "dotnet package removal succeeded."
38+
echo "dotnet package removal succeeded." >&2
3939
exit 0

scripts/obtain/uninstall/dotnet-uninstall-pkgs.sh

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66

77
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
88

9-
current_user=$(whoami)
10-
if [ $current_user != "root" ]; then
11-
echo "$(basename "$0") uninstallation script requires superuser privileges to run"
9+
current_userid=$(id -u)
10+
if [ $current_userid -ne 0 ]; then
11+
echo "$(basename "$0") uninstallation script requires superuser privileges to run" >&2
1212
exit 1
1313
fi
1414

@@ -22,17 +22,17 @@ remove_dotnet_pkgs(){
2222

2323
for i in "${installed_pkgs[@]}"
2424
do
25-
echo "Removing dotnet component - \"$i\""
25+
echo "Removing dotnet component - \"$i\"" >&2
2626
pkgutil --force --forget "$i"
2727
done
2828
}
2929

3030
remove_dotnet_pkgs
31-
[ "$?" -ne 0 ] && echo "Failed to remove dotnet packages." && exit 1
31+
[ "$?" -ne 0 ] && echo "Failed to remove dotnet packages." >&2 && exit 1
3232

33-
echo "Deleting install root - $dotnet_install_root"
34-
rm -r "$dotnet_install_root"
35-
rm "$dotnet_path_file"
33+
echo "Deleting install root - $dotnet_install_root" >&2
34+
rm -rf "$dotnet_install_root"
35+
rm -f "$dotnet_path_file"
3636

37-
echo "dotnet packages removal succeeded."
37+
echo "dotnet packages removal succeeded." >&2
3838
exit 0

0 commit comments

Comments
 (0)