atproto library for bash scripts
atproto bash-atproto
at main 2.6 kB view raw
1#!/bin/bash 2# SPDX-License-Identifier: MIT 3# bap-extra.sh: Other functions that might be useful 4if [ -z "$bap_internalVersion" ]; then >&2 echo "bash-atproto not loaded?"; return 127; fi 5if [ "$bap_internalVersion" != "3" ] || ! [ "$bap_internalMinorVer" -ge "1" ]; then >&2 echo "Incorrect bash-atproto version"; return 1; fi 6 7bapExt_internalVersion=1 8bapExt_internalMinorVer=1 9 10function bapExtErr () { 11 >&2 echo "bap-extra: $*" 12} 13 14function bapExtEcho () { 15 if [ ! "$bap_verbosity" -ge 1 ]; then return 0; fi 16 echo "bap-extra: $*" 17} 18 19function bapExt_authWithATFileCreds () { 20 # Auth with atfile credentials for your convenience 21 if [ -f "$HOME/.config/atfile.env" ]; then while IFS= read -r line; do declare -g "$line"; done < "$HOME/.config/atfile.env" 22 else bapExtErr "no ATFile credentials file to load!"; return 1; fi 23 if [ -z "$ATFILE_USERNAME" ] || [ -z "$ATFILE_PASSWORD" ]; then bapExtErr "ATFile credentials not found!"; fi 24 bap_findPDS $(bap_resolveDID $ATFILE_USERNAME) || { bapExtErr "Couldn't resolve PDS!"; return 1; } 25 bap_getKeys $ATFILE_USERNAME $ATFILE_PASSWORD || { bapExtErr "Couldn't log in with ATFile credentials!"; return 1; } 26 bapInternal_loadFromJwt 27 ATFILE_USERNAME= ATFILE_PASSWORD= 28 bapExtEcho "Auth successful. Use bap_closeSession when done" 29 return 0 30} 31 32function bapExt_fastLogin () { 33 if [ "$2" = "" ]; then bapExtErr "Required argument missing"; return 1; fi 34 bap_findPDS $(bap_resolveDID $1) || return $? 35 bap_getKeys $(bap_resolveDID $1) $2 || return $? 36 bapInternal_loadFromJwt 37 return 0 38} 39 40function bapExt_checkDeps () { 41 local problem=0 42 if ! type file >/dev/null 2>&1; then problem=2; bapExtErr "missing file"; fi 43 if ! type convert >/dev/null 2>&1; then problem=2; bapExtErr "missing convert"; fi 44 if ! type exiftool >/dev/null 2>&1; then problem=2; bapExtErr "missing exiftool"; fi 45 if ! type uuidgen >/dev/null 2>&1; then problem=2; bapExtErr "missing uuidgen"; fi 46 if ! type jq >/dev/null 2>&1; then problem=1; bapExtErr "missing jq"; fi 47 if ! type curl >/dev/null 2>&1; then problem=1; bapExtErr "missing curl"; fi 48 # if you can load this function, you have bash 49 50 case "$problem" in 51 1) 52 bapExtEcho "A core dependency required by bash-atproto is missing." 53 bapExtEcho "bash-atproto will not work.";; 54 2) 55 bapExtEcho "A dependency used by the media subsystems of bash-atproto is missing." 56 bapExtEcho "Processing images and video will not function, but other functionality will work.";; 57 0) 58 bapExtEcho "There are no bash-atproto dependency issues on this system.";; 59 esac 60}