Adding tldirtyaurbuild.bash, a fairly stupid solution to enable my own laziness

This commit is contained in:
David Thurstenson 2020-07-26 19:04:50 -05:00
parent 663acb7f77
commit 1102ae5c8f
1 changed files with 111 additions and 0 deletions

View File

@ -0,0 +1,111 @@
tldaecho() {
local caller="${FUNCNAME[1]:-tldaecho}"
local etype
while :; do
case $1 in
-t|--type)
if [[ $2 ]]; then
case ${2,,} in # NOTE: ${2,,} expands to all lowercase, making the
# matches psuedo-case-insensitive
e|error) etype="ERROR"; shift;;
w|warning) etype="WARNING"; shift;;
i|info) etype="INFO"; shift;;
d|debug) etype="DEBUG"; shift;;
esac
else # If the user used -t but failed to specify type, just use the default of "INFO"
etype="INFO"
fi
;;
*) break;;
esac
shift
done
local msg="$*"
# Only print DEBUG messages if TL_DEBUG is set to 1
if [[ $TL_DEBUG -eq 1 || "$etype" != "DEBUG" ]]; then
printf "%s: [%s] %s\n" \
"$caller" \
"${etype:-INFO}" \
"$msg"
fi
}
tldirtyaurget() (
# NOTE: Using a subshell instead of group so that shell options remain local
set -o errexit
local pkg="$1"
local reposdir="${2:-$HOME/repos/aur}"
local dest="$reposdir/$pkg"
local urlbase="https://aur.archlinux.org/"
local cloneurl="$urlbase$pkg.git"
tldaecho -t i "Repo dest: $reposdir"
# Create reposdir if it doesn't exist already (and let the user know what's going on)
[[ ! -d $reposdir ]] && tldaecho -t i "$reposdir does not exist. Creating..."; mkdir -p "$reposdir"
# If $dest exists and isn't empty...
if [[ -d "$dest" && -n "$(ls -A "$dest")" ]]; then
tldaecho -t d "$dest exists and is not empty."
# If $dest is a git repo...
if git -C "$dest" rev-parse &> /dev/null; then
tldaecho -t d "$dest is a git repo."
# If $dest is already a repo for $pkg (by origin url)...
if [[ "$(git -C "$dest" remote get-url origin)" = "$cloneurl" ]]; then
tldaecho -t i "$pkg has already been cloned to $dest. Updating..."
git -C "$dest" pull
else # If $dest is a git repo, but not for $pkg...
tldaecho -t e "$dest is a git repo, but not for $pkg. Bailing."
return 1
fi
else # If $dest exists, is not empty, and is not a git repo...
tldaecho -t e "$dest exists, is not empty, and is not a git repo. Bailing."
return 1
fi
else # If $dest either doesn't exist, or exists but is empty...
# Do the thing!!
git clone "$cloneurl" "$dest"
fi
)
tldirtyaurbuild() {
local -a makepkg_opts
while :; do
case $1 in
-i|--install) makepkg_opts+=("--install" "--syncdeps");;
-f|--force) makepkg_opts+=("--force");;
-c|--makepkg-config)
if [[ "$2" ]]; then
makepkg_opts+=("--config $2")
shift
else
tldaecho -t e "$1 requires an argument"
return 1
fi
;;
--) shift; break;;
-?*) tldaecho -t w "Ignoring unknown option $1";;
*) break;;
esac
shift
done
local pkg="$1"
local reposdir="${2:-$HOME/repos/aur}"
local dest="$reposdir/$pkg"
# Get the repo for $pkg
if tldirtyaurget "$pkg" "$reposdir"; then ( # Doing this in a subshell so that if the user wants to
# bail during build or install, they won't be stranded
# in the pushd dir.
# Do the thing!
pushd "$dest"
makepkg "${makepkg_opts[@]}"
popd
)
fi
}