diff --git a/crates/alacritty/crate.sh b/crates/alacritty/crate.sh new file mode 100644 index 0000000..a5badc0 --- /dev/null +++ b/crates/alacritty/crate.sh @@ -0,0 +1,6 @@ +name="alacritty" +description="Set up alacritty" + +files() { + descfile -l files/alacritty.yml {{home}}/.config/alacritty/alacritty.yml +} \ No newline at end of file diff --git a/crates/alacritty/files/alacritty.yml b/crates/alacritty/files/alacritty.yml new file mode 100644 index 0000000..e69de29 diff --git a/crates/alacritty/package.list b/crates/alacritty/package.list new file mode 100644 index 0000000..f681b82 --- /dev/null +++ b/crates/alacritty/package.list @@ -0,0 +1 @@ +alacritty \ No newline at end of file diff --git a/crates/arch/crate.arch.sh b/crates/arch/crate.arch.sh new file mode 100644 index 0000000..5e31665 --- /dev/null +++ b/crates/arch/crate.arch.sh @@ -0,0 +1,11 @@ + +name="arch custom" +description="install's custom arch things" + +suscript ./ + +conditionfn is_arch + +is_arch() { + grep -q "arch" /etc/os-release +} \ No newline at end of file diff --git a/crates/arch/package.arch.list b/crates/arch/package.arch.list new file mode 100644 index 0000000..e69de29 diff --git a/crates/i3/crate.sh b/crates/i3/crate.sh new file mode 100755 index 0000000..bc6eeb6 --- /dev/null +++ b/crates/i3/crate.sh @@ -0,0 +1,8 @@ +#!/bin/sh + +name="i3" +description="Installs i3 with config" + +files() { + descfile -l ./files/i3config {{home}}/.config/i3/config +} \ No newline at end of file diff --git a/crates/i3/files/i3config b/crates/i3/files/i3config new file mode 100644 index 0000000..e69de29 diff --git a/crates/i3/package.list b/crates/i3/package.list new file mode 100644 index 0000000..0df1fae --- /dev/null +++ b/crates/i3/package.list @@ -0,0 +1,2 @@ +i3 +i3blocks \ No newline at end of file diff --git a/dot.sh b/dot.sh new file mode 100644 index 0000000..fa1130a --- /dev/null +++ b/dot.sh @@ -0,0 +1,13 @@ +#!/bin/sh + +for lib in $(find ./lib -type f -name *.lib.sh); do + . $lib +done + +__log_lvl=0 + +for crate in $(crates); do + debug "loading $crate..." + +done +echo "OK" \ No newline at end of file diff --git a/lib/crate-runner.sh b/lib/crate-runner.sh new file mode 100644 index 0000000..448b485 --- /dev/null +++ b/lib/crate-runner.sh @@ -0,0 +1,88 @@ +#!/bin/sh + +. ${LIB_DIR:-./lib}/crate.common.sh +. ${LIB_DIR:-./lib}/log.lib.sh +. ${LIB_DIR:-./lib}/vars.lib.sh + +file=$1 +action=$2 + + +run_crate_config_hooks() { + debug "running conditional functions..." + for condfn in $conditionfns; do + debug "running \"$condfn\"..." + $condfn || return 1 + done + files +} + +prompt_pending_actions() { + echo "This crate (${crate:-${1:-unknown}}) wants to make the following changes:" + if [ -n "$packages_marked_for_install" ]; then + echo "Install these packages:" + for pkg in $packages_marked_for_install; do + echo " $pkg" + done + fi + if [ -n "$packages_marked_for_removal" ]; then + echo "Remove these packages:" + for pkg in $packages_marked_for_removal; do + echo " $pkg" + done + fi + if [ -n "$files_to_link" ]; then + echo "Link these files:" + for link in $files_to_link; do + echo " $(echo $link | sed 's/:/ \-\> /')" + done + fi + if [ -n "$files_to_copy" ]; then + echo "Copy these files:" + for file in $files_to_copy; do + echo " $(echo $file | sed 's/:/ \-\> /')" + done + fi + printf "Is this okay? [press enter to continue] " + read +} + + +case $action in + config_check) + if ! run_crate_config_hooks; then + warn "crate config failed" + exit 1 + fi + + skip=0 + trap 'skip=1' INT + prompt_pending_actions + [ $skip -eq 1 ] && exit 1 + trap - INT + ;; + run) + if [ "$UID" = "0" ]; then + . + for script in $scripts_to_run_as_su; do + debug "script $script" + $script + done + pm -i $packages_marked_for_install + pm -r $packages_marked_for_removal + else + for file in $files_to_copy; do + debug "link $(echo "$file" | sed 's/:/ \-\> /g')" + cp $(echo "$file" | sed s'/:.*//g') $(echo "$file" | sed s'/.*://g') + done + for file in $files_to_link; do + debug "link $(echo "$file" | sed 's/:/ \-\> /g')" + ln $(echo "$file" | sed s'/:.*//g') $(echo "$file" | sed s'/.*://g') + done + for script in $scripts_to_run; do + debug "script $script" + $script + done + fi + ;; +esac \ No newline at end of file diff --git a/lib/crate.common.sh b/lib/crate.common.sh new file mode 100644 index 0000000..4712537 --- /dev/null +++ b/lib/crate.common.sh @@ -0,0 +1,44 @@ +#!/bin/sh + +script() { + scripts_to_run="$scripts_to_run $1" +} + +suscript() { + scripts_to_run_as_su="$scripts_to_run_as_su $1" +} + +pkgs() { + for pkg in $@; do + pkgname="$(echo $pkg | cut -c 2-)" + case $(echo $pkg | cut -c 1) in + +) + packages_marked_for_install="$packages_marked_for_install $pkgname" + ;; + -) + packages_marked_for_removal="$packages_marked_for_removal $pkgname" + ;; + esac + done +} + +conditionfn() { + conditionfns="$conditionfns $1" +} + +descfile() { + islink=${ALWAYS_LINK:-0} + while getopts "l" opt; do + case $opt in + l) + islink=1 + ;; + esac + done + shift $((OPTIND-1)) + if [ $islink -eq 1 ]; then + files_to_link="$files_to_link $(subvars $1):$(subvars $2)" + else + files_to_copy="$files_to_copy $(subvars $1):$(subvars $2)" + fi +} \ No newline at end of file diff --git a/lib/crates.lib.sh b/lib/crates.lib.sh new file mode 100644 index 0000000..0cf133b --- /dev/null +++ b/lib/crates.lib.sh @@ -0,0 +1,13 @@ +#!/bin/sh + +crates() { + for c in $(find ./crates -mindepth 1 -maxdepth 1 -type d); do + [ -f "$c/crate.sh" ] && echo $(basename $c) + done +} + +crate_runner() { + [ -d "$1" ] || return 1 + sh ./lib/crate-runner.sh $1 $2 +} + diff --git a/lib/log.lib.sh b/lib/log.lib.sh new file mode 100644 index 0000000..c4a9640 --- /dev/null +++ b/lib/log.lib.sh @@ -0,0 +1,60 @@ +#!/bin/sh + +__log_lvl=1 + +__log_get_lvl() { + case ${1:-$__log_lvl} in + 0) + echo debug + ;; + 1) + echo info + ;; + 2) + echo warn + ;; + 3) + echo err + ;; + 4) + echo fatal + ;; + esac +} + +__log() { + [ $1 -ge $__log_lvl ] || return + level=$(__log_get_lvl $1) + shift + printf "[%s] %s\n" "$level" "$@" +} + +debug() { + __log 0 "$@" +} + +info() { + __log 1 "$@" +} + +warn() { + __log 2 "$@" +} + +err() { + __log 3 "$@" +} + +fatal() { + while getopts "e:" opt; do + case $opt in + e) + exitnum=$OPTARG + ;; + esac + done + shift $((OPTIND-1)) + + __log 4 "$@" + exit ${exitnum:-1} +} \ No newline at end of file diff --git a/lib/vars.lib.sh b/lib/vars.lib.sh new file mode 100644 index 0000000..de58b9b --- /dev/null +++ b/lib/vars.lib.sh @@ -0,0 +1,11 @@ +#!/bin/sh + +safevar() { + echo "$@" | sed 's_/_\\/_g' +} + +subvars() { + echo "$@" \ + | sed "s/{{home}}/$(safevar $HOME)/g" \ + | sed "s/{{user}}/$USER/g" +} \ No newline at end of file