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");; -s|--syncdeps) makepkg_opts+=("--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" if makepkg "${makepkg_opts[@]}"; then return 0 else return 1 fi popd ) fi } tlrepobuild() { local hostcheck="thurstylark-vps" local remotehost="vps" local remote_repo_path="/var/cache/pacman/tl/" local reponame="tl" local pkg="$1" local -a aur_sync_opts aur_sync_opts+=('--no-confirm' '--no-view') local resultdir="$HOME/repos/aur" local full_pkgname local remote_pkg_path case "$(uname -n)" in "$hostcheck") aur sync "${aur_sync_opts[@]}" "$pkg";; *) while true; do read -p "Build [L]ocally, or [R]emotely on $hostcheck? [l/R]" yn case $yn in [Ll]* ) if tldirtyaurbuild -s "$pkg"; then tldaecho "Success, uploading to $hostcheck..." else tldaecho -t e "Unable to build $pkg. Exiting." return 1 fi if full_pkgname="$(find $resultdir/$pkg/$pkg*.pkg.tar.xz -printf '%f')"; then tldaecho "Resulting Package: $full_pkgname" else tldaecho -t e "Unable to find resulting package file. Exiting." return 1 fi if scp "$resultdir/$pkg/$full_pkgname" "$remotehost":"$remote_repo_path"; then tldaecho "Success. Adding $full_pkgname to $reponame..." else tldaecho -t e "Unable to upload package to $hostcheck. Exiting." return 1 fi if remote_pkg_path="$(ssh $remotehost find $remote_repo_path/$full_pkgname)"; then tldaecho "Package's path within repo: $remote_pkg_path" else tldaecho -t e "Unable to find package in $hostcheck:$remote_repo_path Exiting." return 1 fi if ssh "$remotehost" repo-add -n "$remote_repo_path/$reponame.db.tar" "$remote_pkg_path"; then tldaecho "Done. Package built, and added to remote repo." return 0 else tldaecho -t e "Unable to add package to remote repo. Exiting." return 1 fi ;; * ) if ssh "$remotehost" aur sync "${aur_sync_opts[@]}" "$pkg"; then tldaecho "Done." return 0 else tldaecho -t e "Unknown error. Exiting" return 1 fi ;; esac done ;; esac }