Fixed root detection and made more robust
This commit is contained in:
parent
403c2b051c
commit
a99ae6cff7
18
setup.sh
18
setup.sh
@ -52,9 +52,13 @@ VENV_DIR="$DIR/venv"
|
|||||||
|
|
||||||
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
|
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
|
||||||
# Check if root or sudo
|
# Check if root or sudo
|
||||||
root=true
|
root=false
|
||||||
if [ "$EUID" -ne 0 ]; then
|
if [ "$EUID" = 0 ]; then
|
||||||
root=false
|
root=true
|
||||||
|
elif command -v id >/dev/null && [ "$(id -u)" = 0 ]; then
|
||||||
|
root=true
|
||||||
|
elif [ "$UID" = 0 ]; then
|
||||||
|
root=true
|
||||||
fi
|
fi
|
||||||
|
|
||||||
env_var_exists() {
|
env_var_exists() {
|
||||||
@ -149,7 +153,7 @@ if [[ "$OSTYPE" == "linux-gnu"* ]]; then
|
|||||||
if "$distro" | grep -qi "Ubuntu" || "$family" | grep -qi "Ubuntu"; then
|
if "$distro" | grep -qi "Ubuntu" || "$family" | grep -qi "Ubuntu"; then
|
||||||
echo "Ubuntu detected."
|
echo "Ubuntu detected."
|
||||||
if [ $(dpkg-query -W -f='${Status}' python3-tk 2>/dev/null | grep -c "ok installed") = 0 ]; then
|
if [ $(dpkg-query -W -f='${Status}' python3-tk 2>/dev/null | grep -c "ok installed") = 0 ]; then
|
||||||
if [ root = true ]; then
|
if [ "$root" = true ]; then
|
||||||
apt update -y && apt install -y python3-tk
|
apt update -y && apt install -y python3-tk
|
||||||
else
|
else
|
||||||
echo "This script needs to be run as root or via sudo to install packages."
|
echo "This script needs to be run as root or via sudo to install packages."
|
||||||
@ -161,7 +165,7 @@ if [[ "$OSTYPE" == "linux-gnu"* ]]; then
|
|||||||
elif "$distro" | grep -Eqi "Fedora|CentOS|Redhat"; then
|
elif "$distro" | grep -Eqi "Fedora|CentOS|Redhat"; then
|
||||||
echo "Redhat or Redhat base detected."
|
echo "Redhat or Redhat base detected."
|
||||||
if ! rpm -qa | grep -qi python3-tkinter; then
|
if ! rpm -qa | grep -qi python3-tkinter; then
|
||||||
if [ root = true ]; then
|
if [ "$root" = true ]; then
|
||||||
dnf install python3-tkinter -y
|
dnf install python3-tkinter -y
|
||||||
else
|
else
|
||||||
echo "This script needs to be run as root or via sudo to install packages."
|
echo "This script needs to be run as root or via sudo to install packages."
|
||||||
@ -171,7 +175,7 @@ if [[ "$OSTYPE" == "linux-gnu"* ]]; then
|
|||||||
elif "$distro" | grep -Eqi "arch" || "$family" | grep -qi "arch"; then
|
elif "$distro" | grep -Eqi "arch" || "$family" | grep -qi "arch"; then
|
||||||
echo "Arch Linux or Arch base detected."
|
echo "Arch Linux or Arch base detected."
|
||||||
if ! pacman -Qi tk >/dev/null; then
|
if ! pacman -Qi tk >/dev/null; then
|
||||||
if [ root = true ]; then
|
if [ "$root" = true ]; then
|
||||||
pacman --noconfirm -S tk
|
pacman --noconfirm -S tk
|
||||||
else
|
else
|
||||||
echo "This script needs to be run as root or via sudo to install packages."
|
echo "This script needs to be run as root or via sudo to install packages."
|
||||||
@ -181,7 +185,7 @@ if [[ "$OSTYPE" == "linux-gnu"* ]]; then
|
|||||||
elif "$distro" | grep -Eqi "opensuse" || "$family" | grep -qi "opensuse"; then
|
elif "$distro" | grep -Eqi "opensuse" || "$family" | grep -qi "opensuse"; then
|
||||||
echo "OpenSUSE detected."
|
echo "OpenSUSE detected."
|
||||||
if ! rpm -qa | grep -qi python-tk; then
|
if ! rpm -qa | grep -qi python-tk; then
|
||||||
if [ root = true ]; then
|
if [ "$root" = true ]; then
|
||||||
zypper install -y python-tk
|
zypper install -y python-tk
|
||||||
else
|
else
|
||||||
echo "This script needs to be run as root or via sudo to install packages."
|
echo "This script needs to be run as root or via sudo to install packages."
|
||||||
|
Loading…
Reference in New Issue
Block a user