aboutsummaryrefslogtreecommitdiff
path: root/packages
diff options
context:
space:
mode:
authorKenny Ballou <kballou@devnulllabs.io>2021-01-20 19:18:23 -0700
committerKenny Ballou <kballou@devnulllabs.io>2021-01-21 13:16:22 -0700
commitc357715fbe477a903dc89aaab0a9b356411bd4a6 (patch)
treeebc0e2cdb6662dd252ac3d9540bed1c7e8865ecb /packages
parenta59f5bb7da82d6b54b65579432f1b7a3fb03aaa7 (diff)
downloaddotfiles-c357715fbe477a903dc89aaab0a9b356411bd4a6.tar.gz
dotfiles-c357715fbe477a903dc89aaab0a9b356411bd4a6.tar.xz
scripts: move shell scripts into mini nix packages
Move over scripts that were symlinked into the PATH into scripts that are installed as nix "packages". Several docker and mount scripts are not ported and simply removed. Signed-off-by: Kenny Ballou <kballou@devnulllabs.io>
Diffstat (limited to 'packages')
-rw-r--r--packages/scripts/gen-sshconfig-sh/default.nix3
-rwxr-xr-xpackages/scripts/gen-sshconfig-sh/gen-sshconfig.sh32
-rw-r--r--packages/scripts/git-sync-py/default.nix3
-rwxr-xr-xpackages/scripts/git-sync-py/git-sync.py84
-rw-r--r--packages/scripts/install-git-hooks-sh/default.nix3
-rwxr-xr-xpackages/scripts/install-git-hooks-sh/install-git-hooks.sh9
-rw-r--r--packages/scripts/shadir-sh/default.nix7
-rw-r--r--packages/scripts/shreddir-sh/default.nix14
8 files changed, 155 insertions, 0 deletions
diff --git a/packages/scripts/gen-sshconfig-sh/default.nix b/packages/scripts/gen-sshconfig-sh/default.nix
new file mode 100644
index 00000000..0e7fa638
--- /dev/null
+++ b/packages/scripts/gen-sshconfig-sh/default.nix
@@ -0,0 +1,3 @@
+{ pkgs, ... }:
+
+pkgs.writeScriptBin "gen-sshconfig" (builtins.readFile ./gen-sshconfig.sh)
diff --git a/packages/scripts/gen-sshconfig-sh/gen-sshconfig.sh b/packages/scripts/gen-sshconfig-sh/gen-sshconfig.sh
new file mode 100755
index 00000000..1fd796f8
--- /dev/null
+++ b/packages/scripts/gen-sshconfig-sh/gen-sshconfig.sh
@@ -0,0 +1,32 @@
+#!/usr/bin/env bash
+
+# gen_sshconfig.sh -- Simple script to combine ssh configs
+# Copyright (C) 2017 Kenny Ballou
+
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+SSH_CONFIG_DIR=${HOME}/.ssh
+SSH_CONFIG=${SSH_CONFIG_DIR}/config
+SSH_CONFIGS_DIR=${SSH_CONFIG_DIR}/config.d
+
+mv "${SSH_CONFIG}" "${SSH_CONFIG}-$(date -Iseconds).old"
+
+cat << EOF > "${SSH_CONFIG}"
+# vim: filetype=sshconfig:
+# DO NOT EDIT THIS FILE!
+# This file is automatically generated via "gen_sshconfig.sh".
+# Edits will be lost the next time "gen_sshconfig.sh" is used.
+EOF
+
+cat "${SSH_CONFIGS_DIR}"/*.conf | grep --invert-match '^#' >> "${SSH_CONFIG}"
diff --git a/packages/scripts/git-sync-py/default.nix b/packages/scripts/git-sync-py/default.nix
new file mode 100644
index 00000000..273183b2
--- /dev/null
+++ b/packages/scripts/git-sync-py/default.nix
@@ -0,0 +1,3 @@
+{ pkgs, ...}:
+
+pkgs.writeScriptBin "git_sync.py" (builtins.readFile ./git-sync.py)
diff --git a/packages/scripts/git-sync-py/git-sync.py b/packages/scripts/git-sync-py/git-sync.py
new file mode 100755
index 00000000..e449df8e
--- /dev/null
+++ b/packages/scripts/git-sync-py/git-sync.py
@@ -0,0 +1,84 @@
+#!/usr/bin/env python
+'''Synchronize git workspace directories'''
+
+import os
+import subprocess
+import queue
+import threading
+import multiprocessing
+from funcy import compose
+from funcy import partial
+
+NPROC = min(int(multiprocessing.cpu_count() * 2 / 3), 4)
+WORKSPACE_DIR = os.path.join(os.environ['HOME'], 'workspace')
+EXCLUDES = [
+ 'tmp',
+ 'deps',
+ 'fixtures',
+ 'temp']
+
+
+class GitSyncRunner(threading.Thread):
+ '''Threaded git synchronization runner'''
+ def __init__(self, wqueue):
+ threading.Thread.__init__(self)
+ self.wqueue = wqueue
+
+ def run(self):
+ '''thread entry point'''
+ while True:
+ git_project = self.wqueue.get()
+ self.perform_git_sync(git_project)
+
+ def perform_git_sync(self, git_project):
+ '''perform git synchronization'''
+ subprocess.call(['git', '-C', git_project, 'remote', 'update', '-p'],
+ stdout=subprocess.DEVNULL,
+ stderr=subprocess.DEVNULL)
+ self.wqueue.task_done()
+
+
+def main(workspace):
+ '''main entry'''
+ wqueue = collect_git_projects(workspace)
+ for _ in range(NPROC):
+ thread = GitSyncRunner(wqueue)
+ thread.setDaemon(True)
+ thread.start()
+ wqueue.join()
+
+
+def collect_git_projects(workspace):
+ '''Collect the git projects in `workspace`'''
+ wqueue = queue.Queue()
+ compose(lambda projects: list(wqueue.put(x) for x in projects),
+ partial(filter_project_folders, EXCLUDES),
+ get_git_projects)(workspace)
+ return wqueue
+
+
+def get_git_projects(workspace):
+ '''walk workspace, collecting .git folders'''
+ def __walk__(path):
+ for root, dirs, _ in os.walk(path):
+ if '.git' in dirs:
+ dirs.remove('.git')
+ yield root
+ return __walk__(workspace)
+
+
+def filter_project_folders(excludes, projects):
+ '''filter out project folders based on `excludes`'''
+ def __path_in_excludes__(path):
+ for exclude in excludes:
+ if exclude in path:
+ return True
+ return False
+ for project in projects:
+ if __path_in_excludes__(project):
+ continue
+ yield project
+
+
+if __name__ == '__main__':
+ main(WORKSPACE_DIR)
diff --git a/packages/scripts/install-git-hooks-sh/default.nix b/packages/scripts/install-git-hooks-sh/default.nix
new file mode 100644
index 00000000..da2ca76f
--- /dev/null
+++ b/packages/scripts/install-git-hooks-sh/default.nix
@@ -0,0 +1,3 @@
+{ pkgs, ... }:
+
+pkgs.writeScriptBin "install-git-hooks.sh" (builtins.readFile ./install-git-hooks.sh)
diff --git a/packages/scripts/install-git-hooks-sh/install-git-hooks.sh b/packages/scripts/install-git-hooks-sh/install-git-hooks.sh
new file mode 100755
index 00000000..86401e03
--- /dev/null
+++ b/packages/scripts/install-git-hooks-sh/install-git-hooks.sh
@@ -0,0 +1,9 @@
+#!/usr/bin/env bash
+
+HOOKS="${HOME}/.git_template/hooks"
+GWD="$(pwd)/.git/hooks"
+
+mkdir -p ${GWD}
+printf "Installing hooks to: %s\n" "$GWD"
+
+cp --dereference "${HOOKS}"/* "${GWD}"/.
diff --git a/packages/scripts/shadir-sh/default.nix b/packages/scripts/shadir-sh/default.nix
new file mode 100644
index 00000000..4805f062
--- /dev/null
+++ b/packages/scripts/shadir-sh/default.nix
@@ -0,0 +1,7 @@
+{ pkgs, ... }:
+
+pkgs.writeScriptBin "shadir" ''
+#!${pkgs.bash}/bin/bash
+
+exec ${pkgs.findutils}/bin/find "$1" -type f -exec ${pkgs.coreutils}/bin/sha256sum {} > check.sha256 \;
+''
diff --git a/packages/scripts/shreddir-sh/default.nix b/packages/scripts/shreddir-sh/default.nix
new file mode 100644
index 00000000..a358e7f3
--- /dev/null
+++ b/packages/scripts/shreddir-sh/default.nix
@@ -0,0 +1,14 @@
+{ pkgs, ... }:
+
+pkgs.writeScriptBin "shreddir" ''
+#!${pkgs.bash}/bin/bash
+
+if [ "$1" = "" ]; then
+ echo "I'm not comfortable doing this..."
+ exit 1
+fi
+
+${pkgs.findutils}/bin/find "$1" -type f -print -exec ${pkgs.coreutils}/bin/shred -zu {} \;
+rm -rf $1
+
+''