WIP: Converts runs to be text files of packages to install / uninstall, begins before and after scripts to execute during runs.

This commit is contained in:
2025-11-09 22:15:29 -05:00
parent 381a0450e5
commit 9c007c9434
23 changed files with 259 additions and 206 deletions

202
run
View File

@@ -5,11 +5,127 @@
# Runs scripts in the `./runs` directory, which will install or uninstall
# packages. It either runs a single script given an argument (filename in runs)
# or all scripts in the runs directory.
#
set -e
set -o nounset
set -o pipefail
THIS_FILE=${BASH_SOURCE[0]}
LOG_LABEL=$(basename $THIS_FILE)
LOG_FILE=${LOG_FILE:-"$LOG_LABEL.log"}
declare dry_run grep uninstall
log() {
logging log --source "$THIS_FILE" "$@"
}
# TODO: Remove.
run() {
local script=$1
local flag=$2
log "running script: $script $flag"
local actual_flags="-S --noconfirm"
if [[ $flag == "--uninstall" ]]; then
actual_flags="-Rns"
fi
log "ok, here's the actual script:: $s $actual_flags"
if [[ $dry_run == "0" ]]; then
$script $actual_flags
fi
}
after() {
local after
local file=${1:-""}
local arg=${2:-""}
# Check for after script, and run it if found.
after=$(find "$DEV_ENV/runs/after" -mindepth 1 -maxdepth 1 -executable -name "$(basename "$file")" | head -1)
if [[ -n "$after" ]]; then
log --echo " running after script: '$after'"
[[ $dry_run == "0" ]] && source "$after" "$arg"
fi
}
before() {
local before
local file=${1:-""}
local arg=${2:-""}
before=$(find "$DEV_ENV/runs/before" -mindepth 1 -maxdepth 1 -executable -name "$(basename "$file")" | head -1)
if [[ -n "$before" ]]; then
log --echo " running before script: '$before'"
[[ $dry_run == "0" ]] && source "$before" "$arg"
fi
}
install() {
local file line pkg after before
# Ensure yay is installed before proceeding.
[[ $dry_run == "0" ]] && . "$DEV_ENV/runs/before/yay"
file=${1:-""}
# Early out if the file is not readable.
[[ ! -r $file ]] && exit 1
log --echo "Installing packages from: $file"
before "$file" install
# Loop over lines in the file and install the packages.
while read -r line; do
# Skip lines that begin with '#' (comments)
if [[ ! $line =~ ^# ]]; then
# Remove any inline comments.
pkg=${line%% \#*}
if [[ -n $pkg ]]; then
log --echo " pkg: '$pkg'"
[[ $dry_run == "0" ]] && yay -S --noconfirm --needed "$pkg"
fi
fi
done <"$file"
after "$file" install
}
uninstall() {
local file line pkg
file=${1:-""}
# Early out if the file is not readable.
[[ ! -r $file ]] && exit 1
log --echo "Uninstalling packages from: $file"
before "$file" uninstall
# Loop over lines in the file and uninstall the packages.
while read -r line; do
# Skip lines that begin with '#' (comments)
if [[ ! $line =~ ^# ]]; then
# Remove any inline comments.
pkg=${line%% \#*}
log --echo " pkg: '$pkg'"
[[ $dry_run == "0" ]] && yay -Rns "$pkg"
fi
done <"$file"
after "$file" uninstall
}
############################## MAIN ##############################
# Setup logging file and label.
source "$SCRIPTS/hypr/logging"
setup-logging "$LOG_FILE" "$LOG_LABEL"
if [ -z "$DEV_ENV" ]; then
echo "env var DEV_ENV needs to be present"
exit 1
log --error "env var DEV_ENV needs to be present" && exit 1
fi
# if i just did DEV_ENV=$(pwd) ./run then this is needed for the rest of the
@@ -39,78 +155,12 @@ while [[ $# -gt 0 ]]; do
shift
done
# TODO: Setup proper logging using '$SCRIPTS/hypr/logging'
log() {
if [[ $dry_run == "1" ]]; then
echo "[DRY_RUN]: $1"
else
echo "$1"
fi
}
export LOG_ENABLE_DRY_RUN="$dry_run"
# TODO: Remove.
run() {
local script=$1
local flag=$2
log "running script: $script $flag"
log --echo "RUN: -- grep: '$grep'"
runs_dir=$(find $DEV_ENV/runs -mindepth 1 -maxdepth 1 -type f) # TODO: keep
local actual_flags="-S --noconfirm"
if [[ $flag == "--uninstall" ]]; then
actual_flags="-Rns"
fi
log "ok, here's the actual script:: $s $actual_flags"
if [[ $dry_run == "0" ]]; then
$script $actual_flags
fi
}
install() {
local file line pkg
file=${1:-""}
# Early out if the file is not readable.
[[ ! -r $file ]] && exit 1
# Loop over lines in the file and install the packages.
while read -r line; do
# Skip lines that begin with '#' (comments)
if [[ ! $line =~ ^# ]]; then
# Remove any inline comments.
pkg=${line%% \#*}
# TODO: We should log something here??
[[ $dry_run == "0" ]] && yay -S --noconfirm --needed "$pkg"
fi
done <"$file"
}
uninstall() {
local file line pkg
file=${1:-""}
# Early out if the file is not readable.
[[ ! -r $file ]] && exit 1
# Loop over lines in the file and uninstall the packages.
while read -r line; do
# Skip lines that begin with '#' (comments)
if [[ ! $line =~ ^# ]]; then
# Remove any inline comments.
pkg=${line%% \#*}
# TODO: We should log something here??
[[ $dry_run == "0" ]] && yay -Rns "$pkg"
fi
done <"$file"
}
############################## MAIN ##############################
log "RUN: -- grep: $grep"
#runs_dir=$(find $DEV_ENV/runs -mindepth 1 -maxdepth 1 -type f) # TODO: keep
runs_dir=$(find $DEV_ENV/runs -mindepth 1 -maxdepth 1 -executable) # TODO: remove.
#runs_dir=$(find $DEV_ENV/runs -mindepth 1 -maxdepth 1 -executable) # TODO: remove.
for s in $runs_dir; do
if basename $s | grep -vq "$grep"; then
@@ -120,9 +170,11 @@ for s in $runs_dir; do
if [[ $uninstall == "1" ]]; then
# TODO: Use function instead.
run $s --uninstall
# run $s --uninstall
uninstall "$s"
else
# TODO: Use function instead.
run $s --install
# run $s --install
install "$s"
fi
done