From 93fec1c8a4b43b6d5e257143acc4b0eb7a231389 Mon Sep 17 00:00:00 2001 From: John Doty Date: Fri, 10 Nov 2023 15:52:57 +0000 Subject: [PATCH] fix coder setup maybe --- coder-setup.py | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++ install.sh | 22 ++---------------- 2 files changed, 63 insertions(+), 20 deletions(-) create mode 100644 coder-setup.py diff --git a/coder-setup.py b/coder-setup.py new file mode 100644 index 0000000..4da7e98 --- /dev/null +++ b/coder-setup.py @@ -0,0 +1,61 @@ +import os +import pathlib +import subprocess +import urllib.request + + +def run(*args): + subprocess.run(args, check=True) + + +def install_packages(): + packages = [ + "atop", + "fish", + "htop", + "java-common", + "unixodbc-dev", + "wget", + ] + + run("sudo", "apt", "update") + run("sudo", "apt", "install", "-y", *packages) + + +def change_shell(): + run("sudo", "chsh", "-s", "/usr/bin/fish", os.environ["USER"]) + run("/usr/bin/fish", "./setup.fish") + + +def configure_git(): + run("git", "config", "--global", "include.path", ".gitconfig.shared") + + +def backup_pip(): + pip = pathlib.Path.home() / ".config" / "pip" + if pip.exists(): + pip.rename("pip.bak") + + +def restore_pip(): + pip = pathlib.Path.home() / ".config" / "pip.bak" + if pip.exists(): + pip.rename("pip") + + +def configure_python(): + backup_pip() + try: + run("pip3", "install", "black") + run("sudo", "npm", "install", "-g", "prettier", "pyright") + + installer = urllib.request.urlopen("https://install.python-poetry.org").read() + subprocess.run(["python3", "-"], input=installer, check=True) + finally: + restore_pip() + + +install_packages() +change_shell() +configure_git() +configure_python() diff --git a/install.sh b/install.sh index 9b2cde1..64822a1 100755 --- a/install.sh +++ b/install.sh @@ -10,23 +10,5 @@ cd $MY_PATH # Run the basic setup. python3 "./setup.py" -# # OK this stuff here is better in bash, and also is specific to setting up -# # coder.com instances, so. Add packages that I want in my coder image. -sudo apt update -sudo apt install -y wget fish java-common atop htop - -# Change my shell to fish. -sudo chsh -s /usr/bin/fish $USER - -# Install fish related stuff -/usr/bin/fish "./setup.fish" - -# Make sure that the gitconfig that's on my computer links to my shared -# config. -git config --global include.path .gitconfig.shared - -# Install blacken and prettier and some versions of python. -pip3 install --index-url=https://pypi.org/simple black -sudo npm install -g prettier pyright -curl -sSL https://install.python-poetry.org | python3 - - +# Run the coder setup. +python3 "./coder-setup.py"