diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c5b3678 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.installed \ No newline at end of file diff --git a/README.md b/README.md index b630725..6107ec4 100644 --- a/README.md +++ b/README.md @@ -1,12 +1 @@ -# Raine's Dotfiles - -## Crates -Everything is a crate. -If something is distro specific you should follow the following naming scheme: -`crate..sh` - -## Using it -Just use the script tbh -```sh -curl -L https://via.ixvd.net/sh | sh -``` \ No newline at end of file +# Strix's Dotfiles \ No newline at end of file diff --git a/configs/default.sh b/configs/default.sh new file mode 100644 index 0000000..2010628 --- /dev/null +++ b/configs/default.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +crate_apply ssh \ No newline at end of file diff --git a/configs/laptop.sh b/configs/laptop.sh new file mode 100644 index 0000000..fa35a24 --- /dev/null +++ b/configs/laptop.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +crate_apply tlp \ No newline at end of file diff --git a/crates/example/.invalid b/crates/example/.invalid new file mode 100644 index 0000000..e69de29 diff --git a/crates/example/apply.sh b/crates/example/apply.sh new file mode 100644 index 0000000..e69de29 diff --git a/crates/example/remove.sh b/crates/example/remove.sh new file mode 100644 index 0000000..e69de29 diff --git a/crates/ssh/apply.sh b/crates/ssh/apply.sh new file mode 100644 index 0000000..24b6033 --- /dev/null +++ b/crates/ssh/apply.sh @@ -0,0 +1,9 @@ +#!/bin/sh + +echo "pulling ssh key..." +scp \ + strix@hydrogen.red.helix.saluco.nl:.ssh/config \ + strix@hydrogen.red.helix.saluco.nl:.ssh/authorized_keys \ + strix@hydrogen.red.helix.saluco.nl:.ssh/id_rsa \ + strix@hydrogen.red.helix.saluco.nl:.ssh/id_rsa.pub \ + ~/.ssh \ No newline at end of file diff --git a/crates/ssh/remove.sh b/crates/ssh/remove.sh new file mode 100644 index 0000000..ff5c53c --- /dev/null +++ b/crates/ssh/remove.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +rm -rf ~/.ssh \ No newline at end of file diff --git a/crates/tlp/apply.sh b/crates/tlp/apply.sh new file mode 100644 index 0000000..13f4793 --- /dev/null +++ b/crates/tlp/apply.sh @@ -0,0 +1,2 @@ +#!/bin/sh + diff --git a/lib/crates.sh b/lib/crates.sh new file mode 100644 index 0000000..ce4603b --- /dev/null +++ b/lib/crates.sh @@ -0,0 +1,79 @@ +#!/bin/sh + +DF_CRATE_STRICT=${DF_CRATE_STRICT:-0} + +# crate_validate +# example: +# crate_validate $1 1 +# crate_validate $1 0 || return 1 +crate_validate() { + a=$DF_RUNNER_VERBOSE + DF_RUNNER_VERBOSE= + err=0 + [ -d "crates/$1" ] || err=1 + [ -f "crates/$1/apply.sh" ] || err=1 + [ -f "crates/$1/.invalid" ] && err=1 + if [ $err = 1 ]; then + if [ "${2:-$DF_CRATE_STRICT}" = "1" ]; then + echo "$1 is an invalid crate" + exit 1 + else + return 1 + fi + fi + DF_RUNNER_VERBOSE=$a +} + +in_crate() { + crate=$1 + crate_validate $1 0 || return 1 + shift + DF_RUNNER_WORKDIR="$(pwd)/crates/$crate" ./runner $@ +} + +crate_applied() { + crate_validate $1 0 || return 1 + in_crate "$1" [ -f ".installed" ] +} + +crate_has_root_apply() { + crate_validate $1 0 || return 1 + in_crate "$1" [ -f "apply_root.sh" ] +} + +crate_has_root_remove() { + crate_validate $1 0 || return 1 + in_crate "$1" [ -f "remove_root.sh" ] +} + +crate_removable() { + crate_validate $1 0 || return 1 + in_crate "$1" [ -f "remove.sh" ] +} + +crate_info() { + if ! crate_validate $1 0; then + printf "%s " "!" + else + if crate_applied $1; then + if crate_removable $1; then + printf "%s " "+" + else + printf "%s " "*" + fi + else + printf "%s " "-" + fi + fi + printf "%s " $1 + crate_removable $1 && printf "[removable] " + crate_has_root_apply $1 && printf "[has root apply] " + crate_has_root_remove $1 && printf "[has root remove] " + printf "\n" +} + +crate_apply() { + crate_validate $1 1 + echo "applying crates/$1..." + in_crate $1 sh apply.sh +} diff --git a/main b/main new file mode 100755 index 0000000..c22098d --- /dev/null +++ b/main @@ -0,0 +1,26 @@ +#!/bin/sh + +. lib/crates.sh + +cmd=$1 +if [ -z "$cmd" ]; then + exit 1 +else + shift +fi + +case $cmd in +apply-crates) crate_apply $@ ;; +remove-crate) + if crate_removable $1; then + crate_remove $1 + else + echo "crate can't be removed" + fi + ;; +list-crates) + for c in ${@:-$(ls crates)}; do + crate_info $c + done + ;; +esac diff --git a/runner b/runner new file mode 100755 index 0000000..453acab --- /dev/null +++ b/runner @@ -0,0 +1,29 @@ +#!/bin/sh + +# DF_SRC_ROOT: dotfiles source root +# DF_RUNNER_WORKDIR: runner workdir +# DF_RUNNER_LIBS: libs to include in runner +# DF_RUNNER_VERBOSE: verbosity runner + + +if [ -n "$DF_RUNNER_WORKDIR" ]; then + [ $DF_RUNNER_VERBOSE ] && echo "workdir: $DF_RUNNER_WORKDIR" + DF_SRC_ROOT=${DF_SRC_ROOT:-$(pwd)} + cd $DF_RUNNER_WORKDIR +fi + +for lib in ${DF_RUNNER_LIBS:-}; do + if [ -n "$DF_SRC_ROOT" ]; then + oldpwd=$(pwd) + cd $DF_SRC_ROOT + fi + [ $DF_RUNNER_VERBOSE ] && echo "include: lib/$lib.sh" + . lib/$lib.sh + if [ -n "$DF_SRC_ROOT" ]; then + cd $oldpwd + fi +done + +[ $DF_RUNNER_VERBOSE ] && echo "command: $@" + +$@ \ No newline at end of file