mirror of
https://github.com/m-housh/dotfiles.git
synced 2026-02-14 06:12:34 +00:00
100 lines
1.8 KiB
Bash
Executable File
100 lines
1.8 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
|
|
script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" &>/dev/null && pwd)"
|
|
|
|
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"
|
|
create="0"
|
|
|
|
while [[ $# -gt 0 ]]; do
|
|
echo "ARG: \"$1\""
|
|
|
|
# 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 --uninstall argument
|
|
elif [[ "$1" =~ ^--c ]]; then
|
|
create="1"
|
|
# Handle an --install argument (default)
|
|
elif [[ ! "$1" =~ ^--i ]]; then
|
|
grep="$1"
|
|
fi
|
|
shift
|
|
done
|
|
|
|
log() {
|
|
if [[ $dry_run == "1" ]]; then
|
|
echo "[DRY_RUN]: $1"
|
|
else
|
|
echo "$1"
|
|
fi
|
|
}
|
|
|
|
generate-new-run() {
|
|
local file="$script_dir/runs/$1"
|
|
if [ -f "$file" ]; then
|
|
log "File exists: $file"
|
|
exit 1
|
|
fi
|
|
|
|
log "Creating new run: $file"
|
|
|
|
printf "#!/usr/bin/env bash\n\n" >$file
|
|
printf "yay \${1:-\"-S --noconfirm\"} # packages\n" >>$file
|
|
|
|
chmod +x $file
|
|
}
|
|
|
|
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
|
|
|
|
}
|
|
|
|
if [[ "$create" == "1" ]]; then
|
|
generate-new-run "$grep"
|
|
exit 0
|
|
fi
|
|
|
|
log "RUN: env: $env -- grep: $grep"
|
|
|
|
runs_dir=$(find $script_dir/runs -mindepth 1 -maxdepth 1 -executable)
|
|
|
|
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
|
|
run $s --uninstall
|
|
else
|
|
run $s --install
|
|
fi
|
|
done
|