From 27e4b5978c33305d18fe9e4bcbf4930bd0b49e40 Mon Sep 17 00:00:00 2001 From: CrimsonTome Date: Tue, 22 Nov 2022 18:40:45 +0000 Subject: [PATCH] chore: too much pain --- .gitignore | 0 post-install | 27 +++++++++++++++++++++++++++ post-install.py | 44 ++++++++++++++++++++++++++++++++++++++++++++ pyinfra-debug.log | 21 +++++++++++++++++++++ 4 files changed, 92 insertions(+) create mode 100644 .gitignore create mode 100755 post-install create mode 100644 post-install.py create mode 100644 pyinfra-debug.log diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e69de29 diff --git a/post-install b/post-install new file mode 100755 index 0000000..214dd97 --- /dev/null +++ b/post-install @@ -0,0 +1,27 @@ +#!/usr/bin/env bash + + +# set some variables + +homeDir=$HOME +echo $homeDir + +hostname=$HOSTNAME +echo $hostname + +os=$(lsb_release -d| awk '{print $2}') # definitely works on Fedora +echo $os + +# ensure some directories exist +gitDir=$homeDir"/git" +[ ! -d $gitDir ] && mkdir -p $gitDir || echo $gitDir" already exists" + +sshDir=$homeDir"/.ssh" +[ ! -d $sshDir ] && mkdir -p $sshDir || echo $sshDir" already exists" + +configDir=$homeDir"/.config" +[ ! -d $configDir ] && mkdir -p $configDir || echo $configDir" already exists" + + +# create an ssh key, for use with git/github +ssh-keygen -t ed25519 -f $sshDir"/id_ed25519_git" -N '' \ No newline at end of file diff --git a/post-install.py b/post-install.py new file mode 100644 index 0000000..e567ab7 --- /dev/null +++ b/post-install.py @@ -0,0 +1,44 @@ +from pyinfra import host +from pyinfra.facts.files import File +from pyinfra.facts.server import LinuxName +from pyinfra.operations import apt, server, dnf, files + + +os = host.get_fact(LinuxName) +print (os) + + +# why does this not work???? +# username = host.get_fact(User) +username = str(server.shell("whoami")) +print(username) + +hostname = host.get_fact(server.Hostname) +print(hostname) + +# why does this not work???? +# homeDir = host.get_fact(server.Home) + +homeDir = str(server.shell("echo $HOME")) +print(homeDir) + +# files.directory( +# name="Ensure /home/username/git exists", +# path=str(homeDir)+"/git", +# user=username, +# group=username, +# ) + +# files.directory( +# name="Ensure /home/username/.config exists", +# path=str(homeDir)+"/.config", +# user=username, +# group=username, +# ) + +# files.directory( +# name="Ensure /home/username/.ssh exists", +# path=str(homeDir)+"/.ssh", +# user=username, +# group=username, +# ) diff --git a/pyinfra-debug.log b/pyinfra-debug.log new file mode 100644 index 0000000..e2a1c54 --- /dev/null +++ b/pyinfra-debug.log @@ -0,0 +1,21 @@ + File "/home/ctome/.local/pipx/venvs/pyinfra/lib64/python3.11/site-packages/pyinfra_cli/main.py", line 224, in cli + _main(*args, **kwargs) + File "/home/ctome/.local/pipx/venvs/pyinfra/lib64/python3.11/site-packages/pyinfra_cli/main.py", line 355, in _main + state, config = _handle_commands(state, config, command, original_operations, operations, quiet) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + File "/home/ctome/.local/pipx/venvs/pyinfra/lib64/python3.11/site-packages/pyinfra_cli/main.py", line 612, in _handle_commands + state, config, operations = _run_deploy_operations(state, config, operations, quiet) + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + File "/home/ctome/.local/pipx/venvs/pyinfra/lib64/python3.11/site-packages/pyinfra_cli/main.py", line 669, in _run_deploy_operations + load_deploy_file(state, filename) + File "/home/ctome/.local/pipx/venvs/pyinfra/lib64/python3.11/site-packages/pyinfra_cli/util.py", line 247, in load_deploy_file + raise result + File "/home/ctome/.local/pipx/venvs/pyinfra/lib64/python3.11/site-packages/pyinfra_cli/util.py", line 227, in load_file + exec_file(filename) + File "/home/ctome/.local/pipx/venvs/pyinfra/lib64/python3.11/site-packages/pyinfra_cli/util.py", line 50, in exec_file + code = compile(code, filename, "exec") + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + File "post-install.py", line 22 + homeDir = str(server.shell(("echo $HOME")) + ^ +SyntaxError: '(' was never closed