diff --git a/setup.py b/setup.py index 0f3a172..67a53e4 100755 --- a/setup.py +++ b/setup.py @@ -15,6 +15,15 @@ import sys # must be synced with `src/constants.py` tmp_dir = "/tmp/com.developomp.setup" +# +# Util +# + + +def command_exits(command: str) -> bool: + return system(f"command -v {command} &> /dev/null") == 0 + + # # Common # @@ -53,7 +62,7 @@ def exit_if_system_not_compatible(): """Exits script if the OS is not linux or if pacman does not exist""" print("Checking if system is compatible") - if "linux" not in sys.platform.lower() or system("command -v pacman &> /dev/null"): + if "linux" not in sys.platform.lower() or not command_exits("pacman"): print("This script should only be used on arch linux.", file=sys.stderr) exit(1) @@ -77,7 +86,7 @@ def install_git(): """Installs git if it's not installed already""" print("Initializing git") - if system("command -v git &> /dev/null"): + if not command_exits("git"): print("git was not installed already. Installing now.") system("sudo pacman -S --noconfirm --needed git") diff --git a/src/constants.py b/src/constants.py index edf889c..7fe36f7 100644 --- a/src/constants.py +++ b/src/constants.py @@ -2,9 +2,6 @@ # this variable may be altered by the script # most notably by `src/interface/choose_action.py` -from os import system - content_dir = "/tmp/com.developomp.setup" tmp_dir = content_dir home_dir = "/home/pomp" -is_zsh_available: bool = system("command -v zsh &> /dev/null") == 0 diff --git a/src/setup/dev/node.py b/src/setup/dev/node.py index 5a54705..4551df1 100644 --- a/src/setup/dev/node.py +++ b/src/setup/dev/node.py @@ -1,8 +1,8 @@ from os import system from os.path import isdir -from src.constants import home_dir, is_zsh_available -from src.util import paru_install, zsh_system +from src.constants import home_dir +from src.util import paru_install, zsh_system, command_exists from src.setup.system import zsh from src import log @@ -21,7 +21,7 @@ def setup(): """ # Install zsh if it's not installed already - if not is_zsh_available: + if not command_exists("zsh"): zsh.setup() paru_install("nvm") diff --git a/src/util.py b/src/util.py index 6ec8df7..1f8db0a 100644 --- a/src/util.py +++ b/src/util.py @@ -114,6 +114,10 @@ def zsh_system(command: str): system(f"/usr/bin/zsh -c '{command}'") +def command_exists(command: str) -> bool: + return system(f"command -v {command} &> /dev/null") == 0 + + """ def setup_essentials(): setup_fstab