usr

Modulate your userpace into POSIX-compliant shell scripts!
git clone git://clone.theohenson.com/usr.git
Log | Files | Refs | README

commit 23bcabc0b797668f763df3a668dc303774209e60
parent 992467c77d98141f2ad0679167943551b0265610
Author: Theo Henson <[email protected]>
Date:   Sun, 15 Nov 2020 11:11:57 -0500

Start remote functionality

Diffstat:
M.gitignore | 2+-
Mmodules/dotfiles.mod.sh | 0
Amodules/mod.list | 2++
Musr | 41++++++++++++++++++++++++++++++++++++-----
4 files changed, 39 insertions(+), 6 deletions(-)

diff --git a/.gitignore b/.gitignore @@ -1,5 +1,5 @@ *.o -installed/ +var/ home/src/suk/st/st home/src/suk/dwm/dwm home/src/suk/dwmblocks/dwmblocks diff --git a/modules/dotfiles.mod.sh b/modules/dotfiles.mod.sh diff --git a/modules/mod.list b/modules/mod.list @@ -0,0 +1,2 @@ +dotfiles +test diff --git a/usr b/usr @@ -4,8 +4,9 @@ set -e : "${USR_DIR:=$HOME/src/git/usr}" +mkdir -p "$USR_DIR"/var +mkdir -p "$USR_DIR"/home mkdir -p "$USR_DIR"/modules -mkdir -p "$USR_DIR"/installed die() { >&2 printf "%s\n" "$*" @@ -13,13 +14,13 @@ die() { } usage() { - die "usage: usr [-a <module>] [-r <module>] [-i <module>] [-l]" + die "usage: usr [-a <module>] | [-r <module>] | [-i <module>] | [-u] | [-l[i | r]]" } module_add() { MOD="$2" MOD_FILE="$USR_DIR/modules/$MOD".mod.sh - MOD_INSTALL="$USR_DIR/installed/$MOD" + MOD_INSTALL="$USR_DIR/var/$MOD".installed [ -e "$MOD_INSTALL" ] && die "$MOD is already installed" [ -z "$MOD" ] && usage @@ -35,7 +36,7 @@ module_add() { module_remove() { MOD="$2" MOD_FILE="$USR_DIR/modules/$MOD".mod.sh - MOD_INSTALL="$USR_DIR/installed/$MOD" + MOD_INSTALL="$USR_DIR/var/$MOD".installed [ -e "$MOD_INSTALL" ] || die "$MOD is not installed" [ -z "$MOD" ] && usage @@ -62,16 +63,46 @@ module_info() { list_modules() { for MOD in "$USR_DIR"/modules/*; do - [ -f "$MOD" ] && printf "%s\n" "$MOD" + if [ -f "$MOD" ] ; then + if [ "${MOD#*.}" = "mod.sh" ] ; then + NODOT=${MOD%%.*} + printf "%s\n" "${NODOT##*/}" + fi + fi done } +list_installed() { + for MOD in "$USR_DIR"/var/*; do + if [ -f "$MOD" ] ; then + if [ "${MOD#*.}" = "installed" ] ; then + NODOT=${MOD%%.*} + printf "%s\n" "${NODOT##*/}" + fi + fi + done +} + +list_remote() { + xargs printf "%s" <"$USR_DIR"/var/remote.list +} + +update_remote() { + xargs printf "url = %smod.list" <"$USR_DIR"/var/remote | curl -sLf -o "$USR_DIR"/var/remote.list -K - || die "error updating" +} + +[ -e "$USR_DIR"/modules/mod.list ] || list_modules > "$USR_DIR"/modules/mod.list +[ -e "$USR_DIR"/var/remote ] || printf "https://raw.githubusercontent.com/tteeoo/usr/main/modules/" > "$USR_DIR"/var/remote + case ${1#-} in h) usage ;; a) module_add "[email protected]" ;; r) module_remove "[email protected]" ;; i) module_info "[email protected]" ;; l) list_modules ;; + u) update_remote ;; + li) list_installed ;; + lr) list_remote ;; *) usage ;; esac