more stuff

This commit is contained in:
Didier Slof 2023-09-01 01:40:41 +02:00
parent adf4cf3e0e
commit 462b92cb00
Signed by: didier
GPG key ID: 01E71F18AA4398E5
14 changed files with 257 additions and 0 deletions

View file

@ -0,0 +1,6 @@
name="alacritty"
description="Set up alacritty"
files() {
descfile -l files/alacritty.yml {{home}}/.config/alacritty/alacritty.yml
}

View file

View file

@ -0,0 +1 @@
alacritty

11
crates/arch/crate.arch.sh Normal file
View file

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

View file

8
crates/i3/crate.sh Executable file
View file

@ -0,0 +1,8 @@
#!/bin/sh
name="i3"
description="Installs i3 with config"
files() {
descfile -l ./files/i3config {{home}}/.config/i3/config
}

0
crates/i3/files/i3config Normal file
View file

2
crates/i3/package.list Normal file
View file

@ -0,0 +1,2 @@
i3
i3blocks

13
dot.sh Normal file
View file

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

88
lib/crate-runner.sh Normal file
View file

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

44
lib/crate.common.sh Normal file
View file

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

13
lib/crates.lib.sh Normal file
View file

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

60
lib/log.lib.sh Normal file
View file

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

11
lib/vars.lib.sh Normal file
View file

@ -0,0 +1,11 @@
#!/bin/sh
safevar() {
echo "$@" | sed 's_/_\\/_g'
}
subvars() {
echo "$@" \
| sed "s/{{home}}/$(safevar $HOME)/g" \
| sed "s/{{user}}/$USER/g"
}