mirror of https://github.com/bpkg/bpkg
Compare commits
1 Commits
Author | SHA1 | Date |
---|---|---|
Joseph Werle | bb7f11effb | 2 years ago |
@ -1,185 +1,161 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
if [ -z "${BPKG_UTILS}" ]; then
|
if ! type -f bpkg-env &>/dev/null; then
|
||||||
BPKG_UTILS=1
|
echo "error: bpkg-env not found, aborting"
|
||||||
|
exit 1
|
||||||
## Collection of shared bpkg functions
|
else
|
||||||
|
# shellcheck disable=SC2230
|
||||||
## Init local config and set environmental defaults
|
# shellcheck source=lib/env/env.sh
|
||||||
bpkg_initrc () {
|
source "$(which bpkg-env)"
|
||||||
local global_config=${BPKG_GLOBAL_CONFIG:-"/etc/bpkgrc"}
|
fi
|
||||||
# shellcheck disable=SC1090
|
|
||||||
[ -f "$global_config" ] && source "$global_config"
|
|
||||||
local config=${BPKG_CONFIG:-"$HOME/.bpkgrc"}
|
|
||||||
# shellcheck disable=SC1090
|
|
||||||
[ -f "$config" ] && source "$config"
|
|
||||||
## set defaults
|
|
||||||
if [ ${#BPKG_REMOTES[@]} -eq 0 ]; then
|
|
||||||
BPKG_REMOTES[0]=${BPKG_REMOTE-https://raw.githubusercontent.com}
|
|
||||||
BPKG_GIT_REMOTES[0]=${BPKG_GIT_REMOTE-https://github.com}
|
|
||||||
|
|
||||||
export BPKG_REMOTES
|
|
||||||
export BPKG_GIT_REMOTE
|
|
||||||
export BPKG_GIT_REMOTES
|
|
||||||
fi
|
|
||||||
|
|
||||||
export BPKG_PACKAGE_USER="${BPKG_PACKAGE_USER:-"bpkg"}"
|
|
||||||
export BPKG_INDEX=${BPKG_INDEX:-"$HOME/.bpkg/index"}
|
|
||||||
|
|
||||||
bpkg_validate
|
|
||||||
|
|
||||||
return $?
|
|
||||||
}
|
|
||||||
|
|
||||||
## check parameter consistency
|
|
||||||
bpkg_validate () {
|
|
||||||
if [ ${#BPKG_GIT_REMOTES[@]} -ne ${#BPKG_REMOTES[@]} ]; then
|
|
||||||
bpkg_error "$(printf 'BPKG_GIT_REMOTES[%d] differs in size from BPKG_REMOTES[%d] array' "${#BPKG_GIT_REMOTES[@]}" "${#BPKG_REMOTES[@]}")"
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
## format and output message
|
|
||||||
bpkg_message () {
|
|
||||||
bpkg_exec_exist bpkg-term &&
|
|
||||||
bpkg-term color "${1}"
|
|
||||||
shift
|
|
||||||
|
|
||||||
echo -n " ${1}"
|
## Collection of shared bpkg functions
|
||||||
|
|
||||||
|
## Init local config and set environmental defaults
|
||||||
|
bpkg_initrc() {
|
||||||
|
local global_config=${BPKG_GLOBAL_CONFIG:-"/etc/bpkgrc"}
|
||||||
|
# shellcheck disable=SC1090
|
||||||
|
[ -f "$global_config" ] && source "$global_config"
|
||||||
|
local config=${BPKG_CONFIG:-"$HOME/.bpkgrc"}
|
||||||
|
# shellcheck disable=SC1090
|
||||||
|
[ -f "$config" ] && source "$config"
|
||||||
|
## set defaults
|
||||||
|
if [ ${#BPKG_REMOTES[@]} -eq 0 ]; then
|
||||||
|
BPKG_REMOTES[0]=${BPKG_REMOTE-https://raw.githubusercontent.com}
|
||||||
|
BPKG_GIT_REMOTES[0]=${BPKG_GIT_REMOTE-https://github.com}
|
||||||
|
|
||||||
|
export BPKG_REMOTES
|
||||||
|
export BPKG_GIT_REMOTE
|
||||||
|
export BPKG_GIT_REMOTES
|
||||||
|
fi
|
||||||
|
|
||||||
|
export BPKG_PACKAGE_USER="${BPKG_PACKAGE_USER:-"bpkg"}"
|
||||||
|
export BPKG_INDEX=${BPKG_INDEX:-"$HOME/.bpkg/index"}
|
||||||
|
|
||||||
|
bpkg_validate
|
||||||
|
|
||||||
|
return $?
|
||||||
|
}
|
||||||
|
|
||||||
|
## check parameter consistency
|
||||||
|
bpkg_validate () {
|
||||||
|
if [ ${#BPKG_GIT_REMOTES[@]} -ne ${#BPKG_REMOTES[@]} ]; then
|
||||||
|
bpkg_error "$(printf 'BPKG_GIT_REMOTES[%d] differs in size from BPKG_REMOTES[%d] array' "${#BPKG_GIT_REMOTES[@]}" "${#BPKG_REMOTES[@]}")"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
## format and output message
|
||||||
|
bpkg_message () {
|
||||||
|
if type -f bpkg-term > /dev/null 2>&1; then
|
||||||
|
bpkg-term color "${1}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
shift
|
||||||
|
echo -n " ${1}"
|
||||||
|
shift
|
||||||
|
|
||||||
|
if type -f bpkg-term > /dev/null 2>&1; then
|
||||||
|
bpkg-term reset
|
||||||
|
fi
|
||||||
|
|
||||||
|
printf ": "
|
||||||
|
|
||||||
|
if type -f bpkg-term > /dev/null 2>&1; then
|
||||||
|
bpkg-term reset
|
||||||
|
bpkg-term bright
|
||||||
|
fi
|
||||||
|
|
||||||
|
printf "%s\n" "${@}"
|
||||||
|
|
||||||
|
if type -f bpkg-term > /dev/null 2>&1; then
|
||||||
|
bpkg-term reset
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
## output error
|
||||||
|
bpkg_error () {
|
||||||
|
{
|
||||||
|
bpkg_message "red" "error" "${@}"
|
||||||
|
} >&2
|
||||||
|
}
|
||||||
|
|
||||||
|
## output warning
|
||||||
|
bpkg_warn () {
|
||||||
|
{
|
||||||
|
bpkg_message "yellow" "warn" "${@}"
|
||||||
|
} >&2
|
||||||
|
}
|
||||||
|
|
||||||
|
## output info
|
||||||
|
bpkg_info () {
|
||||||
|
local title="info"
|
||||||
|
if (( "${#}" > 1 )); then
|
||||||
|
title="${1}"
|
||||||
shift
|
shift
|
||||||
|
fi
|
||||||
bpkg_exec_exist bpkg-term &&
|
bpkg_message "cyan" "${title}" "${@}"
|
||||||
bpkg-term reset
|
}
|
||||||
|
|
||||||
printf ": "
|
## takes a remote and git-remote and sets the globals:
|
||||||
|
## BPKG_REMOTE: raw remote URI
|
||||||
bpkg_exec_exist bpkg-term && {
|
## BPKG_GIT_REMOTE: git remote for cloning
|
||||||
bpkg-term reset
|
## BPKG_AUTH_GIT_REMOTE: git remote with oauth info embedded,
|
||||||
bpkg-term bright
|
## BPKG_OAUTH_TOKEN: token for x-oauth-basic
|
||||||
}
|
## BPKG_CURL_AUTH_PARAM: auth arguments for raw curl requests
|
||||||
|
## BPKG_REMOTE_INDEX: location of local index for remote
|
||||||
printf "%s\n" "${@}"
|
bpkg_select_remote () {
|
||||||
|
local remote=$1
|
||||||
bpkg_exec_exist bpkg-term &&
|
local git_remote=$2
|
||||||
bpkg-term reset
|
export BPKG_REMOTE_HOST=$(echo "$git_remote" | sed 's/.*:\/\///' | sed 's/\/$//' | tr '/' '_')
|
||||||
}
|
export BPKG_REMOTE_INDEX="$BPKG_INDEX/$BPKG_REMOTE_HOST"
|
||||||
|
# shellcheck disable=SC2034
|
||||||
## output error
|
export BPKG_REMOTE_INDEX_FILE="$BPKG_REMOTE_INDEX/index.txt"
|
||||||
bpkg_error () {
|
export BPKG_OAUTH_TOKEN=""
|
||||||
{
|
export BPKG_CURL_AUTH_PARAM=""
|
||||||
bpkg_message "red" "error" "${@}"
|
export BPKG_GIT_REMOTE=$git_remote
|
||||||
} >&2
|
export BPKG_AUTH_GIT_REMOTE=$git_remote
|
||||||
}
|
if [ "${remote:0:10}" == "raw-oauth|" ]; then
|
||||||
|
OLDIFS="${IFS}"
|
||||||
## output warning
|
IFS="|"
|
||||||
bpkg_warn () {
|
# shellcheck disable=SC2206
|
||||||
{
|
local remote_parts=($remote)
|
||||||
bpkg_message "yellow" "warn" "${@}"
|
IFS="${OLDIFS}"
|
||||||
} >&2
|
export BPKG_OAUTH_TOKEN=${remote_parts[1]}
|
||||||
}
|
|
||||||
|
|
||||||
## output info
|
|
||||||
bpkg_info () {
|
|
||||||
local title="info"
|
|
||||||
if (( "${#}" > 1 )); then
|
|
||||||
title="${1}"
|
|
||||||
shift
|
|
||||||
fi
|
|
||||||
bpkg_message "cyan" "${title}" "${@}"
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
## check if executable exists in path
|
|
||||||
bpkg_exec_exist () {
|
|
||||||
local exec_name="${1}"
|
|
||||||
|
|
||||||
type -f "${exec_name}" > /dev/null 2>&1
|
|
||||||
}
|
|
||||||
|
|
||||||
## executable exists in path or exit with message
|
|
||||||
bpkg_exec_or_exit () {
|
|
||||||
local exec_name="${1}"
|
|
||||||
local exit_error="${2:-1}"
|
|
||||||
|
|
||||||
if ! bpkg_exec_exist "${exec_name}"; then
|
|
||||||
bpkg_error "${exec_name} not found, aborting"
|
|
||||||
exit "${exit_error}"
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
## takes a remote and git-remote and sets the globals:
|
|
||||||
## BPKG_REMOTE: raw remote URI
|
|
||||||
## BPKG_GIT_REMOTE: git remote for cloning
|
|
||||||
## BPKG_AUTH_GIT_REMOTE: git remote with oauth info embedded,
|
|
||||||
## BPKG_OAUTH_TOKEN: token for x-oauth-basic
|
|
||||||
## BPKG_CURL_AUTH_PARAM: auth arguments for raw curl requests
|
|
||||||
## BPKG_REMOTE_INDEX: location of local index for remote
|
|
||||||
bpkg_select_remote () {
|
|
||||||
local remote=$1
|
|
||||||
local git_remote=$2
|
|
||||||
export BPKG_REMOTE_HOST=$(echo "$git_remote" | sed 's/.*:\/\///' | sed 's/\/$//' | tr '/' '_')
|
|
||||||
export BPKG_REMOTE_INDEX="$BPKG_INDEX/$BPKG_REMOTE_HOST"
|
|
||||||
# shellcheck disable=SC2034
|
# shellcheck disable=SC2034
|
||||||
export BPKG_REMOTE_INDEX_FILE="$BPKG_REMOTE_INDEX/index.txt"
|
export BPKG_CURL_AUTH_PARAM="-u $BPKG_OAUTH_TOKEN:x-oauth-basic"
|
||||||
export BPKG_OAUTH_TOKEN=""
|
export BPKG_REMOTE=${remote_parts[2]}
|
||||||
export BPKG_CURL_AUTH_PARAM=""
|
if [[ "$git_remote" == https://* ]] && [[ "$git_remote" != *x-oauth-basic* ]] && [[ "$git_remote" != *${BPKG_OAUTH_TOKEN}* ]]; then
|
||||||
export BPKG_GIT_REMOTE=$git_remote
|
|
||||||
export BPKG_AUTH_GIT_REMOTE=$git_remote
|
|
||||||
if [ "${remote:0:10}" == "raw-oauth|" ]; then
|
|
||||||
OLDIFS="${IFS}"
|
|
||||||
IFS="|"
|
|
||||||
# shellcheck disable=SC2206
|
|
||||||
local remote_parts=($remote)
|
|
||||||
IFS="${OLDIFS}"
|
|
||||||
export BPKG_OAUTH_TOKEN=${remote_parts[1]}
|
|
||||||
# shellcheck disable=SC2034
|
# shellcheck disable=SC2034
|
||||||
export BPKG_CURL_AUTH_PARAM="-u $BPKG_OAUTH_TOKEN:x-oauth-basic"
|
export BPKG_AUTH_GIT_REMOTE=${git_remote/https:\/\//https:\/\/$BPKG_OAUTH_TOKEN:x-oauth-basic@}
|
||||||
export BPKG_REMOTE=${remote_parts[2]}
|
|
||||||
if [[ "$git_remote" == https://* ]] && [[ "$git_remote" != *x-oauth-basic* ]] && [[ "$git_remote" != *${BPKG_OAUTH_TOKEN}* ]]; then
|
|
||||||
# shellcheck disable=SC2034
|
|
||||||
export BPKG_AUTH_GIT_REMOTE=${git_remote/https:\/\//https:\/\/$BPKG_OAUTH_TOKEN:x-oauth-basic@}
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
export BPKG_REMOTE="$remote"
|
|
||||||
fi
|
fi
|
||||||
}
|
else
|
||||||
|
export BPKG_REMOTE="$remote"
|
||||||
## given a user and name, sets BPKG_REMOTE_RAW_PATH using the available
|
fi
|
||||||
## BPKG_REMOTE and BPKG_OAUTH_TOKEN details
|
}
|
||||||
bpkg_select_raw_path () {
|
|
||||||
local user=$1
|
## given a user and name, sets BPKG_REMOTE_RAW_PATH using the available
|
||||||
local name=$2
|
## BPKG_REMOTE and BPKG_OAUTH_TOKEN details
|
||||||
if [ "$BPKG_OAUTH_TOKEN" == "" ]; then
|
bpkg_select_raw_path() {
|
||||||
export BPKG_REMOTE_RAW_PATH="$BPKG_REMOTE/$user/$name"
|
local user=$1
|
||||||
else
|
local name=$2
|
||||||
# shellcheck disable=SC2034
|
if [ "$BPKG_OAUTH_TOKEN" == "" ]; then
|
||||||
Export BPKG_REMOTE_RAW_PATH="$BPKG_REMOTE/$user/$name/raw"
|
export BPKG_REMOTE_RAW_PATH="$BPKG_REMOTE/$user/$name"
|
||||||
fi
|
else
|
||||||
return 0
|
# shellcheck disable=SC2034
|
||||||
}
|
Export BPKG_REMOTE_RAW_PATH="$BPKG_REMOTE/$user/$name/raw"
|
||||||
|
fi
|
||||||
|
return 0
|
||||||
bpkg_exec_or_exit bpkg-env
|
}
|
||||||
|
|
||||||
# shellcheck disable=SC2230
|
|
||||||
# shellcheck source=lib/env/env.sh
|
|
||||||
source "$(which bpkg-env)"
|
|
||||||
|
|
||||||
|
|
||||||
export -f bpkg_initrc
|
|
||||||
export -f bpkg_validate
|
|
||||||
|
|
||||||
export -f bpkg_message
|
export -f bpkg_initrc
|
||||||
export -f bpkg_warn
|
export -f bpkg_validate
|
||||||
export -f bpkg_error
|
|
||||||
export -f bpkg_info
|
|
||||||
|
|
||||||
export -f bpkg_exec_exist
|
export -f bpkg_message
|
||||||
export -f bpkg_exec_or_exit
|
export -f bpkg_warn
|
||||||
|
export -f bpkg_error
|
||||||
|
export -f bpkg_info
|
||||||
|
|
||||||
export -f bpkg_select_remote
|
export -f bpkg_select_remote
|
||||||
export -f bpkg_select_raw_path
|
export -f bpkg_select_raw_path
|
||||||
fi
|
|
||||||
|
@ -1,13 +0,0 @@
|
|||||||
#!/usr/bin/env bash
|
|
||||||
|
|
||||||
declare shell_targets=(setup.sh bpkg.sh)
|
|
||||||
declare json_targets=(bpkg.json)
|
|
||||||
declare latest="$(git describe --tags --abbrev=0)"
|
|
||||||
|
|
||||||
for target in "${shell_targets[@]}"; do
|
|
||||||
sed -i "s/VERSION=.*/VERSION=\"$latest\"/g" "$target"
|
|
||||||
done
|
|
||||||
|
|
||||||
for target in "${json_targets[@]}"; do
|
|
||||||
sed -i "s/\"version\"\s*:\s*\".*\",/\"version\": \"$latest\",/g" "$target"
|
|
||||||
done
|
|
Loading…
Reference in New Issue