From f53e8244ca5b934ba2b9f7d1b8e6302421eaed5f Mon Sep 17 00:00:00 2001
From: "Edgar P. Burkhart" <git@edgarpierre.fr>
Date: Tue, 25 Oct 2022 18:54:00 +0200
Subject: [PATCH] Added Powershell & git configuration

---
 .gitignore                 |  1 +
 config.toml                |  3 +++
 config.windows.toml        |  7 +++++++
 config/__init__.py         |  8 +++++++
 config/__main__.py         | 43 ++++++++++++++++++++++++++++++++++++++
 config/log.conf            | 27 ++++++++++++++++++++++++
 src/Git/gitconfig          |  8 +++++++
 src/PowerShell/profile.ps1 |  8 +++++++
 8 files changed, 105 insertions(+)
 create mode 100644 .gitignore
 create mode 100644 config.toml
 create mode 100644 config.windows.toml
 create mode 100644 config/__init__.py
 create mode 100644 config/__main__.py
 create mode 100644 config/log.conf
 create mode 100644 src/Git/gitconfig
 create mode 100644 src/PowerShell/profile.ps1

diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..bee8a64
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+__pycache__
diff --git a/config.toml b/config.toml
new file mode 100644
index 0000000..9d77372
--- /dev/null
+++ b/config.toml
@@ -0,0 +1,3 @@
+[PowerShell]
+in="src/PowerShell/profile.ps1"
+out="~/Documents/WindowsPowerShell"
diff --git a/config.windows.toml b/config.windows.toml
new file mode 100644
index 0000000..58146ec
--- /dev/null
+++ b/config.windows.toml
@@ -0,0 +1,7 @@
+[PowerShell]
+in="src/PowerShell/profile.ps1"
+out="~/Documents/WindowsPowerShell"
+
+[Git]
+in="src/git/gitconfig"
+out="~/.gitconfig"
diff --git a/config/__init__.py b/config/__init__.py
new file mode 100644
index 0000000..953194e
--- /dev/null
+++ b/config/__init__.py
@@ -0,0 +1,8 @@
+import pathlib
+
+def get_io(conf):
+    _in = pathlib.Path(conf.get("in")).expanduser()
+    _out = pathlib.Path(conf.get("out")).expanduser()
+    if _out.is_dir():
+        _out = _out.joinpath(_in.name)
+    return _in, _out
diff --git a/config/__main__.py b/config/__main__.py
new file mode 100644
index 0000000..a738372
--- /dev/null
+++ b/config/__main__.py
@@ -0,0 +1,43 @@
+import argparse
+import logging
+import logging.config
+import pathlib
+import shutil
+import sys
+import tomllib
+
+
+from . import get_io
+
+
+logging.config.fileConfig(pathlib.Path(__file__).parent.joinpath("log.conf"))
+log = logging.getLogger("config")
+
+_argp = argparse.ArgumentParser(
+        prog="Config",
+        description="Install custom configurations",
+)
+
+_argp.add_argument("-c", "--config", default="config.toml", type=pathlib.Path, help="Configuration file location")
+
+args = _argp.parse_args()
+
+log.info("Config installation starting")
+
+log.info(f"Loading configuration file <{args.config}>")
+try:
+    with open(args.config, "rb") as _config_file:
+        config = tomllib.load(_config_file)
+except FileNotFoundError:
+    log.error(f"Configuration file <{args.config}> does not exist.")
+    sys.exit(1)
+
+if (_ps := config.get("PowerShell", None)):
+    _in, _out = get_io(_ps)
+    log.info(f"Copying PowerShell configuration from <{_in}> to <{_out}>")
+    shutil.copyfile(_in, _out)
+
+if (_git := config.get("Git", None)):
+    _in, _out = get_io(_git)
+    log.info(f"Copying Git configuration from <{_in}> to <{_out}>")
+    shutil.copyfile(_in, _out)
diff --git a/config/log.conf b/config/log.conf
new file mode 100644
index 0000000..45dca6f
--- /dev/null
+++ b/config/log.conf
@@ -0,0 +1,27 @@
+[loggers]
+keys=root,config
+
+[handlers]
+keys=consoleHandler
+
+[formatters]
+keys=simpleFormatter
+
+[logger_root]
+level=INFO
+handlers=consoleHandler
+
+[logger_config]
+level=INFO
+handlers=consoleHandler
+qualName=config
+propagate=0
+
+[handler_consoleHandler]
+class=StreamHandler
+level=INFO
+formatter=simpleFormatter
+args=(sys.stdout,)
+
+[formatter_simpleFormatter]
+format=%(asctime)s - %(name)s#%(levelname)s %(message)s
diff --git a/src/Git/gitconfig b/src/Git/gitconfig
new file mode 100644
index 0000000..d35a81d
--- /dev/null
+++ b/src/Git/gitconfig
@@ -0,0 +1,8 @@
+[user]
+	name = Edgar P. Burkhart
+	email = git@edgarpierre.fr
+	signingkey = 9833D3C5A25BD227
+[commit]
+	gpgsign = true
+[tag]
+	gpgsign = true
diff --git a/src/PowerShell/profile.ps1 b/src/PowerShell/profile.ps1
new file mode 100644
index 0000000..4ade763
--- /dev/null
+++ b/src/PowerShell/profile.ps1
@@ -0,0 +1,8 @@
+if ($host.Name -eq 'ConsoleHost')
+{
+	Import-Module PSReadLine
+	Set-PSReadlineOption -EditMode Emacs
+	function Wake-Orchomenos {
+		ssh leopold.burkhart.ovh wakeonlan 70:85:C2:8C:BA:BB
+	}
+}
