diff --git a/setup.py b/setup.py index 45c88c7..e1e44b7 100755 --- a/setup.py +++ b/setup.py @@ -22,18 +22,6 @@ tmp_dir = "/tmp/com.developomp.setup" # -def run(command: str, hide_stdout: bool = True, hide_stderr: bool = True): - if hide_stderr: - system(f"{command} &> /dev/null") - return - - if hide_stdout: - system(f"{command} > /dev/null") - return - - system(command) - - def run_and_return(command: str) -> list[str]: return popen(command).readlines() @@ -103,7 +91,7 @@ def exit_if_no_internet(): """Exits script if there's no internet connection. Pings archlinux.org for testing.""" - if run("ping -c 1 archlinux.org"): + if system("ping -c 1 archlinux.org"): print(" Failed to connect to the internet.", file=sys.stderr) exit(1) @@ -139,7 +127,7 @@ def install_git(): """Install git if it's not installed already.""" if not command_exists("git"): - run("sudo pacman -S --noconfirm --needed git") + system("sudo pacman -S --noconfirm --needed git") def clone_repository(): @@ -149,12 +137,12 @@ def clone_repository(): cleanup() # clone repository - if run(f"git clone --depth 1 https://github.com/developomp/setup.git {tmp_dir}"): + if system(f"git clone --depth 1 https://github.com/developomp/setup.git {tmp_dir}"): print(" Failed to clone repository", file=sys.stderr) exit(1) # allow everyone to read and write. - if run(f"chmod -R a+rw {tmp_dir}"): + if system(f"chmod -R a+rw {tmp_dir}"): print(" Failed to change file permission for cloned repo", file=sys.stderr) exit(1) diff --git a/src/initialize.py b/src/initialize.py index 8616045..3d184ee 100644 --- a/src/initialize.py +++ b/src/initialize.py @@ -1,15 +1,16 @@ +from os import system + from src import log -from src.util import run def install_via_pacman(package: str): - if run(f"paru -S --noconfirm {package}", True): + if system(f"paru -S --noconfirm {package}"): log.error(f"Failed to install {package} via pacman") exit(1) def install_via_pip(package: str): - if run(f"pip install {package}"): + if system(f"pip install {package}"): log.error(f"Failed to install {package} via pip") exit(1) diff --git a/src/setup/apps/discord.py b/src/setup/apps/discord.py index 3fbfdc2..9a2b0a3 100644 --- a/src/setup/apps/discord.py +++ b/src/setup/apps/discord.py @@ -1,4 +1,6 @@ -from src.util import flatpak_install, paru_install, copy_file, run +from os import system + +from src.util import flatpak_install, paru_install, copy_file from src import log @@ -58,8 +60,8 @@ def setup(): log.log(f"installing {url}") # assumes that plugins is located in "~/.var/app/com.discordapp.Discord/config/BetterDiscord/plugins" because I'm using flatpak - run( + system( f'wget --content-disposition --no-clobber -P ~/.var/app/com.discordapp.Discord/config/BetterDiscord/plugins "{url}"' ) - run("betterdiscordctl -i flatpak install") + system("betterdiscordctl -i flatpak install") diff --git a/src/setup/apps/nautilus.py b/src/setup/apps/nautilus.py index 89e531b..d726b49 100644 --- a/src/setup/apps/nautilus.py +++ b/src/setup/apps/nautilus.py @@ -1,6 +1,6 @@ -from src.util import paru_install, load_dconf, command_exists, run +from src.util import paru_install, load_dconf, command_exists from src.setup.apps import terminal - +from os import system name = "Nautilus" @@ -22,10 +22,12 @@ def setup(): load_dconf("nautilus.conf") # set nautilus terminal settings - run( + system( "gsettings set com.github.stunkymonkey.nautilus-open-any-terminal terminal kitty" ) - run( + system( "gsettings set com.github.stunkymonkey.nautilus-open-any-terminal keybindings ''" ) - run("gsettings set com.github.stunkymonkey.nautilus-open-any-terminal new-tab true") + system( + "gsettings set com.github.stunkymonkey.nautilus-open-any-terminal new-tab true" + ) diff --git a/src/setup/apps/osu_lazer.py b/src/setup/apps/osu_lazer.py index 19a6967..0413482 100644 --- a/src/setup/apps/osu_lazer.py +++ b/src/setup/apps/osu_lazer.py @@ -1,7 +1,8 @@ -from src.util import flatpak_install, paru_install, copy_file, run +from src.util import flatpak_install, paru_install, copy_file from src.setup.system import system76_scheduler from os.path import exists +from os import system name = "osu!lazer" post_install = ["Install osu! skin from https://github.com/developomp/osu-pomp-skin"] @@ -37,15 +38,15 @@ def setup(): for name in modules_to_disable: # Add blacklist rule if it does not exist - run( + system( f'sudo grep -qxF "blacklist {name}" /etc/modprobe.d/blacklist.conf || echo "blacklist {name}" | sudo tee -a /etc/modprobe.d/blacklist.conf' ) # remove module from kernel if it's loaded - run(f"sudo rmmod {name}") + system(f"sudo rmmod {name}") # Reload the systemd user unit daemon - run("systemctl --user daemon-reload") + system("systemctl --user daemon-reload") # Enable and start the user service - run("systemctl --user enable opentabletdriver --now") + system("systemctl --user enable opentabletdriver --now") diff --git a/src/setup/apps/tenacity.py b/src/setup/apps/tenacity.py index db5ea11..b2e189d 100644 --- a/src/setup/apps/tenacity.py +++ b/src/setup/apps/tenacity.py @@ -1,6 +1,6 @@ # https://github.com/tenacityteam/tenacity-flatpak-nightly -from src.util import run +from os import system name = "Tenacity" @@ -8,7 +8,7 @@ name = "Tenacity" def setup(): """Safe audacity fork""" - run( + system( "flatpak remote-add tenacity oci+https://tenacityteam.github.io/tenacity-flatpak-nightly" ) - run("flatpak install tenacity org.tenacityaudio.Tenacity") + system("flatpak install tenacity org.tenacityaudio.Tenacity") diff --git a/src/setup/dev/docker.py b/src/setup/dev/docker.py index a2f6c8d..eef8f18 100644 --- a/src/setup/dev/docker.py +++ b/src/setup/dev/docker.py @@ -1,5 +1,6 @@ -from src.util import paru_install, run +from src.util import paru_install from getpass import getuser +from os import system name = "Docker" @@ -9,5 +10,5 @@ def setup(): paru_install("docker") - run(f'sudo usermod -aG docker "{getuser()}"') - run("sudo systemctl --now enable docker") + system(f'sudo usermod -aG docker "{getuser()}"') + system("sudo systemctl --now enable docker") diff --git a/src/setup/dev/git.py b/src/setup/dev/git.py index bb184c2..d43d6f2 100644 --- a/src/setup/dev/git.py +++ b/src/setup/dev/git.py @@ -1,4 +1,5 @@ -from src.util import paru_install, run +from src.util import paru_install +from os import system name = "git" @@ -8,8 +9,8 @@ def setup(): paru_install("git") - run('git config --global user.email "developomp@gmail.com"') - run('git config --global user.name "developomp"') - run("git config --global pull.rebase false") - run("git config --global init.defaultBranch master") - run("git config --global credential.helper store") + system('git config --global user.email "developomp@gmail.com"') + system('git config --global user.name "developomp"') + system("git config --global pull.rebase false") + system("git config --global init.defaultBranch master") + system("git config --global credential.helper store") diff --git a/src/setup/dev/node.py b/src/setup/dev/node.py index 0ee4158..b31ad17 100644 --- a/src/setup/dev/node.py +++ b/src/setup/dev/node.py @@ -1,9 +1,10 @@ from src.constants import home_dir -from src.util import paru_install, run, command_exists +from src.util import paru_install, command_exists from src.setup.system import zsh from src import log from os.path import isdir +from os import system name = "node" @@ -26,15 +27,15 @@ def setup(): paru_install("nvm") log.log("Installing Node.JS LTS") - run("source /usr/share/nvm/init-nvm.sh; nvm install --lts") + system("source /usr/share/nvm/init-nvm.sh; nvm install --lts") # todo: add "source /usr/share/nvm/init-nvm.sh" to ~/.zshrc log.log("Installing npm") - run("npm install --global npm") + system("npm install --global npm") log.log("Installing pnpm") - run("npm install --global pnpm") + system("npm install --global pnpm") log.log("Installing yarn") - run("npm install --global yarn") + system("npm install --global yarn") diff --git a/src/setup/dev/rust.py b/src/setup/dev/rust.py index e38ff36..e830055 100644 --- a/src/setup/dev/rust.py +++ b/src/setup/dev/rust.py @@ -1,4 +1,5 @@ -from src.util import paru_install, run +from src.util import paru_install +from os import system name = "rust" @@ -8,4 +9,4 @@ def setup(): """C++ but modern""" paru_install(["rustup", "rust-analyzer"]) - run("rustup install stable") + system("rustup install stable") diff --git a/src/setup/dev/virtualbox.py b/src/setup/dev/virtualbox.py index 8fa974b..e337ba2 100644 --- a/src/setup/dev/virtualbox.py +++ b/src/setup/dev/virtualbox.py @@ -1,4 +1,5 @@ -from src.util import paru_install, run +from src.util import paru_install +from os import system name = "virtualbox" @@ -14,6 +15,6 @@ def setup(): ] ) - run("sudo systemctl enable systemd-modules-load") - run("sudo systemctl start systemd-modules-load") - run("sudo modprobe vboxdrv") + system("sudo systemctl enable systemd-modules-load") + system("sudo systemctl start systemd-modules-load") + system("sudo modprobe vboxdrv") diff --git a/src/setup/dev/vscodium.py b/src/setup/dev/vscodium.py index e11c3eb..ce06389 100644 --- a/src/setup/dev/vscodium.py +++ b/src/setup/dev/vscodium.py @@ -1,4 +1,5 @@ -from src.util import paru_install, copy_file, run +from src.util import paru_install, copy_file +from os import system name = "Vscodium" @@ -50,7 +51,7 @@ def setup(): # codium --list-extensions for extension in EXTENSIONS: - run(f"codium --install-extension {extension} --force") + system(f"codium --install-extension {extension} --force") # vscodium settings copy_file("home/.config/VSCodium/User/settings.json") diff --git a/src/setup/system/fonts.py b/src/setup/system/fonts.py index 6f20fdb..c965b50 100644 --- a/src/setup/system/fonts.py +++ b/src/setup/system/fonts.py @@ -1,7 +1,7 @@ from src.util import paru_install, smart_mkdir, download, unzip from src.constants import tmp_dir, home_dir from shutil import rmtree, move -from os import remove +from os import remove, system from os.path import exists, basename import requests import glob @@ -61,7 +61,7 @@ def setup(): move(ttf_file_path, f"{FONT_INSTALL_DIR}/{basename(ttf_file_path)}") # regenerate font cache - run("fc-cache -vf") + system("fc-cache -vf") # cleanup rmtree(TMP_FONTS_DIRECTORY) diff --git a/src/setup/system/fstab.py b/src/setup/system/fstab.py index 3c5936c..988822a 100644 --- a/src/setup/system/fstab.py +++ b/src/setup/system/fstab.py @@ -1,4 +1,4 @@ -from src.util import run +from os import system name = "fstab" @@ -19,4 +19,4 @@ def setup(): # append a line to the end and ignore output # not using python's file interface because I don't wanna deal with permission stuff - run(f'echo "{line_to_write}" | sudo tee -a {fstab_path} >/dev/null') + system(f'echo "{line_to_write}" | sudo tee -a {fstab_path} >/dev/null') diff --git a/src/setup/system/gnome_extensions.py b/src/setup/system/gnome_extensions.py index e9d701a..2bee76e 100644 --- a/src/setup/system/gnome_extensions.py +++ b/src/setup/system/gnome_extensions.py @@ -1,6 +1,8 @@ -from src.util import paru_install, load_dconf, run +from src.util import paru_install, load_dconf from src import log +from os import system + name = "GNOME extensions" post_install = ["Restart GNOME shell", "enable GNOME extensions"] @@ -39,7 +41,7 @@ def setup(): for (extension, dconf_file) in EXTENSIONS: log.log("installing: https://extensions.gnome.org/extension/$1") - run(f"gnome-shell-extension-installer {extension} --yes --update") + system(f"gnome-shell-extension-installer {extension} --yes --update") if dconf_file: # if dconf_file is not empty load_dconf(dconf_file) diff --git a/src/setup/system/zsh.py b/src/setup/system/zsh.py index 519fe39..1affe5b 100644 --- a/src/setup/system/zsh.py +++ b/src/setup/system/zsh.py @@ -1,8 +1,9 @@ -from src.util import paru_install, copy_file, trash, run +from src.util import paru_install, copy_file, trash from src.constants import home_dir from src import log from os.path import isdir +from os import system name = "Zsh" @@ -13,21 +14,23 @@ def setup(): paru_install("zsh") log.log("Installing Oh My Zsh") - run( + system( 'sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"' ) log.log("Installing powerlevel10k theme") p10k_path = f"{home_dir}/.oh-my-zsh/custom/themes/powerlevel10k" trash(p10k_path) - run(f"git clone --depth=1 https://github.com/romkatv/powerlevel10k.git {p10k_path}") + system( + f"git clone --depth=1 https://github.com/romkatv/powerlevel10k.git {p10k_path}" + ) log.log("Installing zsh syntax highlighter") zsh_syntax_highlighting_path = ( f"{home_dir}/.oh-my-zsh/custom/plugins/zsh-syntax-highlighting" ) trash(zsh_syntax_highlighting_path) - run( + system( f"git clone --depth=1 https://github.com/zsh-users/zsh-syntax-highlighting.git {zsh_syntax_highlighting_path}" ) @@ -35,4 +38,4 @@ def setup(): copy_file("home/.zshrc") # set the default terminal to zsh - run("chsh -s /bin/zsh") + system("chsh -s /bin/zsh") diff --git a/src/util.py b/src/util.py index b91898f..b2d78d4 100644 --- a/src/util.py +++ b/src/util.py @@ -8,21 +8,6 @@ from src.log import error import src.constants -def run(command: str, hide_stdout: bool = True, hide_stderr: bool = True) -> None: - """os.system but has an option to hide stdout and/or stderr. - A copy of this function also exists in `setup.py`.""" - - if hide_stderr: - system(f"{command} &> /dev/null") - return - - if hide_stdout: - system(f"{command} > /dev/null") - return - - system(command) - - def run_and_return(command: str) -> list[str]: """Runs command in system shell and return the result. This is a blocking function. @@ -31,9 +16,7 @@ def run_and_return(command: str) -> list[str]: return popen(command).readlines() -def paru_install( - packages: str | list[str], hide_stdout: bool = True, hide_stderr: bool = True -) -> None: +def paru_install(packages: str | list[str]) -> None: """ Download arch linux packages (including AUR). @@ -49,12 +32,10 @@ def paru_install( error("Invalid paru packages format.") return - run(f"paru -S --noconfirm {packages}", hide_stdout, hide_stderr) + system(f"paru -S --noconfirm {packages}") -def flatpak_install( - packages: str, hide_stdout: bool = True, hide_stderr: bool = True -) -> None: +def flatpak_install(packages: str) -> None: """ Download packages from flathub. @@ -62,7 +43,7 @@ def flatpak_install( packages: space-separated list of packages. """ - run(f"flatpak install -y {packages}", hide_stdout, hide_stderr) + system(f"flatpak install -y {packages}") def smart_mkdir(path: str) -> None: @@ -76,23 +57,17 @@ def smart_mkdir(path: str) -> None: pass -def trash(path, hide_stdout: bool = True, hide_stderr: bool = True) -> None: +def trash(path) -> None: """Moves a file or directory to freedesktop trash.""" try: - run(f"trash-put {path}", hide_stdout, hide_stderr) + system(f"trash-put {path}") except Exception as err: print(f"Failed to remove: {path}") raise err -def copy_file( - src_file: str, - mode="644", - sudo=False, - hide_stdout: bool = True, - hide_stderr: bool = True, -) -> None: +def copy_file(src_file: str, mode="644", sudo=False) -> None: """ Copies a file in the repo to the system. If the `src_file` starts with `home/`, it maps to $HOME. @@ -117,12 +92,10 @@ def copy_file( if sudo: command = f"sudo {command}" - run(command, hide_stdout, hide_stderr) + system(command) -def copy_directory( - src: str, dst: str, hide_stdout: bool = True, hide_stderr: bool = True -) -> None: +def copy_directory(src: str, dst: str) -> None: """Copy a directory. Automatically creates parent directory/directories of dst if it does not exist already @@ -131,19 +104,13 @@ def copy_directory( dst: A path-like object or string pointing to a directory. """ - run(f"cp -R {src} {dst}", hide_stdout, hide_stderr) + system(f"cp -R {src.constants.content_dir}{src} {dst}") -def load_dconf( - file_name: str, hide_stdout: bool = True, hide_stderr: bool = True -) -> None: +def load_dconf(file_name: str) -> None: """Loads dconf configuration""" - run( - f'dconf load / < "{src.constants.content_dir}/files/dconf/{file_name}"', - hide_stdout, - hide_stderr, - ) + system(f'dconf load / < "{src.constants.content_dir}/files/dconf/{file_name}"') def download(file_name: str, url: str) -> None: