alnx-build/build_pkg.sh

108 lines
2.0 KiB
Bash
Executable File

#!/bin/bash
# banner, generated via toilet:
# toilet -F border -f future ArchBuild
banner="$(
cat <<EOF
┌─────────────────────────┐
│┏━┓┏━┓┏━╸╻ ╻┏┓ ╻ ╻╻╻ ╺┳┓│
│┣━┫┣┳┛┃ ┣━┫┣┻┓┃ ┃┃┃ ┃┃│
│╹ ╹╹┗╸┗━╸╹ ╹┗━┛┗━┛╹┗━╸╺┻┛│
└─────────────────────────┘
EOF
)"
# colors
cYLW="$(tput setaf 221)"
cRST="$(tput sgr0)"
cGRN="$(tput setaf 119)"
cGRY="$(tput setaf 105)"
# help diagnose errors
LANG=C
function info() {
printf "[*] $cGRY%s$cRST\n" "$1"
}
function warn() {
printf "[!] $cYLW%s$cRST\n" "$1"
}
function success() {
printf "[+] $cGRN%s$cRST\n" "$1"
}
# re-declare pushd/popd to remove stack output
mpushd() {
command pushd "$@" &>/dev/null || exit 1
}
mpopd() {
command popd &>/dev/null || exit 1
}
function gclone() {
local repo="$1"
local dest="$2"
info "cloning $repo"
git clone --quiet "$repo" "$dest"
}
function upd_pkg() {
local pkg="$1"
local out_dir="$PWD/$pkg"
local clone_url="https://aur.archlinux.org/$pkg.git"
info "updating sources for $pkg"
if [[ -d "$out_dir" ]]; then
mpushd "$out_dir"
if git rev-parse --is-inside-work-tree >/dev/null 2>&1; then
info "fetch remote ..."
git fetch --all
info "jump to current master ..."
git reset --hard origin/master
mpopd
else
warn "directory exists but git repo is invalid"
mpopd
warn "deleting old directory"
rm -rf "$out_dir" || exit 2
gclone "$clone_url" "$out_dir"
fi
else
gclone "$clone_url" "$out_dir"
fi
success "updated sources for $pkg"
}
function bld_pkg() {
local pkg="$1"
local src_dir="$2"
mpushd "$src_dir"
info "building $pkg"
makepkg -fsc &>/dev/null || exit 3
success "built ${pkg}"
ls ./*"-$(uname -m).pkg.tar."*
}
echo "$banner"
info "preparing build"
pkgs=("$@")
for pkg in "${pkgs[@]}"; do
upd_pkg "$pkg"
done
for pkg in "${pkgs[@]}"; do
bld_pkg "$pkg" "$pkg"
done