dotfiles

<-- duh.
Log | Files | Refs | LICENSE

commit 91335e29825b71caf18b228e43bdded292886609
parent f396552ad536da37f08f936c19bda6f8c80f1493
Author: hhvn <dev@hhvn.uk>
Date:   Wed, 21 Jul 2021 14:49:08 +0100

.l/rootfiles: manage non-dotfile configs in dotfiles :)

Diffstat:
A.local/rootfiles/etc/doas.conf | 2++
A.local/rootfiles/etc/fuse.conf | 1+
A.local/rootfiles/etc/xbps.d/conf | 2++
A.local/rootfiles/install.sh | 50++++++++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 55 insertions(+), 0 deletions(-)

diff --git a/.local/rootfiles/etc/doas.conf b/.local/rootfiles/etc/doas.conf @@ -0,0 +1,2 @@ +permit nopass $INSTALL_ENV_USER +permit nopass root diff --git a/.local/rootfiles/etc/fuse.conf b/.local/rootfiles/etc/fuse.conf @@ -0,0 +1 @@ +user_allow_other diff --git a/.local/rootfiles/etc/xbps.d/conf b/.local/rootfiles/etc/xbps.d/conf @@ -0,0 +1,2 @@ +ignorepkg=sudo +ignorepkg=dbus diff --git a/.local/rootfiles/install.sh b/.local/rootfiles/install.sh @@ -0,0 +1,50 @@ +#!/bin/sh +# I think a script is more appropriate than a makefile, here + +[ "$USER" = "root" ] && { + printf 'run this from your user account\n' + exit 1 +} + +# substitute $INSTALL_ENV_FOO for $FOO +_envsubst(){ + str=$(cat | tr '\n' '\f') + + env | + while read -r line + do + str=$(printf '%s\n' "$str" | awk -v "var=${line%%=*}" -v "val=${line#*=}" ' + { + regex = sprintf("\\$INSTALL_ENV_%s", var) + gsub(regex, val) + print + }' + ) + printf "\n%s" "$str" + done | tail -n 1 | tr '\f' '\n' + # combine echo/tail here, due to weirdness with while loops + # appears to be like a subshell, but also not: + # - variable persists between each section of a loop + # - variable doesn't persist after leaving the loop +} + +dirs=$(find . -type d) +files=$(find . -mindepth 2 -type f) + +export IFS=$(printf '\n\t') +for dir in $dirs +do + printf 'creating %s... ' "$dir" + dest=$(printf '%s\n' "$dir" | sed 's~^\.~~') + mkdir -p $dest + printf 'done\n' +done + +for file in $files +do + printf 'creating %s... ' "$file" + dest=$(printf '%s\n' "$file" | sed 's~^\.~~') + content=$(_envsubst < "$file") + printf '%s\n' "$content" | doas tee "$dest" >/dev/null + printf 'done\n' +done