commit abba24b484576a8b98d666d49c8819f6a7f7a76b
parent 066dae618f08e8186e71128dce4ae7ebf2d22820
Author: Jacob R. Edwards <jacobouno@protonmail.com>
Date: Sun, 22 Nov 2020 14:25:45 -0800
Add `sysconf' script and related files
This rc(1) script is suppost to be used to copy specific user
configuration files to system wide locations.
Add sysconf config to copy the git, ksh, profile, shell, and tmux
config modules to system wide locations on OpenBSD.
Diffstat:
4 files changed, 89 insertions(+), 0 deletions(-)
diff --git a/Makefile b/Makefile
@@ -8,6 +8,7 @@ MODULES = git\
scripts\
shell\
sxiv\
+ sysconf\
tmux\
vim\
vimb\
diff --git a/modules/profile/.profile b/modules/profile/.profile
@@ -16,6 +16,7 @@ export HISTBASE="$HOME/.local/var"
export INPUTRC="$XDG_CONFIG_HOME/readline"
export PASSWORD_STORE_DIR="$HOME/.local/var/pass"
+export CONFIG_DIR="$HOME/own/config/modules"
export DICT_DIR="$HOME/.local/share/wdef"
export FEED_DIR="$HOME/.local/var/rss"
export PWDLOG="$HOME/.local/var/pwd.log"
diff --git a/modules/scripts/.local/bin/sysconf b/modules/scripts/.local/bin/sysconf
@@ -0,0 +1,78 @@
+#!/usr/local/bin/rc -e
+#! sysconf -- copy or remove files from a list of files
+#!
+#! There are three commands defined, h(elp), i(nstall), u(ninstall), and
+#! l(ist) or ls. The list command is default.
+#!
+#! Each item on the file list not prefixed by hash (`#') and not empty is
+#! evaluated with rc(1)'s eval then executed. The format of each item
+#! should be `$src[<tab><space>]+$dst'.
+#!
+#! sysconf first checks SYSCONF for the list, then
+#! XDG_CONFIG_HOME/sysconf, and finally HOME/.config/sysconf.
+
+__progname = `{ basename $0 }
+
+# utility
+fn warn { printf '%s: ' $__progname && printf $* >[2=1] }
+fn err { warn $*; exit 1 }
+
+# config processing
+fn filter { grep -ve '^#' -e '^$' $* }
+fn match { egrep $* }
+
+# command execution
+fn intern { }
+fn execute {
+ if (test $#* -ne 2) {
+ warn 'execute: Invalid argument count (%d).\n' $#* >[2=1]
+ return 1
+ }
+ intern $*
+}
+
+if (test $#* -lt 1)
+ * = ('ls');
+switch ($1) {
+ case i install
+ fn intern { cp -vr $1 $2 }
+ case u uninstall
+ fn intern {
+ if (test -d $1) {
+ rm -vr $2
+ } else {
+ rm -v $2;
+ }
+ }
+ case l ls list
+ fn intern {
+ suffix = ''
+ if (test -e $2)
+ suffix = ' (installed)'
+ printf '%s -> %s%s\n' $1 $2 $suffix
+ }
+ case h help
+ grep '^#! ' $0 | cut -c4- >[2=1]
+ exit 1
+ case *
+ err '''%s'': Invalid command.\n' $1
+}
+
+if (test -z $SYSCONF) {
+ if (test -z $XDG_CONFIG_HOME)
+ XDG_CONFIG_HOME = $HOME^/.config;
+ SYSCONF = $XDG_CONFIG_HOME^/sysconf
+}
+
+ifs = '
+'
+if (test $#* -eq 1) {
+ commands = `{ filter $SYSCONF }
+} else if (test $#* -eq 2) {
+ commands = `{ filter $SYSCONF | match $2 }
+} else
+ err '''%d'': Too many arguments given.\n' $#*;
+
+ifs = ' ' # <space><tab>
+for (command in $commands)
+ eval execute $command
diff --git a/modules/sysconf/.config/sysconf b/modules/sysconf/.config/sysconf
@@ -0,0 +1,9 @@
+# System configuration paths
+$CONFIG_DIR/git/.config/git/config /etc/gitconfig
+$CONFIG_DIR/ksh/.config/ksh.kshrc /etc/ksh.kshrc
+$CONFIG_DIR/profile/.profile /etc/profile
+$CONFIG_DIR/shell/ /usr/local/share/shell/
+$CONFIG_DIR/tmux/.tmux.conf /etc/tmux.conf
+
+# Vim refuses to source the global vimrc on OpenBSD
+#$CONFIG/vim/.vimrc /usr/local/share/vim/vimrc