mirror of
https://github.com/m-housh/dotfiles.git
synced 2026-02-14 06:12:34 +00:00
129 lines
2.8 KiB
Bash
Executable File
129 lines
2.8 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
|
|
# Adapted from https://github.com/ThePrimeagen/dev/blob/master/run
|
|
#
|
|
# 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.
|
|
#
|
|
|
|
if [ -z "$DEV_ENV" ]; then
|
|
echo "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
|
|
# scripts
|
|
export DEV_ENV="$DEV_ENV"
|
|
|
|
grep=""
|
|
dry_run="0"
|
|
uninstall="0"
|
|
|
|
while [[ $# -gt 0 ]]; do
|
|
echo "ARG: \"$1\""
|
|
|
|
# TODO: Fix some of these arguments, should we add a '--grep' option, should '[un]install' be args / not options?
|
|
# Handle a --dry or --dry-run argument
|
|
if [[ "$1" =~ ^--dry ]]; then
|
|
dry_run="1"
|
|
# Handle an --uninstall argument
|
|
elif [[ "$1" =~ ^--u ]]; then
|
|
uninstall="1"
|
|
# Handle an --install argument (default)
|
|
elif [[ ! "$1" =~ ^--i ]]; then
|
|
grep="$1"
|
|
else
|
|
grep="$1"
|
|
fi
|
|
shift
|
|
done
|
|
|
|
# TODO: Setup proper logging using '$SCRIPTS/hypr/logging'
|
|
log() {
|
|
if [[ $dry_run == "1" ]]; then
|
|
echo "[DRY_RUN]: $1"
|
|
else
|
|
echo "$1"
|
|
fi
|
|
}
|
|
|
|
# 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
|
|
|
|
}
|
|
|
|
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.
|
|
|
|
for s in $runs_dir; do
|
|
if basename $s | grep -vq "$grep"; then
|
|
log "grep \"$grep\" filtered out $s"
|
|
continue
|
|
fi
|
|
|
|
if [[ $uninstall == "1" ]]; then
|
|
# TODO: Use function instead.
|
|
run $s --uninstall
|
|
else
|
|
# TODO: Use function instead.
|
|
run $s --install
|
|
fi
|
|
done
|