init: v2 of dot

This commit is contained in:
Strix 2024-06-04 01:33:44 +02:00
parent 0a8b09ca65
commit 7991035935
13 changed files with 156 additions and 12 deletions

1
.gitignore vendored Normal file
View file

@ -0,0 +1 @@
.installed

View file

@ -1,12 +1 @@
# Raine's Dotfiles # Strix's Dotfiles
## Crates
Everything is a crate.
If something is distro specific you should follow the following naming scheme:
`crate.<DISTRO>.sh`
## Using it
Just use the script tbh
```sh
curl -L https://via.ixvd.net/sh | sh
```

3
configs/default.sh Normal file
View file

@ -0,0 +1,3 @@
#!/bin/sh
crate_apply ssh

3
configs/laptop.sh Normal file
View file

@ -0,0 +1,3 @@
#!/bin/sh
crate_apply tlp

0
crates/example/.invalid Normal file
View file

0
crates/example/apply.sh Normal file
View file

0
crates/example/remove.sh Normal file
View file

9
crates/ssh/apply.sh Normal file
View file

@ -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

3
crates/ssh/remove.sh Normal file
View file

@ -0,0 +1,3 @@
#!/bin/sh
rm -rf ~/.ssh

2
crates/tlp/apply.sh Normal file
View file

@ -0,0 +1,2 @@
#!/bin/sh

79
lib/crates.sh Normal file
View file

@ -0,0 +1,79 @@
#!/bin/sh
DF_CRATE_STRICT=${DF_CRATE_STRICT:-0}
# crate_validate <crate> <exit_on_invalid>
# 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
}

26
main Executable file
View file

@ -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

29
runner Executable file
View file

@ -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: $@"
$@