-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a03b70b
commit a91d8db
Showing
10 changed files
with
226 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
import os | ||
|
||
from zrb.builtin.group import setup_dev_group | ||
from zrb.builtin.setup.dev.asdf_helper import ( | ||
check_asdf_dir, | ||
get_install_prerequisites_cmd, | ||
setup_asdf_ps_config, | ||
setup_asdf_sh_config, | ||
) | ||
from zrb.context.any_context import AnyContext | ||
from zrb.input.bool_input import BoolInput | ||
from zrb.input.option_input import OptionInput | ||
from zrb.task.cmd_task import CmdTask | ||
from zrb.task.make_task import make_task | ||
from zrb.task.task import Task | ||
|
||
install_asdf_prerequisites = CmdTask( | ||
name="install-asdf-prerequisites", | ||
input=[ | ||
OptionInput( | ||
name="package-manager", | ||
description="Your package manager", | ||
prompt="Your package manager", | ||
options=["apt", "dnf", "pacman", "zypper", "brew", "spack"], | ||
default_str="apt", | ||
), | ||
BoolInput( | ||
name="use-sudo", | ||
description="Use sudo or not", | ||
prompt="Need sudo", | ||
default_str="yes", | ||
), | ||
], | ||
cmd=get_install_prerequisites_cmd, | ||
) | ||
|
||
|
||
download_asdf = CmdTask( | ||
name="download-asdf", | ||
cmd="git clone https://github.com/asdf-vm/asdf.git ~/.asdf --branch v0.14.1", | ||
execute_condition=check_asdf_dir, | ||
) | ||
install_asdf_prerequisites >> download_asdf | ||
|
||
|
||
@make_task( | ||
name="setup-asdf-on-bash", | ||
input=BoolInput( | ||
name="setup-bash", | ||
description="Setup bash", | ||
prompt="Setup bash", | ||
default_str="yes", | ||
), | ||
execute_condition='{ctx.input["setup_bash"]}', | ||
upstream=download_asdf, | ||
) | ||
def setup_asdf_on_bash(ctx: AnyContext): | ||
setup_asdf_sh_config(os.path.expanduser(os.path.join("~", ".bashrc"))) | ||
|
||
|
||
@make_task( | ||
name="setup-asdf-on-zsh", | ||
input=BoolInput( | ||
name="setup-zsh", description="Setup zsh", prompt="Setup zsh", default_str="yes" | ||
), | ||
execute_condition='{ctx.input["setup_zsh"]}', | ||
upstream=download_asdf, | ||
) | ||
def setup_asdf_on_zsh(ctx: AnyContext): | ||
setup_asdf_sh_config(os.path.expanduser(os.path.join("~", ".zshrc"))) | ||
|
||
|
||
@make_task( | ||
name="setup-asdf-on-powershell", | ||
input=BoolInput( | ||
name="setup-powershell", | ||
description="Setup powershell", | ||
prompt="Setup powershell", | ||
default_str="yes", | ||
), | ||
execute_condition='{ctx.input["setup_powershell"]}', | ||
upstream=download_asdf, | ||
) | ||
def setup_asdf_on_powershell(ctx: AnyContext): | ||
setup_asdf_ps_config( | ||
os.path.expanduser(os.path.join("~", ".config", "powershell", "profile.ps1")) | ||
) | ||
|
||
|
||
setup_asdf = setup_dev_group.add_task( | ||
Task(name="setup-asdf", description="🧰 Setup `asdf`."), alias="asdf" | ||
) | ||
setup_asdf << [setup_asdf_on_bash, setup_asdf_on_zsh, setup_asdf_on_powershell] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import os | ||
|
||
from zrb.context.any_context import AnyContext | ||
|
||
|
||
def get_install_prerequisites_cmd(ctx: AnyContext) -> str: | ||
package_manager: str = ctx.input["package-manager"] | ||
if package_manager in ["brew", "spack"]: | ||
cmd = "{package_manager} install coreutils curl git" | ||
elif package_manager == "pacman": | ||
cmd = "{package_manager} -S curl git" | ||
else: | ||
cmd = "{package_manager} install curl git" | ||
use_sudo: bool = ctx.input["use-sudo"] | ||
if use_sudo: | ||
return "sudo {cmd}" | ||
return cmd | ||
|
||
|
||
def check_asdf_dir(_: AnyContext): | ||
asdf_dir = os.path.expanduser(os.path.join("~", ".asdf")) | ||
return os.path.isdir(asdf_dir) | ||
|
||
|
||
def setup_asdf_sh_config(file_path: str): | ||
_setup_asdf_config(file_path, '. "$HOME/.asdf/asdf.sh"') | ||
|
||
|
||
def setup_asdf_ps_config(file_path: str): | ||
_setup_asdf_config(file_path, '. "$HOME/.asdf/asdf.ps1"') | ||
|
||
|
||
def _setup_asdf_config(file_path: str, asdf_config: str): | ||
dir_path = os.path.dirname(file_path) | ||
os.makedirs(dir_path, exist_ok=True) | ||
with open(file_path, "r") as f: | ||
content = f.read() | ||
if asdf_config in content: | ||
return | ||
with open(file_path, "a") as f: | ||
f.write(f"\n{asdf_config}\n") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
from zrb.builtin.group import setup_latex_group | ||
from zrb.builtin.setup.system.ubuntu import setup_ubuntu | ||
from zrb.task.cmd_task import CmdTask | ||
|
||
setup_latex_on_ubuntu = setup_latex_group.add_task( | ||
CmdTask( | ||
name="setup-latex-on-ubuntu", | ||
description="🐧 Setup LaTeX on Ubuntu", | ||
cmd=[ | ||
"sudo apt install -y \\", | ||
"texlive-full texlive-latex-base texlive-fonts-recommended \\", | ||
"texlive-fonts-extra texlive-latex-extra", | ||
], | ||
render_cmd=False, | ||
), | ||
alias="ubuntu", | ||
) | ||
setup_ubuntu >> setup_latex_on_ubuntu |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
from zrb.builtin.group import setup_system_group | ||
from zrb.task.cmd_task import CmdTask | ||
|
||
update_ubuntu = CmdTask(name="update-ubuntu", cmd="sudo apt update", render_cmd=False) | ||
|
||
upgrade_todo = CmdTask( | ||
name="upgrade-ubuntu", cmd="sudo apt upgrade -y", render_cmd=False | ||
) | ||
update_ubuntu >> upgrade_todo | ||
|
||
setup_ubuntu = setup_system_group.add_task( | ||
CmdTask( | ||
name="setup-ubuntu", | ||
description="🐧 Setup ubuntu", | ||
cmd=[ | ||
"sudo apt install -y \\", | ||
"build-essential python3-distutils libssl-dev zlib1g-dev \\" | ||
"libbz2-dev libreadline-dev libsqlite3-dev libpq-dev python3-dev \\", | ||
"llvm libncurses5-dev libncursesw5-dev xz-utils tk-dev libffi-dev \\", | ||
"liblzma-dev python3-openssl libblas-dev liblapack-dev rustc \\", | ||
"golang gfortran fd-find ripgrep wget curl git ncat zip unzip \\", | ||
"cmake make tree tmux zsh neovim xdotool xsel", | ||
], | ||
render_cmd=False, | ||
), | ||
alias="ubuntu", | ||
) | ||
upgrade_todo >> setup_ubuntu |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters